cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r835800 - in /cxf/branches/2.2.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/
Date Fri, 13 Nov 2009 10:23:26 GMT
Author: sergeyb
Date: Fri Nov 13 10:23:25 2009
New Revision: 835800

URL: http://svn.apache.org/viewvc?rev=835800&view=rev
Log:
Merged revisions 835621 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r835621 | sergeyb | 2009-11-12 22:50:32 +0000 (Thu, 12 Nov 2009) | 1 line
  
  JAXRS : adding Description annotation for better WADLs
........

Added:
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Description.java
      - copied unchanged from r835621, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Description.java
Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Nov 13 10:23:25 2009
@@ -1 +1 @@
-/cxf/trunk:835613-835617
+/cxf/trunk:835613-835617,835621

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=835800&r1=835799&r2=835800&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
Fri Nov 13 10:23:25 2009
@@ -19,7 +19,9 @@
 package org.apache.cxf.jaxrs.model.wadl;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.StringWriter;
+import java.lang.annotation.Annotation;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
@@ -50,6 +52,7 @@
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
+import org.apache.cxf.BusFactory;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.ReflectionInvokationHandler;
 import org.apache.cxf.common.util.StringUtils;
@@ -58,10 +61,12 @@
 import org.apache.cxf.common.xmlschema.XmlSchemaConstants;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.helpers.IOUtils;
 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.RequestHandler;
 import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
 import org.apache.cxf.jaxrs.impl.UriInfoImpl;
@@ -73,6 +78,7 @@
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
+import org.apache.cxf.jaxrs.utils.schemas.SchemaHandler;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.service.Service;
 import org.apache.cxf.staxutils.StaxUtils;
@@ -87,6 +93,7 @@
     private static final Logger LOG = LogUtils.getL7dLogger(WadlGenerator.class);
     private static final String JAXB_DEFAULT_NAMESPACE = "##default";
     private static final String JAXB_DEFAULT_NAME = "##default";
+    private static final String CLASSPATH_PREFIX = "classpath:";
     
     private boolean ignoreMessageWriters = true;
     
@@ -177,7 +184,7 @@
                                 Set<ClassResourceInfo> visitedResources) {
         visitedResources.add(cri);
         sb.append("<resource path=\"").append(path).append("\">");
-        
+        handleDocs(cri.getServiceClass().getAnnotations(), sb);
         List<OperationResourceInfo> sortedOps = sortOperationsByPath(
             cri.getMethodDispatcher().getOperationResourceInfos());
         
@@ -206,6 +213,7 @@
         boolean useResource = useResource(ori);
         if (useResource) {
             sb.append("<resource path=\"").append(path).append("\">");
+            handleDocs(ori.getAnnotatedMethod().getAnnotations(), sb);
         }
         handleParams(sb, ori, ParameterType.PATH);
         handleParams(sb, ori, ParameterType.MATRIX);
@@ -605,5 +613,39 @@
         this.ignoreMessageWriters = ignoreMessageWriters;
     }
 
-
+    private void handleDocs(Annotation[] anns, StringBuilder sb) {
+        for (Annotation a : anns) {
+            if (a.annotationType() == Description.class) {
+                Description d = (Description)a;
+
+                sb.append("<doc");
+                if (d.lang().length() > 0) {
+                    sb.append(" xml:lang=\"" + d.lang() + "\"");
+                }
+                if (d.title().length() > 0) {
+                    sb.append(" title=\"" + d.title() + "\"");
+                }
+                sb.append(">");
+                if (d.value().length() > 0) {
+                    sb.append(d.value());
+                } else if (d.docuri().length() > 0) {
+                    InputStream is = null;
+                    if (d.docuri().startsWith(CLASSPATH_PREFIX)) {
+                        String path = d.docuri().substring(CLASSPATH_PREFIX.length());
+                        is = ResourceUtils.getClasspathResourceStream(path, SchemaHandler.class,
+                            BusFactory.getDefaultBus());
+                        if (is != null) {
+                            try { 
+                                sb.append(IOUtils.toString(is));
+                            } catch (IOException ex) {
+                                // ignore
+                            }
+                        }
+                    }
+                }
+                sb.append("</doc>");
+            }
+        }
+    }
+    
 }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java?rev=835800&r1=835799&r2=835800&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
Fri Nov 13 10:23:25 2009
@@ -31,11 +31,13 @@
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
 
+import org.apache.cxf.jaxrs.ext.Description;
 import org.apache.cxf.jaxrs.fortest.jaxb.packageinfo.Book2;
 
 @Path("/bookstore/{id}")
 @Consumes({"application/xml", "application/json" })
 @Produces({"application/xml", "application/json" })
+@Description(lang = "en-us", title = "book store resource", value = "super resource")
 public class BookStore {
 
     @GET 

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java?rev=835800&r1=835799&r2=835800&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Fri Nov 13 10:23:25 2009
@@ -130,6 +130,13 @@
     private void checkBookStoreInfo(Element resource) {
         assertEquals("/bookstore/{id}", resource.getAttribute("path"));
         
+        List<Element> docsEls = DOMUtils.getChildrenWithName(resource, 
+                WadlGenerator.WADL_NS, "doc");
+        assertEquals(1, docsEls.size());
+        assertEquals("book store resource", docsEls.get(0).getAttribute("title"));
+        assertEquals("en-us", 
+            docsEls.get(0).getAttributeNS("http://www.w3.org/XML/1998/namespace", "lang"));
+        
         List<Element> resourceEls = DOMUtils.getChildrenWithName(resource, 
                                          WadlGenerator.WADL_NS, "resource");
         assertEquals(6, resourceEls.size());        



Mime
View raw message