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 dm...@apache.org on 2007/03/28 16:33:50 UTC

svn commit: r523402 - in /incubator/yoko/trunk/bindings/src: main/java/org/apache/yoko/bindings/corba/runtime/ main/java/org/apache/yoko/bindings/corba/utils/ test/java/org/apache/yoko/bindings/corba/

Author: dmiddlem
Date: Wed Mar 28 09:33:49 2007
New Revision: 523402

URL: http://svn.apache.org/viewvc?view=rev&rev=523402
Log:
Commit for YOKO-319:
* Fixing bug that prevents enums from being used as discriminators
* Enabling the union portion of the IdlToWsdlTypeTest

Modified:
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/runtime/CorbaStaxObject.java
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/utils/CorbaUtils.java
    incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/AbstractIdlToWsdlTypeTestClient.java
    incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/IdlToWsdlTypeTest.java

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/runtime/CorbaStaxObject.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/runtime/CorbaStaxObject.java?view=diff&rev=523402&r1=523401&r2=523402
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/runtime/CorbaStaxObject.java (original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/runtime/CorbaStaxObject.java Wed Mar 28 09:33:49 2007
@@ -64,6 +64,7 @@
 import org.apache.ws.commons.schema.XmlSchemaGroupRef;
 import org.apache.ws.commons.schema.XmlSchemaObject;
 import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
+import org.apache.ws.commons.schema.XmlSchemaSequence;
 import org.apache.ws.commons.schema.XmlSchemaType;
 
 import org.apache.yoko.bindings.corba.CorbaBindingException;
@@ -1070,6 +1071,17 @@
         if (stype instanceof XmlSchemaComplexType) {
             XmlSchemaComplexType ctype = (XmlSchemaComplexType) stype;
             stype = ctype.getParticle();
+            
+            if (stype instanceof XmlSchemaSequence) {
+                XmlSchemaObjectCollection items = ((XmlSchemaSequence)stype).getItems();
+                for (int i = 0; i < items.getCount(); ++i) {
+                    XmlSchemaObject item = items.getItem(i);
+                    if (item instanceof XmlSchemaChoice) {
+                        stype = item;
+                        break;
+                    }
+                }
+            }
         }
         CorbaObjectHandler obj = null;
         if (!readElement) {
@@ -1141,9 +1153,17 @@
             // Build the entire union with all branches, etc.  Then read info from the XML Event Reader
             String branchName = null;
             XMLEvent evt = reader.peek();
+            
             if (evt.isStartElement()) {
-                StartElement branchElement = evt.asStartElement();
-                branchName = branchElement.getName().getLocalPart();
+                branchName = evt.asStartElement().getName().getLocalPart();
+            }
+            CorbaObjectHandler discObj = null;
+            // Check to see if we have the discriminator definition in Stax
+            if (branchName != null && branchName.equals("discriminator")) {
+                discObj = readObjectFromStax(reader, unionType.getDiscriminator(), null, true);
+                obj.setDiscriminator(discObj);
+                evt = reader.peek();
+                branchName = evt.asStartElement().getName().getLocalPart();
             }
             List<Unionbranch> branches = unionType.getUnionbranch();
             XmlSchemaObjectCollection items = choiceType.getItems();                
@@ -1154,28 +1174,29 @@
                     branchObj = readObjectFromStax(reader, branch.getIdltype(), items.getItem(i), true);
                     // We also need to set the discriminator since this is the branch with the actual
                     // union value
-                    CorbaObjectHandler discObj = 
-                        CorbaHandlerUtils.createTypeHandler(orb,
-                                                            new QName("discriminator"),
-                                                            unionType.getDiscriminator(),
-                                                            typeMaps,
-                                                            serviceInfo);
-                    obj.setDiscriminator(discObj);
+                    if (discObj == null) {
+                        discObj = CorbaHandlerUtils.createTypeHandler(orb,
+                                                                      new QName("discriminator"),
+                                                                      unionType.getDiscriminator(),
+                                                                      typeMaps,
+                                                                      serviceInfo);
+                        obj.setDiscriminator(discObj);
                     
-                    // Determine the value of the discriminator.  
-                    List<CaseType> branchCases = branch.getCase();
-                    String discValue = null;
-                    if (branchCases.size() != 0) {
-                        // This represents a union case.  Set the discriminator based on the first
-                        // label value associated with the branch (since we don't have this information)
-                        // from the Stax representation of the Celtix object).
-                        CaseType caseLabel = branchCases.get(0);
-                        discValue = caseLabel.getLabel();
-                    } else {
-                        // This represents the default case.
-                        discValue = obj.createDefaultDiscriminatorLabel();
+                        // Determine the value of the discriminator.  
+                        List<CaseType> branchCases = branch.getCase();
+                        String discValue = null;
+                        if (branchCases.size() != 0) {
+                            // This represents a union case.  Set the discriminator based on the first
+                            // label value associated with the branch (since we don't have this information)
+                            // from the Stax representation of the Celtix object).
+                            CaseType caseLabel = branchCases.get(0);
+                            discValue = caseLabel.getLabel();
+                        } else {
+                            // This represents the default case.
+                            discValue = obj.createDefaultDiscriminatorLabel();
+                        }
+                        obj.setDiscriminatorValueFromData(discValue);
                     }
-                    obj.setDiscriminatorValueFromData(discValue);
                     obj.setValue(branchName, branchObj);
                 } else {
                     XmlSchemaElement el = (XmlSchemaElement) items.getItem(i);
@@ -1234,6 +1255,22 @@
         } else {
             StartElement startEl = factory.createStartElement(objName, null, null);
             writer.add(startEl);
+            CorbaObjectHandler discValue = unionHandler.getDiscriminator();
+            if (discValue != null) {
+                Object value = null;
+                // the discriminator is either an enum or primitive type
+                if (discValue instanceof CorbaEnumHandler) {
+                    value = ((CorbaEnumHandler)discValue).getValue();
+                } else {
+                    value = ((CorbaPrimitiveHandler)discValue).getValue();
+                }
+
+                // we can have the situation where the discriminator object has
+                // been created but has no real value (a default case)
+                if (value != null) {
+                    writeObjectToStax(discValue, stype, writer, factory, true);
+                }
+            }
             CorbaObjectHandler unionValue = unionHandler.getValue();
             if (unionValue != null) {
                 writeObjectToStax(unionValue, stype, writer, factory, true);

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/utils/CorbaUtils.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/utils/CorbaUtils.java?view=diff&rev=523402&r1=523401&r2=523402
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/utils/CorbaUtils.java (original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/utils/CorbaUtils.java Wed Mar 28 09:33:49 2007
@@ -264,6 +264,7 @@
                     //    * signed & unsigned long long
                     //    * char
                     //    * boolean
+                    //    * enum
                     switch (discTC.kind().value()) {
                     case TCKind._tk_short:
                         member.label.insert_short(Short.parseShort(cs.getLabel()));
@@ -289,8 +290,20 @@
                     case TCKind._tk_boolean:
                         member.label.insert_boolean(Boolean.parseBoolean(cs.getLabel()));
                         break;
+                    case TCKind._tk_enum:
+                        org.omg.CORBA.portable.OutputStream out = member.label.create_output_stream();
+                        Enum enumVal = (Enum)getCorbaType(unionType.getDiscriminator(), typeMaps);
+                        List<Enumerator> enumerators = enumVal.getEnumerator();
+                        for (int i = 0; i < enumerators.size(); ++i) {
+                            Enumerator e = enumerators.get(i);
+                            if (e.getValue().equals(cs.getLabel())) {
+                                out.write_long(i);
+                            }
+                        }
+                        member.label.read_value(out.create_input_stream(), discTC);
+                        break;
                     default:
-                        // TODO: Throw exception since this is an unsupported discriminator type
+                        throw new CorbaBindingException("Unsupported discriminator type");
                     }
                     // Yoko orb is strict on how the case labels are stored for each member.  So we can't
                     // simply insert the labels as strings 

Modified: incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/AbstractIdlToWsdlTypeTestClient.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/AbstractIdlToWsdlTypeTestClient.java?view=diff&rev=523402&r1=523401&r2=523402
==============================================================================
--- incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/AbstractIdlToWsdlTypeTestClient.java (original)
+++ incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/AbstractIdlToWsdlTypeTestClient.java Wed Mar 28 09:33:49 2007
@@ -578,6 +578,11 @@
 
     private boolean compareUnion(IdltowsdlTypeTestUnion1 left, IdltowsdlTypeTestUnion1 right) {
         boolean result = true;
+        // Need to handle the case were we are using the default union case and the discrimintator 
+        // is not set (i.e. null).
+        if (left.getDiscriminator() == null) {
+            return (left.getU13().equals(right.getU13()));
+        }
         if (left.getDiscriminator().equals(right.getDiscriminator())) {
             IdltowsdlTypeTestEnum1 discriminator = left.getDiscriminator();
             if (discriminator.equals(IdltowsdlTypeTestEnum1.E_1_1)) {

Modified: incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/IdlToWsdlTypeTest.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/IdlToWsdlTypeTest.java?view=diff&rev=523402&r1=523401&r2=523402
==============================================================================
--- incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/IdlToWsdlTypeTest.java (original)
+++ incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/IdlToWsdlTypeTest.java Wed Mar 28 09:33:49 2007
@@ -116,5 +116,5 @@
     public void testOctet () { }
     public void testAny () { }
     public void testWstring() { }
-    public void testUnion() { }    
+    //public void testUnion() { }    
 }