You are viewing a plain text version of this content. The canonical link for it is here.
Posted to yoko-commits@incubator.apache.org by en...@apache.org on 2006/08/31 11:29:22 UTC
svn commit: r438866 - in /incubator/yoko/trunk/tools/src:
main/java/org/apache/yoko/tools/processors/idl/
test/java/org/apache/yoko/tools/processors/ test/resources/idl/
Author: enolan
Date: Thu Aug 31 04:29:21 2006
New Revision: 438866
URL: http://svn.apache.org/viewvc?rev=438866&view=rev
Log:
Yoko-127 applying Matteo's patch for adding support for IDL union type to IDLToWSDL tool.
Added:
incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/UnionVisitor.java (with props)
incubator/yoko/trunk/tools/src/test/resources/idl/Union.idl
incubator/yoko/trunk/tools/src/test/resources/idl/expected_Union.wsdl (with props)
Modified:
incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/PortTypeVisitor.java
incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/TypesVisitor.java
incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/IDLToWSDLGenerationTest.java
Modified: incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/PortTypeVisitor.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/PortTypeVisitor.java?rev=438866&r1=438865&r2=438866&view=diff
==============================================================================
--- incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/PortTypeVisitor.java (original)
+++ incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/PortTypeVisitor.java Thu Aug 31 04:29:21 2006
@@ -79,6 +79,7 @@
case IDLTokenTypes.LITERAL_exception:
case IDLTokenTypes.LITERAL_const:
case IDLTokenTypes.LITERAL_enum:
+ case IDLTokenTypes.LITERAL_union:
typesVisitor.visit(node2);
break;
default:
Modified: incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/TypesVisitor.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/TypesVisitor.java?rev=438866&r1=438865&r2=438866&view=diff
==============================================================================
--- incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/TypesVisitor.java (original)
+++ incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/TypesVisitor.java Thu Aug 31 04:29:21 2006
@@ -173,6 +173,10 @@
EnumVisitor enumVisitor = new EnumVisitor(schemas, schema, typeMap);
enumVisitor.visit(node);
break;
+ case IDLTokenTypes.LITERAL_union:
+ UnionVisitor unionVisitor = new UnionVisitor(schemas, schema, typeMap);
+ unionVisitor.visit(node);
+ break;
case IDLTokenTypes.IDENT: {
XmlSchemaType stype = TypesUtils.findType(schemas, schema, node);
if (currentType instanceof XmlSchemaElement) {
Added: incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/UnionVisitor.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/UnionVisitor.java?rev=438866&view=auto
==============================================================================
--- incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/UnionVisitor.java (added)
+++ incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/UnionVisitor.java Thu Aug 31 04:29:21 2006
@@ -0,0 +1,166 @@
+/**
+ * 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.yoko.tools.processors.idl;
+
+import javax.xml.namespace.QName;
+
+import antlr.collections.AST;
+
+import org.apache.schemas.yoko.bindings.corba.CaseType;
+import org.apache.schemas.yoko.bindings.corba.TypeMappingType;
+import org.apache.schemas.yoko.bindings.corba.Union;
+import org.apache.schemas.yoko.bindings.corba.Unionbranch;
+
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaChoice;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaComplexType;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaSequence;
+import org.apache.ws.commons.schema.XmlSchemaType;
+
+import org.apache.yoko.tools.common.CORBAConstants;
+
+public class UnionVisitor extends TypesVisitorBase {
+
+ private final String discriminator = "discriminator";
+
+ public UnionVisitor(XmlSchemaCollection xmlSchemas,
+ XmlSchema xmlSchema,
+ TypeMappingType typeMappingType) {
+ super(xmlSchemas, xmlSchema, typeMappingType);
+ }
+
+ public void visit(AST unionNode) {
+ AST identifierNode = unionNode.getFirstChild();
+ AST discriminatorNode = identifierNode.getNextSibling();
+ AST caseNode = discriminatorNode.getNextSibling();
+
+ // xmlschema:union
+ XmlSchemaComplexType unionSchemaComplexType = new XmlSchemaComplexType(schema);
+ XmlSchemaSequence sequence = new XmlSchemaSequence();
+ unionSchemaComplexType.setName(identifierNode.toString());
+ unionSchemaComplexType.setParticle(sequence);
+
+ XmlSchemaElement discriminatorElement = new XmlSchemaElement();
+ XmlSchemaType type = TypesUtils.findType(schemas, schema, discriminatorNode);
+ discriminatorElement.setName(discriminator);
+ discriminatorElement.setSchemaTypeName(type.getQName());
+ discriminatorElement.setMinOccurs(1);
+ discriminatorElement.setMaxOccurs(1);
+ sequence.getItems().add(discriminatorElement);
+
+ XmlSchemaChoice choice = new XmlSchemaChoice();
+ choice.setMinOccurs(0);
+ choice.setMaxOccurs(1);
+ sequence.getItems().add(choice);
+
+
+ // corba:union
+ Union corbaUnion = new Union();
+ corbaUnion.setQName(new QName(typeMap.getTargetNamespace(), identifierNode.toString()));
+ corbaUnion.setRepositoryID(CORBAConstants.REPO_STRING
+ + identifierNode.toString()
+ + CORBAConstants.IDL_VERSION);
+ corbaUnion.setType(unionSchemaComplexType.getQName());
+ corbaUnion.setDiscriminator(TypesUtils.findCorbaType(typeMap, type.getQName()).getQName());
+
+ processCaseNodes(caseNode, choice, corbaUnion);
+
+
+ // add xmlschema:union
+ schema.getItems().add(unionSchemaComplexType);
+ schema.addType(unionSchemaComplexType);
+
+ // add corba:union
+ typeMap.getStructOrExceptionOrUnion().add(corbaUnion);
+ }
+
+ private void processCaseNodes(AST caseNode,
+ XmlSchemaChoice choice,
+ Union corbaUnion) {
+ while (caseNode != null) {
+ AST typeNode = null;
+ AST nameNode = null;
+ AST labelNode = null;
+
+ // xmlschema:element
+ XmlSchemaElement element = new XmlSchemaElement();
+
+ // corba:unionbranch
+ Unionbranch unionBranch = new Unionbranch();
+
+ if (caseNode.getType() == IDLTokenTypes.LITERAL_default) {
+ // default:
+ unionBranch.setDefault(true);
+
+ typeNode = caseNode.getFirstChild();
+ nameNode = typeNode.getNextSibling();
+ } else {
+ // case:
+ createCase(caseNode, unionBranch);
+
+ labelNode = caseNode.getFirstChild();
+ if (labelNode.getType() == IDLTokenTypes.LITERAL_case) {
+ labelNode = labelNode.getNextSibling();
+ }
+
+ typeNode = labelNode.getNextSibling();
+ nameNode = typeNode.getNextSibling();
+ }
+
+ // xmlschema:element
+ element.setName(nameNode.toString());
+ XmlSchemaType type = TypesUtils.findType(schemas, schema, typeNode);
+ element.setSchemaTypeName(type.getQName());
+ choice.getItems().add(element);
+
+
+ // corba:unionbranch
+ unionBranch.setName(nameNode.toString());
+ QName idlType = TypesUtils.findCorbaType(typeMap, type.getQName()).getQName();
+ unionBranch.setIdltype(idlType);
+ corbaUnion.getUnionbranch().add(unionBranch);
+
+
+ caseNode = caseNode.getNextSibling();
+ }
+ }
+
+ private void createCase(AST caseNode, Unionbranch unionBranch) {
+ AST node = caseNode.getFirstChild();
+ if (node != null) {
+ if (node.getType() == IDLTokenTypes.LITERAL_case) {
+ // corba:case
+ CaseType caseType = new CaseType();
+ caseType.setLabel(node.getNextSibling().toString());
+ unionBranch.getCase().add(caseType);
+
+ // recursive call
+ createCase(node, unionBranch);
+ } else {
+ // corba:case
+ CaseType caseType = new CaseType();
+ caseType.setLabel(node.toString());
+ unionBranch.getCase().add(caseType);
+ }
+ }
+ }
+}
Propchange: incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/UnionVisitor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/UnionVisitor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/IDLToWSDLGenerationTest.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/IDLToWSDLGenerationTest.java?rev=438866&r1=438865&r2=438866&view=diff
==============================================================================
--- incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/IDLToWSDLGenerationTest.java (original)
+++ incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/IDLToWSDLGenerationTest.java Thu Aug 31 04:29:21 2006
@@ -154,4 +154,8 @@
testWSDLGeneration("/idl/Enum.idl", "/idl/expected_Enum.wsdl");
}
+ public void testUnionGeneration() throws Exception {
+ testWSDLGeneration("/idl/Union.idl", "/idl/expected_Union.wsdl");
+ }
+
}
Added: incubator/yoko/trunk/tools/src/test/resources/idl/Union.idl
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/test/resources/idl/Union.idl?rev=438866&view=auto
==============================================================================
--- incubator/yoko/trunk/tools/src/test/resources/idl/Union.idl (added)
+++ incubator/yoko/trunk/tools/src/test/resources/idl/Union.idl Thu Aug 31 04:29:21 2006
@@ -0,0 +1,69 @@
+enum e1 {
+ e1_1,
+ e1_2,
+ e1_3,
+ e1_4
+};
+struct s1 {
+ short s1_1;
+ short s1_2;
+ short s1_3;
+};
+union u1 switch (e1) {
+ case e1_1:
+ long u1_1;
+ case e1_2:
+ case e1_2:
+ case e1_3:
+ string u1_2;
+ default:
+ s1 u1_3;
+};
+
+interface if {
+ enum e2 {
+ e2_1,
+ e2_2,
+ e2_3,
+ e2_4
+ };
+ struct s2 {
+ short s2_1;
+ short s2_2;
+ short s2_3;
+ };
+ union u2 switch (e2) {
+ case e2_1:
+ long u2_1;
+ case e2_2:
+ case e2_2:
+ case e2_3:
+ string u2_2;
+ default:
+ s2 u2_3;
+ };
+};
+
+module m {
+ enum e3 {
+ e3_1,
+ e3_2,
+ e3_3,
+ e3_4
+ };
+ struct s3 {
+ short s3_1;
+ short s3_2;
+ short s3_3;
+ };
+ union u3 switch (e3) {
+ case e3_1:
+ long u3_1;
+ case e3_2:
+ case e3_2:
+ case e3_3:
+ string u3_2;
+ default:
+ s3 u3_3;
+ };
+};
Added: incubator/yoko/trunk/tools/src/test/resources/idl/expected_Union.wsdl
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/test/resources/idl/expected_Union.wsdl?rev=438866&view=auto
==============================================================================
--- incubator/yoko/trunk/tools/src/test/resources/idl/expected_Union.wsdl (added)
+++ incubator/yoko/trunk/tools/src/test/resources/idl/expected_Union.wsdl Thu Aug 31 04:29:21 2006
@@ -0,0 +1,193 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<wsdl:definitions targetNamespace="http://schemas.apache.org/yoko/idl/Union" xmlns:tns="http://schemas.apache.org/yoko/idl/Union" xmlns:corba="http://schemas.apache.org/yoko/bindings/corba" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
+ <corba:typeMapping targetNamespace="http://schemas.apache.org/yoko/idl/Union/typemap">
+ <corba:enum xmlns:ns4="http://schemas.apache.org/yoko/idl/Union" xmlns="http://schemas.apache.org/yoko/idl/Union/typemap" repositoryID="IDL:e1:1.0" name="e1" type="ns4:e1">
+ <corba:enumerator value="e1_1" />
+ <corba:enumerator value="e1_2" />
+ <corba:enumerator value="e1_3" />
+ <corba:enumerator value="e1_4" />
+ </corba:enum>
+ <corba:struct xmlns:ns4="http://schemas.apache.org/yoko/idl/Union" xmlns="http://schemas.apache.org/yoko/idl/Union/typemap" repositoryID="IDL:s1:1.0" name="s1" type="ns4:s1">
+ <corba:member name="s1_1" idltype="corba:short" />
+ <corba:member name="s1_2" idltype="corba:short" />
+ <corba:member name="s1_3" idltype="corba:short" />
+ </corba:struct>
+ <corba:union xmlns:ns4="http://schemas.apache.org/yoko/idl/Union" xmlns="http://schemas.apache.org/yoko/idl/Union/typemap" discriminator="e1" repositoryID="IDL:u1:1.0" name="u1" type="ns4:u1">
+ <corba:unionbranch name="u1_1" idltype="corba:long">
+ <corba:case label="e1_1" />
+ </corba:unionbranch>
+ <corba:unionbranch name="u1_2" idltype="corba:string">
+ <corba:case label="e1_3" />
+ <corba:case label="e1_2" />
+ <corba:case label="e1_2" />
+ </corba:unionbranch>
+ <corba:unionbranch name="u1_3" idltype="s1" default="true" />
+ </corba:union>
+ <corba:enum xmlns:ns4="http://schemas.apache.org/yoko/idl/Union" xmlns="http://schemas.apache.org/yoko/idl/Union/typemap" repositoryID="IDL:e2:1.0" name="e2" type="ns4:e2">
+ <corba:enumerator value="e2_1" />
+ <corba:enumerator value="e2_2" />
+ <corba:enumerator value="e2_3" />
+ <corba:enumerator value="e2_4" />
+ </corba:enum>
+ <corba:struct xmlns:ns4="http://schemas.apache.org/yoko/idl/Union" xmlns="http://schemas.apache.org/yoko/idl/Union/typemap" repositoryID="IDL:s2:1.0" name="s2" type="ns4:s2">
+ <corba:member name="s2_1" idltype="corba:short" />
+ <corba:member name="s2_2" idltype="corba:short" />
+ <corba:member name="s2_3" idltype="corba:short" />
+ </corba:struct>
+ <corba:union xmlns:ns4="http://schemas.apache.org/yoko/idl/Union" xmlns="http://schemas.apache.org/yoko/idl/Union/typemap" discriminator="e2" repositoryID="IDL:u2:1.0" name="u2" type="ns4:u2">
+ <corba:unionbranch name="u2_1" idltype="corba:long">
+ <corba:case label="e2_1" />
+ </corba:unionbranch>
+ <corba:unionbranch name="u2_2" idltype="corba:string">
+ <corba:case label="e2_3" />
+ <corba:case label="e2_2" />
+ <corba:case label="e2_2" />
+ </corba:unionbranch>
+ <corba:unionbranch name="u2_3" idltype="s2" default="true" />
+ </corba:union>
+ <corba:enum xmlns:ns4="http://schemas.apache.org/yoko/idl/Union" xmlns="http://schemas.apache.org/yoko/idl/Union/typemap" repositoryID="IDL:e3:1.0" name="e3" type="ns4:e3">
+ <corba:enumerator value="e3_1" />
+ <corba:enumerator value="e3_2" />
+ <corba:enumerator value="e3_3" />
+ <corba:enumerator value="e3_4" />
+ </corba:enum>
+ <corba:struct xmlns:ns4="http://schemas.apache.org/yoko/idl/Union" xmlns="http://schemas.apache.org/yoko/idl/Union/typemap" repositoryID="IDL:s3:1.0" name="s3" type="ns4:s3">
+ <corba:member name="s3_1" idltype="corba:short" />
+ <corba:member name="s3_2" idltype="corba:short" />
+ <corba:member name="s3_3" idltype="corba:short" />
+ </corba:struct>
+ <corba:union xmlns:ns4="http://schemas.apache.org/yoko/idl/Union" xmlns="http://schemas.apache.org/yoko/idl/Union/typemap" discriminator="e3" repositoryID="IDL:u3:1.0" name="u3" type="ns4:u3">
+ <corba:unionbranch name="u3_1" idltype="corba:long">
+ <corba:case label="e3_1" />
+ </corba:unionbranch>
+ <corba:unionbranch name="u3_2" idltype="corba:string">
+ <corba:case label="e3_3" />
+ <corba:case label="e3_2" />
+ <corba:case label="e3_2" />
+ </corba:unionbranch>
+ <corba:unionbranch name="u3_3" idltype="s3" default="true" />
+ </corba:union>
+ </corba:typeMapping>
+ <wsdl:types>
+ <xs:schema attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://schemas.apache.org/yoko/idl/Union" xmlns="http://schemas.apache.org/yoko/idl/Union" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <xs:simpleType name="e1">
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="e1_1">
+ </xs:enumeration>
+ <xs:enumeration value="e1_2">
+ </xs:enumeration>
+ <xs:enumeration value="e1_3">
+ </xs:enumeration>
+ <xs:enumeration value="e1_4">
+ </xs:enumeration>
+ </xs:restriction>
+ </xs:simpleType>
+ <xs:complexType name="s1">
+ <xs:sequence>
+ <xs:element name="s1_1" type="xs:short">
+ </xs:element>
+ <xs:element name="s1_2" type="xs:short">
+ </xs:element>
+ <xs:element name="s1_3" type="xs:short">
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="u1">
+ <xs:sequence>
+ <xs:element name="discriminator" type="e1">
+ </xs:element>
+ <xs:choice>
+ <xs:element name="u1_1" type="xs:int">
+ </xs:element>
+ <xs:element name="u1_2" type="xs:string">
+ </xs:element>
+ <xs:element name="u1_3" type="s1">
+ </xs:element>
+ </xs:choice>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:simpleType name="e2">
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="e2_1">
+ </xs:enumeration>
+ <xs:enumeration value="e2_2">
+ </xs:enumeration>
+ <xs:enumeration value="e2_3">
+ </xs:enumeration>
+ <xs:enumeration value="e2_4">
+ </xs:enumeration>
+ </xs:restriction>
+ </xs:simpleType>
+ <xs:complexType name="s2">
+ <xs:sequence>
+ <xs:element name="s2_1" type="xs:short">
+ </xs:element>
+ <xs:element name="s2_2" type="xs:short">
+ </xs:element>
+ <xs:element name="s2_3" type="xs:short">
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="u2">
+ <xs:sequence>
+ <xs:element name="discriminator" type="e2">
+ </xs:element>
+ <xs:choice>
+ <xs:element name="u2_1" type="xs:int">
+ </xs:element>
+ <xs:element name="u2_2" type="xs:string">
+ </xs:element>
+ <xs:element name="u2_3" type="s2">
+ </xs:element>
+ </xs:choice>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:simpleType name="e3">
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="e3_1">
+ </xs:enumeration>
+ <xs:enumeration value="e3_2">
+ </xs:enumeration>
+ <xs:enumeration value="e3_3">
+ </xs:enumeration>
+ <xs:enumeration value="e3_4">
+ </xs:enumeration>
+ </xs:restriction>
+ </xs:simpleType>
+ <xs:complexType name="s3">
+ <xs:sequence>
+ <xs:element name="s3_1" type="xs:short">
+ </xs:element>
+ <xs:element name="s3_2" type="xs:short">
+ </xs:element>
+ <xs:element name="s3_3" type="xs:short">
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="u3">
+ <xs:sequence>
+ <xs:element name="discriminator" type="e3">
+ </xs:element>
+ <xs:choice>
+ <xs:element name="u3_1" type="xs:int">
+ </xs:element>
+ <xs:element name="u3_2" type="xs:string">
+ </xs:element>
+ <xs:element name="u3_3" type="s3">
+ </xs:element>
+ </xs:choice>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:schema>
+ </wsdl:types>
+ <wsdl:portType name="if">
+ </wsdl:portType>
+ <wsdl:binding name="ifCORBABinding" type="tns:if">
+ <corba:binding repositoryID="IDL:if:1.0" />
+ </wsdl:binding>
+ <wsdl:service name="ifCORBAService">
+ <wsdl:port name="ifCORBAPort" binding="tns:ifCORBABinding">
+ <corba:address location="IOR:" />
+ </wsdl:port>
+ </wsdl:service>
+</wsdl:definitions>
Propchange: incubator/yoko/trunk/tools/src/test/resources/idl/expected_Union.wsdl
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/yoko/trunk/tools/src/test/resources/idl/expected_Union.wsdl
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: incubator/yoko/trunk/tools/src/test/resources/idl/expected_Union.wsdl
------------------------------------------------------------------------------
svn:mime-type = text/xml