incubator-yoko-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r501962 - in /incubator/yoko/trunk: bindings/src/main/java/org/apache/yoko/bindings/corba/ bindings/src/main/java/org/apache/yoko/bindings/corba/types/ bindings/src/test/java/org/apache/yoko/bindings/corba/ tools/src/main/java/org/apache/yo...
Date Wed, 31 Jan 2007 19:44:03 GMT
Author: bravi
Date: Wed Jan 31 11:44:02 2007
New Revision: 501962

URL: http://svn.apache.org/viewvc?view=rev&rev=501962
Log:
[YOKO-170] - Fixing the Choice types in the corba binding. Also enabled the test cases in
the type test.

Modified:
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReader.java
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectWriter.java
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStaxObject.java
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaUtils.java
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/types/CorbaHandlerUtils.java
    incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaTypeTest.java
    incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToCorbaHelper.java

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReader.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReader.java?view=diff&rev=501962&r1=501961&r2=501962
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReader.java
(original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReader.java
Wed Jan 31 11:44:02 2007
@@ -313,49 +313,49 @@
 
     public void readUnion(CorbaObjectHandler obj) throws CorbaBindingException {
         CorbaUnionHandler unionHandler = (CorbaUnionHandler)obj;
-        CorbaObjectHandler discriminator = unionHandler.getDiscriminator();
-        
-        this.read(discriminator);
-        
-        String discLabel = null;
-        if (discriminator.getTypeCodeKind().value() == TCKind._tk_enum) {
-            discLabel = ((CorbaEnumHandler)discriminator).getValue();
-        } else {
-            discLabel = ((CorbaPrimitiveHandler)discriminator).getDataFromValue(); 
-        }
-        
-        // Now find the label in the union to get the right case
         Union unionType = (Union)unionHandler.getType();
         List<Unionbranch> branches = unionType.getUnionbranch();
-        Unionbranch defaultBranch = null;
-        boolean caseFound = false;
-        for (Iterator<Unionbranch> branchIter = branches.iterator(); branchIter.hasNext();)
{
-            Unionbranch branch = branchIter.next();
-            if (branch.isSetDefault() && branch.isDefault()) {
-                defaultBranch = branch;
+        CorbaObjectHandler discriminator = unionHandler.getDiscriminator();
+        if (branches.size() > 0) {
+            this.read(discriminator);
+            String discLabel = null;
+            if (discriminator.getTypeCodeKind().value() == TCKind._tk_enum) {
+                discLabel = ((CorbaEnumHandler)discriminator).getValue();
+            } else {
+                discLabel = ((CorbaPrimitiveHandler)discriminator).getDataFromValue(); 
             }
-            List<CaseType> cases = branch.getCase();
-            for (Iterator<CaseType> caseIter = cases.iterator(); caseIter.hasNext();)
{
-                CaseType c = caseIter.next();
-                if (c.getLabel().equalsIgnoreCase(discLabel)) {
-                    CorbaObjectHandler branchObj = unionHandler.getBranchByName(branch.getName());
-                    this.read(branchObj);
-                    unionHandler.setValue(branch.getName(), branchObj);
-                    caseFound = true;
+        
+            // Now find the label in the union to get the right case
+            Unionbranch defaultBranch = null;
+            boolean caseFound = false;
+            for (Iterator<Unionbranch> branchIter = branches.iterator(); branchIter.hasNext();)
{
+                Unionbranch branch = branchIter.next();
+                if (branch.isSetDefault() && branch.isDefault()) {
+                    defaultBranch = branch;
+                }
+                List<CaseType> cases = branch.getCase();
+                for (Iterator<CaseType> caseIter = cases.iterator(); caseIter.hasNext();)
{
+                    CaseType c = caseIter.next();
+                    if (c.getLabel().equalsIgnoreCase(discLabel)) {
+                        CorbaObjectHandler branchObj = unionHandler.getBranchByName(branch.getName());
+                        this.read(branchObj);
+                        unionHandler.setValue(branch.getName(), branchObj);
+                        caseFound = true;
+                        break;
+                    }
+                }
+                if (caseFound) {
                     break;
                 }
             }
-            if (caseFound) {
-                break;
+            
+            // If we never find a case that matches the value of the discriminiator, then
we must have
+            // found the default case.
+            if (!caseFound && defaultBranch != null) {
+                CorbaObjectHandler branchObj = unionHandler.getBranchByName(defaultBranch.getName());
+                this.read(branchObj);
+                unionHandler.setValue(defaultBranch.getName(), branchObj);
             }
-        }
-        
-        // If we never find a case that matches the value of the discriminiator, then we
must have
-        // found the default case.
-        if (!caseFound && defaultBranch != null) {
-            CorbaObjectHandler branchObj = unionHandler.getBranchByName(defaultBranch.getName());
-            this.read(branchObj);
-            unionHandler.setValue(defaultBranch.getName(), branchObj);
         }
     }
 

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectWriter.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectWriter.java?view=diff&rev=501962&r1=501961&r2=501962
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectWriter.java
(original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectWriter.java
Wed Jan 31 11:44:02 2007
@@ -24,6 +24,8 @@
 import org.apache.schemas.yoko.bindings.corba.Enum;
 import org.apache.schemas.yoko.bindings.corba.Enumerator;
 import org.apache.schemas.yoko.bindings.corba.Exception;
+import org.apache.schemas.yoko.bindings.corba.Union;
+import org.apache.schemas.yoko.bindings.corba.Unionbranch;
 import org.apache.yoko.bindings.corba.types.CorbaAnyHandler;
 import org.apache.yoko.bindings.corba.types.CorbaArrayHandler;
 import org.apache.yoko.bindings.corba.types.CorbaEnumHandler;
@@ -229,11 +231,15 @@
     }
 
     public void writeUnion(CorbaObjectHandler obj) throws CorbaBindingException {
-        CorbaObjectHandler discriminator = ((CorbaUnionHandler)obj).getDiscriminator();
-        this.write(discriminator);
-        CorbaObjectHandler unionValue = ((CorbaUnionHandler)obj).getValue();
-        if (unionValue != null) {
-            this.write(unionValue);
+        Union unionType = (Union) obj.getType();
+        List<Unionbranch> branches = unionType.getUnionbranch();
+        if (branches.size() > 0) {
+            CorbaObjectHandler discriminator = ((CorbaUnionHandler)obj).getDiscriminator();
+            this.write(discriminator);
+            CorbaObjectHandler unionValue = ((CorbaUnionHandler)obj).getValue();
+            if (unionValue != null) {
+                this.write(unionValue);
+            }
         }
     }
 

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStaxObject.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStaxObject.java?view=diff&rev=501962&r1=501961&r2=501962
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStaxObject.java
(original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStaxObject.java
Wed Jan 31 11:44:02 2007
@@ -54,6 +54,7 @@
 import org.apache.schemas.yoko.bindings.corba.Unionbranch;
 
 import org.apache.ws.commons.schema.XmlSchemaAttribute;
+import org.apache.ws.commons.schema.XmlSchemaChoice;
 import org.apache.ws.commons.schema.XmlSchemaComplexType;
 import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.ws.commons.schema.XmlSchemaGroupBase;
@@ -929,73 +930,25 @@
             if (stype == null) {
                 stype = CorbaUtils.getXmlSchemaType(serviceInfo, el.getRefName());
             }       
+        } 
+        if (stype instanceof XmlSchemaComplexType) {
+            XmlSchemaComplexType ctype = (XmlSchemaComplexType) stype;
+            stype = ctype.getParticle();
         }
-        CorbaUnionHandler obj = null;
+        CorbaObjectHandler obj = null;
         if (!readElement) {
-            obj = readAttributeOrNillableElementFromStax(reader, elName, idlType, tc, schemaType);
+            obj = readAttributeOrNillableElementFromStax(reader, elName, idlType, tc, stype);
         } else {
-            try {
-                Union unionType = (Union) CorbaUtils.getCorbaType(idlType, typeMaps);
-                elName = reader.nextEvent().asStartElement().getName();
-                obj = new CorbaUnionHandler(elName, idlType, tc, unionType);
-                // Build the entire union with all branches, etc.  Then read info from the
XML Event Reader
-                StartElement branchElement = reader.peek().asStartElement();
-                String branchName = branchElement.getName().getLocalPart();
-                List<Unionbranch> branches = unionType.getUnionbranch();
-                for (Iterator<Unionbranch> branchesIter = branches.iterator(); branchesIter.hasNext();)
{
-                    Unionbranch branch = branchesIter.next();
-                    CorbaObjectHandler branchObj = null;
-                    if (branch.getName().equals(branchName)) {
-                        branchObj = readObjectFromStax(reader, branch.getIdltype(), stype,
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);
-
-                        // 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.setValue(branchName, branchObj);
-                    } else {
-                        // Create an object holder with no value
-                        branchObj = CorbaHandlerUtils.createTypeHandler(orb,
-                                                                        new QName(branch.getName()),
-                                                                        branch.getIdltype(),
-                                                                        typeMaps,
-                                                                        serviceInfo);
-                    }
-                    obj.addCase(branchObj);
-                }
-                reader.nextEvent().asEndElement();
-            } catch (java.lang.Exception ex) {
-                LOG.log(Level.SEVERE, "Received exception while reading object of type "
+ idlType);
-                throw new CorbaBindingException("Error while reading union corba type", ex);
-            }
+            obj = readChoiceFromStax(reader, idlType, tc, stype);
         }
         return obj;
     }
  
-    private CorbaUnionHandler readAttributeOrNillableElementFromStax(XMLEventReader reader,
-                                                                     QName name,
-                                                                     QName idlType,
-                                                                     TypeCode tc,
-                                                                     XmlSchemaObject schemaType)
+    private CorbaObjectHandler readAttributeOrNillableElementFromStax(XMLEventReader reader,
+                                                                      QName name,
+                                                                      QName idlType,
+                                                                      TypeCode tc,
+                                                                      XmlSchemaObject schemaType)
         throws CorbaBindingException {
         Union unionType = (Union) CorbaUtils.getCorbaType(idlType, typeMaps);
         CorbaUnionHandler obj = new CorbaUnionHandler(name, idlType, tc, unionType);
@@ -1038,6 +991,79 @@
         return obj;
     }
    
+    protected CorbaObjectHandler readChoiceFromStax(XMLEventReader reader,
+                                                    QName idlType,
+                                                    TypeCode tc,
+                                                    XmlSchemaObject schemaType)
+        throws CorbaBindingException {
+        CorbaUnionHandler obj = null;
+        try {
+            XmlSchemaChoice choiceType = (XmlSchemaChoice) schemaType;
+            Union unionType = (Union) CorbaUtils.getCorbaType(idlType, typeMaps);
+            QName elName = reader.nextEvent().asStartElement().getName();
+            obj = new CorbaUnionHandler(elName, idlType, tc, unionType);
+            // 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();
+            }
+            List<Unionbranch> branches = unionType.getUnionbranch();
+            XmlSchemaObjectCollection items = choiceType.getItems();                
+            for (int i = 0; i < branches.size(); i++) {
+                Unionbranch branch = branches.get(i);
+                CorbaObjectHandler branchObj = null;
+                if (branch.getName().equals(branchName)) {
+                    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);
+                    
+                    // 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.setValue(branchName, branchObj);
+                } else {
+                    XmlSchemaElement el = (XmlSchemaElement) items.getItem(i);
+                    QName qname = new QName("", branch.getName());
+                    if (CorbaUtils.isElementFormQualified(serviceInfo, el.getQName().getNamespaceURI()))
{
+                        qname = el.getQName();
+                    }
+                    // Create an object holder with no value
+                    branchObj = CorbaHandlerUtils.createTypeHandler(orb,
+                                                                    qname,
+                                                                    branch.getIdltype(),
+                                                                    typeMaps,
+                                                                    serviceInfo);
+                }
+                obj.addCase(branchObj);
+            }
+            reader.nextEvent().asEndElement();
+        } catch (java.lang.Exception ex) {
+            LOG.log(Level.SEVERE, "Received exception while reading object of type " + idlType);
+            throw new CorbaBindingException("Error while reading union corba type", ex);
+        }
+        return obj;
+    }
+
     protected void writeUnionToStax(CorbaObjectHandler obj,
                                     QName objName,
                                     XmlSchemaObject schemaType,
@@ -1073,7 +1099,9 @@
             StartElement startEl = factory.createStartElement(objName, null, null);
             writer.add(startEl);
             CorbaObjectHandler unionValue = unionHandler.getValue();
-            writeObjectToStax(unionValue, stype, writer, factory, true);
+            if (unionValue != null) {
+                writeObjectToStax(unionValue, stype, writer, factory, true);
+            }
             EndElement endEl = factory.createEndElement(objName, null);
             writer.add(endEl);
         }

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaUtils.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaUtils.java?view=diff&rev=501962&r1=501961&r2=501962
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaUtils.java
(original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaUtils.java
Wed Jan 31 11:44:02 2007
@@ -82,7 +82,6 @@
 
     public static TypeCode getTypeCode(ORB orb, QName type, CorbaType obj, List<CorbaTypeMap>
typeMaps) {
         TypeCode tc = null;
-
         // first see if it is a primitive
         tc = getPrimitiveTypeCode(orb, type);
         if (tc == null) {

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/types/CorbaHandlerUtils.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/types/CorbaHandlerUtils.java?view=diff&rev=501962&r1=501961&r2=501962
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/types/CorbaHandlerUtils.java
(original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/types/CorbaHandlerUtils.java
Wed Jan 31 11:44:02 2007
@@ -114,8 +114,6 @@
         XmlSchemaType schemaType = null;
         if (type != null) {
             schemaType = CorbaUtils.getXmlSchemaType(serviceInfo, type.getType());
-            String nsUri = getNamespaceURI(serviceInfo, type.getType());
-            name = new QName(nsUri, name.getLocalPart());
         }
         return initializeObjectHandler(orb, name, idlType, schemaType, typeMaps, serviceInfo);
     }
@@ -127,7 +125,12 @@
                                                              List<CorbaTypeMap> typeMaps,
                                                              ServiceInfo serviceInfo) {
         CorbaObjectHandler obj = createTypeHandler(orb, name, idlType, typeMaps, serviceInfo);
-        name = obj.getName();
+        if (obj.getType() != null) {
+            String nsUri = getNamespaceURI(serviceInfo, obj.getType().getType());
+            name = new QName(nsUri, obj.getName().getLocalPart());
+        } else {
+            name = obj.getName();
+        }
         if (!CorbaUtils.isPrimitiveIdlType(idlType)) {
             switch (obj.getTypeCode().kind().value()) {
             case TCKind._tk_array:

Modified: incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaTypeTest.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaTypeTest.java?view=diff&rev=501962&r1=501961&r2=501962
==============================================================================
--- incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaTypeTest.java
(original)
+++ incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaTypeTest.java
Wed Jan 31 11:44:02 2007
@@ -76,12 +76,6 @@
     public void testHexBinary() throws Exception  {
     }
 
-    public void testEmptyChoice() throws Exception {
-    }
-
-    public void testSimpleChoice() throws Exception {
-    }
-
     public void testNumberEnum() throws Exception {
     }
     public void testStringEnum() throws Exception {

Modified: incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToCorbaHelper.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToCorbaHelper.java?view=diff&rev=501962&r1=501961&r2=501962
==============================================================================
--- incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToCorbaHelper.java
(original)
+++ incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToCorbaHelper.java
Wed Jan 31 11:44:02 2007
@@ -224,9 +224,9 @@
         QName choicename = null;
 
         if (schemaTypeName == null) {
-            choicename = createQNameTargetNamespace(defaultName.getLocalPart());
+            choicename = createQNameCorbaNamespace(defaultName.getLocalPart());
         } else {
-            choicename = createQNameTargetNamespace(schemaTypeName.getLocalPart());
+            choicename = createQNameCorbaNamespace(schemaTypeName.getLocalPart());
         }
         choicename = checkPrefix(choicename);
 
@@ -843,7 +843,6 @@
         throws Exception {
         QName name;
         Struct corbaStruct = null;
-        
         QName schematypeName = checkPrefix(complex.getQName());               
         if (schematypeName == null) {
             schematypeName = checkPrefix(defaultName);
@@ -1132,9 +1131,9 @@
 
         if (schematypeName == null) {
             schematypeName = defaultName;
-            name = createQNameTargetNamespace(defaultName.getLocalPart() + "Type");
+            name = createQNameCorbaNamespace(defaultName.getLocalPart() + "Type");
         } else {
-            name = createQNameTargetNamespace(schematypeName.getLocalPart());
+            name = createQNameCorbaNamespace(schematypeName.getLocalPart());
         }
 
         corbaUnion = new Union();
@@ -1216,9 +1215,9 @@
         
         if (schematypeName == null) {
             schematypeName = defaultName;
-            name = createQNameTargetNamespace(defaultName.getLocalPart() + "Type");
+            name = createQNameCorbaNamespace(defaultName.getLocalPart() + "Type");
         } else {
-            name = createQNameTargetNamespace(schematypeName.getLocalPart());
+            name = createQNameCorbaNamespace(schematypeName.getLocalPart());
         }
 
         return createUnion(name, (XmlSchemaChoice)complex.getParticle(), defaultName, schematypeName);
       



Mime
View raw message