You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2004/03/27 12:47:55 UTC
cvs commit: ws-axis/java/test/wsdl/extensibility ExtensibilityQueryBindingImpl.java ExtensibilityQueryTestCase.java QueryTypes.wsdl
dims 2004/03/27 03:47:55
Modified: java/src/org/apache/axis/wsdl/symbolTable SchemaUtils.java
java/src/org/apache/axis/wsdl/toJava JavaBeanWriter.java
java/test/wsdl/extensibility
ExtensibilityQueryBindingImpl.java
ExtensibilityQueryTestCase.java QueryTypes.wsdl
Log:
Fix for AXIS-1269 - Improvement to mixed=true code generation
from Jarek Gawor
Revision Changes Path
1.39 +29 -0 ws-axis/java/src/org/apache/axis/wsdl/symbolTable/SchemaUtils.java
Index: SchemaUtils.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/symbolTable/SchemaUtils.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- SchemaUtils.java 24 Mar 2004 17:36:37 -0000 1.38
+++ SchemaUtils.java 27 Mar 2004 11:47:55 -0000 1.39
@@ -20,6 +20,7 @@
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.w3c.dom.Element;
import javax.xml.namespace.QName;
import javax.xml.rpc.holders.BooleanHolder;
@@ -39,6 +40,34 @@
/** Field VALUE_QNAME */
static final QName VALUE_QNAME = Utils.findQName("", "value");
+
+ /**
+ * This method checks mixed=true attribute is set either on
+ * complexType or complexContent element.
+ */
+ public static boolean isMixed(Node node) {
+ // Expecting a schema complexType
+ if (isXSDNode(node, "complexType")) {
+ String mixed = ((Element)node).getAttribute("mixed");
+ if (mixed != null && mixed.length() > 0) {
+ return ("true".equalsIgnoreCase(mixed) ||
+ "1".equals(mixed));
+ }
+ // Under the complexType there could be complexContent with
+ // mixed="true"
+ NodeList children = node.getChildNodes();
+
+ for (int j = 0; j < children.getLength(); j++) {
+ Node kid = children.item(j);
+ if (isXSDNode(kid, "complexContent")) {
+ mixed = ((Element)kid).getAttribute("mixed");
+ return ("true".equalsIgnoreCase(mixed) ||
+ "1".equals(mixed));
+ }
+ }
+ }
+ return false;
+ }
/**
* This method checks out if the given node satisfies the 3rd condition
1.60 +8 -13 ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanWriter.java
Index: JavaBeanWriter.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanWriter.java,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -r1.59 -r1.60
--- JavaBeanWriter.java 25 Mar 2004 10:36:38 -0000 1.59
+++ JavaBeanWriter.java 27 Mar 2004 11:47:55 -0000 1.60
@@ -290,18 +290,13 @@
}
}
- if (!type.isSimpleType()) {
- Node node = type.getNode();
- String mixed = ((Element)node).getAttribute("mixed");
- if ("true".equalsIgnoreCase(mixed) ||
- "1".equals(mixed)) {
- isMixed = true;
- if (!isAny) {
- names.add("org.apache.axis.message.MessageElement []");
- names.add(Constants.ANYCONTENT);
- }
- }
- }
+ if (enableMemberFields && SchemaUtils.isMixed(type.getNode())) {
+ isMixed = true;
+ if (!isAny) {
+ names.add("org.apache.axis.message.MessageElement []");
+ names.add(Constants.ANYCONTENT);
+ }
+ }
// Add attribute names
if (attributes != null) {
@@ -423,7 +418,7 @@
implementsText += ", org.apache.axis.encoding.AnyContentType";
}
- if (isMixed) {
+ if (isMixed) {
implementsText += ", org.apache.axis.encoding.MixedContentType";
}
1.20 +46 -46 ws-axis/java/test/wsdl/extensibility/ExtensibilityQueryBindingImpl.java
Index: ExtensibilityQueryBindingImpl.java
===================================================================
RCS file: /home/cvs/ws-axis/java/test/wsdl/extensibility/ExtensibilityQueryBindingImpl.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- ExtensibilityQueryBindingImpl.java 24 Mar 2004 19:44:58 -0000 1.19
+++ ExtensibilityQueryBindingImpl.java 27 Mar 2004 11:47:55 -0000 1.20
@@ -83,56 +83,56 @@
}
public ExtensibilityType mixedQuery(ExtensibilityType query)
- throws RemoteException {
- MessageElement [] elements = query.get_any();
- if (elements == null) {
- throw new RemoteException("No any");
- }
- if (elements.length != 3) {
- throw new RemoteException("Expected: 3 got: " + elements.length +
- " element");
- }
-
- String expected = "123 456";
- String received = elements[0].toString();
-
- if (!expected.equals(received)) {
- throw new RemoteException("Expected: " + expected +
- " received: " + received);
- }
-
- Object obj = null;
+ throws RemoteException {
+ MessageElement [] elements = query.get_any();
+ if (elements == null) {
+ throw new RemoteException("No any");
+ }
+ if (elements.length != 3) {
+ throw new RemoteException("Expected: 3 got: " + elements.length +
+ " element");
+ }
+
+ String expected = "123 456";
+ String received = elements[0].toString();
+
+ if (!expected.equals(received)) {
+ throw new RemoteException("Expected: " + expected +
+ " received: " + received);
+ }
+
+ Object obj = null;
try {
obj = elements[1].getObjectValue(BookType.class);
} catch (Exception e) {
throw new RemoteException("Failed to deserialize", e);
}
- BookType bookQuery = (BookType)obj;
- String subject = bookQuery.getSubject();
- if (!"all".equals(subject)) {
- throw new RemoteException("ExtensibilityQueryBindingImpl: Book subject query should be all, instead was " + subject);
- }
-
- expected = "789";
- received = elements[2].toString();
-
- if (!expected.equals(received)) {
- throw new RemoteException("Expected: " + expected +
- " received: " + received);
- }
-
- ExtensibilityType reply = new ExtensibilityType();
-
- MessageElement [] replyElements = new MessageElement[2];
-
- BookType book = new BookType();
- book.setSubject("gotAll");
- QName elementName = _FindBooksQueryExpressionElement.getTypeDesc().getFields()[0].getXmlName();
- replyElements[0] = new MessageElement(elementName.getNamespaceURI(), elementName.getLocalPart(), book);
- replyElements[1] = new Text("ABCD");
-
- reply.set_any(replyElements);
-
- return reply;
+ BookType bookQuery = (BookType)obj;
+ String subject = bookQuery.getSubject();
+ if (!"all".equals(subject)) {
+ throw new RemoteException("ExtensibilityQueryBindingImpl: Book subject query should be all, instead was " + subject);
+ }
+
+ expected = "789";
+ received = elements[2].toString();
+
+ if (!expected.equals(received)) {
+ throw new RemoteException("Expected: " + expected +
+ " received: " + received);
+ }
+
+ ExtensibilityType reply = new ExtensibilityType();
+
+ MessageElement [] replyElements = new MessageElement[2];
+
+ BookType book = new BookType();
+ book.setSubject("gotAll");
+ QName elementName = _FindBooksQueryExpressionElement.getTypeDesc().getFields()[0].getXmlName();
+ replyElements[0] = new MessageElement(elementName.getNamespaceURI(), elementName.getLocalPart(), book);
+ replyElements[1] = new Text("ABCD");
+
+ reply.set_any(replyElements);
+
+ return reply;
}
}
1.22 +53 -42 ws-axis/java/test/wsdl/extensibility/ExtensibilityQueryTestCase.java
Index: ExtensibilityQueryTestCase.java
===================================================================
RCS file: /home/cvs/ws-axis/java/test/wsdl/extensibility/ExtensibilityQueryTestCase.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- ExtensibilityQueryTestCase.java 24 Mar 2004 19:44:58 -0000 1.21
+++ ExtensibilityQueryTestCase.java 27 Mar 2004 11:47:55 -0000 1.22
@@ -28,7 +28,7 @@
public ExtensibilityQueryTestCase(String name) {
super(name);
}
-
+
public void testExtensibilityQueryPortWSDL() throws Exception {
javax.xml.rpc.ServiceFactory serviceFactory = javax.xml.rpc.ServiceFactory.newInstance();
java.net.URL url = new java.net.URL(new test.wsdl.extensibility.ExtensibilityQueryLocator().getExtensibilityQueryPortAddress() + "?WSDL");
@@ -91,57 +91,57 @@
throw new junit.framework.AssertionFailedError("Binding initialization Exception caught: " + e);
}
assertTrue("binding is null", binding != null);
-
+
try {
- ExtensibilityType expression = new ExtensibilityType();
-
- MessageElement [] elements = new MessageElement[4];
-
+ ExtensibilityType expression = new ExtensibilityType();
+
+ MessageElement [] elements = new MessageElement[4];
+
elements[0] = new Text("123");
- elements[1] = new Text(" 456");
-
+ elements[1] = new Text(" 456");
+
BookType book = new BookType();
book.setSubject("all");
QName elementName = _FindBooksQueryExpressionElement.getTypeDesc().getFields()[0].getXmlName();
elements[2] = new MessageElement(elementName.getNamespaceURI(), elementName.getLocalPart(), book);
-
- elements[3] = new Text("789");
-
+
+ elements[3] = new Text("789");
+
expression.set_any(elements);
-
+
// call the operation
ExtensibilityType any = binding.mixedQuery(expression);
-
- if (any == null) {
- throw new Exception("No output returned");
- }
-
- // validate results
+
+ if (any == null) {
+ throw new Exception("No output returned");
+ }
+
+ // validate results
MessageElement [] anyContent = any.get_any();
-
- if (anyContent == null) {
- throw new Exception("No any");
- }
- if (anyContent.length != 2) {
- throw new Exception("Expected: 2 got: " +
- anyContent.length + " element");
- }
-
- Object obj = anyContent[0].getObjectValue(BookType.class);
- BookType bookQuery = (BookType)obj;
- String subject = bookQuery.getSubject();
- if (!"gotAll".equals(subject)) {
- throw new Exception("Book subject query reply should be gotAll, instead was " + subject);
- }
-
- String expected = "ABCD";
- String received = anyContent[1].toString();
-
- if (!expected.equals(received)) {
- throw new Exception("Expected: " + expected +
- " received: " + received);
- }
-
+
+ if (anyContent == null) {
+ throw new Exception("No any");
+ }
+ if (anyContent.length != 2) {
+ throw new Exception("Expected: 2 got: " +
+ anyContent.length + " element");
+ }
+
+ Object obj = anyContent[0].getObjectValue(BookType.class);
+ BookType bookQuery = (BookType)obj;
+ String subject = bookQuery.getSubject();
+ if (!"gotAll".equals(subject)) {
+ throw new Exception("Book subject query reply should be gotAll, instead was " + subject);
+ }
+
+ String expected = "ABCD";
+ String received = anyContent[1].toString();
+
+ if (!expected.equals(received)) {
+ throw new Exception("Expected: " + expected +
+ " received: " + received);
+ }
+
}
catch (Exception e) {
e.printStackTrace();
@@ -185,5 +185,16 @@
assertTrue("Unable to deploy " + INPUT_FILE + ". ERROR: " + e, false);
}
}
+
+ public void testMixedType() {
+ MixedType1 t1 = new MixedType1();
+ assertTrue(t1 instanceof org.apache.axis.encoding.MixedContentType);
+ // restriction cases
+ MixedType2 t2 = new MixedType2();
+ assertFalse(t2 instanceof org.apache.axis.encoding.MixedContentType);
+ MixedType3 t3 = new MixedType3();
+ assertFalse(t3 instanceof org.apache.axis.encoding.MixedContentType);
+ }
+
}
1.4 +18 -0 ws-axis/java/test/wsdl/extensibility/QueryTypes.wsdl
Index: QueryTypes.wsdl
===================================================================
RCS file: /home/cvs/ws-axis/java/test/wsdl/extensibility/QueryTypes.wsdl,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- QueryTypes.wsdl 18 Jun 2003 23:01:52 -0000 1.3
+++ QueryTypes.wsdl 27 Mar 2004 11:47:55 -0000 1.4
@@ -15,6 +15,24 @@
</xsd:complexType>
</xsd:element>
+ <xsd:complexType name="MixedType1" mixed="1">
+ <xsd:complexContent>
+ <xsd:extension base="tns:BookType"/>
+ </xsd:complexContent>
+ </xsd:complexType>
+
+ <xsd:complexType name="MixedType2" mixed="1">
+ <xsd:complexContent>
+ <xsd:restriction base="tns:BookType"/>
+ </xsd:complexContent>
+ </xsd:complexType>
+
+ <xsd:complexType name="MixedType3">
+ <xsd:complexContent mixed="true">
+ <xsd:restriction base="tns:BookType"/>
+ </xsd:complexContent>
+ </xsd:complexType>
+
<xsd:element name="QueryResultElement">
<xsd:complexType>
<xsd:sequence>