incubator-yoko-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r500339 - in /incubator/yoko/trunk/bindings/src: main/java/org/apache/yoko/bindings/corba/CorbaStaxObject.java test/java/org/apache/yoko/bindings/corba/CorbaStaxObjectTest.java test/java/org/apache/yoko/bindings/corba/CorbaTypeTest.java
Date Fri, 26 Jan 2007 20:51:31 GMT
Author: bravi
Date: Fri Jan 26 12:51:31 2007
New Revision: 500339

URL: http://svn.apache.org/viewvc?view=rev&rev=500339
Log:
[YOKO-170] - Adding XmlSchemaObject when writing to stax & also enabled the anonymous
struct type_test.

Modified:
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStaxObject.java
    incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaStaxObjectTest.java
    incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaTypeTest.java

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=500339&r1=500338&r2=500339
==============================================================================
--- 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
Fri Jan 26 12:51:31 2007
@@ -204,10 +204,16 @@
     public void writeObjectToStax(CorbaObjectHandler obj,
                                   XMLEventWriter writer,
                                   XMLEventFactory factory) {
-        writeObjectToStax(obj, writer, factory, false);
+        XmlSchemaType schemaType = null;
+        if (obj != null && obj.getType() != null) {
+            CorbaTypeImpl type = obj.getType();
+            schemaType = CorbaUtils.getXmlSchemaType(serviceInfo, type.getType());
+        }
+        writeObjectToStax(obj, schemaType, writer, factory, false);
     }
 
     protected void writeObjectToStax(CorbaObjectHandler obj,
+                                     XmlSchemaObject schemaType,
                                      XMLEventWriter writer,
                                      XMLEventFactory factory,
                                      boolean isNested) {
@@ -215,41 +221,41 @@
             if (obj != null) {
                 TypeCode tc = obj.getTypeCode();
                 if (CorbaUtils.isPrimitiveIdlType(obj.getIdlType())) {
-                    writePrimitiveToStax(obj, writer, factory);
+                    writePrimitiveToStax(obj, schemaType, writer, factory);
                 } else {
                     switch (tc.kind().value()) {
                     case TCKind._tk_array:
                         LOG.log(Level.INFO, "Writing array type to XML writer");
-                        writeArrayToStax(obj, writer, factory, !isNested);
+                        writeArrayToStax(obj, schemaType, writer, factory, !isNested);
                         break;
                     case TCKind._tk_enum:
                         LOG.log(Level.INFO, "Writing enum type to XML writer");
-                        writeEnumToStax(obj, writer, factory);
+                        writeEnumToStax(obj, schemaType, writer, factory);
                         break;
                     case TCKind._tk_except:
                         LOG.log(Level.INFO, "Writing exception type to XML writer");
-                        writeExceptionToStax(obj, writer, factory);
+                        writeExceptionToStax(obj, schemaType, writer, factory);
                         break;
                     case TCKind._tk_fixed:
                         LOG.log(Level.INFO, "Writing fixed type to XML writer");
-                        writeFixedToStax(obj, writer, factory);
+                        writeFixedToStax(obj, schemaType, writer, factory);
                         break;
                     case TCKind._tk_sequence:
                         LOG.log(Level.INFO, "Writing sequence type to XML writer");
-                        writeSequenceToStax(obj, writer, factory, !isNested);
+                        writeSequenceToStax(obj, schemaType, writer, factory, !isNested);
                         break;
                     case TCKind._tk_struct:
                         LOG.log(Level.INFO, "Writing struct type to XML writer");
-                        writeStructToStax(obj, writer, factory);
+                        writeStructToStax(obj, schemaType, writer, factory);
                         break;
                     case TCKind._tk_union:
                         LOG.log(Level.INFO, "Writing union type to XML writer");
-                        writeUnionToStax(obj, writer, factory);
+                        writeUnionToStax(obj, schemaType, writer, factory);
                         break;
                     case TCKind._tk_string:
                     case TCKind._tk_wstring:
                         LOG.log(Level.INFO, "Wrting anonymous string to XML writer");
-                        writePrimitiveToStax(obj, writer, factory);
+                        writePrimitiveToStax(obj, schemaType, writer, factory);
                         break;
                     default:
                         throw new CorbaBindingException("Unsupported complex type");
@@ -315,6 +321,7 @@
     }
     
     protected void writePrimitiveToStax(CorbaObjectHandler obj,
+                                        XmlSchemaObject schemaObj,
                                         XMLEventWriter writer,
                                         XMLEventFactory factory) 
         throws XMLStreamException {
@@ -445,16 +452,21 @@
     }
 
     protected void writeArrayToStax(CorbaObjectHandler obj,
+                                    XmlSchemaObject schemaType,
                                     XMLEventWriter writer,
                                     XMLEventFactory factory,
                                     boolean isTopLevel) 
         throws XMLStreamException {
+        if (schemaType == null) {
+            throw new CorbaBindingException("Couldn't find xml schema object for : " + obj.getIdlType());
+        }
         QName objName = obj.getName();
         if (isTopLevel) {
             StartElement startEl = factory.createStartElement(objName, null, null);
             writer.add(startEl);
         }
         CorbaArrayHandler arrayHandler = (CorbaArrayHandler)obj;
+        XmlSchemaElement el = getXmlSchemaSequenceElement(schemaType, obj.getIdlType());
         List<CorbaObjectHandler> elements = arrayHandler.getElements();
         for (Iterator<CorbaObjectHandler> elementsIter = elements.iterator(); elementsIter.hasNext();)
{
             CorbaObjectHandler handler = elementsIter.next();
@@ -464,7 +476,7 @@
                 StartElement startEl = factory.createStartElement(handlerName, null, null);
                 writer.add(startEl);
             }
-            writeObjectToStax(handler, writer, factory, true);
+            writeObjectToStax(handler, el, writer, factory, true);
             if (nestedArray) {
                 EndElement endEl = factory.createEndElement(handlerName, null);
                 writer.add(endEl);
@@ -497,7 +509,10 @@
         return obj;
     }
     
-    protected void writeEnumToStax(CorbaObjectHandler obj, XMLEventWriter writer, XMLEventFactory
factory) 
+    protected void writeEnumToStax(CorbaObjectHandler obj,
+                                   XmlSchemaObject schemaType,
+                                   XMLEventWriter writer,
+                                   XMLEventFactory factory) 
         throws XMLStreamException {
         QName objName = obj.getName();
         StartElement startEl = factory.createStartElement(objName, null, null);
@@ -542,16 +557,22 @@
     }
 
     protected void writeExceptionToStax(CorbaObjectHandler obj,
+                                        XmlSchemaObject schemaType,
                                         XMLEventWriter writer,
                                         XMLEventFactory factory) 
         throws XMLStreamException {
+        if (schemaType == null) {
+            throw new CorbaBindingException("Couldn't find xml schema object for : " + obj.getIdlType());
+        }
         QName objName = obj.getName();
         StartElement startEl = factory.createStartElement(objName, null, null);
         writer.add(startEl);
         CorbaExceptionHandler exObj = (CorbaExceptionHandler)obj;
+        XmlSchemaComplexType ctype = (XmlSchemaComplexType) schemaType;
+        XmlSchemaGroupBase group = (XmlSchemaGroupBase) ctype.getParticle();
         List<CorbaObjectHandler> elements = exObj.getMembers();
-        for (Iterator<CorbaObjectHandler> elementsIter = elements.iterator(); elementsIter.hasNext();)
{
-            writeObjectToStax(elementsIter.next(), writer, factory, true);
+        for (int i = 0; i < elements.size(); i++) {
+            writeObjectToStax(elements.get(i), group.getItems().getItem(i), writer, factory,
true);
         }
         EndElement endEl = factory.createEndElement(objName, null);
         writer.add(endEl); 
@@ -642,15 +663,20 @@
     }
 
     protected void writeSequenceToStax(CorbaObjectHandler obj,
+                                       XmlSchemaObject schemaType,
                                        XMLEventWriter writer,
                                        XMLEventFactory factory,
                                        boolean isTopLevel) 
         throws XMLStreamException {
+        if (schemaType == null) {
+            throw new CorbaBindingException("Couldn't find xml schema object for : " + obj.getIdlType());
+        }
         QName name = obj.getName();
         if (isTopLevel) {
             StartElement startEl = factory.createStartElement(name, null, null);
             writer.add(startEl);
         }
+        XmlSchemaElement el = getXmlSchemaSequenceElement(schemaType, obj.getIdlType());
         CorbaSequenceHandler seqHandler = (CorbaSequenceHandler)obj;
         List<CorbaObjectHandler> elements = seqHandler.getElements();
         for (Iterator<CorbaObjectHandler> elementsIter = elements.iterator(); elementsIter.hasNext();)
{
@@ -661,7 +687,7 @@
                 StartElement startEl = factory.createStartElement(objName, null, null);
                 writer.add(startEl);
             }
-            writeObjectToStax(handler, writer, factory, true);
+            writeObjectToStax(handler, el, writer, factory, true);
             if (nestedSequence) {
                 EndElement endEl = factory.createEndElement(objName, null);
                 writer.add(endEl);
@@ -746,18 +772,63 @@
         return obj;
     }
 
-    protected void writeStructToStax(CorbaObjectHandler obj, XMLEventWriter writer, XMLEventFactory
factory) 
+    protected void writeStructToStax(CorbaObjectHandler obj,
+                                     XmlSchemaObject schemaType,
+                                     XMLEventWriter writer,
+                                     XMLEventFactory factory) 
         throws XMLStreamException {
+        if (schemaType == null) {
+            throw new CorbaBindingException("Couldn't find xml schema object for : " + obj.getIdlType());
+        }
         QName objName = obj.getName();
-        StartElement startEl = factory.createStartElement(objName, null, null);
-        writer.add(startEl);
+        XmlSchemaObjectCollection attrs = null;
+        XmlSchemaObjectCollection members = null;
+            
+        boolean writeElement = false;
+
+        XmlSchemaObject stype = schemaType;
+        if (schemaType instanceof XmlSchemaElement) {
+            XmlSchemaElement el = (XmlSchemaElement) schemaType;
+            stype = el.getSchemaType();
+            if (stype == null) {
+                stype = CorbaUtils.getXmlSchemaType(serviceInfo, el.getRefName());
+            }
+            writeElement = true;
+        }
+        if (stype instanceof XmlSchemaComplexType) {
+            XmlSchemaComplexType ctype = (XmlSchemaComplexType) stype;
+            attrs = ctype.getAttributes();
+            stype = ctype.getParticle();
+            writeElement = true;
+        }
+        if (stype instanceof XmlSchemaGroupRef) {
+            members = ((XmlSchemaGroupRef) stype).getParticle().getItems();
+        } else if (stype instanceof XmlSchemaGroupBase) {
+            members = ((XmlSchemaGroupBase) stype).getItems();
+        }
+        
+        if (writeElement) {
+            StartElement startEl = factory.createStartElement(objName, null, null);
+            writer.add(startEl);
+        }
+        
         CorbaStructHandler structHandler = (CorbaStructHandler)obj;
         List<CorbaObjectHandler> elements = structHandler.getMembers();
+        int attrCount = 0;
+        int memberCount = 0;
         for (Iterator<CorbaObjectHandler> elementsIter = elements.iterator(); elementsIter.hasNext();)
{
-            writeObjectToStax(elementsIter.next(), writer, factory, true);
+            XmlSchemaObject schemaObj;
+            if ((attrs != null) && (attrCount != attrs.getCount())) {
+                schemaObj = attrs.getItem(attrCount++);
+            } else {
+                schemaObj = members.getItem(memberCount++);
+            }
+            writeObjectToStax(elementsIter.next(), schemaObj, writer, factory, true);
+        }
+        if (writeElement) {
+            EndElement endEl = factory.createEndElement(objName, null);
+            writer.add(endEl);
         }
-        EndElement endEl = factory.createEndElement(objName, null);
-        writer.add(endEl); 
     }
 
 
@@ -838,16 +909,19 @@
         return obj;
     }
     
-    protected void writeUnionToStax(CorbaObjectHandler obj, XMLEventWriter writer, XMLEventFactory
factory)
+    protected void writeUnionToStax(CorbaObjectHandler obj,
+                                    XmlSchemaObject schemaType,
+                                    XMLEventWriter writer,
+                                    XMLEventFactory factory)
         throws XMLStreamException {
         QName objName = obj.getName();
         StartElement startEl = factory.createStartElement(objName, null, null);
         writer.add(startEl);
         CorbaUnionHandler unionHandler = (CorbaUnionHandler)obj;
         CorbaObjectHandler discValue = unionHandler.getDiscriminator();
-        writeObjectToStax(discValue, writer, factory, true);
+        writeObjectToStax(discValue, null, writer, factory, true);
         CorbaObjectHandler unionValue = unionHandler.getValue();
-        writeObjectToStax(unionValue, writer, factory, true);
+        writeObjectToStax(unionValue, null, writer, factory, true);
         EndElement endEl = factory.createEndElement(objName, null);
         writer.add(endEl); 
     }
@@ -872,7 +946,10 @@
         return obj;
     }
     
-    protected void writeFixedToStax(CorbaObjectHandler obj, XMLEventWriter writer, XMLEventFactory
factory) 
+    protected void writeFixedToStax(CorbaObjectHandler obj,
+                                    XmlSchemaObject schemaType,
+                                    XMLEventWriter writer,
+                                    XMLEventFactory factory) 
         throws XMLStreamException {
         QName objName = obj.getName();
         StartElement startEl = factory.createStartElement(objName, null, null);

Modified: incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaStaxObjectTest.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaStaxObjectTest.java?view=diff&rev=500339&r1=500338&r2=500339
==============================================================================
--- incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaStaxObjectTest.java
(original)
+++ incubator/yoko/trunk/bindings/src/test/java/org/apache/yoko/bindings/corba/CorbaStaxObjectTest.java
Fri Jan 26 12:51:31 2007
@@ -423,7 +423,6 @@
         } catch (XMLStreamException ex) {
             
         }
-        System.out.println(new String(outStream.toByteArray()));
         ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
       
         XMLEventReader evtReader = null;
         try {            

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=500339&r1=500338&r2=500339
==============================================================================
--- 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
Fri Jan 26 12:51:31 2007
@@ -79,12 +79,6 @@
     public void testStructWithNillables() throws Exception  {
     }
 
-    public void testCompoundArray() throws Exception  {
-    }
-
-    public void testAnonymousStruct() throws Exception {
-    }
-
     public void testEmptyChoice() throws Exception {
     }
 



Mime
View raw message