incubator-yoko-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eno...@apache.org
Subject svn commit: r483585 [2/2] - in /incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba: ./ extensions/
Date Thu, 07 Dec 2006 18:10:26 GMT
Added: 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=auto&rev=483585
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStaxObject.java
(added)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStaxObject.java
Thu Dec  7 10:10:25 2006
@@ -0,0 +1,629 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.yoko.bindings.corba;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventFactory;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.Characters;
+import javax.xml.stream.events.EndElement;
+import javax.xml.stream.events.StartElement;
+
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.schemas.yoko.bindings.corba.Anonarray;
+import org.apache.schemas.yoko.bindings.corba.Anonsequence;
+import org.apache.schemas.yoko.bindings.corba.Array;
+import org.apache.schemas.yoko.bindings.corba.CaseType;
+import org.apache.schemas.yoko.bindings.corba.Enum;
+import org.apache.schemas.yoko.bindings.corba.Exception;
+import org.apache.schemas.yoko.bindings.corba.MemberType;
+import org.apache.schemas.yoko.bindings.corba.Sequence;
+import org.apache.schemas.yoko.bindings.corba.Struct;
+import org.apache.schemas.yoko.bindings.corba.Union;
+import org.apache.schemas.yoko.bindings.corba.Unionbranch;
+import org.apache.yoko.bindings.corba.interceptors.CorbaOutInterceptor;
+import org.apache.yoko.bindings.corba.types.CorbaAnyHandler;
+import org.apache.yoko.bindings.corba.types.CorbaArrayHandler;
+import org.apache.yoko.bindings.corba.types.CorbaEnumHandler;
+import org.apache.yoko.bindings.corba.types.CorbaExceptionHandler;
+import org.apache.yoko.bindings.corba.types.CorbaFixedHandler;
+import org.apache.yoko.bindings.corba.types.CorbaHandlerUtils;
+import org.apache.yoko.bindings.corba.types.CorbaObjectHandler;
+import org.apache.yoko.bindings.corba.types.CorbaPrimitiveHandler;
+import org.apache.yoko.bindings.corba.types.CorbaSequenceHandler;
+import org.apache.yoko.bindings.corba.types.CorbaStructHandler;
+import org.apache.yoko.bindings.corba.types.CorbaUnionHandler;
+import org.apache.yoko.wsdl.CorbaConstants;
+import org.apache.yoko.wsdl.CorbaTypeImpl;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.TCKind;
+import org.omg.CORBA.TypeCode;
+
+
+/**
+ * Holder for reading and writing stax methods.
+ */
+public class CorbaStaxObject {
+
+    private static final Logger LOG = LogUtils.getL7dLogger(CorbaOutInterceptor.class);
+
+    private static final String XSI_NAMESPACE_URI = "http://www.w3.org/2001/XMLSchema-instance";
+    private static final String XSI_PREFIX = "xsi";
+    private static final String XMLSCHEMA_NAMESPACE_URI = "http://www.w3.org/2001/XMLSchema";
+    private static final String XMLSCHEMA_PREFIX = "xs";
+    
+    private ORB orb;
+    private List<CorbaTypeMap> typeMaps;       
+    
+    
+    public CorbaStaxObject() {         
+    }
+    
+    public CorbaStaxObject(ORB mOrb) {
+        this.orb = mOrb;    
+    }
+    
+    public ORB getOrb() {
+        return this.orb;
+    }
+
+    public void setOrb(ORB tOrb) {
+        this.orb = tOrb;
+    }
+
+    public void setTypeMaps(List<CorbaTypeMap> tMaps) {
+        this.typeMaps = tMaps;
+    }
+    
+    public List<CorbaTypeMap> getTypeMaps() {
+        return this.typeMaps;
+    }
+
+    public CorbaObjectHandler readObjectFromStax(XMLEventReader reader, QName idlType, boolean
isNested)
+        throws CorbaBindingException {
+        CorbaObjectHandler obj = null;
+        // Find the first start element in the reader. This should be the
+        // beginning of our object
+        try {
+            if (!isNested) {
+                while (reader.peek().getEventType() != XMLStreamConstants.START_ELEMENT)
{
+                    reader.nextEvent();
+                }
+            }
+        } catch (XMLStreamException ex) {
+            throw new CorbaBindingException("Unable to locate start of object", ex);
+        }
+
+        TypeCode tc = CorbaUtils.getTypeCode(orb, idlType, typeMaps);
+        if (CorbaUtils.isPrimitiveIdlType(idlType)) {
+            LOG.log(Level.INFO, "Reading primitive type from XML reader");
+            obj = readPrimitiveFromStax(reader, idlType, tc);
+        } else {
+            switch (tc.kind().value()) {
+            case TCKind._tk_array:
+                LOG.log(Level.INFO, "Reading array type from XML reader");
+                obj = readArrayFromStax(reader, idlType, tc);
+                break;
+            case TCKind._tk_enum:
+                LOG.log(Level.INFO, "Reading enumeration type from XML reader");
+                obj = readEnumFromStax(reader, idlType, tc);
+                break;
+            case TCKind._tk_except:
+                LOG.log(Level.INFO, "Reading exception type from XML reader");
+                obj = readExceptionFromStax(reader, idlType, tc);
+                break;
+            case TCKind._tk_fixed:
+                LOG.log(Level.INFO, "Reading fixed type from XML reader");
+                obj = readFixedFromStax(reader, idlType, tc);
+                break;
+            case TCKind._tk_sequence:
+                LOG.log(Level.INFO, "Reading sequence type from XML reader");
+                obj = readSequenceFromStax(reader, idlType, tc);
+                break;
+            case TCKind._tk_string:
+            case TCKind._tk_wstring:
+                // These will be the case if we have anonymous strings
+                LOG.log(Level.INFO, "Reading anonymous string from XML reader");
+                obj = readAnonStringsFromStax(reader, idlType, tc);
+                break;
+            case TCKind._tk_struct:
+                LOG.log(Level.INFO, "Reading struct type from XML reader");
+                obj = readStructFromStax(reader, idlType, tc);
+                break;
+            case TCKind._tk_union:
+                LOG.log(Level.INFO, "Reading union type from XML reader");
+                obj = readUnionFromStax(reader, idlType, tc);
+                break;
+            default:
+                throw new CorbaBindingException("Unsupported complex type");
+            }
+        }
+
+        return obj;
+    }
+
+    public void writeObjectToStax(CorbaObjectHandler obj, XMLEventWriter writer, XMLEventFactory
factory,
+                                  boolean isNested) {
+        try {
+            if (obj != null) {
+                QName objName = null;
+                if (isNested) {
+                    objName = new QName(obj.getName().getLocalPart());
+                } else {
+                    objName = obj.getName();
+                }
+
+                StartElement startEl = null;
+                TypeCode tc = obj.getTypeCode();
+                if (CorbaUtils.isPrimitiveIdlType(obj.getIdlType())) {
+                    LOG.log(Level.INFO, "Writing primitive type to XML writer");
+
+                    if (obj.getTypeCodeKind().value() == TCKind._tk_any) {
+                        // Any is a special case. Create an attribute called
+                        // xsi:type which identifies the type
+                        // of object stored in the Any. Also create a 'dummy'
+                        // attribute to get the XML schema
+                        // namespace included in the Stax event.
+                        // createNamespace() doesn't work for some reason.
+                        // TODO: Revisit this.
+                        String schemaType = ((CorbaAnyHandler)obj).getSchemaType();
+                        QName attrName = new QName(XSI_NAMESPACE_URI, 
+                                                   "type", XSI_PREFIX);
+                        Attribute attr = factory.createAttribute(attrName, 
+                                                                 schemaType);
+                        QName nsName = new QName(XMLSCHEMA_NAMESPACE_URI, 
+                                         "namespace", XMLSCHEMA_PREFIX);
+                        Attribute ns = factory.createAttribute(nsName, "");
+                        List<Attribute> attributes = new ArrayList<Attribute>();
+                        attributes.add(attr);
+                        attributes.add(ns);
+
+                        startEl = factory.createStartElement(objName, attributes.iterator(),
null);
+                    } else {
+                        startEl = factory.createStartElement(objName, null, null);
+                    }
+
+                    writer.add(startEl);
+                    writePrimitiveToStax(obj, writer, factory);
+                } else {
+                    startEl = factory.createStartElement(objName, null, null);
+                    writer.add(startEl);
+
+                    switch (tc.kind().value()) {
+                    case TCKind._tk_array:
+                        LOG.log(Level.INFO, "Writing array type to XML writer");
+                        writeArrayToStax(obj, writer, factory);
+                        break;
+                    case TCKind._tk_enum:
+                        LOG.log(Level.INFO, "Writing enum type to XML writer");
+                        writeEnumToStax(obj, writer, factory);
+                        break;
+                    case TCKind._tk_except:
+                        LOG.log(Level.INFO, "Writing exception type to XML writer");
+                        writeExceptionToStax(obj, writer, factory);
+                        break;
+                    case TCKind._tk_fixed:
+                        LOG.log(Level.INFO, "Writing fixed type to XML writer");
+                        writeFixedToStax(obj, writer, factory);
+                        break;
+                    case TCKind._tk_sequence:
+                        LOG.log(Level.INFO, "Writing sequence type to XML writer");
+                        writeSequenceToStax(obj, writer, factory);
+                        break;
+                    case TCKind._tk_struct:
+                        LOG.log(Level.INFO, "Writing struct type to XML writer");
+                        writeStructToStax(obj, writer, factory);
+                        break;
+                    case TCKind._tk_union:
+                        LOG.log(Level.INFO, "Writing union type to XML writer");
+                        writeUnionToStax(obj, 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);
+                        break;
+                    default:
+                        throw new CorbaBindingException("Unsupported complex type");
+                    }
+                }
+
+                EndElement endEl = factory.createEndElement(objName, null);
+                writer.add(endEl);                
+            }
+        } catch (XMLStreamException ex) {
+            LOG.log(Level.SEVERE, "STAX exception while writing to STAX event writer: " +
ex.toString());
+            LOG.log(Level.SEVERE, "Object being written: " + obj);
+            throw new CorbaBindingException("writeObjectToStax STAX exception", ex);
+        } catch (java.lang.Exception ex) {
+            LOG.log(Level.SEVERE, "Non-STAX exception while writing to STAX event writer:
" + ex.toString());
+            LOG.log(Level.SEVERE, "Object being written: " + obj);
+            throw new CorbaBindingException("writeObjectToStax exception", ex);
+        }
+    }
+
+    public CorbaObjectHandler readPrimitiveFromStax(XMLEventReader reader, QName idlType,
TypeCode tc) 
+        throws CorbaBindingException {
+        try {
+            StartElement startEl = reader.nextEvent().asStartElement();
+            Characters charEl = reader.nextEvent().asCharacters();
+            reader.nextEvent().asEndElement();
+            if (tc.kind().value() == TCKind._tk_any) {
+                Iterator attrIter = startEl.getAttributes();
+                String anySchemaType = null;
+                while (attrIter.hasNext()) {
+                    Attribute attr = (Attribute)attrIter.next();
+                    QName attrName = attr.getName();
+                    if (attrName.getNamespaceURI().equals(XSI_NAMESPACE_URI)
+                        && attrName.getLocalPart().equals("type")) {
+                        anySchemaType = attr.getValue();
+                        break;
+                    }
+                }
+                           
+                CorbaAnyHandler obj = new CorbaAnyHandler(startEl.getName(), idlType, tc,
null);
+                obj.setValueFromData(orb, charEl.getData(), anySchemaType);
+                return obj;
+                
+            } else {
+                CorbaPrimitiveHandler obj = new CorbaPrimitiveHandler(startEl.getName(),
idlType, tc, null);
+                obj.setValueFromData(charEl.getData());
+                return obj;
+            }
+        } catch (java.lang.Exception ex) {
+            LOG.log(Level.SEVERE, "Error: Object not correctly defined in the XML reader");
+            throw new CorbaBindingException("Invalid XML event read", ex);
+        }
+    }
+    
+    public void writePrimitiveToStax(CorbaObjectHandler obj, XMLEventWriter writer, XMLEventFactory
factory) 
+        throws XMLStreamException {
+        Characters charEvt = null;
+        if (obj.getTypeCodeKind() == TCKind.tk_any) {
+            charEvt = factory.createCharacters(((CorbaAnyHandler)obj).getValueData());
+        } else {
+            charEvt = factory.createCharacters(((CorbaPrimitiveHandler)obj).getValueData());
+        }
+        writer.add(charEvt);
+    }
+
+    public CorbaObjectHandler readAnonStringsFromStax(XMLEventReader reader, QName idlType,
TypeCode tc) {
+        CorbaPrimitiveHandler obj = null;
+        
+        try {
+            StartElement startEl = reader.nextEvent().asStartElement();
+            Characters charEl = reader.nextEvent().asCharacters();
+            reader.nextEvent().asEndElement();
+            
+            if (tc.kind().value() == TCKind._tk_string) {
+                obj = 
+                    new CorbaPrimitiveHandler(startEl.getName(), CorbaConstants.NT_CORBA_STRING,
tc, null);
+            } else {
+                obj = 
+                    new CorbaPrimitiveHandler(startEl.getName(), CorbaConstants.NT_CORBA_WSTRING,
tc, null);
+            }
+            obj.setValueFromData(charEl.getData());
+        } catch (java.lang.Exception ex) {
+            LOG.log(Level.SEVERE, "Error: Object not correctly defined in the XML reader");
+            throw new CorbaBindingException("Invalid XML event read", ex);
+        }
+        return obj;
+    }
+    
+    // Anonymous strings do not need an equivalent write - the primitive handler write is
sufficuent. 
+    
+    public CorbaObjectHandler readArrayFromStax(XMLEventReader reader, QName idlType, TypeCode
tc)
+        throws CorbaBindingException {
+        CorbaArrayHandler obj = null;
+        CorbaTypeImpl typeDefinition = CorbaUtils.getCorbaType(idlType, typeMaps);
+        
+        try {
+            QName arrayElemType = null;
+            long arrayBound = 0;
+            // Arrays and anonymous arrays can be handled by the same method
+            if (typeDefinition instanceof Anonarray) {
+                Anonarray anonArrayType = (Anonarray)typeDefinition;
+                arrayElemType = anonArrayType.getElemtype();
+                arrayBound = anonArrayType.getBound();
+            } else {
+                Array arrayType = (Array)typeDefinition;
+                arrayElemType = arrayType.getElemtype();
+                arrayBound = arrayType.getBound();
+            }
+            StartElement arrayStartEl = reader.nextEvent().asStartElement();
+            obj = new CorbaArrayHandler(arrayStartEl.getName(), idlType, tc, typeDefinition);
+            for (int i = 0; i < arrayBound; ++i) {
+                CorbaObjectHandler element = readObjectFromStax(reader, arrayElemType, true);
+                obj.addElement(element);
+            }
+            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 array corba type", ex);
+        }
+        
+        return obj;
+    }
+
+    public void writeArrayToStax(CorbaObjectHandler obj, XMLEventWriter writer, XMLEventFactory
factory) 
+        throws XMLStreamException {
+        CorbaArrayHandler arrayHandler = (CorbaArrayHandler)obj;
+        List<CorbaObjectHandler> elements = arrayHandler.getElements();
+        for (Iterator<CorbaObjectHandler> elementsIter = elements.iterator(); elementsIter.hasNext();)
{
+            writeObjectToStax(elementsIter.next(), writer, factory, true);
+        }
+    }
+    
+    public CorbaObjectHandler readEnumFromStax(XMLEventReader reader, QName idlType, TypeCode
tc)
+        throws CorbaBindingException {
+        CorbaEnumHandler obj = null;
+        CorbaTypeImpl typeDefinition = CorbaUtils.getCorbaType(idlType, typeMaps);
+        
+        try {
+            Enum enumType = (Enum)typeDefinition;
+            StartElement enumStartEl = reader.nextEvent().asStartElement();
+            obj = new CorbaEnumHandler(enumStartEl.getName(), idlType, tc, enumType);
+            Characters enumCharEl = reader.nextEvent().asCharacters();
+            obj.setValue(enumCharEl.getData());
+            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 enum corba type", ex);
+        }
+        
+        return obj;
+    }
+    
+    public void writeEnumToStax(CorbaObjectHandler obj, XMLEventWriter writer, XMLEventFactory
factory) 
+        throws XMLStreamException {
+        CorbaEnumHandler enumHandler = (CorbaEnumHandler)obj;
+        Characters charEvt = factory.createCharacters(enumHandler.getValue());
+        writer.add(charEvt);
+    }
+
+    public CorbaObjectHandler readExceptionFromStax(XMLEventReader reader, QName idlType,
TypeCode tc)
+        throws CorbaBindingException {
+        CorbaExceptionHandler obj = null;
+        CorbaTypeImpl typeDefinition = CorbaUtils.getCorbaType(idlType, typeMaps);
+        
+        try {
+            Exception exType = (Exception)typeDefinition;
+            StartElement exStartEl = reader.nextEvent().asStartElement();
+            obj = new CorbaExceptionHandler(exStartEl.getName(), idlType, tc, exType);
+            List<MemberType> exMembers = exType.getMember();
+            for (int i = 0; i < exMembers.size(); ++i) {
+                CorbaObjectHandler member = readObjectFromStax(reader, exMembers.get(i).getIdltype(),
true);
+                obj.addMember(member);
+            }
+            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 exception corba type", ex);
+        }
+        
+        return obj;
+    }
+
+    public void writeExceptionToStax(CorbaObjectHandler obj, XMLEventWriter writer, XMLEventFactory
factory) 
+        throws XMLStreamException {
+        CorbaExceptionHandler exObj = (CorbaExceptionHandler)obj;
+        List<CorbaObjectHandler> elements = exObj.getMembers();
+        for (Iterator<CorbaObjectHandler> elementsIter = elements.iterator(); elementsIter.hasNext();)
{
+            writeObjectToStax(elementsIter.next(), writer, factory, true);
+        }
+    }
+
+    public CorbaObjectHandler readSequenceFromStax(XMLEventReader reader, QName idlType,
TypeCode tc)
+        throws CorbaBindingException {
+        CorbaSequenceHandler obj = null;
+        CorbaTypeImpl typeDefinition = CorbaUtils.getCorbaType(idlType, typeMaps);
+        
+        try {
+            QName seqElementType = null;
+            long bound = 0;
+            if (typeDefinition instanceof Anonsequence) {
+                Anonsequence anonSeqType = (Anonsequence)typeDefinition;
+                seqElementType = anonSeqType.getElemtype();
+                bound = anonSeqType.getBound();
+            } else {
+                Sequence seqType = (Sequence)typeDefinition;
+                seqElementType = seqType.getElemtype();
+                bound = seqType.getBound();
+            }
+            StartElement seqStartEl = reader.nextEvent().asStartElement();
+            obj = new CorbaSequenceHandler(seqStartEl.getName(), idlType, tc, typeDefinition);
+            if (bound == 0) {
+                LOG.log(Level.INFO, "Unbounded sequence found");
+                while (reader.peek().getEventType() == XMLStreamConstants.START_ELEMENT)
{
+                    CorbaObjectHandler element = readObjectFromStax(reader, seqElementType,
true);
+                    obj.addElement(element);
+                }
+            } else {
+                LOG.log(Level.INFO, "Bounded sequence found");
+                for (long i = 0; i < bound; ++i) {
+                    CorbaObjectHandler element = readObjectFromStax(reader, seqElementType,
true);
+                    obj.addElement(element);
+                }
+            }
+            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 sequence corba type", ex);
+        }
+        
+        return obj;
+    }
+
+    public void writeSequenceToStax(CorbaObjectHandler obj, XMLEventWriter writer, XMLEventFactory
factory) 
+        throws XMLStreamException {
+        CorbaSequenceHandler seqHandler = (CorbaSequenceHandler)obj;
+        List<CorbaObjectHandler> elements = seqHandler.getElements();
+        for (Iterator<CorbaObjectHandler> elementsIter = elements.iterator(); elementsIter.hasNext();)
{
+            writeObjectToStax(elementsIter.next(), writer, factory, true);
+        }
+    }
+
+    public CorbaObjectHandler readStructFromStax(XMLEventReader reader, QName idlType, TypeCode
tc)
+        throws CorbaBindingException {
+        CorbaStructHandler obj = null;
+        CorbaTypeImpl typeDefinition = CorbaUtils.getCorbaType(idlType, typeMaps);
+        
+        try {
+            Struct structType = (Struct)typeDefinition;
+            StartElement structStartEl = reader.nextEvent().asStartElement();
+            obj = new CorbaStructHandler(structStartEl.getName(), idlType, tc, structType);
+            List<MemberType> structMembers = structType.getMember();
+            for (int i = 0; i < structMembers.size(); ++i) {
+                CorbaObjectHandler member = readObjectFromStax(reader, 
+                                                               structMembers.get(i).getIdltype(),

+                                                               true);
+                obj.addMember(member);
+            }
+            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 struct corba type", ex);
+        }
+        
+        return obj;
+    }
+
+    public void writeStructToStax(CorbaObjectHandler obj, XMLEventWriter writer, XMLEventFactory
factory) 
+        throws XMLStreamException {
+        CorbaStructHandler structHandler = (CorbaStructHandler)obj;
+        List<CorbaObjectHandler> elements = structHandler.getMembers();
+        for (Iterator<CorbaObjectHandler> elementsIter = elements.iterator(); elementsIter.hasNext();)
{
+            writeObjectToStax(elementsIter.next(), writer, factory, true);
+        }
+    }
+
+
+    public CorbaObjectHandler readUnionFromStax(XMLEventReader reader, QName idlType, TypeCode
tc)
+        throws CorbaBindingException {
+        CorbaUnionHandler obj = null;
+        CorbaTypeImpl typeDefinition = CorbaUtils.getCorbaType(idlType, typeMaps);
+        
+        try {
+            Union unionType = (Union)typeDefinition;
+            StartElement unionStartEl = reader.nextEvent().asStartElement();
+            obj = new CorbaUnionHandler(unionStartEl.getName(), idlType, tc, unionType);
+
+            // Read the discriminator value from the reader.  We can't rely on the value
from 
+            // Stax since it may be a default value if the caller has forgotten to explicitly
+            // set the discriminator in their union class.  This could cause all sorts of

+            // problems when we try create the CORBA union.  For now, we'll just read and
ignore.
+            // TODO: Revisit this if we want to make this assumption.
+            reader.nextEvent().asStartElement().getName();
+            reader.nextEvent().asCharacters();
+            reader.nextEvent().asEndElement();
+            
+            // 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(), 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);
+                    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.  Since Celtix does not provide
a 
+                        // discriminator value, we'll create one.
+                        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);
+                }
+                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;
+    }
+    
+    public void writeUnionToStax(CorbaObjectHandler obj, XMLEventWriter writer, XMLEventFactory
factory)
+        throws XMLStreamException {
+        CorbaUnionHandler unionHandler = (CorbaUnionHandler)obj;
+        CorbaObjectHandler discValue = unionHandler.getDiscriminator();
+        writeObjectToStax(discValue, writer, factory, true);
+        CorbaObjectHandler unionValue = unionHandler.getValue();
+        writeObjectToStax(unionValue, writer, factory, true);
+    }
+    
+    public CorbaObjectHandler readFixedFromStax(XMLEventReader reader, QName idlType, TypeCode
tc) 
+        throws CorbaBindingException {
+        CorbaFixedHandler obj = null;
+        CorbaTypeImpl typeDefinition = CorbaUtils.getCorbaType(idlType, typeMaps);
+        
+        try {
+            StartElement fixedStartEl = reader.nextEvent().asStartElement();
+            obj = new CorbaFixedHandler(fixedStartEl.getName(), idlType, tc, typeDefinition);
+            Characters fixedCharEl = reader.nextEvent().asCharacters();
+            obj.setValueFromData(fixedCharEl.getData());
+            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 fixed corba type", ex);
+        }
+        return obj;
+    }
+    
+    public void writeFixedToStax(CorbaObjectHandler obj, XMLEventWriter writer, XMLEventFactory
factory) 
+        throws XMLStreamException {
+        CorbaFixedHandler fixedHandler = (CorbaFixedHandler)obj;
+        Characters charEvt = factory.createCharacters(fixedHandler.getValueData());
+        writer.add(charEvt);
+    }    
+}

Propchange: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStaxObject.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStaxObject.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStreamable.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStreamable.java?view=diff&rev=483585&r1=483584&r2=483585
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStreamable.java
(original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStreamable.java
Thu Dec  7 10:10:25 2006
@@ -83,4 +83,4 @@
     public String getName() {
         return name.getLocalPart();
     }
-}
\ No newline at end of file
+}

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaTypeMap.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaTypeMap.java?view=diff&rev=483585&r1=483584&r2=483585
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaTypeMap.java
(original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaTypeMap.java
Thu Dec  7 10:10:25 2006
@@ -47,12 +47,4 @@
     public String getTargetNamespace() {
         return targetNamespace;
     }
-
-    public void setPrefix(String pfx) {
-        prefix = pfx;
-    }
-
-    public String getPrefix() {
-        return prefix;
-    }
 }

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=483585&r1=483584&r2=483585
==============================================================================
--- 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
Thu Dec  7 10:10:25 2006
@@ -28,13 +28,10 @@
 import java.util.Map;
 import java.util.logging.Logger;
 
-import javax.wsdl.Binding;
-import javax.wsdl.BindingOperation;
-import javax.wsdl.Definition;
-import javax.wsdl.Port;
 import javax.xml.namespace.QName;
 
-import org.apache.schemas.yoko.bindings.corba.AddressType;
+import org.apache.cxf.common.logging.LogUtils;
+
 import org.apache.schemas.yoko.bindings.corba.Alias;
 import org.apache.schemas.yoko.bindings.corba.Anonarray;
 import org.apache.schemas.yoko.bindings.corba.Anonfixed;
@@ -42,7 +39,6 @@
 import org.apache.schemas.yoko.bindings.corba.Anonstring;
 import org.apache.schemas.yoko.bindings.corba.Anonwstring;
 import org.apache.schemas.yoko.bindings.corba.Array;
-import org.apache.schemas.yoko.bindings.corba.BindingType;
 import org.apache.schemas.yoko.bindings.corba.CaseType;
 import org.apache.schemas.yoko.bindings.corba.Const;
 import org.apache.schemas.yoko.bindings.corba.CorbaType;
@@ -51,7 +47,6 @@
 import org.apache.schemas.yoko.bindings.corba.Exception;
 import org.apache.schemas.yoko.bindings.corba.Fixed;
 import org.apache.schemas.yoko.bindings.corba.MemberType;
-import org.apache.schemas.yoko.bindings.corba.OperationType;
 import org.apache.schemas.yoko.bindings.corba.Sequence;
 import org.apache.schemas.yoko.bindings.corba.Struct;
 import org.apache.schemas.yoko.bindings.corba.TypeMappingType;
@@ -60,12 +55,6 @@
 import org.apache.yoko.wsdl.CorbaConstants;
 import org.apache.yoko.wsdl.CorbaTypeImpl;
 
-import org.objectweb.celtix.Bus;
-import org.objectweb.celtix.common.logging.LogUtils;
-import org.objectweb.celtix.helpers.WSDLHelper;
-import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
-import org.objectweb.celtix.wsdl.EndpointReferenceUtils;
-
 import org.omg.CORBA.ORB;
 import org.omg.CORBA.StructMember;
 import org.omg.CORBA.TCKind;
@@ -306,77 +295,10 @@
         return null;
     }
 
-    public static AddressType getCorbaAddressType(Bus bus, EndpointReferenceType endpointRef)
{
-        AddressType addrType = null;
-        try {
-            Port wsdlPort = EndpointReferenceUtils.getPort(bus.getWSDLManager(), 
-                                                           endpointRef);
-            
-            List extElements = wsdlPort.getExtensibilityElements();
-            for (int i = 0; i < extElements.size(); ++i) {
-                Object e = extElements.get(i);
-                if (e instanceof AddressType) {
-                    addrType = (AddressType) e;
-                    break;
-                }
-            }
-        } catch (java.lang.Exception ex) {
-            throw new CorbaBindingException("Unable to obtain corba address information",
ex);
-        }
-        
-        return addrType;
-    }
-    
-    public static BindingType getCorbaBindingType(Bus bus, EndpointReferenceType endpointRef)
{
-        BindingType bindType = null;
-        try {
-            Port wsdlPort = EndpointReferenceUtils.getPort(bus.getWSDLManager(), endpointRef);
-            Binding wsdlBinding = wsdlPort.getBinding();
-            
-            List extElements = wsdlBinding.getExtensibilityElements();
-            for (int i = 0; i < extElements.size(); ++i) {
-                Object e = extElements.get(i);
-                if (e instanceof BindingType) {
-                    bindType = (BindingType) e;
-                    break;
-                }
-            } 
-        } catch (java.lang.Exception ex) {
-            throw new CorbaBindingException("Unable to obtain corba binding information",
ex);            
-        }
-        return bindType;
-    }
-    
-    public static OperationType getCorbaOperationType(String opName, 
-                                                      Bus bus, 
-                                                      EndpointReferenceType endpoint) {
-        try {
-            WSDLHelper helper = new WSDLHelper();
-            Port port = EndpointReferenceUtils.getPort(bus.getWSDLManager(), endpoint);
-            BindingOperation bindingOp = helper.getBindingOperation(port.getBinding(), opName);
-
-            OperationType operation = null;
-            List extElements = bindingOp.getExtensibilityElements();
-            for (int i = 0; i < extElements.size(); ++i) {
-                Object e = extElements.get(i);
-                if (e instanceof OperationType) {
-                    operation = (OperationType) e;
-                    break;
-                }
-            }
-            return operation;
-        } catch (java.lang.Exception ex) {
-            throw new CorbaBindingException("Unable to obtain corba operation information",
ex);
-        }
-    }
-
-    public static void getTypeMapFromDefinition(List<CorbaTypeMap> typeMaps, Definition
wsdlDef) {
-        List extElements = wsdlDef.getExtensibilityElements();
-
-        for (Iterator iter = extElements.iterator(); iter.hasNext();) {
-            Object e = iter.next();
-            if (e instanceof TypeMappingType) {
-                TypeMappingType tmType = (TypeMappingType) e;
+    public static void createCorbaTypeMap(List<CorbaTypeMap> typeMaps, List<TypeMappingType>
tmTypes) {
+        if (tmTypes != null) {
+            for (int i = 0; i < tmTypes.size(); i++) {
+                TypeMappingType tmType = tmTypes.get(i);
 
                 CorbaTypeMap map = null;
                 for (Iterator<CorbaTypeMap> it = typeMaps.iterator(); it.hasNext();)
{
@@ -387,15 +309,13 @@
                         break;
                     }
                 }
-                
+
                 if (map == null) {
                     map = new CorbaTypeMap(tmType.getTargetNamespace());
-                    map.setPrefix(wsdlDef.getPrefix(tmType.getTargetNamespace()));
                     typeMaps.add(map);
                 }
-                
-                LOG.info("Found typemap in WSDL (Namespace: " + tmType.getTargetNamespace()
-                         + ", Prefix: " + wsdlDef.getPrefix(tmType.getTargetNamespace()));
+
+                LOG.info("Found typemap in WSDL (Namespace: " + tmType.getTargetNamespace()
+ ")");
 
                 List<CorbaTypeImpl> types = tmType.getStructOrExceptionOrUnion();
                 LOG.info("Found " + types.size() + " types defined in the typemap");

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/Messages.properties?view=diff&rev=483585&r1=483584&r2=483585
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/Messages.properties
(original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/Messages.properties
Thu Dec  7 10:10:25 2006
@@ -1,13 +1 @@
-# Licensed 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.
-
 // TODO: Add messages here for exceptions



Mime
View raw message