You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2010/02/03 15:13:03 UTC

svn commit: r906058 - in /incubator/clerezza: issues/CLEREZZA-91/ trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.typehandlerspace/ trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.a...

Author: reto
Date: Wed Feb  3 14:13:02 2010
New Revision: 906058

URL: http://svn.apache.org/viewvc?rev=906058&view=rev
Log:
CLEREZZA-91: closing

Removed:
    incubator/clerezza/issues/CLEREZZA-91/
Modified:
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.typehandlerspace/   (props changed)
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.typehandlerspace/src/main/java/org/apache/clerezza/platform/typehandlerspace/TypeHandlerSpace.java

Propchange: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.typehandlerspace/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Wed Feb  3 14:13:02 2010
@@ -0,0 +1 @@
+/incubator/clerezza/issues/CLEREZZA-91/org.apache.clerezza.platform.typehandlerspace:905991-906055

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.typehandlerspace/src/main/java/org/apache/clerezza/platform/typehandlerspace/TypeHandlerSpace.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.typehandlerspace/src/main/java/org/apache/clerezza/platform/typehandlerspace/TypeHandlerSpace.java?rev=906058&r1=906057&r2=906058&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.typehandlerspace/src/main/java/org/apache/clerezza/platform/typehandlerspace/TypeHandlerSpace.java (original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.typehandlerspace/src/main/java/org/apache/clerezza/platform/typehandlerspace/TypeHandlerSpace.java Wed Feb  3 14:13:02 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();
+		}
 	}
 }