[Registry-dev] svn commit r19954 - in trunk/registry/modules: core/src/main/java/org/wso2/registry/config core/src/main/java/org/wso2/registry/jdbc core/src/main/java/org/wso2/registry/jdbc/handlers core/src/main/java/org/wso2/registry/jdbc/handlers/filters extensions/src/org/wso2/registry/servlet samples/handler-sample/resources
chathura at wso2.com
chathura at wso2.com
Thu Jul 24 05:09:48 PDT 2008
Author: chathura
Date: Thu Jul 24 05:09:48 2008
New Revision: 19954
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=19954
Log:
Added support for specifying the applicable methods for handlers.
Now it is possible specify to which methods (e.g. GET, PUT) a particular handler should be engaged (without activating the associated filter).
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfigurationProcessor.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/HandlerManager.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/filters/Filter.java
trunk/registry/modules/extensions/src/org/wso2/registry/servlet/registry.xml
trunk/registry/modules/samples/handler-sample/resources/registry.xml
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfigurationProcessor.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfigurationProcessor.java?rev=19954&r1=19953&r2=19954&view=diff
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfigurationProcessor.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfigurationProcessor.java Thu Jul 24 05:09:48 2008
@@ -36,6 +36,8 @@
import java.lang.reflect.Method;
import java.lang.reflect.Constructor;
import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
public class RegistryConfigurationProcessor {
@@ -265,6 +267,16 @@
OMElement handlerConfigElement = handlerConfigs.next();
String handlerClassName = handlerConfigElement.getAttributeValue(new QName("class"));
+ String methodsValue = handlerConfigElement.getAttributeValue(new QName("methods"));
+
+ String[] methods = null;
+ if (methodsValue != null) {
+
+ methods = methodsValue.split(",");
+ for (int i = 0; i < methods.length; i++) {
+ methods[i] = methods[i].trim();
+ }
+ }
Class handlerClass = Class.forName(handlerClassName);
Handler handler = (Handler) handlerClass.newInstance();
@@ -317,7 +329,8 @@
setter.invoke(filter, propValue);
}
- registryContext.getHandlerManager().addHandler(0, filter, handler);
+ registryContext.getHandlerManager().addHandler(methods, filter, handler);
+
//HandlerConfiguration handlerConfiguration = new HandlerConfiguration();
//handlerConfiguration.setHandler(handler);
//handlerConfiguration.setFilter(filter);
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java?rev=19954&r1=19953&r2=19954&view=diff
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java Thu Jul 24 05:09:48 2008
@@ -30,6 +30,7 @@
import org.wso2.registry.jdbc.handlers.builtin.*;
import org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher;
import org.wso2.registry.jdbc.handlers.filters.URLMatcher;
+import org.wso2.registry.jdbc.handlers.filters.Filter;
import org.wso2.registry.jdbc.queries.QueryProcessorManager;
import org.wso2.registry.jdbc.realm.RegistryRealm;
import org.wso2.registry.jdbc.utils.Transaction;
@@ -48,6 +49,7 @@
import java.sql.ResultSet;
import java.util.Date;
import java.util.Map;
+import java.util.ArrayList;
import java.io.IOException;
/**
@@ -160,52 +162,58 @@
basicRegistry =
new BasicRegistry(registryContext, repository,
- versionRepository, queryProcessorManager);
+ versionRepository, queryProcessorManager);
atomicRegistry = new AtomicRegistry(
basicRegistry, dataSource);
}
private void registerBuiltInHandlers() {
+
HandlerManager handlerManager = registryContext.getHandlerManager();
SQLQueryHandler sqlQueryHandler = new SQLQueryHandler();
MediaTypeMatcher sqlMediaTypeMatcher =
new MediaTypeMatcher(RegistryConstants.SQL_QUERY_MEDIA_TYPE);
- handlerManager.addHandler(0, sqlMediaTypeMatcher, sqlQueryHandler);
+ handlerManager.addHandler(
+ new String[] {Filter.GET, Filter.PUT}, sqlMediaTypeMatcher, sqlQueryHandler);
CommentURLHandler commentURLHandler = new CommentURLHandler();
URLMatcher commentURLMatcher = new URLMatcher();
commentURLMatcher.setGetPattern(".+;comments:[0-9]+");
commentURLMatcher.setDeletePattern(".+;comments:[0-9]+");
- handlerManager.addHandler(0, commentURLMatcher, commentURLHandler);
+ handlerManager.addHandler(
+ new String[] {Filter.GET, Filter.DELETE} , commentURLMatcher, commentURLHandler);
CommentCollectionURLHandler commentCollectionURLHandler = new CommentCollectionURLHandler();
URLMatcher commentCollectionURLMatcher = new URLMatcher();
commentCollectionURLMatcher.setGetPattern(".+;comments");
- handlerManager.addHandler(0, commentCollectionURLMatcher, commentCollectionURLHandler);
+ handlerManager.addHandler(new String[] {Filter.GET},
+ commentCollectionURLMatcher, commentCollectionURLHandler);
RatingURLHandler ratingURLHandler = new RatingURLHandler();
URLMatcher ratingURLMatcher = new URLMatcher();
ratingURLMatcher.setGetPattern(".+;ratings:.+");
- handlerManager.addHandler(0, ratingURLMatcher, ratingURLHandler);
+ handlerManager.addHandler(new String[] {Filter.GET}, ratingURLMatcher, ratingURLHandler);
RatingCollectionURLHandler ratingCollectionURLHandler = new RatingCollectionURLHandler();
URLMatcher ratingCollectionURLMatcher = new URLMatcher();
ratingCollectionURLMatcher.setGetPattern(".+;ratings");
- handlerManager.addHandler(0, ratingCollectionURLMatcher, ratingCollectionURLHandler);
+ handlerManager.addHandler(
+ new String[] {Filter.GET}, ratingCollectionURLMatcher, ratingCollectionURLHandler);
TagURLHandler tagURLHandler = new TagURLHandler();
URLMatcher tagURLMatcher = new URLMatcher();
tagURLMatcher.setGetPattern(".+;.+:.+:.+");
- handlerManager.addHandler(0, tagURLMatcher, tagURLHandler);
+ handlerManager.addHandler(new String[] {Filter.GET}, tagURLMatcher, tagURLHandler);
}
private void initializeIndex() throws RegistryException{
try{
- ResultSet rs =dataSource.getConnection().getMetaData().getTables(null, null, "indexTable", null);
+ ResultSet rs = dataSource.getConnection().
+ getMetaData().getTables(null, null, "indexTable", null);
jdbcDir = new JdbcDirectory(dataSource, DialectFactory.getDialect(dataSource)
-, "indexTable");
+ , "indexTable");
if(!rs.next()){
jdbcDir.create();
}
@@ -472,7 +480,7 @@
public Association[] getAssociations(String resourcePath, String associationType)
throws RegistryException {
- if (Transaction.isStarted()) {
+ if (Transaction.isStarted()) {
return basicRegistry.getAssociations(resourcePath, associationType);
} else {
return atomicRegistry.getAssociations(resourcePath, associationType);
@@ -692,5 +700,5 @@
return registryContext;
}
-
+
}
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/HandlerManager.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/HandlerManager.java?rev=19954&r1=19953&r2=19954&view=diff
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/HandlerManager.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/HandlerManager.java Thu Jul 24 05:09:48 2008
@@ -16,58 +16,58 @@
package org.wso2.registry.jdbc.handlers;
-import org.wso2.registry.Registry;
import org.wso2.registry.exceptions.RegistryException;
import org.wso2.registry.Resource;
-import org.wso2.registry.RegistryConstants;
import org.wso2.registry.utils.RegistryUtils;
-import org.wso2.registry.jdbc.Repository;
import org.wso2.registry.jdbc.handlers.filters.Filter;
import java.util.*;
public class HandlerManager {
- private Map<Filter, Handler> handlerMap = new HashMap();
- private List getFilters = new ArrayList();
- private List putFilters = new ArrayList();
- private List deleteFilters = new ArrayList();
- private List importFilters = new ArrayList();
- private List putChildFilters = new ArrayList();
- private List importChildFilters = new ArrayList();
+ private Map <Filter, Handler> getHandlerMap = new HashMap <Filter, Handler> ();
+ private Map <Filter, Handler> putHandlerMap = new HashMap <Filter, Handler> ();
+ private Map <Filter, Handler> deleteHandlerMap = new HashMap <Filter, Handler> ();
+ private Map <Filter, Handler> importHandlerMap = new HashMap <Filter, Handler> ();
+ private Map <Filter, Handler> putChildHandlerMap = new HashMap <Filter, Handler> ();
+ private Map <Filter, Handler> importChildHandlerMap = new HashMap <Filter, Handler> ();
- public void addHandler(int methods, Filter filter, Handler handler) {
- if ((methods & Filter.GET) != 0) {
- getFilters.add(filter);
- }
- if ((methods & Filter.PUT) != 0) {
- putFilters.add(filter);
+ public void addHandler(String[] methods, Filter filter, Handler handler) {
+
+ if (methods == null || RegistryUtils.containsString(Filter.GET, methods)) {
+ getHandlerMap.put(filter, handler);
}
- if ((methods & Filter.DELETE) != 0) {
- deleteFilters.add(filter);
+
+ if (methods == null || RegistryUtils.containsString(Filter.PUT, methods)) {
+ putHandlerMap.put(filter, handler);
}
- if ((methods & Filter.IMPORT) != 0) {
- importFilters.add(filter);
+
+ if (methods == null || RegistryUtils.containsString(Filter.DELETE, methods)) {
+ deleteHandlerMap.put(filter, handler);
}
- if ((methods & Filter.PUT_CHILD) != 0) {
- putChildFilters.add(filter);
+
+ if (methods == null || RegistryUtils.containsString(Filter.IMPORT, methods)) {
+ importHandlerMap.put(filter, handler);
}
- if ((methods & Filter.IMPORT_CHILD) != 0) {
- importChildFilters.add(filter);
+
+ if (methods == null || RegistryUtils.containsString(Filter.PUT_CHILD, methods)) {
+ putChildHandlerMap.put(filter, handler);
}
- handlerMap.put(filter, handler);
+ if (methods == null || RegistryUtils.containsString(Filter.IMPORT_CHILD, methods)) {
+ importChildHandlerMap.put(filter, handler);
+ }
}
public Resource get(RequestContext requestContext) throws RegistryException {
Resource resource = null;
- Iterator<Filter> filters = handlerMap.keySet().iterator();
+ Iterator<Filter> filters = getHandlerMap.keySet().iterator();
while (filters.hasNext()) {
Filter filter = filters.next();
if (filter.handleGet(requestContext)) {
- Handler handler = handlerMap.get(filter);
+ Handler handler = getHandlerMap.get(filter);
resource = handler.get(requestContext);
}
@@ -81,11 +81,11 @@
public String put(RequestContext requestContext) throws RegistryException {
- Iterator<Filter> filters = handlerMap.keySet().iterator();
+ Iterator<Filter> filters = putHandlerMap.keySet().iterator();
while (filters.hasNext()) {
Filter filter = filters.next();
if (filter.handlePut(requestContext)) {
- handlerMap.get(filter).put(requestContext);
+ putHandlerMap.get(filter).put(requestContext);
}
if (requestContext.isProcessingComplete()) {
@@ -102,11 +102,11 @@
public String importResource(RequestContext requestContext) throws RegistryException {
- Iterator<Filter> filters = handlerMap.keySet().iterator();
+ Iterator<Filter> filters = importHandlerMap.keySet().iterator();
while (filters.hasNext()) {
Filter filter = filters.next();
if (filter.handleImportResource(requestContext)) {
- handlerMap.get(filter).importResource(requestContext);
+ importHandlerMap.get(filter).importResource(requestContext);
}
if (requestContext.isProcessingComplete()) {
@@ -123,11 +123,11 @@
public void delete(RequestContext requestContext) throws RegistryException {
- Iterator<Filter> filters = handlerMap.keySet().iterator();
+ Iterator<Filter> filters = deleteHandlerMap.keySet().iterator();
while (filters.hasNext()) {
Filter filter = filters.next();
if (filter.handleDelete(requestContext)) {
- handlerMap.get(filter).delete(requestContext);
+ deleteHandlerMap.get(filter).delete(requestContext);
}
if (requestContext.isProcessingComplete()) {
@@ -138,11 +138,11 @@
public void putChild(RequestContext requestContext) throws RegistryException {
- Iterator<Filter> filters = handlerMap.keySet().iterator();
+ Iterator<Filter> filters = putChildHandlerMap.keySet().iterator();
while (filters.hasNext()) {
Filter filter = filters.next();
if (filter.handlePutChild(requestContext)) {
- handlerMap.get(filter).putChild(requestContext);
+ putChildHandlerMap.get(filter).putChild(requestContext);
}
if (requestContext.isProcessingComplete()) {
@@ -153,11 +153,11 @@
public void importChild(RequestContext requestContext) throws RegistryException {
- Iterator<Filter> filters = handlerMap.keySet().iterator();
+ Iterator<Filter> filters = importChildHandlerMap.keySet().iterator();
while (filters.hasNext()) {
Filter filter = filters.next();
if (filter.handleImportChild(requestContext)) {
- handlerMap.get(filter).importChild(requestContext);
+ importChildHandlerMap.get(filter).importChild(requestContext);
}
if (requestContext.isProcessingComplete()) {
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/filters/Filter.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/filters/Filter.java?rev=19954&r1=19953&r2=19954&view=diff
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/filters/Filter.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/filters/Filter.java Thu Jul 24 05:09:48 2008
@@ -27,12 +27,12 @@
*/
public abstract class Filter {
// Bit flags for supported methods
- public static final int GET = 1;
- public static final int PUT = 2;
- public static final int DELETE = 4;
- public static final int IMPORT = 8;
- public static final int PUT_CHILD = 16;
- public static final int IMPORT_CHILD = 32;
+ public static final String GET = "GET";
+ public static final String PUT = "PUT";
+ public static final String DELETE = "DELETE";
+ public static final String IMPORT = "IMPORT";
+ public static final String PUT_CHILD = "PUT_CHILD";
+ public static final String IMPORT_CHILD = "IMPORT_CHILD";
/**
* Determines whether the associating handler should handle the get action.
Modified: trunk/registry/modules/extensions/src/org/wso2/registry/servlet/registry.xml
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/extensions/src/org/wso2/registry/servlet/registry.xml?rev=19954&r1=19953&r2=19954&view=diff
==============================================================================
--- trunk/registry/modules/extensions/src/org/wso2/registry/servlet/registry.xml (original)
+++ trunk/registry/modules/extensions/src/org/wso2/registry/servlet/registry.xml Thu Jul 24 05:09:48 2008
@@ -35,25 +35,25 @@
</dbconfig>
- <handler class="org.wso2.registry.handlers.SynapseRepositoryHandler">
+ <handler class="org.wso2.registry.handlers.SynapseRepositoryHandler" methods="PUT, PUT_CHILD">
<filter class="org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher">
<property name="mediaType">application/vnd.apache.synapse</property>
</filter>
</handler>
- <handler class="org.wso2.registry.handlers.SynapseRepositoryHandler">
+ <handler class="org.wso2.registry.handlers.SynapseRepositoryHandler" methods="PUT, PUT_CHILD">
<filter class="org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher">
<property name="mediaType">application/vnd.wso2.esb</property>
</filter>
</handler>
- <handler class="org.wso2.registry.handlers.Axis2RepositoryHandler">
+ <handler class="org.wso2.registry.handlers.Axis2RepositoryHandler" methods="PUT, PUT_CHILD">
<filter class="org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher">
<property name="mediaType">application/vnd.apache.axis2</property>
</filter>
</handler>
- <handler class="org.wso2.registry.handlers.Axis2RepositoryHandler">
+ <handler class="org.wso2.registry.handlers.Axis2RepositoryHandler" methods="PUT, PUT_CHILD">
<filter class="org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher">
<property name="mediaType">application/vnd.wso2.wsas</property>
</filter>
@@ -121,7 +121,7 @@
<property name="mediaType">application/vnd.server-collection</property>
</filter>
</handler-->
- <handler class="org.wso2.registry.handlers.IndexingHandler">
+ <handler class="org.wso2.registry.handlers.IndexingHandler" methods="PUT, DELETE">
<filter class="org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher">
<property name="mediaType">text/plain</property>
</filter>
Modified: trunk/registry/modules/samples/handler-sample/resources/registry.xml
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/samples/handler-sample/resources/registry.xml?rev=19954&r1=19953&r2=19954&view=diff
==============================================================================
--- trunk/registry/modules/samples/handler-sample/resources/registry.xml (original)
+++ trunk/registry/modules/samples/handler-sample/resources/registry.xml Thu Jul 24 05:09:48 2008
@@ -26,25 +26,25 @@
<dataSource>dataSourceName</dataSource>
</dbconfig>
- <handler class="org.wso2.registry.jdbc.handlers.builtin.SynapseRepositoryHandler">
+ <handler class="org.wso2.registry.jdbc.handlers.builtin.SynapseRepositoryHandler" methods="PUT, PUT_CHILD">
<filter class="org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher">
<property name="mediaType">application/vnd.apache.synapse</property>
</filter>
</handler>
- <handler class="org.wso2.registry.jdbc.handlers.builtin.SynapseRepositoryHandler">
+ <handler class="org.wso2.registry.jdbc.handlers.builtin.SynapseRepositoryHandler" methods="PUT, PUT_CHILD">
<filter class="org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher">
<property name="mediaType">application/vnd.wso2.esb</property>
</filter>
</handler>
- <handler class="org.wso2.registry.jdbc.handlers.builtin.Axis2RepositoryHandler">
+ <handler class="org.wso2.registry.jdbc.handlers.builtin.Axis2RepositoryHandler" methods="PUT, PUT_CHILD">
<filter class="org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher">
<property name="mediaType">application/vnd.apache.axis2</property>
</filter>
</handler>
- <handler class="org.wso2.registry.jdbc.handlers.builtin.Axis2RepositoryHandler">
+ <handler class="org.wso2.registry.jdbc.handlers.builtin.Axis2RepositoryHandler" methods="PUT, PUT_CHILD">
<filter class="org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher">
<property name="mediaType">application/vnd.wso2.wsas</property>
</filter>
@@ -62,7 +62,7 @@
</filter>
</handler>
- <handler class="org.wso2.registry.plugins.mediatypes.pp.ProjectProposalMediaTypeHandler">
+ <handler class="org.wso2.registry.plugins.mediatypes.pp.ProjectProposalMediaTypeHandler" methods="PUT">
<filter class="org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher">
<property name="mediaType">application/vnd.project.proposal</property>
</filter>
More information about the Registry-dev
mailing list