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/07/19 12:53:17 UTC
svn commit: r423450 - in /incubator/yoko/trunk/tools/src:
main/java/org/apache/yoko/tools/common/idltypes/
main/java/org/apache/yoko/tools/processors/wsdl/
test/java/org/apache/yoko/tools/processors/ test/resources/idlgen/
test/resources/wsdl/
Author: enolan
Date: Wed Jul 19 05:53:16 2006
New Revision: 423450
URL: http://svn.apache.org/viewvc?rev=423450&view=rev
Log:
Adding basic support for union types for wsdltoidl and union tests.
Added:
incubator/yoko/trunk/tools/src/test/resources/idlgen/expected_uniontypes.idl
incubator/yoko/trunk/tools/src/test/resources/idlgen/uniontypes.wsdl (with props)
incubator/yoko/trunk/tools/src/test/resources/wsdl/uniontype.wsdl (with props)
Modified:
incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/common/idltypes/IdlUnion.java
incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/common/idltypes/IdlUnionBranch.java
incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLParameter.java
incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToCorbaBinding.java
incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToIDLAction.java
incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/WSDLToCorbaBindingTest.java
incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/WSDLToIDLGenerationTest.java
Modified: incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/common/idltypes/IdlUnion.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/common/idltypes/IdlUnion.java?rev=423450&r1=423449&r2=423450&view=diff
==============================================================================
--- incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/common/idltypes/IdlUnion.java (original)
+++ incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/common/idltypes/IdlUnion.java Wed Jul 19 05:53:16 2006
@@ -36,7 +36,7 @@
}
- void addBranch(IdlUnionBranch ub) {
+ public void addBranch(IdlUnionBranch ub) {
addToScope(ub);
}
Modified: incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/common/idltypes/IdlUnionBranch.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/common/idltypes/IdlUnionBranch.java?rev=423450&r1=423449&r2=423450&view=diff
==============================================================================
--- incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/common/idltypes/IdlUnionBranch.java (original)
+++ incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/common/idltypes/IdlUnionBranch.java Wed Jul 19 05:53:16 2006
@@ -38,7 +38,7 @@
}
- void addCase(String label) {
+ public void addCase(String label) {
if (!isDefault) {
cases.add(label);
}
Modified: incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLParameter.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLParameter.java?rev=423450&r1=423449&r2=423450&view=diff
==============================================================================
--- incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLParameter.java (original)
+++ incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLParameter.java Wed Jul 19 05:53:16 2006
@@ -135,7 +135,7 @@
private void orderParameters(List<ParamType> inputs, List<ParamType> outputs,
boolean simpleOrdering) {
- ListIterator inputit = inputs.listIterator();
+ ListIterator<ParamType> inputit = inputs.listIterator();
while (inputit.hasNext()) {
ParamType d2 = (ParamType)inputit.next();
@@ -160,7 +160,7 @@
}
}
}
- ListIterator it = outputs.listIterator();
+ ListIterator<ParamType> it = outputs.listIterator();
while (it.hasNext()) {
ParamType d3 = (ParamType)it.next();
Modified: incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToCorbaBinding.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToCorbaBinding.java?rev=423450&r1=423449&r2=423450&view=diff
==============================================================================
--- incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToCorbaBinding.java (original)
+++ incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToCorbaBinding.java Wed Jul 19 05:53:16 2006
@@ -21,10 +21,13 @@
import java.io.File;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -62,7 +65,6 @@
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.XmlSchemaAttribute;
import org.apache.ws.commons.schema.XmlSchemaChoice;
@@ -73,6 +75,7 @@
import org.apache.ws.commons.schema.XmlSchemaEnumerationFacet;
import org.apache.ws.commons.schema.XmlSchemaFacet;
import org.apache.ws.commons.schema.XmlSchemaObjectTable;
+import org.apache.ws.commons.schema.XmlSchemaParticle;
import org.apache.ws.commons.schema.XmlSchemaSequence;
import org.apache.ws.commons.schema.XmlSchemaSimpleContent;
import org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension;
@@ -92,6 +95,11 @@
public class WSDLToCorbaBinding {
protected static final Logger LOG = LogUtils.getL7dLogger(WSDLToCorbaBinding.class);
+ protected static final String DISCRIMINATORTYPES[]
+ = new String[] {"long", "short", "boolean", "char"};
+ protected static final Set<String> SUPPORTEDDISTYPES =
+ new TreeSet<String>(Arrays.asList(DISCRIMINATORTYPES));
+
static XmlSchema xmlSchemaType;
static CorbaPrimitiveMap corbaPrimitiveMap;
static String idlNamespace;
@@ -554,7 +562,7 @@
MemberType memberType = (MemberType)iterator.next();
corbaex.getMember().add(memberType);
}
- List members = processContainerAsMembers(complex, stype.getQName(), schemaTypeName);
+ List members = processContainerAsMembers(complex.getParticle(), stype.getQName(), schemaTypeName);
Iterator it = members.iterator();
while (it.hasNext()) {
MemberType memberType = (MemberType)it.next();
@@ -564,33 +572,129 @@
return corbaex;
}
- protected List processContainerAsMembers(XmlSchemaComplexType container, QName defaultName,
+ protected List processContainerAsMembers(XmlSchemaParticle particle, QName defaultName,
QName schemaTypeName) throws Exception {
- List members = new ArrayList();
+ List<MemberType> members = new ArrayList<MemberType>();
+
+ Iterator iterL = null;
+ if (particle instanceof XmlSchemaSequence) {
+ XmlSchemaSequence scontainer = (XmlSchemaSequence)particle;
+ iterL = scontainer.getItems().getIterator();
+ } else if (particle instanceof XmlSchemaChoice) {
+ XmlSchemaChoice scontainer = (XmlSchemaChoice)particle;
+ iterL = scontainer.getItems().getIterator();
+ }
+
+ while (iterL.hasNext()) {
+ XmlSchemaParticle container = (XmlSchemaParticle)iterL.next();
+
+ if (container instanceof XmlSchemaSequence) {
+ XmlSchemaSequence sequence = (XmlSchemaSequence)container;
+ CorbaTypeImpl memberType = processSequenceType(sequence, defaultName, schemaTypeName);
+ if (memberType instanceof Struct) {
+ Struct str = (Struct)memberType;
+ Iterator iter = str.getMember().iterator();
+ while (iter.hasNext()) {
+ MemberType member = (MemberType)iter.next();
+ members.add(member);
+ }
+ }
+ } else if (container instanceof XmlSchemaChoice) {
+ XmlSchemaChoice choice = (XmlSchemaChoice)container;
+ CorbaTypeImpl corbatype = processChoice(choice, defaultName, schemaTypeName);
+ MemberType member = new MemberType();
+ member.setName(corbatype.getQName().getLocalPart());
+ member.setIdltype(corbatype.getQName());
+ members.add(member);
+ } else if (container instanceof XmlSchemaElement) {
+ XmlSchemaElement element = (XmlSchemaElement)container;
+ CorbaTypeImpl corbatype = processLocalElement(element);
+
+ if (corbatype != null) {
+ MemberType member;
+ String memberName = element.getQName().getLocalPart();
- if (container.getParticle() instanceof XmlSchemaSequence) {
- XmlSchemaSequence sequence = (XmlSchemaSequence)container.getParticle();
- CorbaTypeImpl memberType = processSequenceType(sequence, defaultName, schemaTypeName);
- if (memberType instanceof Struct) {
- Struct str = (Struct)memberType;
- Iterator iter = str.getMember().iterator();
- while (iter.hasNext()) {
- MemberType member = (MemberType)iter.next();
+ member = new MemberType();
+ member.setName(memberName);
+ member.setIdltype(corbatype.getQName());
members.add(member);
+ } else {
+ String msg = "Unsupported Element Found in CORBA Binding Generation:"
+ + element.getQName();
+ LOG.log(Level.WARNING, msg.toString());
}
}
- } else if (container.getParticle() instanceof XmlSchemaChoice) {
- // Need to DO
- System.out.println("processChoice");
- } else if (container.getParticle() instanceof XmlSchemaElement) {
- XmlSchemaElement element = (XmlSchemaElement)container.getParticle();
- // Need to Do
- System.out.println("processElement");
}
-
return members;
}
+ private CorbaTypeImpl processChoice(XmlSchemaChoice choice, QName defaultName,
+ QName schemaTypeName) throws Exception {
+ QName choicename = null;
+
+ if (schemaTypeName == null) {
+ choicename = createQNameTargetNamespace(defaultName.getLocalPart());
+ } else {
+ choicename = createQNameTargetNamespace(schemaTypeName.getLocalPart());
+ }
+
+ CorbaTypeImpl corbatype = createUnion(choicename, choice, defaultName, schemaTypeName);
+ String repoId = repoString + corbatype.getQName().getLocalPart().replace('.', '/')
+ + idlversion;
+ ((Union)corbatype).setRepositoryID(repoId);
+
+ if (!"1".equals(choice.getMaxOccurs()) || !"1".equals(choice.getMinOccurs())) {
+ QName name = createQNameTargetNamespace(corbatype.getQName().getLocalPart() + "Array");
+ CorbaTypeImpl arrayType =
+ createArray(name, corbatype.getQName(), corbatype.getQName(),
+ choice.getMaxOccurs(), choice.getMinOccurs(), false);
+
+ if (arrayType != null) {
+ arrayType.setQName(null);
+ typeMappingType.getStructOrExceptionOrUnion().add(corbatype);
+ }
+ }
+ return corbatype;
+ }
+
+ private CorbaTypeImpl processLocalElement(XmlSchemaElement element) throws Exception {
+ CorbaTypeImpl membertype = null;
+
+ if (element.isNillable()) {
+
+ CorbaTypeImpl elemtype = convertSchemaToCorbaType(element.getSchemaType(), element.getQName(),
+ element.getSchemaType(), true);
+ QName name = createQNameTargetNamespace(elemtype.getQName().getLocalPart() + "_nil");
+ membertype = createNillableUnion(name, element.getQName(), elemtype.getQName());
+ } else {
+ XmlSchemaType st = element.getSchemaType();
+ membertype = convertSchemaToCorbaType(st, element.getQName(), element.getSchemaType(), false);
+ }
+
+ if (!"1".equals(element.getMaxOccurs()) || !"1".equals(element.getMinOccurs())) {
+ QName name = createQNameTargetNamespace(getModulePrefix(membertype)
+ + element.getQName().getLocalPart() + "Array");
+
+ CorbaTypeImpl arraytype =
+ createArray(name, element.getQName(), membertype.getQName(), element.getMaxOccurs(),
+ element.getMinOccurs(), false);
+
+ if (arraytype != null) {
+ arraytype.setQName(null);
+ typeMappingType.getStructOrExceptionOrUnion().add(arraytype);
+ }
+ }
+
+ return membertype;
+ }
+
+ private String getModulePrefix(CorbaTypeImpl type) {
+ String name = type.getQName().getLocalPart();
+ int dotPos = name.lastIndexOf(".");
+ return dotPos == -1 ? "" : name.substring(0, dotPos + 1);
+ }
+
+
protected CorbaTypeImpl processSequenceType(XmlSchemaSequence seq,
QName defaultName, QName schemaTypeName)
throws Exception {
@@ -601,20 +705,11 @@
struct.setQName(schemaTypeName);
struct.setRepositoryID(repoString + schemaTypeName.getLocalPart().replace('.', '/') + idlversion);
struct.setType(schemaTypeName);
-
- Iterator i = seq.getItems().getIterator();
- Iterator i2 = seq.getItems().getIterator();
- while (i.hasNext()) {
- if (i.next() instanceof XmlSchemaElement) {
- XmlSchemaElement el = (XmlSchemaElement)i2.next();
- org.apache.schemas.yoko.bindings.corba.MemberType membertype =
- new org.apache.schemas.yoko.bindings.corba.MemberType();
- membertype.setName(el.getName());
- CorbaTypeImpl corbaTypeImpl =
- convertSchemaToCorbaType(el.getSchemaType(), defaultName, el.getSchemaType(), false);
- membertype.setIdltype(corbaTypeImpl.getQName());
- struct.getMember().add(membertype);
- }
+
+ List members = processContainerAsMembers(seq, defaultName, schemaTypeName);
+ for (Iterator iterator = members.iterator(); iterator.hasNext();) {
+ MemberType memberType = (MemberType)iterator.next();
+ struct.getMember().add(memberType);
}
type = struct;
@@ -668,13 +763,13 @@
CorbaTypeImpl corbaTypeImpl = null;
QName name;
- QName schematypeName;
-
- if (stype.getName() == null) {
+ QName schematypeName = null;
+
+ if (stype.getQName() == null) {
schematypeName = defaultName;
name = createQNameTargetNamespace(defaultName.getLocalPart() + "Type");
} else {
- schematypeName = createQNameTargetNamespace(stype.getName());
+ schematypeName = checkPrefix(stype.getQName());
name = createQNameCorbaNamespace(schematypeName.getLocalPart());
}
@@ -870,7 +965,7 @@
*/
protected CorbaTypeImpl createArray(QName name, QName schematypeName, QName arrayType,
Long maxOccurs, Long minOccurs, boolean anonymous) {
- if (maxOccurs.equals("unbounded")) {
+ if ("unbounded".equals(maxOccurs)) {
return mapToSequence(name, schematypeName, arrayType, 0, anonymous);
}
@@ -953,6 +1048,10 @@
if (isLiteralArray(complex)) {
corbatype = processLiteralArray(complex, defaultName, anonymous);
+ } else if (isOMGUnion(complex)) {
+ corbatype = processOMGUnion(complex, defaultName);
+ } else if (isUnion(complex)) {
+ corbatype = processRegularUnion(complex, defaultName);
} else if (complex.getQName() != null && isIDLObjectType(complex.getQName())) {
// process it.
} else {
@@ -999,7 +1098,7 @@
corbaStruct.getMember().add(member);
}
- List members = processContainerAsMembers(complex, defaultName, schematypeName);
+ List members = processContainerAsMembers(complex.getParticle(), defaultName, schematypeName);
for (Iterator it = members.iterator(); it.hasNext();) {
MemberType memberType = (MemberType)it.next();
@@ -1099,16 +1198,9 @@
MemberType member;
String memberName = attribute.getQName().getLocalPart();
- if (memberName.equalsIgnoreCase(membertype.getQName().getLocalPart())) {
- member = new MemberType();
- member.setName(memberName + "_f");
- member.setIdltype(membertype.getQName());
- } else {
- member = new MemberType();
- member.setName(memberName);
- member.setIdltype(membertype.getQName());
- }
-
+ member = new MemberType();
+ member.setName(memberName);
+ member.setIdltype(membertype.getQName());
members.add(member);
} else {
String msg = "Unsupported Attribute Found in CORBA Binding Generation:"
@@ -1134,6 +1226,7 @@
Unionbranch branch = new Unionbranch();
branch.setName("value");
branch.setIdltype(membertype);
+ branch.setDefault(false);
CaseType caseType = new CaseType();
caseType.setLabel("TRUE");
branch.getCase().add(caseType);
@@ -1149,16 +1242,207 @@
private CorbaTypeImpl processLiteralArray(XmlSchemaComplexType complex, QName defaultName,
boolean anonymous) throws Exception {
+ // NEED TO DO
return new CorbaTypeImpl();
}
+
+ private CorbaTypeImpl processOMGUnion(XmlSchemaComplexType complex, QName defaultName) throws Exception {
+ QName name;
+ Union corbaUnion = null;
+ QName schematypeName = checkPrefix(complex.getQName());
+
+ if (schematypeName == null) {
+ schematypeName = defaultName;
+ name = createQNameTargetNamespace(defaultName.getLocalPart() + "Type");
+ } else {
+ name = createQNameTargetNamespace(schematypeName.getLocalPart());
+ }
+
+ corbaUnion = new Union();
+ corbaUnion.setName(name.getLocalPart());
+ corbaUnion.setQName(name);
+ String id = repoString + name.getLocalPart().replace('.', '/') + idlversion;
+ corbaUnion.setRepositoryID(id);
+ corbaUnion.setType(schematypeName);
+
+ XmlSchemaSequence stype = (XmlSchemaSequence)complex.getParticle();
+ Iterator it = stype.getItems().getIterator();
+ XmlSchemaParticle st1 = (XmlSchemaParticle)it.next();
+ XmlSchemaParticle st2 = (XmlSchemaParticle)it.next();
+ XmlSchemaElement discEl = null;
+ XmlSchemaChoice choice = null;
+
+ if (st1 instanceof XmlSchemaElement) {
+ discEl = (XmlSchemaElement)st1;
+ choice = (XmlSchemaChoice)st2;
+ } else {
+ discEl = (XmlSchemaElement)st2;
+ choice = (XmlSchemaChoice)st1;
+ }
+
+ CorbaTypeImpl disctype = convertSchemaToCorbaType(discEl.getSchemaType(), discEl.getQName(), discEl
+ .getSchemaType(), false);
+ corbaUnion.setDiscriminator(disctype.getQName());
+
+ List fields = processContainerAsMembers(choice, defaultName, schematypeName);
+
+ List<String> caselist = new ArrayList<String>();
+
+ if (disctype instanceof Enum) {
+ Enum corbaenum = (Enum)disctype;
+ Iterator iterator = corbaenum.getEnumerator().iterator();
+
+ while (iterator.hasNext()) {
+ Enumerator enumerator = (Enumerator)iterator.next();
+ caselist.add(enumerator.getValue());
+ }
+ } else if (SUPPORTEDDISTYPES.contains(disctype.getQName().getLocalPart())) {
+ if (disctype.getQName().getLocalPart().equals("long")
+ || disctype.getQName().getLocalPart().equals("short")) {
+ for (int i = 0; i < fields.size(); i++) {
+ caselist.add(Integer.toString(i));
+ }
+ } else if (disctype.getQName().getLocalPart().equals("char")) {
+ for (int i = 0; i < fields.size(); i++) {
+ caselist.add(Integer.toString(i));
+ }
+ } else if (disctype.getQName().getLocalPart().equals("char")) {
+ for (int i = 0; i < fields.size(); i++) {
+ caselist.add(Integer.toString(i));
+ }
+ } else if (disctype.getQName().getLocalPart().equals("boolean")) {
+ if (fields.size() == 2) {
+ caselist.add("TRUE");
+ caselist.add("FALSE");
+ } else if (fields.size() == 1) {
+ caselist.add("TRUE");
+ } else {
+ String msg = "Discriminator Type doesnt match number of Choices in Union:" + name;
+ LOG.log(Level.WARNING, msg.toString());
+ }
+ }
+ }
+
+ processUnionBranches(corbaUnion, fields, caselist);
+
+ return corbaUnion;
+ }
+
+
+ private CorbaTypeImpl processRegularUnion(XmlSchemaComplexType complex,
+ QName defaultName) throws Exception {
+ //NEED TO DO
+ QName name = null;
+ QName schematypeName = complex.getQName();
+
+ if (schematypeName == null) {
+ schematypeName = defaultName;
+ name = createQNameTargetNamespace(defaultName.getLocalPart() + "Type");
+ } else {
+ name = createQNameTargetNamespace(schematypeName.getLocalPart());
+ }
+
+ return createUnion(name, (XmlSchemaChoice)complex.getParticle(), defaultName, schematypeName);
+ }
+
+ protected Union createUnion(QName name, XmlSchemaChoice choice, QName defaultName,
+ QName schematypeName)
+ throws Exception {
+ Union corbaUnion = new Union();
+ corbaUnion.setName(name.getLocalPart());
+ corbaUnion.setQName(name);
+ corbaUnion.setType(schematypeName);
+ String id = repoString + name.getLocalPart().replace('.', '/') + idlversion;
+ corbaUnion.setRepositoryID(id);
+
+ //Set Integer as Discriminator
+ corbaUnion.setDiscriminator(CORBAConstants.NT_CORBA_LONG);
+
+ List fields = processContainerAsMembers(choice, defaultName, schematypeName);
+
+ //Choose an Integer as a Discriminator
+ List<String> caselist = new ArrayList<String>();
+
+ for (int i = 0; i < fields.size(); i++) {
+ caselist.add(Integer.toString(i));
+ }
+
+ return processUnionBranches(corbaUnion, fields, caselist);
+ }
+
+
+ private Union processUnionBranches(Union corbaUnion, List fields, List<String> caselist) {
+ int caseIndex = 0;
+
+ for (int i = 0; i < fields.size(); i++) {
+ MemberType field = (MemberType)fields.get(i);
+ Unionbranch branch = new Unionbranch();
+ branch.setName(field.getName());
+ branch.setIdltype(field.getIdltype());
+ branch.setDefault(false);
+
+ CaseType c = new CaseType();
+ c.setLabel((String)caselist.get(caseIndex));
+ caseIndex++;
+ branch.getCase().add(c);
+ corbaUnion.getUnionbranch().add(branch);
+ }
+ return corbaUnion;
+ }
+
+
+ public boolean isOMGUnion(XmlSchemaComplexType type) {
+ boolean isUnion = false;
+
+ if (type.getParticle() instanceof XmlSchemaSequence
+ && type.getAttributes().getCount() == 0) {
+
+ XmlSchemaSequence stype = (XmlSchemaSequence)type.getParticle();
+
+ if (stype.getItems().getCount() == 2) {
+ Iterator it = stype.getItems().getIterator();
+ XmlSchemaParticle st1 = (XmlSchemaParticle)it.next();
+ XmlSchemaParticle st2 = (XmlSchemaParticle)it.next();
+ XmlSchemaElement discEl = null;
+
+ if (st1 instanceof XmlSchemaChoice && st2 instanceof XmlSchemaElement) {
+ isUnion = true;
+ discEl = (XmlSchemaElement)st2;
+ } else if (st2 instanceof XmlSchemaChoice && st1 instanceof XmlSchemaElement) {
+ isUnion = true;
+ discEl = (XmlSchemaElement)st1;
+ }
+ if (isUnion && !"discriminator".equals(discEl.getQName().getLocalPart())) {
+ isUnion = false;
+ }
+ }
+ }
+ return isUnion;
+ }
+ public boolean isUnion(XmlSchemaComplexType type) {
+ boolean isUnion = false;
+
+ if (type.getParticle() instanceof XmlSchemaChoice && type.getAttributes().getCount() == 0) {
+ isUnion = true;
+ }
+
+ return isUnion;
+ }
+
+
private QName checkPrefix(QName schematypeName) {
QName name = schematypeName;
if (name.getPrefix() == null || name.getPrefix().equals("")) {
- return new QName(name.getNamespaceURI(), name.getLocalPart(),
- def.getPrefix(name.getNamespaceURI()));
+ String prefix = def.getPrefix(name.getNamespaceURI());
+ if (prefix != null) {
+ return new QName(name.getNamespaceURI(), name.getLocalPart(),
+ def.getPrefix(name.getNamespaceURI()));
+ } else {
+ return null;
+ }
}
return name;
}
Modified: incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToIDLAction.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToIDLAction.java?rev=423450&r1=423449&r2=423450&view=diff
==============================================================================
--- incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToIDLAction.java (original)
+++ incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToIDLAction.java Wed Jul 19 05:53:16 2006
@@ -39,6 +39,7 @@
import org.apache.schemas.yoko.bindings.corba.ArgType;
import org.apache.schemas.yoko.bindings.corba.BindingType;
+import org.apache.schemas.yoko.bindings.corba.CaseType;
import org.apache.schemas.yoko.bindings.corba.Enum;
import org.apache.schemas.yoko.bindings.corba.Enumerator;
import org.apache.schemas.yoko.bindings.corba.MemberType;
@@ -47,6 +48,8 @@
import org.apache.schemas.yoko.bindings.corba.Sequence;
import org.apache.schemas.yoko.bindings.corba.Struct;
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.yoko.tools.common.CORBAConstants;
import org.apache.yoko.tools.common.idltypes.CorbaUtils;
@@ -65,6 +68,8 @@
import org.apache.yoko.tools.common.idltypes.IdlSequence;
import org.apache.yoko.tools.common.idltypes.IdlStruct;
import org.apache.yoko.tools.common.idltypes.IdlType;
+import org.apache.yoko.tools.common.idltypes.IdlUnion;
+import org.apache.yoko.tools.common.idltypes.IdlUnionBranch;
import org.apache.yoko.tools.utils.FileOutputStreamFactory;
import org.apache.yoko.tools.utils.OutputStreamFactory;
import org.apache.yoko.wsdl.CorbaTypeImpl;
@@ -466,9 +471,10 @@
instanceof org.apache.schemas.yoko.bindings.corba.Exception) {
result = createIdlException(corbaTypeImpl, scope, local);
} else if (corbaTypeImpl instanceof Struct) {
- result = createStruct(corbaTypeImpl, scope, local);
-
- }
+ result = createStruct(corbaTypeImpl, scope, local);
+ } else if (corbaTypeImpl instanceof Union) {
+ result = createUnion(corbaTypeImpl, scope, local);
+ }
return result;
}
@@ -500,6 +506,49 @@
}
return result;
+ }
+
+ private IdlType createUnion(CorbaTypeImpl ctype, IdlScopeBase scope, String local) {
+ Union u = (Union)ctype;
+ boolean undefinedCircular = false;
+ IdlType disc = findType(u.getDiscriminator());
+ IdlUnion union = IdlUnion.create(scope, local, disc);
+ scope.holdForScope(union);
+
+ Iterator it = u.getUnionbranch().iterator();
+ while (it.hasNext()) {
+ Unionbranch ub = (Unionbranch)it.next();
+ QName qname = ub.getIdltype();
+ IdlType bt = findType(qname);
+ IdlUnionBranch b = IdlUnionBranch.create(union, ub.getName(), bt, false);
+
+ Iterator it2 = ub.getCase().iterator();
+ while (it2.hasNext()) {
+ b.addCase(((CaseType)it2.next()).getLabel());
+ }
+
+ // Ensure that this union will not be written until all of its circular members are
+ // defined, unless the undefined circular members are of sequence type.
+
+ if (!undefinedCircular && !(bt instanceof IdlSequence)) {
+ String mlocal = qname.getLocalPart();
+ String mname[] = unscopeName(mlocal);
+ undefinedCircular = null != root.lookup(mname, true);
+ }
+
+ union.addBranch(b);
+ }
+
+ if (undefinedCircular) {
+ scope.parkHeld();
+ } else {
+ scope.promoteHeldToScope();
+ if (union.isCircular()) {
+ // resolving this union closed a recursion
+ scope.flush();
+ }
+ }
+ return union;
}
private IdlType createStruct(CorbaTypeImpl ctype, IdlScopeBase scope, String local) {
Modified: incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/WSDLToCorbaBindingTest.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/WSDLToCorbaBindingTest.java?rev=423450&r1=423449&r2=423450&view=diff
==============================================================================
--- incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/WSDLToCorbaBindingTest.java (original)
+++ incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/WSDLToCorbaBindingTest.java Wed Jul 19 05:53:16 2006
@@ -65,6 +65,32 @@
junit.textui.TestRunner.run(WSDLToCorbaBindingTest.class);
}
+
+ public void testUnionType() throws Exception {
+ WSDLToCorbaBinding generator = new WSDLToCorbaBinding();
+ String fileName = getClass().getResource("/wsdl/uniontype.wsdl").toString();
+ generator.setWsdlFile(fileName);
+ generator.addInterfaceName("Test.MultiPart");
+
+ Definition model = generator.generateCORBABinding();
+ WSDLCorbaFactory wsdlfactory = WSDLCorbaFactory
+ .newInstance("org.apache.yoko.tools.common.WSDLCorbaFactoryImpl");
+ WSDLWriter writer = wsdlfactory.newWSDLWriter();
+ Document document = writer.getDocument(model);
+
+ Element typemap = null;
+ Element root = document.getDocumentElement();
+ for (Node nd = root.getFirstChild(); nd != null; nd = nd.getNextSibling()) {
+ if (Node.ELEMENT_NODE == nd.getNodeType() && ("corba:typeMapping".equals(nd.getNodeName()))) {
+ typemap = (Element)nd;
+ }
+ }
+ assertNotNull(typemap);
+ assertEquals(1, typemap.getElementsByTagName("corba:union").getLength());
+ assertEquals(1, typemap.getElementsByTagName("corba:enum").getLength());
+ }
+
+
// next story to add Fault support
public void testExceptionCORBABindingGeneration() throws Exception {
WSDLToCorbaBinding generator = new WSDLToCorbaBinding();
@@ -171,8 +197,7 @@
}
}
}
- }
-
+ }
public void testCORBATypeMapGeneration() throws Exception {
WSDLToCorbaBinding generator = new WSDLToCorbaBinding();
@@ -262,7 +287,7 @@
} finally {
new File("multipart.idl").deleteOnExit();
}
- }
+ }
public void testMultipartCORBABindingGeneration() throws Exception {
WSDLToCorbaBinding generator = new WSDLToCorbaBinding();
@@ -418,6 +443,6 @@
}
}
- }
+ }
}
Modified: incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/WSDLToIDLGenerationTest.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/WSDLToIDLGenerationTest.java?rev=423450&r1=423449&r2=423450&view=diff
==============================================================================
--- incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/WSDLToIDLGenerationTest.java (original)
+++ incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/WSDLToIDLGenerationTest.java Wed Jul 19 05:53:16 2006
@@ -168,6 +168,27 @@
new File("integertypes.idl").deleteOnExit();
}
}
+
+ public void testUniontypesIdlgen() throws Exception {
+ try {
+ WSDLToIDLAction idlgen = new WSDLToIDLAction();
+ String fileName = getClass().getResource("/idlgen/uniontypes.wsdl").toString();
+ idlgen.setWsdlFile(fileName);
+
+ idlgen.setBindingName("Test.MultiPartCORBABinding");
+ idlgen.setOutputFile("uniontypes.idl");
+ ByteArrayOutputStream idloutput = new ByteArrayOutputStream();
+ idlgen.setOutput(new PrintWriter(idloutput));
+ idlgen.generateIDL(null);
+
+ InputStream origstream = getClass().getResourceAsStream("/idlgen/expected_uniontypes.idl");
+ byte orig[] = inputStreamToBytes(origstream);
+
+ checkIDLStrings(orig, idloutput.toByteArray());
+ } finally {
+ new File("integertypes.idl").deleteOnExit();
+ }
+ }
public void testExceptionIdlgen() throws Exception {
@@ -191,7 +212,7 @@
}
}
- /*public void testEnumIdlgen() throws Exception {
+ /*public void testEnumIdlgen() throws Exception {
try {
WSDLToIDLAction idlgen = new WSDLToIDLAction();
Added: incubator/yoko/trunk/tools/src/test/resources/idlgen/expected_uniontypes.idl
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/test/resources/idlgen/expected_uniontypes.idl?rev=423450&view=auto
==============================================================================
--- incubator/yoko/trunk/tools/src/test/resources/idlgen/expected_uniontypes.idl (added)
+++ incubator/yoko/trunk/tools/src/test/resources/idlgen/expected_uniontypes.idl Wed Jul 19 05:53:16 2006
@@ -0,0 +1,41 @@
+/*
+ * 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.
+*/
+module Test {
+ interface MultiPart {
+ enum Colour {
+ Colour_RED,
+ Colour_GREEN,
+ Colour_BLUE
+ };
+ union Description switch(Colour) {
+ case RED:
+ string x;
+ case GREEN:
+ long y;
+ case BLUE:
+ short z;
+ };
+ Description
+ test_union(
+ in Description x,
+ inout Description y,
+ out Description z
+ );
+ };
+};
\ No newline at end of file
Added: incubator/yoko/trunk/tools/src/test/resources/idlgen/uniontypes.wsdl
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/test/resources/idlgen/uniontypes.wsdl?rev=423450&view=auto
==============================================================================
--- incubator/yoko/trunk/tools/src/test/resources/idlgen/uniontypes.wsdl (added)
+++ incubator/yoko/trunk/tools/src/test/resources/idlgen/uniontypes.wsdl Wed Jul 19 05:53:16 2006
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<definitions name="multipart.idl"
+ targetNamespace="http://schemas.apache.org/idl/multipart.idl"
+ xmlns="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:corba="http://schemas.apache.org/yoko/bindings/corba"
+ xmlns:corbatm="http://schemas.apache.org/yoko/bindings/corba/typemap"
+ xmlns:ns1="http://schemas.apache.org/idl/multipart.idl/corba/typemap/"
+ xmlns:tns="http://schemas.apache.org/idl/multipart.idl"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd1="http://schemas.apache.org/idltypes/multipart.idl">
+ <corba:typeMapping
+ targetNamespace="http://schemas.apache.org/idl/multipart.idl/corba/typemap/">
+ <corba:enum name="Test.MultiPart.Colour"
+ repositoryID="IDL:Test/MultiPart/Colour:1.0"
+ type="xsd1:Test.MultiPart.Colour">
+ <corba:enumerator value="RED"/>
+ <corba:enumerator value="GREEN"/>
+ <corba:enumerator value="BLUE"/>
+ </corba:enum>
+ <corba:union discriminator="ns1:Test.MultiPart.Colour"
+ name="Test.MultiPart.Description"
+ repositoryID="IDL:Test/MultiPart/Description:1.0"
+ type="xsd1:Test.MultiPart.Description">
+ <corba:unionbranch idltype="corba:string" name="x">
+ <corba:case label="RED"/>
+ </corba:unionbranch>
+ <corba:unionbranch idltype="corba:long" name="y">
+ <corba:case label="GREEN"/>
+ </corba:unionbranch>
+ <corba:unionbranch idltype="corba:short" name="z">
+ <corba:case label="BLUE"/>
+ </corba:unionbranch>
+ </corba:union>
+ </corba:typeMapping>
+ <types>
+ <schema targetNamespace="http://schemas.apache.org/idltypes/multipart.idl"
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
+ <simpleType name="Test.MultiPart.Colour">
+ <restriction base="string">
+ <enumeration value="RED"/>
+ <enumeration value="GREEN"/>
+ <enumeration value="BLUE"/>
+ </restriction>
+ </simpleType>
+ <complexType name="Test.MultiPart.Description">
+ <sequence>
+ <element maxOccurs="1" minOccurs="1" name="discriminator"
+ type="xsd1:Test.MultiPart.Colour"/>
+ <choice>
+ <element name="x" type="string"/>
+ <element name="y" type="int"/>
+ <element name="z" type="short"/>
+ </choice>
+ </sequence>
+ </complexType>
+ <element name="Test.MultiPart.test_enum.x" type="xsd1:Test.MultiPart.Colour"/>
+ <element name="Test.MultiPart.test_enum.y" type="xsd1:Test.MultiPart.Colour"/>
+ <element name="Test.MultiPart.test_enum.z" type="xsd1:Test.MultiPart.Colour"/>
+ <element name="Test.MultiPart.test_enum.return"
+ type="xsd1:Test.MultiPart.Colour"/>
+ <element name="Test.MultiPart.test_union.x"
+ type="xsd1:Test.MultiPart.Description"/>
+ <element name="Test.MultiPart.test_union.y"
+ type="xsd1:Test.MultiPart.Description"/>
+ <element name="Test.MultiPart.test_union.z"
+ type="xsd1:Test.MultiPart.Description"/>
+ <element name="Test.MultiPart.test_union.return"
+ type="xsd1:Test.MultiPart.Description"/>
+ </schema>
+ </types>
+ <message name="Test.MultiPart.test_union">
+ <part element="xsd1:Test.MultiPart.test_union.x" name="x"/>
+ <part element="xsd1:Test.MultiPart.test_union.y" name="y"/>
+ </message>
+ <message name="Test.MultiPart.test_unionResponse">
+ <part element="xsd1:Test.MultiPart.test_union.return" name="return"/>
+ <part element="xsd1:Test.MultiPart.test_union.y" name="y"/>
+ <part element="xsd1:Test.MultiPart.test_union.z" name="z"/>
+ </message>
+ <portType name="Test.MultiPart">
+ <operation name="test_union">
+ <input message="tns:Test.MultiPart.test_union" name="test_union"/>
+ <output message="tns:Test.MultiPart.test_unionResponse"
+ name="test_unionResponse"/>
+ </operation>
+ </portType>
+ <binding name="Test.MultiPartCORBABinding" type="tns:Test.MultiPart">
+ <corba:binding repositoryID="IDL:Test/MultiPart:1.0"/>
+ <operation name="test_union">
+ <corba:operation name="test_union">
+ <corba:param idltype="ns1:Test.MultiPart.Description" mode="in" name="x"/>
+ <corba:param idltype="ns1:Test.MultiPart.Description" mode="inout"
+ name="y"/>
+ <corba:param idltype="ns1:Test.MultiPart.Description" mode="out" name="z"/>
+ <corba:return idltype="ns1:Test.MultiPart.Description" name="return"/>
+ </corba:operation>
+ <input name="test_union"/>
+ <output name="test_unionResponse"/>
+ </operation>
+ </binding>
+</definitions>
Propchange: incubator/yoko/trunk/tools/src/test/resources/idlgen/uniontypes.wsdl
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/yoko/trunk/tools/src/test/resources/idlgen/uniontypes.wsdl
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: incubator/yoko/trunk/tools/src/test/resources/wsdl/uniontype.wsdl
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/test/resources/wsdl/uniontype.wsdl?rev=423450&view=auto
==============================================================================
--- incubator/yoko/trunk/tools/src/test/resources/wsdl/uniontype.wsdl (added)
+++ incubator/yoko/trunk/tools/src/test/resources/wsdl/uniontype.wsdl Wed Jul 19 05:53:16 2006
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ * 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.
+-->
+
+<definitions name="multipart.idl"
+ targetNamespace="http://schemas.apache.org/idl/multipart.idl"
+ xmlns="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:tns="http://schemas.apache.org/idl/multipart.idl"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd1="http://schemas.apache.org/idltypes/multipart.idl"
+ xmlns:corba="http://schemas.apache.org/bindings/corba"
+ xmlns:corbatm="http://schemas.apache.org/bindings/corba/typemap">
+
+ <types>
+ <schema targetNamespace="http://schemas.apache.org/idltypes/multipart.idl"
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
+
+ <xsd:simpleType name="Test.MultiPart.Colour">
+ <xsd:restriction base="xsd:string">
+ <xsd:enumeration value="RED"/>
+ <xsd:enumeration value="GREEN"/>
+ <xsd:enumeration value="BLUE"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+
+ <xsd:complexType name="Test.MultiPart.Description">
+ <xsd:sequence>
+ <xsd:element minOccurs="1" maxOccurs="1" name="discriminator"
+ type="xsd1:Test.MultiPart.Colour"/>
+ <xsd:choice>
+ <xsd:element name="x" type="xsd:string"/>
+ <xsd:element name="y" type="xsd:int"/>
+ <xsd:element name="z" type="xsd:short"/>
+ </xsd:choice>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:element name="Test.MultiPart.test_enum.x" type="xsd1:Test.MultiPart.Colour"/>
+ <xsd:element name="Test.MultiPart.test_enum.y" type="xsd1:Test.MultiPart.Colour"/>
+ <xsd:element name="Test.MultiPart.test_enum.z" type="xsd1:Test.MultiPart.Colour"/>
+ <xsd:element name="Test.MultiPart.test_enum.return" type="xsd1:Test.MultiPart.Colour"/>
+
+ <xsd:element name="Test.MultiPart.test_union.x" type="xsd1:Test.MultiPart.Description"/>
+ <xsd:element name="Test.MultiPart.test_union.y" type="xsd1:Test.MultiPart.Description"/>
+ <xsd:element name="Test.MultiPart.test_union.z" type="xsd1:Test.MultiPart.Description"/>
+ <xsd:element name="Test.MultiPart.test_union.return" type="xsd1:Test.MultiPart.Description"/>
+ </schema>
+ </types>
+
+ <message name="Test.MultiPart.test_union">
+ <part name="x" element="xsd1:Test.MultiPart.test_union.x"/>
+ <part name="y" element="xsd1:Test.MultiPart.test_union.y"/>
+ </message>
+ <message name="Test.MultiPart.test_unionResponse">
+ <part name="return" element="xsd1:Test.MultiPart.test_union.return"/>
+ <part name="y" element="xsd1:Test.MultiPart.test_union.y"/>
+ <part name="z" element="xsd1:Test.MultiPart.test_union.z"/>
+ </message>
+
+ <portType name="Test.MultiPart">
+ <operation name="test_union">
+ <input message="tns:Test.MultiPart.test_union" name="test_union"/>
+ <output message="tns:Test.MultiPart.test_unionResponse" name="test_unionResponse"/>
+ </operation>
+ </portType>
+</definitions>
Propchange: incubator/yoko/trunk/tools/src/test/resources/wsdl/uniontype.wsdl
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/yoko/trunk/tools/src/test/resources/wsdl/uniontype.wsdl
------------------------------------------------------------------------------
svn:mime-type = text/xml