cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1354002 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/ main/java/org/apache/cxf/jaxrs/model/ main/java/org/apache/cxf/jaxrs/model/wadl/ main/java/org/apache/cxf/jaxrs/provider/ main/java/org/apache/cxf/jaxrs/utils/ ...
Date Tue, 26 Jun 2012 13:12:14 GMT
Author: sergeyb
Date: Tue Jun 26 13:12:12 2012
New Revision: 1354002

URL: http://svn.apache.org/viewvc?rev=1354002&view=rev
Log:
[CXF-4144] Updating generated schemas with wrapper element names when possible

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ResourceTypes.java
  (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.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/provider/JAXBElementProviderTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java?rev=1354002&r1=1354001&r2=1354002&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
Tue Jun 26 13:12:12 2012
@@ -345,7 +345,8 @@ public class AbstractJAXRSFactoryBean ex
             return;
         }
         if (db instanceof PropertiesAwareDataBinding) {
-            Map<Class<?>, Type> allClasses = ResourceUtils.getAllRequestResponseTypes(cris,
false);
+            Map<Class<?>, Type> allClasses = 
+                ResourceUtils.getAllRequestResponseTypes(cris, false).getAllTypes();
             Map<String, Object> props = new HashMap<String, Object>();
             props.put(PropertiesAwareDataBinding.TYPES_PROPERTY, allClasses);
             ((PropertiesAwareDataBinding)db).initialize(props);

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ResourceTypes.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ResourceTypes.java?rev=1354002&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ResourceTypes.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ResourceTypes.java
Tue Jun 26 13:12:12 2012
@@ -0,0 +1,42 @@
+/**
+ * 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;
+
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+public class ResourceTypes {
+    private Map<Class<?>, Type> allTypes = new HashMap<Class<?>, Type>();
+    private Map<Class<?>, QName> collectionMap = new HashMap<Class<?>,
QName>();
+    public Map<Class<?>, Type> getAllTypes() {
+        return allTypes;
+    }
+    public void setAllTypes(Map<Class<?>, Type> allTypes) {
+        this.allTypes = allTypes;
+    }
+    public Map<Class<?>, QName> getCollectionMap() {
+        return collectionMap;
+    }
+    public void setCollectionMap(Map<Class<?>, QName> collectionMap) {
+        this.collectionMap = collectionMap;
+    }
+}

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

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

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=1354002&r1=1354001&r2=1354002&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
Tue Jun 26 13:12:12 2012
@@ -95,6 +95,7 @@ import org.apache.cxf.jaxrs.model.ClassR
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
 import org.apache.cxf.jaxrs.model.Parameter;
 import org.apache.cxf.jaxrs.model.ParameterType;
+import org.apache.cxf.jaxrs.model.ResourceTypes;
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
@@ -129,7 +130,8 @@ public class WadlGenerator implements Re
     private boolean ignoreRequests;
     private boolean linkJsonToXmlSchema;
     private boolean useJaxbContextForQnames = true;
-
+    private boolean supportCollections = true;
+    
     private List<String> externalSchemasCache;
     private List<URI> externalSchemaLinks;
     private Map<String, List<String>> externalQnamesMap;
@@ -212,12 +214,14 @@ public class WadlGenerator implements Re
 
         List<ClassResourceInfo> cris = getResourcesList(m, resource);
 
-        Set<Class<?>> allTypes =
-            ResourceUtils.getAllRequestResponseTypes(cris, useJaxbContextForQnames).keySet();
+        ResourceTypes resourceTypes =
+            ResourceUtils.getAllRequestResponseTypes(cris, useJaxbContextForQnames);
+        Set<Class<?>> allTypes = resourceTypes.getAllTypes().keySet();
+        
         JAXBContext context = useJaxbContextForQnames 
             ? ResourceUtils.createJaxbContext(new HashSet<Class<?>>(allTypes),
null, null) : null;
         
-        SchemaWriter schemaWriter = createSchemaWriter(context, ui);
+        SchemaWriter schemaWriter = createSchemaWriter(resourceTypes, context, ui);
         ElementQNameResolver qnameResolver =
             schemaWriter == null ? null : createElementQNameResolver(context);
 
@@ -738,14 +742,20 @@ public class WadlGenerator implements Re
                 doWriteParam(sb, p, type, type, p.getName() == null ? "request" : p.getName(),
anns, isJson);
                 sb.append("</representation>");
             } else  { 
-                type = ResourceUtils.getActualJaxbType(type, opMethod, inbound);
+                boolean isCollection = InjectionUtils.isSupportedCollectionOrArray(type);
+                if (isCollection) {
+                    type = InjectionUtils.getActualType(!inbound ? opMethod.getGenericReturnType()

+                        : opMethod.getGenericParameterTypes()[getRequestBodyParam(ori).getIndex()]);
+                } else {
+                    type = ResourceUtils.getActualJaxbType(type, opMethod, inbound);
+                }
                 if (isJson) {
                     sb.append(" element=\"").append(type.getSimpleName()).append("\"");
                 } else if (qnameResolver != null 
                         && (mt.getSubtype().contains("xml")
                                 || linkJsonToXmlSchema && mt.getSubtype().contains("json"))
                         && jaxbTypes.contains(type)) {
-                    generateQName(sb, qnameResolver, clsMap, type,
+                    generateQName(sb, qnameResolver, clsMap, type, isCollection,
                                   getBodyAnnotations(ori, inbound));
                 }
                 addDocsAndCloseElement(sb, anns, "representation", docCategory, allowDefault,
isJson);
@@ -910,20 +920,33 @@ public class WadlGenerator implements Re
                                ElementQNameResolver qnameResolver,
                                Map<Class<?>, QName> clsMap,
                                Class<?> type,
+                               boolean isCollection,
                                Annotation[] annotations) {
-
-        QName typeQName = clsMap.get(type);
-        if (typeQName != null) {
-            writeQName(sb, typeQName);
-            return;
+        if (!isCollection) {
+            QName typeQName = clsMap.get(type);
+            if (typeQName != null) {
+                writeQName(sb, typeQName);
+                return;
+            }
         }
 
         QName qname = qnameResolver.resolve(type, annotations,
                                             Collections.unmodifiableMap(clsMap));
 
         if (qname != null) {
-            writeQName(sb, qname);
-            clsMap.put(type, qname);
+            if (!isCollection) {
+                writeQName(sb, qname);
+                clsMap.put(type, qname);
+            } else {
+                XMLName name = AnnotationUtils.getAnnotation(annotations, XMLName.class);
+                QName collectionName = null;
+                if (name != null) {
+                    QName tempQName = JAXRSUtils.convertStringToQName(name.value());
+                    collectionName = new QName(qname.getPrefix(), qname.getNamespaceURI(),

+                                               tempQName.getLocalPart());
+                    writeQName(sb, collectionName);
+                }
+            }
         }
     }
 
@@ -932,7 +955,7 @@ public class WadlGenerator implements Re
             .append(qname.getLocalPart()).append("\"");
     }
 
-    private SchemaCollection getSchemaCollection(JAXBContext context) {
+    private SchemaCollection getSchemaCollection(ResourceTypes resourceTypes, JAXBContext
context) {
         if (context == null) {
             return null;
         }
@@ -942,7 +965,37 @@ public class WadlGenerator implements Re
         try {
             for (DOMResult r : JAXBUtils.generateJaxbSchemas(context,
                                     CastUtils.cast(Collections.emptyMap(), String.class,
DOMResult.class))) {
-                DOMSource source = new DOMSource(r.getNode(), r.getSystemId());
+                Document doc = (Document)r.getNode();
+                if (supportCollections && !resourceTypes.getCollectionMap().isEmpty())
{
+                    ElementQNameResolver theResolver = createElementQNameResolver(context);
+                    String tns = doc.getDocumentElement().getAttribute("targetNamespace");
+                    for (Map.Entry<Class<?>, QName> entry : resourceTypes.getCollectionMap().entrySet())
{
+                        if (tns.equals(entry.getValue().getNamespaceURI())) {
+                            QName typeName = theResolver.resolve(entry.getKey(), new Annotation[]{},

+                                                           Collections.<Class<?>,
QName>emptyMap());
+                            if (typeName != null) {
+                                Element newElement = doc.createElementNS(XmlSchemaConstants.XSD_NAMESPACE_URI,

+                                                                         "xs:element");
+                                newElement.setAttribute("name", entry.getValue().getLocalPart());
+                                Element ctElement = doc.createElementNS(XmlSchemaConstants.XSD_NAMESPACE_URI,

+                                    "xs:complexType");
+                                newElement.appendChild(ctElement);
+                                Element seqElement = doc.createElementNS(XmlSchemaConstants.XSD_NAMESPACE_URI,

+                                    "xs:sequence");
+                                ctElement.appendChild(seqElement);
+                                Element xsElement = doc.createElementNS(XmlSchemaConstants.XSD_NAMESPACE_URI,

+                                    "xs:element");
+                                seqElement.appendChild(xsElement);
+                                xsElement.setAttribute("ref", "tns:" + typeName.getLocalPart());
+                                xsElement.setAttribute("minOccurs", "0");
+                                xsElement.setAttribute("maxOccurs", "unbounded");
+                                
+                                doc.getDocumentElement().appendChild(newElement);
+                            }
+                        }
+                    }
+                }
+                DOMSource source = new DOMSource(doc, r.getSystemId());
                 schemas.add(source);
                 String tns = 
                     ((Document)source.getNode()).getDocumentElement().getAttribute("targetNamespace");
@@ -1284,7 +1337,8 @@ public class WadlGenerator implements Re
         }
     }
 
-    protected SchemaWriter createSchemaWriter(JAXBContext context, UriInfo ui) {
+    protected SchemaWriter createSchemaWriter(ResourceTypes resourceTypes, JAXBContext context,

+                                              UriInfo ui) {
         // if neither externalSchemaLinks nor externalSchemasCache is set
         // then JAXBContext will be used to generate the schema
         if (externalSchemaLinks != null && externalSchemasCache == null) {
@@ -1292,7 +1346,7 @@ public class WadlGenerator implements Re
         } else if (externalSchemasCache != null) {
             return new StringSchemaWriter(externalSchemasCache, externalSchemaLinks, ui);
         } else if (context != null) {
-            SchemaCollection coll = getSchemaCollection(context);
+            SchemaCollection coll = getSchemaCollection(resourceTypes, context);
             if (coll != null) {
                 return new SchemaCollectionWriter(coll);
             }
@@ -1545,6 +1599,10 @@ public class WadlGenerator implements Re
     public void setIgnoreRequests(boolean ignoreRequests) {
         this.ignoreRequests = ignoreRequests;
     }
+    
+    public void setSupportCollections(boolean support) {
+        this.supportCollections = support;
+    }
 
     public void setDefaultMediaType(String mt) {
         this.defaultMediaType = MediaType.valueOf(mt);

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=1354002&r1=1354001&r2=1354002&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
Tue Jun 26 13:12:12 2012
@@ -161,7 +161,8 @@ public abstract class AbstractJAXBProvid
     public void init(List<ClassResourceInfo> cris) {
         if (singleJaxbContext) {
             Set<Class<?>> allTypes = 
-                new HashSet<Class<?>>(ResourceUtils.getAllRequestResponseTypes(cris,
true).keySet());
+                new HashSet<Class<?>>(ResourceUtils.getAllRequestResponseTypes(cris,
true)
+                    .getAllTypes().keySet());
             JAXBContext context = 
                 ResourceUtils.createJaxbContext(allTypes, extraClass, cProperties);
             if (context != null) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java?rev=1354002&r1=1354001&r2=1354002&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
Tue Jun 26 13:12:12 2012
@@ -81,10 +81,12 @@ import org.apache.cxf.jaxrs.model.Method
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
 import org.apache.cxf.jaxrs.model.Parameter;
 import org.apache.cxf.jaxrs.model.ParameterType;
+import org.apache.cxf.jaxrs.model.ResourceTypes;
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.model.UserOperation;
 import org.apache.cxf.jaxrs.model.UserResource;
 import org.apache.cxf.jaxrs.model.wadl.ElementClass;
+import org.apache.cxf.jaxrs.model.wadl.XMLName;
 import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.resource.ResourceManager;
@@ -467,9 +469,9 @@ public final class ResourceUtils {
     }
     
 
-    public static Map<Class<?>, Type> getAllRequestResponseTypes(List<ClassResourceInfo>
cris, 
-                                                                 boolean jaxbOnly) {
-        Map<Class<?>, Type> types = new HashMap<Class<?>, Type>();
+    public static ResourceTypes getAllRequestResponseTypes(List<ClassResourceInfo>
cris, 
+                                                           boolean jaxbOnly) {
+        ResourceTypes types = new ResourceTypes();
         for (ClassResourceInfo resource : cris) {
             getAllTypesForResource(resource, types, jaxbOnly);
         }
@@ -487,29 +489,33 @@ public final class ResourceUtils {
         return type;
     }
     
-    private static void getAllTypesForResource(ClassResourceInfo resource, Map<Class<?>,
Type> types,
+    private static void getAllTypesForResource(ClassResourceInfo resource, 
+                                               ResourceTypes types,
                                                boolean jaxbOnly) {
         for (OperationResourceInfo ori : resource.getMethodDispatcher().getOperationResourceInfos())
{
-            Class<?> realReturnType = ori.getMethodToInvoke().getReturnType();
+            Method method = ori.getMethodToInvoke();
+            Class<?> realReturnType = method.getReturnType();
             Class<?> cls = realReturnType;
             if (cls == Response.class) {
-                cls = getActualJaxbType(cls, ori.getMethodToInvoke(), false);
+                cls = getActualJaxbType(cls, method, false);
             }
-            Type type = ori.getMethodToInvoke().getGenericReturnType();
+            Type type = method.getGenericReturnType();
             if (jaxbOnly) {
-                checkJaxbType(cls, realReturnType == Response.class ? cls : type, types);
+                checkJaxbType(cls, realReturnType == Response.class ? cls : type, types,

+                    method.getAnnotations());
             } else {
-                types.put(cls, type);
+                types.getAllTypes().put(cls, type);
             }
             
             for (Parameter pm : ori.getParameters()) {
                 if (pm.getType() == ParameterType.REQUEST_BODY) {
-                    Class<?> inType = ori.getMethodToInvoke().getParameterTypes()[pm.getIndex()];
-                    Type paramType = ori.getMethodToInvoke().getGenericParameterTypes()[pm.getIndex()];
+                    Class<?> inType = method.getParameterTypes()[pm.getIndex()];
+                    Type paramType = method.getGenericParameterTypes()[pm.getIndex()];
                     if (jaxbOnly) {
-                        checkJaxbType(inType, paramType, types);
+                        checkJaxbType(inType, paramType, types, 
+                                      method.getParameterAnnotations()[pm.getIndex()]);
                     } else {
-                        types.put(inType, paramType);
+                        types.getAllTypes().put(inType, paramType);
                     }
                     
                 }
@@ -524,18 +530,28 @@ public final class ResourceUtils {
         }
     }
     
-    private static void checkJaxbType(Class<?> type, Type genericType, Map<Class<?>,
Type> types) {
+    private static void checkJaxbType(Class<?> type, 
+                                      Type genericType, 
+                                      ResourceTypes types,
+                                      Annotation[] anns) {
+        if (InjectionUtils.isSupportedCollectionOrArray(type)) {
+            type = InjectionUtils.getActualType(genericType);
+            XMLName name = AnnotationUtils.getAnnotation(anns, XMLName.class);
+            if (name != null) {
+                types.getCollectionMap().put(type, JAXRSUtils.convertStringToQName(name.value()));
+            }
+        }
         JAXBElementProvider<?> provider = new JAXBElementProvider<Object>();
         if (type != null 
             && !InjectionUtils.isPrimitive(type) 
             && !JAXBElement.class.isAssignableFrom(type)
             && provider.isReadable(type, type, new Annotation[0], MediaType.APPLICATION_XML_TYPE))
{
-            types.put(type, type);
+            types.getAllTypes().put(type, type);
             
             Class<?> genCls = InjectionUtils.getActualType(genericType);
             if (genCls != type && genCls instanceof Class && genCls != Object.class

                 && !InjectionUtils.isSupportedCollectionOrArray(genCls)) {
-                types.put(genCls, genCls);
+                types.getAllTypes().put(genCls, genCls);
             }
         }
     }

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=1354002&r1=1354001&r2=1354002&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
Tue Jun 26 13:12:12 2012
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.jaxrs.model.wadl;
 
+import java.util.Collections;
 import java.util.List;
 
 import javax.ws.rs.Consumes;
@@ -58,6 +59,13 @@ public class BookStore {
     }
     
     @GET 
+    @Produces("application/xml")
+    @XMLName("{http://superbooks}books")
+    public List<Book> getBooks() {
+        return Collections.emptyList();
+    }
+    
+    @GET 
     @Produces("text/plain")
     public String getName(@PathParam("id") Long id, @QueryParam("") QueryBean query) {
         return "store";

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=1354002&r1=1354001&r2=1354002&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
Tue Jun 26 13:12:12 2012
@@ -38,6 +38,7 @@ import javax.xml.bind.annotation.XmlRoot
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.common.xmlschema.XmlSchemaConstants;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.jaxrs.JAXRSServiceImpl;
@@ -211,7 +212,7 @@ public class WadlGeneratorTest extends A
         checkResponse(r);
         Document doc = DOMUtils.readXml(new StringReader(r.getEntity().toString()));
         checkDocs(doc.getDocumentElement(), "My Application", "", "");
-        checkGrammars(doc.getDocumentElement(), "thebook", "thebook2", "thechapter");
+        checkGrammars(doc.getDocumentElement(), "thebook", "books", "thebook2", "thechapter");
         List<Element> els = getWadlResourcesInfo(doc, "http://localhost:8080/baz",
1);
         checkBookStoreInfo(els.get(0), "ns1:thebook", "ns1:thebook2", "ns1:thechapter");
     }
@@ -301,14 +302,24 @@ public class WadlGeneratorTest extends A
                      r.getMetadata().getFirst(HttpHeaders.CONTENT_TYPE));
         String wadl = r.getEntity().toString();
         Document doc = DOMUtils.readXml(new StringReader(wadl));
-        checkGrammars(doc.getDocumentElement(), "thebook", "thebook2", "thechapter");
+        checkGrammars(doc.getDocumentElement(), "thebook", "books", "thebook2", "thechapter");
         List<Element> els = getWadlResourcesInfo(doc, "http://localhost:8080/baz",
2);
         checkBookStoreInfo(els.get(0), "prefix1:thebook", "prefix1:thebook2", "prefix1:thechapter");
         Element orderResource = els.get(1);
         assertEquals("/orders", orderResource.getAttribute("path"));
     }
 
-    private void checkGrammars(Element appElement, String bookEl, String book2El, String
chapterEl) {
+    private void checkGrammars(Element appElement, 
+                               String bookEl,
+                               String book2El, 
+                               String chapterEl) {
+        checkGrammars(appElement, bookEl, null, book2El, chapterEl);
+    }
+    private void checkGrammars(Element appElement, 
+                               String bookEl,
+                               String booksEl,
+                               String book2El,
+                               String chapterEl) {
         List<Element> grammarEls = DOMUtils.getChildrenWithName(appElement, WadlGenerator.WADL_NS,

                                                                 "grammars");
         assertEquals(1, grammarEls.size());
@@ -320,14 +331,21 @@ public class WadlGeneratorTest extends A
                             XmlSchemaConstants.XSD_NAMESPACE_URI, "element");
         
         int size = book2El == null ? 2 : 3;
+        int elementSize = size;
+        if (booksEl != null) {
+            elementSize++;
+        }
         
-        assertEquals(size, elementEls.size());
+        assertEquals(elementSize, elementEls.size());
         
         assertTrue(checkElement(elementEls, bookEl, "book"));
         if (book2El != null) {
             assertTrue(checkElement(elementEls, book2El, "book2"));
         }
         assertTrue(checkElement(elementEls, chapterEl, "chapter"));
+        if (booksEl != null) {
+            assertTrue(checkElement(elementEls, booksEl, "books"));
+        }
         
         List<Element> complexTypesEls = DOMUtils.getChildrenWithName(schemasEls.get(0),

                                         XmlSchemaConstants.XSD_NAMESPACE_URI, "complexType");
@@ -370,18 +388,38 @@ public class WadlGeneratorTest extends A
         for (Element e : els) {
             if (name.equals(e.getAttribute("name"))) {
                 String type = e.getAttribute("type");
-                
-                String expectedType1 = "tns:" + localTypeName;
-                String expectedType2 = "os:" + localTypeName;
-                if (type.equals(expectedType1) || type.equals(expectedType2)) {
-                    return true;
+                if (!StringUtils.isEmpty(type)) {
+                    String expectedType1 = "tns:" + localTypeName;
+                    String expectedType2 = "os:" + localTypeName;
+                    if (type.equals(expectedType1) || type.equals(expectedType2)) {
+                        return true;
+                    }
+                } else if ("books".equals(name)) {
+                    Element ctElement = 
+                        (Element)e.getElementsByTagNameNS(XmlSchemaConstants.XSD_NAMESPACE_URI,

+                                                          "complexType").item(0);
+                    Element seqElement = 
+                        (Element)ctElement.getElementsByTagNameNS(XmlSchemaConstants.XSD_NAMESPACE_URI,

+                                                          "sequence").item(0);
+                    Element xsElement = 
+                        (Element)seqElement.getElementsByTagNameNS(XmlSchemaConstants.XSD_NAMESPACE_URI,

+                                                          "element").item(0);
+                    String ref = xsElement.getAttribute("ref");
+                    String expectedRef = "tns:thebook";
+                    String expectedRef2 = "os:thebook";
+                    if (ref.equals(expectedRef) || ref.equals(expectedRef2)) {
+                        return true;
+                    }
                 }
             }
         }
         return false;
     }
     
-    private void checkBookStoreInfo(Element resource, String bookEl, String book2El, String
chapterEl) {
+    private void checkBookStoreInfo(Element resource, 
+                                    String bookEl, 
+                                    String book2El, 
+                                    String chapterEl) {
         assertEquals("/bookstore/{id}", resource.getAttribute("path"));
         
         checkDocs(resource, "book store resource", "super resource", "en-us");
@@ -401,10 +439,10 @@ public class WadlGeneratorTest extends A
         // must have a single template parameter
         verifyParameters(resource, 1, new Param("id", "template", "xs:long"));
         
-        // must have 3 methods, GET, POST and PUT
-        List<Element> methodEls = getElements(resource, "method", 3);
+        // must have 4 methods, 2 GETs, POST and PUT
+        List<Element> methodEls = getElements(resource, "method", 4);
         
-        // verify GET
+        // verify 1st GET
         assertEquals("GET", methodEls.get(0).getAttribute("name"));
         assertEquals(0, DOMUtils.getChildrenWithName(methodEls.get(0), 
                         WadlGenerator.WADL_NS, "param").size());
@@ -424,16 +462,19 @@ public class WadlGeneratorTest extends A
         //check response
         verifyRepresentation(methodEls.get(0), "response", "text/plain", "");
         
+        // verify 2nd GET
+        assertEquals("GET", methodEls.get(1).getAttribute("name"));
+        
         // verify POST
-        assertEquals("POST", methodEls.get(1).getAttribute("name"));
-        Element formRep = verifyRepresentation(methodEls.get(1), "request", "multipart/form-data",
"");
+        assertEquals("POST", methodEls.get(2).getAttribute("name"));
+        Element formRep = verifyRepresentation(methodEls.get(2), "request", "multipart/form-data",
"");
         checkDocs(formRep, "", "Attachments", "");
         
         // verify PUT
-        assertEquals("PUT", methodEls.get(2).getAttribute("name"));
-        verifyRepresentation(methodEls.get(2), "request", "text/plain", "");
+        assertEquals("PUT", methodEls.get(3).getAttribute("name"));
+        verifyRepresentation(methodEls.get(3), "request", "text/plain", "");
         
-        verifyResponseWithStatus(methodEls.get(2), "204");
+        verifyResponseWithStatus(methodEls.get(3), "204");
         
         // verify resource starting with /book2
         verifyGetResourceMethod(resourceEls.get(0), book2El, null);

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java?rev=1354002&r1=1354001&r2=1354002&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
Tue Jun 26 13:12:12 2012
@@ -144,6 +144,8 @@ public class JAXBElementProviderTest ext
         assertNotNull(bookContext);
         JAXBContext superBookContext = provider.getJAXBContext(SuperBook.class, SuperBook.class);
         assertSame(bookContext, superBookContext);
+        JAXBContext book2Context = provider.getJAXBContext(Book2.class, Book2.class);
+        assertSame(bookContext, book2Context);
     }
     
     @Test
@@ -1466,6 +1468,12 @@ public class JAXBElementProviderTest ext
         public SuperBook getSuperBook() {
             return null;
         }
+        
+        @GET
+        public List<Book2> getBook2() {
+            return null;
+        }
+        
     }
     
     @XmlRootElement(name = "list")

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java?rev=1354002&r1=1354001&r2=1354002&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java
Tue Jun 26 13:12:12 2012
@@ -111,7 +111,8 @@ public class ResourceUtilsTest extends A
         ClassResourceInfo cri1 = 
             ResourceUtils.createClassResourceInfo(BookInterface.class, BookInterface.class,
true, true);
         Map<Class<?>, Type> types = 
-            ResourceUtils.getAllRequestResponseTypes(Collections.singletonList(cri1), true);
+            ResourceUtils.getAllRequestResponseTypes(Collections.singletonList(cri1), true)
+                .getAllTypes();
         assertEquals(2, types.size());
         assertTrue(types.containsKey(Book.class));
         assertTrue(types.containsKey(Chapter.class));



Mime
View raw message