[jbossws-commits] JBossWS SVN: r4942 - in stack/native/branches/rest: src/main/java/org/jboss/rs and 3 other directories.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Tue Oct 30 16:57:23 EDT 2007


Author: heiko.braun at jboss.com
Date: 2007-10-30 16:57:23 -0400 (Tue, 30 Oct 2007)
New Revision: 4942

Added:
   stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModelParser.java
   stack/native/branches/rest/src/main/java/org/jboss/rs/model/RuntimeContext.java
   stack/native/branches/rest/src/main/java/org/jboss/rs/util/
   stack/native/branches/rest/src/main/java/org/jboss/rs/util/Convert.java
   stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ModelParserTestCase.java
Removed:
   stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModelFactory.java
   stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ResourceFactoryTestCase.java
Modified:
   stack/native/branches/rest/src/main/java/org/jboss/rs/model/RegexQualifier.java
   stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceMethod.java
   stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModel.java
   stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceResolver.java
   stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ResolverTestCase.java
   stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/Widget.java
   stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/WidgetList.java
   stack/native/branches/rest/version.properties
Log:
Parse resource methods. Added content negotitation hook

Modified: stack/native/branches/rest/src/main/java/org/jboss/rs/model/RegexQualifier.java
===================================================================
--- stack/native/branches/rest/src/main/java/org/jboss/rs/model/RegexQualifier.java	2007-10-30 20:24:48 UTC (rev 4941)
+++ stack/native/branches/rest/src/main/java/org/jboss/rs/model/RegexQualifier.java	2007-10-30 20:57:23 UTC (rev 4942)
@@ -31,6 +31,8 @@
    public final int patternLength;
    public final String nextUriToken;
 
+   public static RegexQualifier NONE = new RegexQualifier(0,0,"");
+   
    public RegexQualifier(int matchingGroups, int patternLenght, String uriToken)
    {
       this.numGroups = matchingGroups;

Modified: stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceMethod.java
===================================================================
--- stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceMethod.java	2007-10-30 20:24:48 UTC (rev 4941)
+++ stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceMethod.java	2007-10-30 20:57:23 UTC (rev 4942)
@@ -23,22 +23,23 @@
 
 import org.jboss.rs.MethodHTTP;
 
+import java.lang.reflect.Method;
+
 /**
  * @author Heiko.Braun at jboss.com
  * @version $Revision$
  */
 public class ResourceMethod extends AbstractRegexResolveable
-{
-   private EntityModel entityModel;
+{   
    private MethodHTTP methodHTTP;
    private String uriTemplate;
+   private Method invocationTarget;
 
-   public ResourceMethod(MethodHTTP method, String uriTemplate, EntityModel entityModel)
+   public ResourceMethod(MethodHTTP method, String uriTemplate, Method invocationTarget)
    {
       this.uriTemplate = uriTemplate;
       this.methodHTTP = method;
-      this.entityModel = entityModel;
-
+      this.invocationTarget = invocationTarget;
    }
 
    public MethodHTTP getMethodHTTP()
@@ -46,12 +47,6 @@
       return methodHTTP;
    }
 
-
-   public EntityModel getEntityModel()
-   {
-      return entityModel;
-   }
-
    public String getUriTemplate()
    {
       return this.uriTemplate;
@@ -63,6 +58,11 @@
       return false;  
    }
 
+   public Method getInvocationTarget()
+   {
+      return invocationTarget;
+   }
+
    void freeze()
    {
       initFromUriTemplate(this.uriTemplate);     
@@ -71,6 +71,6 @@
 
    public String toString()
    {
-      return "ResourceMethod {"+methodHTTP+" uri="+uriTemplate+", regex="+regexPattern+", entity="+entityModel+"}";
+      return "ResourceMethod {"+methodHTTP+" uri="+uriTemplate+", regex="+regexPattern+"}";
    }
 }

Modified: stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModel.java
===================================================================
--- stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModel.java	2007-10-30 20:24:48 UTC (rev 4941)
+++ stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModel.java	2007-10-30 20:57:23 UTC (rev 4942)
@@ -33,9 +33,9 @@
    private ResourceModel parent = null;
 
    private String uriTemplate;
-   private Class implementation;
+   private Class invocationTarget;
 
-   /*TODO : parse resource methods = no UriTemplatem but HttpMethod annotation */
+   /*TODO : parse resource methods => no UriTemplate but HttpMethod annotation */
    private List<ResourceMethod> resourceMethods = new ArrayList<ResourceMethod>();
    private List<ResourceMethod> subResourceMethods = new ArrayList<ResourceMethod>();
    private List<ResourceLocator> resourceLocators = new ArrayList<ResourceLocator>();
@@ -45,11 +45,11 @@
       this(null, uriTemplate, implementation);
    }
 
-   public ResourceModel(ResourceModel parent, String uriTemplate, Class implementation)
+   public ResourceModel(ResourceModel parent, String uriTemplate, Class invocationTarget)
    {
       this.parent = parent;
       this.uriTemplate = uriTemplate;
-      this.implementation = implementation;      
+      this.invocationTarget = invocationTarget;
    }
 
    /**
@@ -60,6 +60,11 @@
       initFromUriTemplate(this.uriTemplate);     
    }
 
+   public void addResourceMethod(ResourceMethod srm)
+   {
+      resourceMethods.add(srm);
+   }
+
    public void addSubResourceMethod(ResourceMethod srm)
    {
       subResourceMethods.add(srm);
@@ -80,9 +85,9 @@
       return parent;
    }
 
-   public Class getImplementation()
+   public Class getInvocationTarget()
    {
-      return implementation;
+      return invocationTarget;
    }
 
    public String getUriTemplate()
@@ -90,13 +95,17 @@
       return uriTemplate;
    }
 
+   public List<ResourceMethod> getResourceMethods()
+   {
+      return resourceMethods;
+   }
 
-   List<ResourceMethod> getSubResourceMethods()
+   public List<ResourceMethod> getSubResourceMethods()
    {
       return subResourceMethods;
    }
 
-   List<ResourceLocator> getResourceLocator()
+   public List<ResourceLocator> getResourceLocator()
    {
       return resourceLocators;
    }
@@ -108,6 +117,6 @@
 
    public String toString()
    {
-      return "ResourceModel {uri=" + uriTemplate + ", regex=" + regexPattern + ", impl=" + implementation + "}";      
+      return "ResourceModel {uri=" + uriTemplate + ", regex=" + regexPattern + ", impl=" + invocationTarget + "}";
    }
 }

Deleted: stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModelFactory.java
===================================================================
--- stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModelFactory.java	2007-10-30 20:24:48 UTC (rev 4941)
+++ stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModelFactory.java	2007-10-30 20:57:23 UTC (rev 4942)
@@ -1,103 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.rs.model;
-
-import org.jboss.rs.MethodHTTP;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.UriTemplate;
-import java.lang.reflect.Method;
-
-/**
- * @author Heiko.Braun at jboss.com
- * @version $Revision$
- */
-public class ResourceModelFactory
-{
-   public static ResourceModel createModel(Class bean)
-   {
-      assert bean.isAnnotationPresent(UriTemplate.class);
-
-      // the root resource
-      UriTemplate rootUri = (UriTemplate)bean.getAnnotation(UriTemplate.class);
-      ResourceModel rootResource = new ResourceModel(rootUri.value(), bean);
-
-      System.out.println("Creating resource model from bean: " + bean);
-
-      parseMetaData(rootResource);
-
-      return rootResource;
-   }
-
-   private static void parseMetaData(ResourceModel resource)
-   {
-      String parent = resource.getParent()!=null ? resource.getParent().getImplementation().getName() : "";
-      
-      for( Method m : resource.getImplementation().getDeclaredMethods() )
-      {
-         // handle subresources
-         if(m.isAnnotationPresent(UriTemplate.class))
-         {
-            UriTemplate uri = m.getAnnotation(UriTemplate.class);
-            Class<?> returnType = m.getReturnType();
-
-            // TODO: extend to other http methods
-            if(m.isAnnotationPresent(GET.class))
-            {
-               // sub resource method
-               GET http = (GET)m.getAnnotation(GET.class);
-               ResourceMethod resourceMethod = new ResourceMethod(
-                 MethodHTTP.valueOf("GET"), uri.value(), new EntityModel(returnType)
-               );
-               resource.addSubResourceMethod(resourceMethod);
-            }
-            else
-            {
-               // locator
-               ResourceModel subResource = new ResourceModel(resource, uri.value(), returnType);
-               ResourceLocator locator = new ResourceLocator(subResource);
-               locator.freeze();
-               resource.addSubResourceLocator(locator);
-
-               // recursive
-               parseMetaData(subResource);
-            }
-         }
-
-      }
-
-      // freeze resource
-      resource.freeze();
-
-      System.out.println("---");
-      System.out.println(resource);
-
-      // freeze sub resource methods
-      for(ResourceMethod srm : resource.getSubResourceMethods())
-      {
-         srm.freeze();
-         System.out.println(srm);
-      }
-      
-      System.out.println("---");
-   }
-}

Copied: stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModelParser.java (from rev 4914, stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModelFactory.java)
===================================================================
--- stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModelParser.java	                        (rev 0)
+++ stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModelParser.java	2007-10-30 20:57:23 UTC (rev 4942)
@@ -0,0 +1,145 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.rs.model;
+
+import org.jboss.rs.util.Convert;
+
+import javax.ws.rs.UriTemplate;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
+/**
+ * @author Heiko.Braun at jboss.com
+ * @version $Revision$
+ */
+public class ResourceModelParser
+{
+   ResourceModelParser()
+   {
+   }
+
+   public static ResourceModelParser newInstance()
+   {
+      return new ResourceModelParser();
+   }
+
+   public ResourceModel parse(Class bean)
+   {
+      assert bean.isAnnotationPresent(UriTemplate.class);
+
+      // the root resource
+      UriTemplate rootUri = (UriTemplate)bean.getAnnotation(UriTemplate.class);
+      ResourceModel rootResource = new ResourceModel(rootUri.value(), bean);
+
+      System.out.println("Creating resource model from bean: " + bean);
+
+      parseInternal(rootResource);
+
+      return rootResource;
+   }
+
+   private void parseInternal(ResourceModel resource)
+   {
+
+      for( Method m : resource.getInvocationTarget().getDeclaredMethods() )
+      {         
+         parseMethod(m, resource);
+
+         // todo: constructors
+      }
+
+      // freeze resource
+      resource.freeze();
+
+      System.out.println("---");
+      System.out.println(resource);
+
+      // freeze resource methods
+      for(ResourceMethod rm : resource.getResourceMethods())
+      {
+         rm.freeze();
+         System.out.println(rm);
+      }
+
+      // freeze sub resource methods
+      for(ResourceMethod srm : resource.getSubResourceMethods())
+      {
+         srm.freeze();
+         System.out.println(srm);
+      }
+
+      System.out.println("---");
+   }
+
+   private void parseMethod(Method method, ResourceModel resource)
+   {      
+      if(method.isAnnotationPresent(UriTemplate.class))
+      {
+         UriTemplate uri = method.getAnnotation(UriTemplate.class);
+
+         ResourceMethod resourceMethod = null;
+
+         // subresource methods
+         for(Class requestType : Convert.REQUEST_TYPES)
+         {
+            if(method.isAnnotationPresent(requestType))
+            {
+               // sub resource method
+               Annotation a = method.getAnnotation(requestType);
+               resourceMethod = new ResourceMethod(
+                 Convert.annotationToMethodHTTP(a), uri.value(), method
+               );
+               resource.addSubResourceMethod(resourceMethod);
+            }
+         }
+
+         // subresource locator
+         if(null == resourceMethod)
+         {
+            // locator
+            ResourceModel subResource = new ResourceModel(resource, uri.value(), method.getReturnType());
+            ResourceLocator locator = new ResourceLocator(subResource);
+            locator.freeze();
+            resource.addSubResourceLocator(locator);
+
+            // recursive
+            parseInternal(subResource);
+         }
+      }
+      else
+      {
+         for(Class requestType : Convert.REQUEST_TYPES)
+         {
+            if(method.isAnnotationPresent(requestType))
+            {
+               // resource method
+               Annotation a = method.getAnnotation(requestType);
+               ResourceMethod resourceMethod = new ResourceMethod(
+                 Convert.annotationToMethodHTTP(a), "", method
+               );
+               resource.addResourceMethod(resourceMethod);
+            }
+         }
+      }
+   }
+
+}


Property changes on: stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModelParser.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceResolver.java
===================================================================
--- stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceResolver.java	2007-10-30 20:24:48 UTC (rev 4941)
+++ stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceResolver.java	2007-10-30 20:57:23 UTC (rev 4942)
@@ -32,7 +32,19 @@
  */
 public class ResourceResolver
 {
-   public ResourceMethod resolve(List<ResourceModel> rootResources, String uri)
+   private RuntimeContext context;
+
+   public static ResourceResolver newInstance(RuntimeContext context)
+   {
+      return new ResourceResolver(context);
+   }
+
+   private ResourceResolver(RuntimeContext context)
+   {
+      this.context = context;
+   }
+
+   public ResourceMethod resolve()
      throws NoResourceException, NoMethodException
    {
       ResourceMethod resourceMethod = null;
@@ -40,18 +52,18 @@
       // Filter the set of resource classes by rejecting those whose
       // regular expression does not match uri
       List<ResourceMatch> includedResources = new ArrayList<ResourceMatch>();
-      Iterator<ResourceModel> it1 = rootResources.iterator();
+      Iterator<ResourceModel> it1 = context.getRootResources().iterator();
       while(it1.hasNext())
       {
          ResourceModel model = it1.next();
-         RegexQualifier qualifier = model.resolve(uri);
+         RegexQualifier qualifier = model.resolve(context.getUri());
          if(qualifier!=null)
             includedResources.add( new ResourceMatch(model, qualifier) );
       }
 
       if(includedResources.isEmpty())
-         throw new NoResourceException("No resource matches URI '"+uri+"'");
-            
+         throw new NoResourceException("No resource matches URI '"+context.getUri()+"'");
+
       Collections.sort(includedResources);
 
       // DFS by locator, should result in a resource match
@@ -63,7 +75,7 @@
       }
 
       if(null == resourceMethod)
-         throw new NoMethodException("No method for URI '"+uri);
+         throw new NoMethodException("No method for URI '"+context.getUri());
 
       // gotcha
       return resourceMethod;
@@ -72,15 +84,18 @@
    /**
     * Recursive scan for resource methods.
     * Inspect a resource match for methods and it fails try the locators.
-    * 
+    *
     * @param dfsEntry
     * @return
     */
    private ResourceMethod dfsResourceMatch(ResourceMatch dfsEntry)
    {
       ResourceMethod resourceMethod = null;
-      resourceMethod = resolveResourceMethod(dfsEntry, dfsEntry.qualifier.nextUriToken);
+      String nextUriToken = dfsEntry.qualifier.nextUriToken;
 
+      // resource and subresource methods first
+      resourceMethod = resolveResourceMethod(dfsEntry, nextUriToken);
+
       // root didn't match, so recurse locators to find a resource
       if(null == resourceMethod)
       {
@@ -88,6 +103,7 @@
          if(subResource!=null)
             resourceMethod = dfsResourceMatch(subResource);
       }
+
       return resourceMethod;
    }
 
@@ -108,40 +124,67 @@
       if(!weightedResults.isEmpty())
       {
          Collections.sort(weightedResults);
-         match = weightedResults.get(0);         
+         match = weightedResults.get(0);
       }
-      
+
       return match;
    }
 
    private ResourceMethod resolveResourceMethod(ResourceMatch<ResourceModel> methodTarget, String uriToken)
    {
       ResourceMethod match = null;
+      List<ResourceMatch<ResourceMethod>> matches = new ArrayList<ResourceMatch<ResourceMethod>>();
 
-      List<ResourceMatch<ResourceMethod>> matches = new ArrayList<ResourceMatch<ResourceMethod>>();
-      List<ResourceMethod> methods = methodTarget.model.getSubResourceMethods();
-      Iterator<ResourceMethod> it = methods.iterator();
-      while(it.hasNext())
+      if("".equals(uriToken) || "/".equals(uriToken)) // resources methods
       {
-         ResourceMethod method = it.next();
-         RegexQualifier qualifier = method.resolve(uriToken);
-         if(qualifier!=null && ("".equals(qualifier.nextUriToken) || "/".equals(qualifier.nextUriToken)))
+         // use any available resource method for further mathing by mimetype, etc
+         for(ResourceMethod resourceMethod : methodTarget.model.getResourceMethods())
          {
             matches.add(
-              new ResourceMatch<ResourceMethod>(method, qualifier)
-            );            
+              new ResourceMatch<ResourceMethod>(resourceMethod, RegexQualifier.NONE)
+            );
          }
       }
-
+      else // subresource methods
+      {
+         List<ResourceMethod> methods = methodTarget.model.getSubResourceMethods();
+         Iterator<ResourceMethod> it = methods.iterator();
+         while(it.hasNext())
+         {
+            ResourceMethod method = it.next();
+            RegexQualifier qualifier = method.resolve(uriToken);
+            if(qualifier!=null && ("".equals(qualifier.nextUriToken) || "/".equals(qualifier.nextUriToken)))
+            {
+               matches.add(
+                 new ResourceMatch<ResourceMethod>(method, qualifier)
+               );
+            }
+         }
+      }
+      
       if(!matches.isEmpty())
       {
          Collections.sort(matches);
-         match = matches.get(0).model;
+         match = contentNegotiation(matches);
       }
-      
+
       return match;
    }
 
+   private ResourceMethod contentNegotiation(List<ResourceMatch<ResourceMethod>> matches)
+   {
+      ResourceMethod match = null;
+      for(ResourceMatch<ResourceMethod> candiate : matches)
+      {
+         if(context.getRequestMethod() == candiate.model.getMethodHTTP())
+         {
+            match = candiate.model;
+            break;
+         }
+      }
+      return match;
+   }
+
    class ResourceMatch<T> implements Comparable
    {
       final T model;

Added: stack/native/branches/rest/src/main/java/org/jboss/rs/model/RuntimeContext.java
===================================================================
--- stack/native/branches/rest/src/main/java/org/jboss/rs/model/RuntimeContext.java	                        (rev 0)
+++ stack/native/branches/rest/src/main/java/org/jboss/rs/model/RuntimeContext.java	2007-10-30 20:57:23 UTC (rev 4942)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.rs.model;
+
+import org.jboss.rs.MethodHTTP;
+
+import java.util.List;
+
+/**
+ * @author Heiko.Braun at jboss.com
+ * @version $Revision$
+ */
+public class RuntimeContext
+{
+   private MethodHTTP requestMethod;
+   private List<ResourceModel> rootResources;
+   private String uri;
+
+   public RuntimeContext(MethodHTTP requestMethod, String uri, List<ResourceModel> rootResources)
+   {
+      this.requestMethod = requestMethod;
+      this.rootResources = rootResources;
+      this.uri = uri;
+   }
+
+   public MethodHTTP getRequestMethod()
+   {
+      return requestMethod;
+   }
+
+
+   public List<ResourceModel> getRootResources()
+   {
+      return rootResources;
+   }
+
+   public String getUri()
+   {
+      return uri;
+   }
+}


Property changes on: stack/native/branches/rest/src/main/java/org/jboss/rs/model/RuntimeContext.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: stack/native/branches/rest/src/main/java/org/jboss/rs/util/Convert.java
===================================================================
--- stack/native/branches/rest/src/main/java/org/jboss/rs/util/Convert.java	                        (rev 0)
+++ stack/native/branches/rest/src/main/java/org/jboss/rs/util/Convert.java	2007-10-30 20:57:23 UTC (rev 4942)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.rs.util;
+
+import org.jboss.rs.MethodHTTP;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.DELETE;
+import java.lang.annotation.Annotation;
+
+/**
+ * @author Heiko.Braun at jboss.com
+ * @version $Revision$
+ */
+public class Convert
+{
+   public static Class[] REQUEST_TYPES = new Class[] { GET.class, POST.class, PUT.class, DELETE.class };
+
+   public static MethodHTTP annotationToMethodHTTP(Annotation a)
+   {
+      MethodHTTP m = null;
+
+      if(a instanceof GET)
+         m = MethodHTTP.GET;
+      else if(a instanceof POST)
+         m = MethodHTTP.POST;
+      else if(a instanceof PUT)
+         m = MethodHTTP.PUT;
+      else if(a instanceof DELETE)
+         m = MethodHTTP.DELETE;
+
+      return m;
+
+   }
+}


Property changes on: stack/native/branches/rest/src/main/java/org/jboss/rs/util/Convert.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Copied: stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ModelParserTestCase.java (from rev 4914, stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ResourceFactoryTestCase.java)
===================================================================
--- stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ModelParserTestCase.java	                        (rev 0)
+++ stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ModelParserTestCase.java	2007-10-30 20:57:23 UTC (rev 4942)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.rs.model;
+
+import junit.framework.TestCase;
+import org.jboss.rs.model.ResourceModelParser;
+import org.jboss.rs.model.ResourceModel;
+import org.jboss.rs.model.ResourceMethod;
+import org.jboss.rs.MethodHTTP;
+
+/**
+ * @author Heiko.Braun at jboss.com
+ * @version $Revision$
+ */
+public class ModelParserTestCase extends TestCase
+{
+   public void testParseMetaModel() throws Exception
+   {
+      ResourceModel root = ResourceModelParser.newInstance().parse(WidgetList.class);
+
+      ResourceMethod match = null;
+      for(ResourceMethod m : root.getSubResourceMethods())
+      {
+         if(m.getMethodHTTP() == MethodHTTP.POST
+           && m.getUriTemplate().equals("special"))
+         {
+            match = m;
+            break;
+         }
+      }
+
+      assertNotNull(match);
+   }
+}


Property changes on: stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ModelParserTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ResolverTestCase.java
===================================================================
--- stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ResolverTestCase.java	2007-10-30 20:24:48 UTC (rev 4941)
+++ stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ResolverTestCase.java	2007-10-30 20:57:23 UTC (rev 4942)
@@ -23,12 +23,15 @@
 
 import junit.framework.TestCase;
 import org.jboss.rs.ResourceRegistry;
+import org.jboss.rs.MethodHTTP;
 import org.jboss.rs.model.ResourceModel;
-import org.jboss.rs.model.ResourceModelFactory;
+import org.jboss.rs.model.ResourceModelParser;
 import org.jboss.rs.model.ResourceResolver;
 import org.jboss.rs.model.ResourceMethod;
+import org.jboss.rs.model.RuntimeContext;
 
 import java.util.List;
+import java.lang.reflect.Method;
 
 /**
  * @author Heiko.Braun at jboss.com
@@ -43,15 +46,16 @@
    protected void setUp() throws Exception
    {
       this.registry = new ResourceRegistry();
-      ResourceModel root = ResourceModelFactory.createModel(WidgetList.class);
+      ResourceModel root = ResourceModelParser.newInstance().parse(WidgetList.class);
       registry.addResourceModelForContext("/rest", root);
       rootModels = registry.getResourceModelsForContext("/rest");
    }
 
    public void testRegexResolver1() throws Exception
    {
-      ResourceResolver resolver = new ResourceResolver();
-      ResourceMethod method = resolver.resolve(rootModels, "widgets/Id/spec");
+      RuntimeContext context = new RuntimeContext(MethodHTTP.GET, "widgets/Id/spec", rootModels );
+      ResourceResolver resolver = ResourceResolver.newInstance(context);
+      ResourceMethod method = resolver.resolve();
 
       assertNotNull(method);
       assertEquals("spec", method.getUriTemplate());
@@ -59,9 +63,10 @@
 
    public void testRegexResolver2() throws Exception
    {
-      ResourceResolver resolver = new ResourceResolver();
+      RuntimeContext context = new RuntimeContext(MethodHTTP.POST, "widgets/special", rootModels );
+      ResourceResolver resolver = ResourceResolver.newInstance(context);
 
-      ResourceMethod method = resolver.resolve(rootModels, "widgets/special");
+      ResourceMethod method = resolver.resolve();
 
       assertNotNull(method);
       assertEquals("special", method.getUriTemplate());
@@ -69,24 +74,37 @@
 
    public void testRegexResolver3() throws Exception
    {
-      ResourceResolver resolver = new ResourceResolver();
+      RuntimeContext context = new RuntimeContext(MethodHTTP.GET, "widgets/offers", rootModels );
+      ResourceResolver resolver = ResourceResolver.newInstance(context);
 
-      ResourceMethod method = resolver.resolve(rootModels, "widgets/offers");
+      ResourceMethod method = resolver.resolve();
 
       assertNotNull(method);
-      assertEquals("offers", method.getUriTemplate());
-      assertTrue(method.getEntityModel().getImplementation().equals(WidgetList.class));
+      assertEquals("offers", method.getUriTemplate());      
    }
 
    public void testRegexResolver4() throws Exception
    {
-      ResourceResolver resolver = new ResourceResolver();
+      RuntimeContext context = new RuntimeContext(MethodHTTP.GET, "widgets/Id/spec/SpecName", rootModels );
+      ResourceResolver resolver = ResourceResolver.newInstance(context);
 
-      ResourceMethod method = resolver.resolve(rootModels, "widgets/Id/spec/SpecName");
+      ResourceMethod method = resolver.resolve();
 
       assertNotNull(method);                 
-      assertEquals("spec/{name}", method.getUriTemplate());
-      assertTrue(method.getEntityModel().getImplementation().equals(Specification.class));
+      assertEquals("spec/{name}", method.getUriTemplate());      
    }
 
+    public void testRegexResolver5() throws Exception
+   {
+      RuntimeContext context = new RuntimeContext(MethodHTTP.GET, "widgets", rootModels );
+      ResourceResolver resolver = ResourceResolver.newInstance(context);
+
+      ResourceMethod method = resolver.resolve();
+
+      assertNotNull(method);      
+      Method target = method.getInvocationTarget();
+      String result = (String)target.invoke( target.getDeclaringClass().newInstance());
+      assertEquals("A widgetlist", result);
+   }
+
 }

Deleted: stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ResourceFactoryTestCase.java
===================================================================
--- stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ResourceFactoryTestCase.java	2007-10-30 20:24:48 UTC (rev 4941)
+++ stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/ResourceFactoryTestCase.java	2007-10-30 20:57:23 UTC (rev 4942)
@@ -1,43 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.rs.model;
-
-import junit.framework.TestCase;
-import org.jboss.rs.model.ResourceModelFactory;
-import org.jboss.rs.model.ResourceModel;
-
-/**
- * @author Heiko.Braun at jboss.com
- * @version $Revision$
- */
-public class ResourceFactoryTestCase extends TestCase
-{
-   public void testParseMetaModel() throws Exception
-   {
-      ResourceModel root = ResourceModelFactory.createModel(WidgetList.class);
-   }
-
-   private void dumpModel(ResourceModel model)
-   {
-            
-   }
-}

Modified: stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/Widget.java
===================================================================
--- stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/Widget.java	2007-10-30 20:24:48 UTC (rev 4941)
+++ stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/Widget.java	2007-10-30 20:57:23 UTC (rev 4942)
@@ -22,8 +22,8 @@
 package org.jboss.test.rs.model;
 
 import javax.ws.rs.GET;
+import javax.ws.rs.UriParam;
 import javax.ws.rs.UriTemplate;
-import javax.ws.rs.UriParam;
 
 /**
  * @author Heiko.Braun at jboss.com

Modified: stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/WidgetList.java
===================================================================
--- stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/WidgetList.java	2007-10-30 20:24:48 UTC (rev 4941)
+++ stack/native/branches/rest/src/test/java/org/jboss/test/rs/model/WidgetList.java	2007-10-30 20:57:23 UTC (rev 4942)
@@ -30,6 +30,11 @@
 public class WidgetList
 {
    @GET
+   String getDescription() {
+      return "A widgetlist";
+   }
+
+   @GET
    @UriTemplate("offers")
    WidgetList getDiscounted() {
       return null;

Modified: stack/native/branches/rest/version.properties
===================================================================
--- stack/native/branches/rest/version.properties	2007-10-30 20:24:48 UTC (rev 4941)
+++ stack/native/branches/rest/version.properties	2007-10-30 20:57:23 UTC (rev 4942)
@@ -67,6 +67,7 @@
 jboss-vfs=2.0.0.Beta2
 jbossas-core-libs=4.2.0.GA
 junit=3.8.1
+jsr311=0.3
 oswego-concurrent=1.3.4
 qdox=1.4
 sun-hudson=1.93




More information about the jbossws-commits mailing list