cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1085366 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/ext/ main/java/org/apache/cxf/jaxrs/ext/xml/ main/java/org/apache/cxf/jaxrs/model/wadl/ test/java/org/apache/cxf/jaxrs/model/wadl/ test/java/org/apache/cxf/jaxrs...
Date Fri, 25 Mar 2011 13:53:56 GMT
Author: sergeyb
Date: Fri Mar 25 13:53:56 2011
New Revision: 1085366

URL: http://svn.apache.org/viewvc?rev=1085366&view=rev
Log:
[CXF-3423] Better support for WADL doc extensions

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/Description.java
      - copied, changed from r1084902, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Description.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/Descriptions.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/DocTarget.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/ElementClass.java
      - copied, changed from r1084902, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlElement.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/XMLName.java
      - copied, changed from r1084902, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XMLName.java
Removed:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Description.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XMLName.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlElement.java
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Book.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Chapter.java

Copied: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/Description.java
(from r1084902, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Description.java)
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/Description.java?p2=cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/Description.java&p1=cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Description.java&r1=1084902&r2=1085366&rev=1085366&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Description.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/Description.java
Fri Mar 25 13:53:56 2011
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.cxf.jaxrs.ext;
+package org.apache.cxf.jaxrs.model.wadl;
 
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;
@@ -29,7 +29,7 @@ import java.lang.annotation.Target;
  * 
  * See {@link <a href="http://www.w3.org/Submission/wadl/#x3-80002.3">WADL Documentation</a>}.
  */
-@Target({ElementType.TYPE, ElementType.METHOD })
+@Target({ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER })
 @Retention(RetentionPolicy.RUNTIME)
 public @interface Description {
     /**
@@ -49,4 +49,9 @@ public @interface Description {
      * the content which will be set as WADL doc content
      */
     String docuri() default "";
+    
+    /**
+     * Target of this description, see {@link DocTarget}
+     */
+    String target() default "";
 }

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/Descriptions.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/Descriptions.java?rev=1085366&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/Descriptions.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/Descriptions.java
Fri Mar 25 13:53:56 2011
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.model.wadl;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Collection of categorized {@link Description} annotations.
+ * 
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Descriptions {
+    Description[] value();
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/Descriptions.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/Descriptions.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/DocTarget.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/DocTarget.java?rev=1085366&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/DocTarget.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/DocTarget.java
Fri Mar 25 13:53:56 2011
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.model.wadl;
+
+/**
+ * {@link Description} can use one of DocTarget constants to bind
+ * itself to a specific WADL element.
+ * {@link Description} annotations documenting WADL 'resource', 'method',
+ * 'param' and input 'representation' elements do not have use these constants.   
+ */
+public final class DocTarget {
+    /**
+     * WADL resource element, in most cases it corresponds 
+     * to the root resource or sub-resource classes
+     */
+    public static final String RESOURCE = "resource";
+    /**
+     * WADL method element, corresponds to a class resource method
+     */
+    public static final String METHOD = "method";
+    /**
+     * WADL request param or representation elements, correspond to 
+     * input parameters of the resource method
+     */
+    public static final String PARAM = "param";
+    /**
+     * WADL response representation element, corresponds to 
+     * the return type of the resource method
+     */
+    public static final String RETURN = "return";
+    
+    /**
+     * WADL request element
+     */    
+    public static final String REQUEST = "request";
+    /**
+     * WADL request element
+     */
+    public static final String RESPONSE = "response";
+    
+    private DocTarget() {
+        
+    }
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/DocTarget.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/DocTarget.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/ElementClass.java
(from r1084902, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlElement.java)
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/ElementClass.java?p2=cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/ElementClass.java&p1=cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlElement.java&r1=1084902&r2=1085366&rev=1085366&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlElement.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/ElementClass.java
Fri Mar 25 13:53:56 2011
@@ -23,10 +23,17 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
+/**
+ * References the concrete response or request class for 
+ * WADL generator be able to generate representations and link
+ * them to schema elements. For example, it can be applied to 
+ * methods returning a JAX-RS {@link Response}. 
+ * 
+ */
 @Retention(RetentionPolicy.RUNTIME)
 @Target({ElementType.METHOD })
-public @interface WadlElement {
-    Class<?> request() default WadlElement.class;
-    Class<?> response() default WadlElement.class;
+public @interface ElementClass {
+    Class<?> request() default Object.class;
+    Class<?> response() default Object.class;
 }
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=1085366&r1=1085365&r2=1085366&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
Fri Mar 25 13:53:56 2011
@@ -77,10 +77,8 @@ import org.apache.cxf.jaxb.JAXBBeanInfo;
 import org.apache.cxf.jaxb.JAXBContextProxy;
 import org.apache.cxf.jaxb.JAXBUtils;
 import org.apache.cxf.jaxrs.JAXRSServiceImpl;
-import org.apache.cxf.jaxrs.ext.Description;
 import org.apache.cxf.jaxrs.ext.Oneway;
 import org.apache.cxf.jaxrs.ext.RequestHandler;
-import org.apache.cxf.jaxrs.ext.xml.XMLName;
 import org.apache.cxf.jaxrs.ext.xml.XMLSource;
 import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
 import org.apache.cxf.jaxrs.impl.UriInfoImpl;
@@ -183,7 +181,7 @@ public class WadlGenerator implements Re
         Set<ClassResourceInfo> visitedResources = new HashSet<ClassResourceInfo>();
         for (ClassResourceInfo cri : cris) {
             startResourceTag(sbResources, cri.getServiceClass(), cri.getURITemplate().getValue());
-            handleDocs(cri.getServiceClass().getAnnotations(), sbResources);
+            handleDocs(cri.getServiceClass().getAnnotations(), sbResources, DocTarget.RESOURCE,
true);
             handleResource(sbResources, allTypes, qnameResolver, clsMap, cri, visitedResources);
             sbResources.append("</resource>");
         }
@@ -237,11 +235,11 @@ public class WadlGenerator implements Re
             OperationResourceInfo ori = sortedOps.get(i);
 
             if (ori.getHttpMethod() == null) {
-                Class<?> cls = ori.getMethodToInvoke().getReturnType();
+                Class<?> cls = getMethod(ori).getReturnType();
                 ClassResourceInfo subcri = cri.findResource(cls, cls);
                 if (subcri != null && !visitedResources.contains(subcri)) {
                     startResourceTag(sb, subcri.getServiceClass(), ori.getURITemplate().getValue());
-                    handleDocs(subcri.getServiceClass().getAnnotations(), sb);
+                    handleDocs(subcri.getServiceClass().getAnnotations(), sb, DocTarget.RESOURCE,
true);
                     handlePathAndMatrixParams(sb, ori);
                     handleResource(sb, jaxbTypes, qnameResolver, clsMap, subcri,
                                    visitedResources);
@@ -276,7 +274,7 @@ public class WadlGenerator implements Re
     private void startMethodTag(StringBuilder sb, OperationResourceInfo ori) {
         sb.append("<method name=\"").append(ori.getHttpMethod()).append("\"");
         if (addResourceAndMethodIds) {
-            sb.append(" id=\"").append(ori.getMethodToInvoke().getName()).append("\"");
+            sb.append(" id=\"").append(getMethod(ori).getName()).append("\"");
         }
         sb.append(">");
     }
@@ -309,9 +307,11 @@ public class WadlGenerator implements Re
         }
 
         startMethodTag(sb, ori);
-        handleDocs(ori.getAnnotatedMethod().getAnnotations(), sb);
-        if (ori.getMethodToInvoke().getParameterTypes().length != 0) {
+        Annotation[] anns = getMethod(ori).getAnnotations();
+        handleDocs(anns, sb, DocTarget.METHOD, true);
+        if (getMethod(ori).getParameterTypes().length != 0) {
             sb.append("<request>");
+            handleDocs(anns, sb, DocTarget.REQUEST, false);
             if (isFormRequest(ori)) {
                 handleFormRepresentation(sb, jaxbTypes, qnameResolver, clsMap, ori, getFormClass(ori));
             } else {
@@ -322,15 +322,17 @@ public class WadlGenerator implements Re
             sb.append("</request>");
         }
         sb.append("<response");
-        boolean isVoid = void.class == ori.getMethodToInvoke().getReturnType();
+        Class<?> returnType = getMethod(ori).getReturnType();
+        boolean isVoid = void.class == returnType;
         if (isVoid) {
-            boolean oneway = ori.getMethodToInvoke().getAnnotation(Oneway.class) != null;
+            boolean oneway = getMethod(ori).getAnnotation(Oneway.class) != null;
             sb.append(" status=\"" + (oneway ? 202 : 204) + "\"");
         }
         sb.append(">");
-        if (void.class != ori.getMethodToInvoke().getReturnType()) {
+        handleDocs(anns, sb, DocTarget.RESPONSE, false);
+        if (!isVoid) {
             handleRepresentation(sb, jaxbTypes, qnameResolver, clsMap, ori,
-                                 ori.getMethodToInvoke().getReturnType(), false);
+                                 returnType, false);
         }
         sb.append("</response>");
 
@@ -402,7 +404,7 @@ public class WadlGenerator implements Re
     private void handleParameter(StringBuilder sb, Set<Class<?>> jaxbTypes,
                                  ElementQNameResolver qnameResolver,
                                  Map<Class<?>, QName> clsMap, OperationResourceInfo
ori, Parameter pm) {
-        Class<?> cls = ori.getMethodToInvoke().getParameterTypes()[pm.getIndex()];
+        Class<?> cls = getMethod(ori).getParameterTypes()[pm.getIndex()];
         if (pm.getType() == ParameterType.REQUEST_BODY) {
             handleRepresentation(sb, jaxbTypes, qnameResolver, clsMap, ori, cls, true);
             return;
@@ -425,22 +427,24 @@ public class WadlGenerator implements Re
     }
 
     private Annotation[] getBodyAnnotations(OperationResourceInfo ori, boolean inbound) {
+        Method opMethod = getMethod(ori);
         if (inbound) {
             for (Parameter pm : ori.getParameters()) {
                 if (pm.getType() == ParameterType.REQUEST_BODY) {
-                    return ori.getAnnotatedMethod().getParameterAnnotations()[pm.getIndex()];
+                    return opMethod.getParameterAnnotations()[pm.getIndex()];
                 }
             }
             return new Annotation[]{};
         } else {
-            return ori.getAnnotatedMethod().getDeclaredAnnotations();
+            return opMethod.getDeclaredAnnotations();
         }
     }
 
     private void writeParam(StringBuilder sb, Parameter pm, OperationResourceInfo ori) {
-        Class<?> type = ori.getMethodToInvoke().getParameterTypes()[pm.getIndex()];
+        Method method = getMethod(ori);
+        Class<?> type = method.getParameterTypes()[pm.getIndex()];
         if (!"".equals(pm.getName())) {
-            doWriteParam(sb, pm, type, pm.getName());
+            doWriteParam(sb, pm, type, pm.getName(), method.getParameterAnnotations()[pm.getIndex()]);
         } else {
             doWriteBeanParam(sb, type, pm, null);
         }
@@ -454,14 +458,15 @@ public class WadlGenerator implements Re
                 name = parentName + "." + name;
             }
             if (InjectionUtils.isPrimitive(entry.getValue())) {
-                doWriteParam(sb, entry.getKey(), entry.getValue(), name);
+                doWriteParam(sb, entry.getKey(), entry.getValue(), name, new Annotation[]{});
             } else {
                 doWriteBeanParam(sb, entry.getValue(), entry.getKey(), name);
             }
         }
     }
 
-    protected void doWriteParam(StringBuilder sb, Parameter pm, Class<?> type, String
paramName) {
+    protected void doWriteParam(StringBuilder sb, Parameter pm, Class<?> type, String
paramName,
+                                Annotation[] anns) {
         sb.append("<param name=\"").append(paramName).append("\" ");
         String style = ParameterType.PATH == pm.getType() ? "template"
                        : ParameterType.FORM == pm.getType() ? "query"
@@ -475,9 +480,25 @@ public class WadlGenerator implements Re
         if (value != null) {
             sb.append(" type=\"").append(value).append("\"");
         }
-        sb.append("/>");
+        addDocsAndCloseElement(sb, anns, "param", DocTarget.PARAM, true);
     }
 
+    private void addDocsAndCloseElement(StringBuilder sb, Annotation[] anns, String elementName,
+                                        String category, boolean allowDefault) {
+        if (isDocAvailable(anns)) {
+            sb.append(">");
+            handleDocs(anns, sb, category, allowDefault);
+            sb.append("</" + elementName + ">");
+        } else {
+            sb.append("/>");
+        }
+    }
+    
+    private boolean isDocAvailable(Annotation[] anns) {
+        return AnnotationUtils.getAnnotation(anns, Description.class) != null
+                   || AnnotationUtils.getAnnotation(anns, Descriptions.class) != null;
+    }
+    
     private void handleRepresentation(StringBuilder sb, Set<Class<?>> jaxbTypes,
                                       ElementQNameResolver qnameResolver,
                                       Map<Class<?>, QName> clsMap, OperationResourceInfo
ori,
@@ -489,25 +510,38 @@ public class WadlGenerator implements Re
             types = Collections.singletonList(MediaType.APPLICATION_OCTET_STREAM_TYPE);
         } 
         
+        Method opMethod = getMethod(ori);
         boolean isPrimitive = InjectionUtils.isPrimitive(type);
         for (MediaType mt : types) {
             
             sb.append("<representation");
             sb.append(" mediaType=\"").append(mt.toString()).append("\"");
 
+            boolean allowDefault = true;
+            String docCategory;
+            Annotation[] anns;
+            if (inbound) {
+                int index = getRequestBodyParam(ori).getIndex();
+                anns = opMethod.getParameterAnnotations()[index];
+                docCategory = DocTarget.PARAM;
+            } else {
+                anns = opMethod.getAnnotations();
+                docCategory = DocTarget.RETURN;
+                allowDefault = false;
+            }
             if (isPrimitive) {
                 sb.append(">");    
                 Parameter p = inbound ? getRequestBodyParam(ori) 
                     : new Parameter(ParameterType.REQUEST_BODY, 0, "result"); 
-                doWriteParam(sb, p, type, p.getName() == null ? "request" : p.getName());
+                doWriteParam(sb, p, type, p.getName() == null ? "request" : p.getName(),
anns);
                 sb.append("</representation>");
             } else  { 
-                type = getActualJaxbType(type, ori.getAnnotatedMethod(), inbound);
+                type = getActualJaxbType(type, opMethod, inbound);
                 if (qnameResolver != null && mt.getSubtype().contains("xml") &&
jaxbTypes.contains(type)) {
                     generateQName(sb, qnameResolver, clsMap, type,
                                   getBodyAnnotations(ori, inbound));
                 }
-                sb.append("/>");
+                addDocsAndCloseElement(sb, anns, "representation", docCategory, allowDefault);
             }
         }
         
@@ -546,8 +580,15 @@ public class WadlGenerator implements Re
     }
 
     protected Class<?> getActualJaxbType(Class<?> type, Method resourceMethod,
boolean inbound) {
-        WadlElement element = resourceMethod.getAnnotation(WadlElement.class);
-        return element == null ? type : inbound ? element.request() : element.response();
+        ElementClass element = resourceMethod.getAnnotation(ElementClass.class);
+        if  (element != null) {
+            Class<?> cls = inbound ? element.request() : element.response();
+            if (cls != Object.class) {
+                return cls;
+            }
+        }
+        return type;
+        
     }
 
     protected List<OperationResourceInfo> sortOperationsByPath(Set<OperationResourceInfo>
ops) {
@@ -684,7 +725,7 @@ public class WadlGenerator implements Re
         for (Parameter p : ori.getParameters()) {
             if (p.getType() == ParameterType.FORM
                 || p.getType() == ParameterType.REQUEST_BODY 
-                && ori.getMethodToInvoke().getParameterTypes()[p.getIndex()] == MultivaluedMap.class)
{
+                && getMethod(ori).getParameterTypes()[p.getIndex()] == MultivaluedMap.class)
{
                 return true;
             }
         }
@@ -797,11 +838,20 @@ public class WadlGenerator implements Re
         this.ignoreMessageWriters = ignoreMessageWriters;
     }
 
-    private void handleDocs(Annotation[] anns, StringBuilder sb) {
+    private void handleDocs(Annotation[] anns, StringBuilder sb, String category, boolean
allowDefault) {
         for (Annotation a : anns) {
+            if (a.annotationType() == Descriptions.class) {
+                Descriptions ds = (Descriptions)a;
+                handleDocs(ds.value(), sb, category, allowDefault);
+                return;
+            }
             if (a.annotationType() == Description.class) {
                 Description d = (Description)a;
-
+                if (d.target().length() == 0 && !allowDefault 
+                    || d.target().length() > 0 && !d.target().equals(category))
{
+                    continue;
+                }
+                
                 sb.append("<doc");
                 if (d.lang().length() > 0) {
                     sb.append(" xml:lang=\"" + d.lang() + "\"");
@@ -1139,6 +1189,11 @@ public class WadlGenerator implements Re
         this.addResourceAndMethodIds = addResourceAndMethodIds;
     }
 
+    private Method getMethod(OperationResourceInfo ori) {
+        Method annMethod = ori.getAnnotatedMethod();
+        return annMethod != null ? annMethod : ori.getMethodToInvoke();
+    }
+    
     private static class SchemaConverter extends DelegatingXMLStreamWriter {
         private static final String SCHEMA_LOCATION = "schemaLocation";
         private Map<String, String> locsMap;

Copied: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/XMLName.java
(from r1084902, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XMLName.java)
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/XMLName.java?p2=cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/XMLName.java&p1=cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XMLName.java&r1=1084902&r2=1085366&rev=1085366&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XMLName.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/XMLName.java
Fri Mar 25 13:53:56 2011
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.cxf.jaxrs.ext.xml;
+package org.apache.cxf.jaxrs.model.wadl;
 
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java?rev=1085366&r1=1085365&r2=1085366&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
Fri Mar 25 13:53:56 2011
@@ -35,8 +35,6 @@ import javax.ws.rs.core.Response;
 import javax.xml.bind.annotation.XmlTransient;
 
 import org.apache.cxf.aegis.type.java5.IgnoreProperty;
-import org.apache.cxf.jaxrs.ext.Description;
-import org.apache.cxf.jaxrs.ext.xml.XMLName;
 import org.apache.cxf.jaxrs.fortest.jaxb.packageinfo.Book2;
 import org.apache.cxf.jaxrs.model.wadl.jaxb.Book;
 import org.apache.cxf.jaxrs.model.wadl.jaxb.Chapter;
@@ -67,16 +65,25 @@ public class BookStore {
     
     @POST
     @Path("books/{bookid}")
-    @Description("Update the books collection")
+    @Descriptions({ 
+        @Description(value = "Update the books collection", target = DocTarget.METHOD),
+        @Description(value = "Requested Book", target = DocTarget.RETURN),
+        @Description(value = "Request", target = DocTarget.REQUEST),
+        @Description(value = "Response", target = DocTarget.RESPONSE)
+    })
+    
     //CHECKSTYLE:OFF
-    public Book addBook(@PathParam("id") int id,
+    public Book addBook(@Description("book id")
+                        @PathParam("id") int id,
                         @PathParam("bookid") int bookId,
                         @MatrixParam("mid") int matrixId,
+                        @Description("header param")
                         @HeaderParam("hid") int headerId,
                         @CookieParam("cid") int cookieId,
                         @QueryParam("provider.bar") int queryParam,
                         @Context HttpHeaders headers,
-                        @XMLName(value = "{http://books}thesuperbook2", prefix = "p1")
+                        @Description("InputBook")      
+                        @XMLName(value = "{http://books}thesuperbook2")
                         Book2 b) {
         return new Book(1);
     }
@@ -105,7 +112,7 @@ public class BookStore {
     
     @GET
     @Path("chapter2")
-    @WadlElement(response = Chapter.class)
+    @ElementClass(response = Chapter.class)
     public Response getChaper2() {
         return Response.ok().entity(new Chapter(1)).build();
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java?rev=1085366&r1=1085365&r2=1085366&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Fri Mar 25 13:53:56 2011
@@ -326,11 +326,10 @@ public class WadlGeneratorTest extends A
     private void checkBookStoreInfo(Element resource, String bookEl, String book2El, String
chapterEl) {
         assertEquals("/bookstore/{id}", resource.getAttribute("path"));
         
-        checkRootDocs(resource);
+        checkDocs(resource, "book store resource", "super resource", "en-us");
+        
+        List<Element> resourceEls = getElements(resource, "resource", 8);
         
-        List<Element> resourceEls = DOMUtils.getChildrenWithName(resource, 
-                                         WadlGenerator.WADL_NS, "resource");
-        assertEquals(8, resourceEls.size());        
         assertEquals("/book2", resourceEls.get(0).getAttribute("path"));
         assertEquals("/books/{bookid}", resourceEls.get(1).getAttribute("path"));
         assertEquals("/chapter", resourceEls.get(2).getAttribute("path"));
@@ -345,18 +344,14 @@ public class WadlGeneratorTest extends A
         verifyParameters(resource, 1, new Param("id", "template", "xs:long"));
         
         // must have 2 methods, GET and PUT
-        List<Element> methodEls = DOMUtils.getChildrenWithName(resource, 
-                                                               WadlGenerator.WADL_NS, "method");
-        assertEquals(2, methodEls.size());
+        List<Element> methodEls = getElements(resource, "method", 2);
         
         // verify GET
         assertEquals("GET", methodEls.get(0).getAttribute("name"));
         assertEquals(0, DOMUtils.getChildrenWithName(methodEls.get(0), 
                         WadlGenerator.WADL_NS, "param").size());
         // check request 
-        List<Element> requestEls = DOMUtils.getChildrenWithName(methodEls.get(0), 
-                                                               WadlGenerator.WADL_NS, "request");
-        assertEquals(1, requestEls.size());
+        List<Element> requestEls = getElements(methodEls.get(0), "request", 1);
         
         // 4 parameters are expected
         verifyParameters(requestEls.get(0), 4, 
@@ -377,98 +372,97 @@ public class WadlGeneratorTest extends A
         verifyResponseWithStatus(methodEls.get(1), "204");
         
         // verify resource starting with /book2
-        verifyGetResourceMethod(resourceEls.get(0), book2El);
+        verifyGetResourceMethod(resourceEls.get(0), book2El, null);
         
         //verify resource starting with /books/{bookid}
         verifyParameters(resourceEls.get(1), 3, 
-                         new Param("id", "template", "xs:int"),
+                         new Param("id", "template", "xs:int", "book id"),
                          new Param("bookid", "template", "xs:int"),
                          new Param("mid", "matrix", "xs:int"));
         
         // and 2 methods
-        methodEls = DOMUtils.getChildrenWithName(resourceEls.get(1), 
-                                                 WadlGenerator.WADL_NS, "method");
-        assertEquals(2, methodEls.size());
-        
+        methodEls = getElements(resourceEls.get(1), "method", 2);
+                
         // POST 
         assertEquals("POST", methodEls.get(0).getAttribute("name"));
+        checkDocs(methodEls.get(0), "", "Update the books collection", "");
+        requestEls = getElements(methodEls.get(0), "request", 1);
         
-        requestEls = DOMUtils.getChildrenWithName(methodEls.get(0), 
-                                             WadlGenerator.WADL_NS, "request");
-        assertEquals(1, requestEls.size());
+        checkDocs(requestEls.get(0), "", "Request", "");
         
         verifyParameters(requestEls.get(0), 2, 
                          new Param("hid", "header", "xs:int"),
                          new Param("provider.bar", "query", "xs:int"));
-        verifyXmlJsonRepresentations(requestEls.get(0), book2El);
+        
+        verifyXmlJsonRepresentations(requestEls.get(0), book2El, "InputBook");
+        List<Element> responseEls = getElements(methodEls.get(0), "response", 1);
+        checkDocs(responseEls.get(0), "", "Response", "");
+        verifyXmlJsonRepresentations(responseEls.get(0), bookEl, "Requested Book");
         
         // PUT
         assertEquals("PUT", methodEls.get(1).getAttribute("name"));
-        requestEls = DOMUtils.getChildrenWithName(methodEls.get(1), 
-                                                                WadlGenerator.WADL_NS, "request");
+        checkDocs(methodEls.get(1), "", "Update the book", "");
+        requestEls = getElements(methodEls.get(1), "request", 1);
         assertEquals(1, requestEls.size());
-        verifyXmlJsonRepresentations(requestEls.get(0), bookEl);
+        verifyXmlJsonRepresentations(requestEls.get(0), bookEl, null);
         verifyResponseWithStatus(methodEls.get(1), "204");
         
         // verify resource starting with /chapter
-        verifyGetResourceMethod(resourceEls.get(2), chapterEl);
+        verifyGetResourceMethod(resourceEls.get(2), chapterEl, null);
         // verify resource starting with /chapter2
-        verifyGetResourceMethod(resourceEls.get(3), chapterEl);
+        verifyGetResourceMethod(resourceEls.get(3), chapterEl, null);
         
         // verify resource starting from /booksubresource
         // should have 2 parameters
         verifyParameters(resourceEls.get(5), 2, 
                          new Param("id", "template", "xs:int"),
                          new Param("mid", "matrix", "xs:int"));
-        
+        checkDocs(resourceEls.get(5), "", "Book subresource", ""); 
         // should have 4 child resources
-        List<Element> subResourceEls = DOMUtils.getChildrenWithName(resourceEls.get(5),

-                                         WadlGenerator.WADL_NS, "resource");
-        assertEquals(4, subResourceEls.size());        
+        List<Element> subResourceEls = getElements(resourceEls.get(5), "resource",
4);
+
         assertEquals("/book", subResourceEls.get(0).getAttribute("path"));
         assertEquals("/form1", subResourceEls.get(1).getAttribute("path"));
         assertEquals("/form2", subResourceEls.get(2).getAttribute("path"));
         assertEquals("/chapter/{cid}", subResourceEls.get(3).getAttribute("path"));
+        checkDocs(subResourceEls.get(3), "", "Chapter subresource", "");
         // verify book-subresource /book resource
         // GET 
-        verifyGetResourceMethod(subResourceEls.get(0), bookEl);
-        
+        verifyGetResourceMethod(subResourceEls.get(0), bookEl, null);
         // verify book-subresource /form1 resource
-        List<Element> form1MethodEls = DOMUtils.getChildrenWithName(subResourceEls.get(1),

-                                                              WadlGenerator.WADL_NS, "method");
-        assertEquals(1, form1MethodEls.size());
+        List<Element> form1MethodEls = getElements(subResourceEls.get(1), "method",
1);
+        
         assertEquals("POST", form1MethodEls.get(0).getAttribute("name"));
         verifyRepresentation(form1MethodEls.get(0), "request", MediaType.APPLICATION_FORM_URLENCODED,
"");
         verifyResponseWithStatus(form1MethodEls.get(0), "204");
         
         // verify book-subresource /form2 resource
-        List<Element> form2MethodEls = DOMUtils.getChildrenWithName(subResourceEls.get(2),

-                                                                    WadlGenerator.WADL_NS,
"method");
-        assertEquals(1, form2MethodEls.size());
+        List<Element> form2MethodEls = getElements(subResourceEls.get(2), "method",
1);
         assertEquals("POST", form2MethodEls.get(0).getAttribute("name"));
         verifyRepresentation(form2MethodEls.get(0), "response", MediaType.TEXT_PLAIN, "");
         verifyRepresentation(form2MethodEls.get(0), "request", MediaType.APPLICATION_FORM_URLENCODED,
"");
         
-        List<Element> form2RequestEls = DOMUtils.getChildrenWithName(
-                                        form2MethodEls.get(0), 
-                                        WadlGenerator.WADL_NS, "request");
-        List<Element> form2RequestRepEls = DOMUtils.getChildrenWithName(
-                                        form2RequestEls.get(0), 
-                                        WadlGenerator.WADL_NS, "representation");
+        List<Element> form2RequestEls = getElements(form2MethodEls.get(0), "request",
1);
+        List<Element> form2RequestRepEls = getElements(form2RequestEls.get(0), "representation",
1);
         verifyParameters(form2RequestRepEls.get(0), 2, 
                          new Param("field1", "query", "xs:string"),
                          new Param("field2", "query", "xs:string"));
         
         
         // verify subresource /chapter/{id}
-        List<Element> chapterMethodEls = DOMUtils.getChildrenWithName(subResourceEls.get(3),

-                                                                    WadlGenerator.WADL_NS,
"resource");
-        assertEquals(1, chapterMethodEls.size());        
+        List<Element> chapterMethodEls = getElements(subResourceEls.get(3), "resource",
1);
         assertEquals("/id", chapterMethodEls.get(0).getAttribute("path"));
         verifyParameters(subResourceEls.get(3), 1, 
                          new Param("cid", "template", "xs:int"));
         // GET
-        verifyGetResourceMethod(chapterMethodEls.get(0), chapterEl);
+        verifyGetResourceMethod(chapterMethodEls.get(0), chapterEl, "Get the chapter");
+    }
+    
+    private List<Element> getElements(Element resource, String name, int expectedSize)
{
+        List<Element> elements = DOMUtils.getChildrenWithName(resource, 
+                                     WadlGenerator.WADL_NS, name);
+        assertEquals(expectedSize, elements.size());
+        return elements;
     }
     
     private void verifyParameters(Element el, int number, Param... params) {
@@ -478,30 +472,33 @@ public class WadlGeneratorTest extends A
         assertEquals(number, params.length);
         
         for (int i = 0; i < number; i++) {
-            Param p = params[i];
-            checkParameter(paramsEls.get(i), p.getName(), p.getType(), p.getSchemaType());
+            checkParameter(paramsEls.get(i), params[i]);
         }
     }
     
-    private void checkRootDocs(Element el) {
+    private void checkDocs(Element el, String title, String value, String language) {
         List<Element> docsEls = DOMUtils.getChildrenWithName(el, 
                                                              WadlGenerator.WADL_NS, "doc");
         assertEquals(1, docsEls.size());
-        assertEquals("book store resource", docsEls.get(0).getAttribute("title"));
-        assertEquals("en-us", 
+        assertEquals(title, docsEls.get(0).getAttribute("title"));
+        assertEquals(value, docsEls.get(0).getTextContent());
+        assertEquals(language, 
             docsEls.get(0).getAttributeNS("http://www.w3.org/XML/1998/namespace", "lang"));
     }
     
-    private void verifyGetResourceMethod(Element element, String type) {
+    private void verifyGetResourceMethod(Element element, String type, String docs) {
         List<Element> methodEls = DOMUtils.getChildrenWithName(element, WadlGenerator.WADL_NS,
"method");
         assertEquals(1, methodEls.size());
+        if (docs != null) {
+            checkDocs(methodEls.get(0), "", docs, "");
+        }
         assertEquals("GET", methodEls.get(0).getAttribute("name"));
         assertEquals(0, DOMUtils.getChildrenWithName(methodEls.get(0), 
                       WadlGenerator.WADL_NS, "request").size());
         List<Element> responseEls = DOMUtils.getChildrenWithName(methodEls.get(0),

                                 WadlGenerator.WADL_NS, "response");
         assertEquals(1, responseEls.size());
-        verifyXmlJsonRepresentations(responseEls.get(0), type);
+        verifyXmlJsonRepresentations(responseEls.get(0), type, null);
     }
     
     private void verifyResponseWithStatus(Element element, String status) {
@@ -523,30 +520,38 @@ public class WadlGeneratorTest extends A
         List<Element> representationEls = DOMUtils.getChildrenWithName(elements.get(0),

                     WadlGenerator.WADL_NS, "representation"); 
         assertEquals(1, representationEls.size());
-        verifyMediTypeAndElementValue(representationEls.get(0), mediaType, elementValue);
+        verifyMediTypeAndElementValue(representationEls.get(0), mediaType, elementValue,
null);
         if ("text/plain".equals(mediaType)) { 
             String pName = "request".equals(name) ? "request" : "result";
             verifyParameters(representationEls.get(0), 1, new Param(pName, "plain", "xs:string"));
         }
     }
     
-    private void verifyXmlJsonRepresentations(Element element, String type) {
+    private void verifyXmlJsonRepresentations(Element element, String type, String docs)
{
         List<Element> repEls = DOMUtils.getChildrenWithName(element, 
-                                                            WadlGenerator.WADL_NS, "representation");
+                                        WadlGenerator.WADL_NS, "representation");
         assertEquals(2, repEls.size());
-        verifyMediTypeAndElementValue(repEls.get(0), "application/xml", type);
-        verifyMediTypeAndElementValue(repEls.get(1), "application/json", "");
+        verifyMediTypeAndElementValue(repEls.get(0), "application/xml", type, docs);
+        verifyMediTypeAndElementValue(repEls.get(1), "application/json", "", docs);
     }
     
-    private void verifyMediTypeAndElementValue(Element el, String mediaType, String elementValue)
{
+    private void verifyMediTypeAndElementValue(Element el, String mediaType, String elementValue,

+                                               String docs) {
         assertEquals(mediaType, el.getAttribute("mediaType"));
         assertEquals(elementValue, el.getAttribute("element"));
+        if (docs != null) {
+            checkDocs(el, "", docs, "");
+        }
     }
     
-    private void checkParameter(Element paramEl, String name, String style, String type)
{
-        assertEquals(name, paramEl.getAttribute("name"));
-        assertEquals(style, paramEl.getAttribute("style"));
-        assertEquals(type, paramEl.getAttribute("type"));
+    private void checkParameter(Element paramEl, Param p) {
+        assertEquals(p.getName(), paramEl.getAttribute("name"));
+        assertEquals(p.getType(), paramEl.getAttribute("style"));
+        assertEquals(p.getSchemaType(), paramEl.getAttribute("type"));
+        String docs = p.getDocs();
+        if (docs != null) {
+            checkDocs(paramEl, "", docs, "");
+        }
     }
     
     private List<Element> getWadlResourcesInfo(Document doc, String baseURI, int size)
throws Exception {
@@ -591,10 +596,16 @@ public class WadlGeneratorTest extends A
         private String name;
         private String type;
         private String schemaType;
+        private String docs;
         public Param(String name, String type, String schemaType) {
+            this(name, type, schemaType, null);
+        }
+        
+        public Param(String name, String type, String schemaType, String docs) {
             this.name = name;
             this.type = type;
             this.schemaType = schemaType;
+            this.docs = docs;
         }
         
         public String getName() {
@@ -608,5 +619,9 @@ public class WadlGeneratorTest extends A
         public String getSchemaType() {
             return schemaType;
         }
+        
+        public String getDocs() {
+            return docs;
+        }
     }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Book.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Book.java?rev=1085366&r1=1085365&r2=1085366&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Book.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Book.java
Fri Mar 25 13:53:56 2011
@@ -27,14 +27,14 @@ import javax.xml.bind.annotation.XmlElem
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
 
-import org.apache.cxf.jaxrs.ext.Description;
-import org.apache.cxf.jaxrs.ext.xml.XMLName;
+import org.apache.cxf.jaxrs.model.wadl.Description;
 import org.apache.cxf.jaxrs.model.wadl.FormInterface;
+import org.apache.cxf.jaxrs.model.wadl.XMLName;
 
 @XmlRootElement(name = "thebook", namespace = "http://superbooks")
 @XmlType(name = "book", namespace = "http://superbooks")
 @Description("Book subresource")
-@XMLName(value = "{http://books}thesuperbook", prefix = "p1")
+@XMLName(value = "{http://books}thesuperbook")
 public class Book implements FormInterface {
 
     private int id;

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Chapter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Chapter.java?rev=1085366&r1=1085365&r2=1085366&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Chapter.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Chapter.java
Fri Mar 25 13:53:56 2011
@@ -24,13 +24,13 @@ import javax.ws.rs.Produces;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
 
-import org.apache.cxf.jaxrs.ext.Description;
-import org.apache.cxf.jaxrs.ext.xml.XMLName;
+import org.apache.cxf.jaxrs.model.wadl.Description;
+import org.apache.cxf.jaxrs.model.wadl.XMLName;
 
 @XmlRootElement(name = "thechapter", namespace = "http://superbooks")
 @XmlType(name = "chapter", namespace = "http://superbooks")
 @Description("Chapter subresource")
-@XMLName(value = "{http://books}thesuperchapter", prefix = "p1")
+@XMLName(value = "{http://books}thesuperchapter")
 public class Chapter {
 
     private int id;



Mime
View raw message