Author: reto
Date: Wed Feb  3 14:10:19 2010
New Revision: 906055

URL: http://svn.apache.org/viewvc?rev=906055&view=rev
Log:
CLEREZZA-91: applyied patch agrom with small changes

Added:
    incubator/clerezza/issues/CLEREZZA-91/
    
incubator/clerezza/issues/CLEREZZA-91/org.apache.clerezza.platform.typehandlerspace/
      - copied from r905990, 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.typehandlerspace/
Modified:
    
incubator/clerezza/issues/CLEREZZA-91/org.apache.clerezza.platform.typehandlerspace/src/main/java/org/apache/clerezza/platform/typehandlerspace/TypeHandlerSpace.java

Modified: 
incubator/clerezza/issues/CLEREZZA-91/org.apache.clerezza.platform.typehandlerspace/src/main/java/org/apache/clerezza/platform/typehandlerspace/TypeHandlerSpace.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-91/org.apache.clerezza.platform.typehandlerspace/src/main/java/org/apache/clerezza/platform/typehandlerspace/TypeHandlerSpace.java?rev=906055&r1=905990&r2=906055&view=diff
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-91/org.apache.clerezza.platform.typehandlerspace/src/main/java/org/apache/clerezza/platform/typehandlerspace/TypeHandlerSpace.java
 (original)
+++ 
incubator/clerezza/issues/CLEREZZA-91/org.apache.clerezza.platform.typehandlerspace/src/main/java/org/apache/clerezza/platform/typehandlerspace/TypeHandlerSpace.java
 Wed Feb  3 14:10:19 2010
@@ -22,17 +22,13 @@
 import java.util.Iterator;
 import java.util.Set;
 
-import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
-import javax.ws.rs.HEAD;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Request;
 import javax.ws.rs.core.UriInfo;
 
 import org.apache.clerezza.jaxrs.extensions.HttpRequest;
-import org.apache.clerezza.jaxrs.extensions.MethodResponse;
 import org.apache.clerezza.jaxrs.extensions.ResourceMethodException;
 import org.apache.clerezza.jaxrs.extensions.RootResourceExecutor;
 import org.apache.clerezza.rdf.core.MGraph;
@@ -53,7 +49,7 @@
  * resource, that is registered with TypeHandlerDiscovery to handle a specific
  * rdf-type.
  * 
- * @author mir
+ * @author mir, agron
  * 
  * @scr.component
  * @scr.service interface="java.lang.Object"
@@ -81,93 +77,38 @@
                        "http://tpf.localhost/content.graph";);
        
        private final String DESCRIPTION_SUFFIX = "-description";
+       private DescriptionHandler descriptionHandler = new 
DescriptionHandler();
 
-       /**
-        * See the <code>handlerGet</code> method. this method is to provide a
-        * resource method (not a sub-resource method) as well
-        */
-       @GET
-       public Object handleGetOnRoot(@Context UriInfo uriInfo,
-                       @Context HttpRequest request) throws 
ResourceMethodException {
-               return handleGet(uriInfo, request);
-       }
 
        /**
-        * Handles requests, which have the http-method GET. The requests are
-        * handled with the TypeHandler according the most important rdf-type 
of the
-        * resource.
-        * 
-        * If the request-URI ends with "-description" then context of the 
resource
-        * in the content-graph is returned.
+        * Returns a TypeHandler according the most important rdf-type of the
+        * requested resource.
         * 
         * @param uriInfo
-        * @param request
-        * @return MethodResponse or a Graph
-        */
-       @GET
-       @Path("{path:.+}")
-       public Object handleGet(@Context UriInfo uriInfo,
-                       @Context HttpRequest request) throws 
ResourceMethodException {
+        * @param httpRequest
+        * @return
+        * @throws ResourceMethodException
+        */
+       @Path("{path:.*}")
+       public Object getHandler(@Context UriInfo uriInfo,
+                       @Context Request request) throws 
ResourceMethodException  {
                String absoluteUriPath = uriInfo.getAbsolutePath().toString();
-               UriRef uri;
                if (absoluteUriPath.endsWith(DESCRIPTION_SUFFIX)) {
-                       MGraph contentMGraph = 
tcManager.getMGraph(CONTENT_GRAPH_URI);
-                       uri = new UriRef(absoluteUriPath.substring(0, 
absoluteUriPath
-                                       .length()
-                                       - DESCRIPTION_SUFFIX.length()));
-                       GraphNode graphNode = new GraphNode(uri, contentMGraph);
-                       return graphNode.getNodeContext();
-               } else {
-                       return handleWithTypeHandler(request, absoluteUriPath);
+                       if (request.getMethod().equalsIgnoreCase("GET")) {
+                               return descriptionHandler;
+                       }
                }
+               return getTypeHandler(absoluteUriPath);
        }
 
-
-       /**
-        * See the <code>handleHttpMethods</code> method. this method is to 
provide a
-        * resource method (not a sub-resource method) as well
-        */
-       @PUT
-       @POST
-       @DELETE
-       @HEAD
-       @OPTIONS
-       public MethodResponse handleHttpMethodsRoot(@Context UriInfo uriInfo,
-                       @Context HttpRequest request) throws 
ResourceMethodException {
-               return handleHttpMethods(uriInfo, request);
-       }
-       /**
-        * Handles requests, which have the http-methods PUT, POST, DELETE, 
HEAD and
-        * OPTIONS. The requests are handled with the TypeHandler according the 
most
-        * important rdf-type of the requested resource.
-        * 
-        * @param uriInfo
-        * @param request
-        * @return MethodResponse
-        */
-       @PUT
-       @POST
-       @DELETE
-       @HEAD
-       @OPTIONS
-       @Path("{path:.+}")
-       public MethodResponse handleHttpMethods(@Context UriInfo uriInfo,
-                       @Context HttpRequest request) throws 
ResourceMethodException {
-               String absoluteUriPath = uriInfo.getAbsolutePath().toString();
-               return handleWithTypeHandler(request, absoluteUriPath);
-       }
-
-       private MethodResponse handleWithTypeHandler(HttpRequest request,
-                       String absoluteUriPath) throws ResourceMethodException {
+       private Object getTypeHandler(String absoluteUriPath) throws 
ResourceMethodException {
                MGraph contentMGraph = tcManager.getMGraph(CONTENT_GRAPH_URI);
                UriRef uri = new UriRef(absoluteUriPath);
 
                Set<UriRef> rdfTypes = getRdfTypesOfUriRef(contentMGraph, uri);
 
-               Object typeHandler = 
typeHandlerDiscovery.getTypeHandler(rdfTypes);
-               MethodResponse MethodResponse = executeOnTypeHandler(request,
-                               typeHandler);
-               return MethodResponse;
+               return typeHandlerDiscovery.getTypeHandler(rdfTypes);
+               
        }
 
        private Set<UriRef> getRdfTypesOfUriRef(MGraph contentMGraph, UriRef 
uri) {
@@ -187,13 +128,16 @@
                return rdfTypes;
        }
 
-       private MethodResponse executeOnTypeHandler(HttpRequest request,
-                       Object typeHandler) throws ResourceMethodException {
-               MethodResponse MethodResponse = null;
-               
-               MethodResponse = resourceExecutor.execute(request,
-                               typeHandler,"", null);
-               
-               return MethodResponse;
+       public class DescriptionHandler {
+
+               @GET
+               public Object getDescription(@Context UriInfo uriInfo){
+                       String absoluteUriPath = 
uriInfo.getAbsolutePath().toString();
+                       MGraph contentMGraph = 
tcManager.getMGraph(CONTENT_GRAPH_URI);
+                               UriRef uri = new 
UriRef(absoluteUriPath.substring(0,
+                                               absoluteUriPath.length() - 
DESCRIPTION_SUFFIX.length()));
+                               GraphNode graphNode = new GraphNode(uri, 
contentMGraph);
+                               return graphNode.getNodeContext();
+               }
        }
 }


Reply via email to