Author: ema
Date: Thu Nov 22 22:17:56 2007
New Revision: 597566
URL: http://svn.apache.org/viewvc?rev=597566&view=rev
Log:
[CXF-1177]Generate xsd:list schema type for a parameter annotated with XmlList
Added:
incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/xmllist/
incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/xmllist/AddNumberImpl.java
incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/xmllist/AddNumbersPortType.java
Modified:
incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2ws/JavaToWSTest.java
Modified:
incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java?rev=597566&r1=597565&r2=597566&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
(original)
+++
incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
Thu Nov 22 22:17:56 2007
@@ -42,6 +42,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.xml.bind.annotation.XmlList;
import javax.xml.bind.annotation.XmlMimeType;
import javax.xml.namespace.QName;
import javax.xml.ws.Holder;
@@ -94,6 +95,8 @@
import org.apache.ws.commons.schema.XmlSchemaObject;
import org.apache.ws.commons.schema.XmlSchemaObjectTable;
import org.apache.ws.commons.schema.XmlSchemaSequence;
+import org.apache.ws.commons.schema.XmlSchemaSimpleType;
+import org.apache.ws.commons.schema.XmlSchemaSimpleTypeList;
import org.apache.ws.commons.schema.XmlSchemaType;
import org.apache.ws.commons.schema.constants.Constants;
import org.apache.ws.commons.schema.utils.NamespaceMap;
@@ -842,7 +845,7 @@
}
- private void createWrappedMessageSchema(ServiceInfo serviceInfo,
+ private void createWrappedMessageSchema(ServiceInfo serviceInfo,
AbstractMessageContainer
wrappedMessage,
AbstractMessageContainer
unwrappedMessage,
XmlSchema schema,
@@ -876,12 +879,13 @@
addImport(schema, mpi.getElementQName().getNamespaceURI());
el.setRefName(mpi.getElementQName());
} else {
- if (mpi.getTypeQName() != null) {
+ if (mpi.getTypeQName() != null && !existXmlListAnno(mpi)) {
el.setSchemaTypeName(mpi.getTypeQName());
addImport(schema, mpi.getTypeQName().getNamespaceURI());
}
-
+
el.setSchemaType((XmlSchemaType)mpi.getXmlSchema());
+
if
(schema.getElementFormDefault().getValue().equals(XmlSchemaForm.UNQUALIFIED)) {
mpi.setConcreteName(new QName(null,
mpi.getName().getLocalPart()));
} else {
@@ -896,9 +900,8 @@
mpi.setElementQName(el.getQName());
mpi.setConcreteName(concreteName);
}
- mpi.setXmlSchema(el);
- addMimeType(el, getMethodParameterAnnotations(mpi));
+ addMimeType(el, getMethodParameterAnnotations(mpi));
Annotation[] methodAnnotations = getMethodAnnotations(mpi);
if (methodAnnotations != null) {
addMimeType(el, methodAnnotations);
@@ -906,19 +909,19 @@
if (mpi.getTypeClass() != null && mpi.getTypeClass().isArray()
&&
!Byte.TYPE.equals(mpi.getTypeClass().getComponentType())) {
- String min = (String)mpi.getProperty("minOccurs");
- String max = (String)mpi.getProperty("maxOccurs");
- if (min == null) {
- min = "0";
- }
- if (max == null) {
- max = "unbounded";
- }
- el.setMinOccurs(Long.parseLong(min));
- el.setMaxOccurs("unbounded".equals(max) ? Long.MAX_VALUE :
Long.parseLong(max));
- Boolean b = (Boolean)mpi.getProperty("nillable");
- if (b != null && b.booleanValue()) {
- el.setNillable(b.booleanValue());
+ if (existXmlListAnno(mpi)) {
+ setSimpleTypeList(schema, el, mpi);
+ } else {
+ String min = (String)mpi.getProperty("minOccurs");
+ String max = (String)mpi.getProperty("maxOccurs");
+ min = min == null ? "0" : min;
+ max = max == null ? "unbounded" : max;
+ el.setMinOccurs(Long.parseLong(min));
+ el.setMaxOccurs("unbounded".equals(max) ?
Long.MAX_VALUE : Long.parseLong(max));
+ Boolean b = (Boolean)mpi.getProperty("nillable");
+ if (b != null && b.booleanValue()) {
+ el.setNillable(b.booleanValue());
+ }
}
} else if
(Collection.class.isAssignableFrom(mpi.getTypeClass())
&& mpi.getTypeClass().isInterface()) {
@@ -938,6 +941,7 @@
}
}
seq.getItems().add(el);
+ mpi.setXmlSchema(el);
}
if (Boolean.TRUE.equals(mpi.getProperty(HEADER))) {
QName qn = (QName)mpi.getProperty(ELEMENT_NAME);
@@ -981,6 +985,30 @@
}
}
+ private boolean existXmlListAnno(MessagePartInfo mpi) {
+ Annotation[] anns = getMethodParameterAnnotations(mpi);
+ if (anns != null) {
+ for (Annotation anno : anns) {
+ if (anno instanceof XmlList) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private void setSimpleTypeList(XmlSchema schema, XmlSchemaElement el,
MessagePartInfo mpi) {
+ XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType(schema);
+ XmlSchemaSimpleTypeList simpleList = new XmlSchemaSimpleTypeList();
+ if (mpi.getXmlSchema() instanceof XmlSchemaType) {
+ XmlSchemaType type = (XmlSchemaType)mpi.getXmlSchema();
+ simpleList.setItemTypeName(type.getQName());
+ } else {
+ simpleList.setItemTypeName(mpi.getTypeQName());
+ }
+ simpleType.setContent(simpleList);
+ el.setSchemaType(simpleType);
+ }
private SchemaInfo getOrCreateSchema(ServiceInfo serviceInfo,
String namespaceURI,
Added:
incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/xmllist/AddNumberImpl.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/xmllist/AddNumberImpl.java?rev=597566&view=auto
==============================================================================
---
incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/xmllist/AddNumberImpl.java
(added)
+++
incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/xmllist/AddNumberImpl.java
Thu Nov 22 22:17:56 2007
@@ -0,0 +1,30 @@
+/**
+ * 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.tools.fortest.xmllist;
+
+import java.util.List;
+
+import javax.jws.WebService;
[EMAIL PROTECTED](endpointInterface =
"org.apache.cxf.tools.fortest.xmllist.AddNumbersPortType")
+public class AddNumberImpl implements AddNumbersPortType {
+ public List<Integer> addNumbers(List<String> arg) {
+ return null;
+ }
+
+}
Added:
incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/xmllist/AddNumbersPortType.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/xmllist/AddNumbersPortType.java?rev=597566&view=auto
==============================================================================
---
incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/xmllist/AddNumbersPortType.java
(added)
+++
incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/xmllist/AddNumbersPortType.java
Thu Nov 22 22:17:56 2007
@@ -0,0 +1,51 @@
+/**
+ * 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.tools.fortest.xmllist;
+
+import java.util.List;
+
+import javax.jws.WebMethod;
+import javax.jws.WebParam;
+import javax.jws.WebResult;
+import javax.jws.WebService;
+import javax.xml.bind.annotation.XmlList;
+import javax.xml.ws.RequestWrapper;
+import javax.xml.ws.ResponseWrapper;
+
+
[EMAIL PROTECTED](name = "AddNumbersPortType", targetNamespace =
"http://apache.org/xmllist")
+public interface AddNumbersPortType {
+
+
+ /**
+ *
+ * @param arg
+ * @return
+ * returns java.util.List<java.lang.Integer>
+ */
+ @WebMethod
+ @WebResult(name = "arg0", targetNamespace = "http://apache.org/xmllist")
+ @RequestWrapper(localName = "addNumbers", targetNamespace =
"http://apache.org/xmllist")
+ @ResponseWrapper(localName = "addNumbersResponse", targetNamespace =
"http://apache.org/xmllist")
+ List<Integer> addNumbers(
+ @WebParam(name = "arg", targetNamespace = "http://apache.org/xmllist")
+ @XmlList
+ List<String> arg);
+
+}
Modified:
incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2ws/JavaToWSTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2ws/JavaToWSTest.java?rev=597566&r1=597565&r2=597566&view=diff
==============================================================================
---
incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2ws/JavaToWSTest.java
(original)
+++
incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2ws/JavaToWSTest.java
Thu Nov 22 22:17:56 2007
@@ -242,7 +242,20 @@
File server =
outputFile("org/apache/cxf/tools/fortest/GreeterImpl_PortTypeServer.java");
assertTrue("Failed to generate SEI file :
GreeterImpl_PortTypeServer.java", server.exists());
}
+
+ @Test
+ public void testXmlList() throws Exception {
+ String[] args = new String[] {"-o", output.getPath() +
"/xml-list.wsdl", "-verbose",
+ "-wsdl",
"org.apache.cxf.tools.fortest.xmllist.AddNumbersPortType"};
+ JavaToWS.main(args);
+ File file = new File(output.getPath() + "/xml-list.wsdl");
+ String str = FileUtils.getStringFromFile(file);
+ assertTrue("Java2wsdl did not generate xsd:list element",
+ str.indexOf("<xsd:list itemType=") > -1);
+
+ }
+
protected String getClassPath() throws URISyntaxException {
ClassLoader loader = getClass().getClassLoader();
StringBuffer classPath = new StringBuffer();