[Registry-dev] svn commit r6782 - in
trunk/registry/java/modules/core/src/main/java/org/wso2/registry:
. servlet
svn at wso2.org
svn at wso2.org
Fri Aug 31 02:38:12 PDT 2007
Author: deepal
Date: Fri Aug 31 02:38:07 2007
New Revision: 6782
Removed:
trunk/registry/java/modules/core/src/main/java/org/wso2/registry/RegistryContext.java
Modified:
trunk/registry/java/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
trunk/registry/java/modules/core/src/main/java/org/wso2/registry/servlet/Utils.java
Log:
one more cleanup round , now it is much more cleaner
Modified: trunk/registry/java/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
==============================================================================
--- trunk/registry/java/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java (original)
+++ trunk/registry/java/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java Fri Aug 31 02:38:07 2007
@@ -23,8 +23,10 @@
import org.apache.commons.logging.LogFactory;
import org.wso2.registry.*;
import org.wso2.registry.i18n.Messages;
+import org.wso2.registry.inmemory.InMemoryDataStore;
import org.wso2.registry.resources.Resource;
import org.wso2.registry.servlet.actions.ActionProcessor;
+import org.wso2.registry.servlet.actions.GetResourceActionProcessor;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
@@ -32,6 +34,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
+import java.util.HashMap;
import java.util.Map;
/**
@@ -42,20 +45,19 @@
private static final Log log = LogFactory.getLog(RegistryServlet.class);
protected transient ServletConfig servletConfig;
- private RegistryContext registryContext = null;
+ private Registry registry = null;
+ private Map actionMap;
//To store the conetxt path
private String contextRoot = null;
public void init(ServletConfig config) throws ServletException {
super.init(config);
-
- this.registryContext = new RegistryContext();
- config.getServletContext().setAttribute(RegistryConstants.REGISTRY_ENGINE, registryContext);
-
+ //The implementation of the data store need to read from a some where
+ this.registry = new Registry(new InMemoryDataStore());
+ config.getServletContext().setAttribute(RegistryConstants.REGISTRY_ENGINE, registry);
+ populateActionMap();
log.info(Messages.getMessage("server.initalized"));
- // we are initializing action processors in a hard coded manner. there is no need configure
- // action processors dynamically
}
public void init() throws ServletException {
@@ -71,32 +73,17 @@
initContextRoot(httpServletRequest);
Resource fileElement = FileUploadUtil.processUpload(httpServletRequest, httpServletResponse);
try {
- registryContext.getRegistry().put("/d1/d2", fileElement);
+ //TODO : dummy data
+ registry.put("/d1/d2", fileElement);
} catch (RegistryException e) {
e.printStackTrace();
}
}
- protected void doPut(HttpServletRequest httpServletRequest,
- HttpServletResponse httpServletResponse)
- throws ServletException, IOException {
- initContextRoot(httpServletRequest);
- super.doPut(httpServletRequest, httpServletResponse);
- }
-
- protected void doDelete(HttpServletRequest httpServletRequest,
- HttpServletResponse httpServletResponse)
- throws ServletException, IOException {
- initContextRoot(httpServletRequest);
- super.doDelete(httpServletRequest, httpServletResponse);
- }
-
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
initContextRoot(request);
- //TODO : Need to add user validation and user managment code here
- // At the moment we do not consider about the user
//First need to check whether user is valid
String uri = request.getRequestURI();
String path = uri.substring((contextRoot + RegistryConstants.TAG_REGISTRY).length(), uri.length());
@@ -109,13 +96,14 @@
.include(request, response);
return;
}
- Map params = new Utils().getParameters(request.getQueryString());
- String action = (String) params.get(RegistryConstants.ACTION);
- if (action == null) {
- //TODO is this right ?
+ String action;
+ if (request.getQueryString() != null) {
+ Map params = Utils.getParameters(request.getQueryString());
+ action = (String) params.get(RegistryConstants.ACTION);
+ } else {
action = ActionConstants.GET;
}
- ActionProcessor actionProcessor = registryContext.getActionProcessor(action);
+ ActionProcessor actionProcessor = (ActionProcessor) actionMap.get(action);
actionProcessor.process(path, request, response);
}
@@ -135,4 +123,11 @@
}
this.contextRoot = contextPath;
}
+
+ private void populateActionMap() {
+ actionMap = new HashMap();
+ GetResourceActionProcessor getResourceActionProcessor =
+ new GetResourceActionProcessor(registry);
+ actionMap.put(ActionConstants.GET, getResourceActionProcessor);
+ }
}
Modified: trunk/registry/java/modules/core/src/main/java/org/wso2/registry/servlet/Utils.java
==============================================================================
--- trunk/registry/java/modules/core/src/main/java/org/wso2/registry/servlet/Utils.java (original)
+++ trunk/registry/java/modules/core/src/main/java/org/wso2/registry/servlet/Utils.java Fri Aug 31 02:38:07 2007
@@ -19,8 +19,12 @@
package org.wso2.registry.servlet;
-import java.util.Map;
+import org.wso2.registry.Registry;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.resources.Resource;
+
import java.util.HashMap;
+import java.util.Map;
public class Utils {
@@ -36,8 +40,8 @@
* @param queryString query string of the URL
* @return Map containg paramter name --> paramter value pairs
*/
- public Map getParameters(String queryString) {
-
+ public static Map getParameters(String queryString) {
+
Map paramMap = new HashMap();
String[] params = queryString.split(",");
@@ -49,4 +53,40 @@
return paramMap;
}
+
+ public static void populateDummyData(Registry registry) {
+ try {
+ // create a content resource
+ Resource resource1 = new Resource();
+ resource1.setAuthor("Chathura");
+ String content1 = "This is the content2.";
+ resource1.setContent(content1);
+
+ // store it in a non existence path
+ String path1 = "/d1/d2/myresource";
+ registry.put(path1, resource1);
+
+ // store another content resource in the same path
+ Resource resource2 = new Resource();
+ resource2.setAuthor("Asankha");
+ String content2 = "This is content2";
+ resource2.setContent(content2);
+
+ String path2 = "/d1/d2/secondresource";
+ registry.put(path2, resource2);
+
+ // store the third resource in a path starting from previous path
+ Resource resource3 = new Resource();
+ resource3.setAuthor("Ruwan");
+ String content3 = "This is content3";
+ resource3.setContent(content3);
+
+ String path3 = "/d1/d2/d3/thirdresource";
+ registry.put(path3, resource3);
+
+ } catch (RegistryException e) {
+ e.printStackTrace();
+ }
+
+ }
}
More information about the Registry-dev
mailing list