incubator-yoko-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eno...@apache.org
Subject svn commit: r483584 - in /incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors: ./ CorbaFaultInInterceptor.java CorbaFaultOutInterceptor.java CorbaInInterceptor.java CorbaOutInterceptor.java Messages.properties
Date Thu, 07 Dec 2006 18:09:38 GMT
Author: enolan
Date: Thu Dec  7 10:09:37 2006
New Revision: 483584

URL: http://svn.apache.org/viewvc?view=rev&rev=483584
Log:
yoko-225 - porting yoko from celtix to use cxf.

Added:
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaFaultInInterceptor.java
  (with props)
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaFaultOutInterceptor.java
  (with props)
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaInInterceptor.java
  (with props)
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaOutInterceptor.java
  (with props)
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/Messages.properties
  (with props)

Added: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaFaultInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaFaultInInterceptor.java?view=auto&rev=483584
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaFaultInInterceptor.java
(added)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaFaultInInterceptor.java
Thu Dec  7 10:09:37 2006
@@ -0,0 +1,115 @@
+/**
+ * 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.interceptors;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.schemas.yoko.bindings.corba.OperationType;
+import org.apache.schemas.yoko.bindings.corba.RaisesType;
+import org.apache.yoko.bindings.corba.CorbaBindingException;
+import org.apache.yoko.bindings.corba.CorbaMessage;
+import org.apache.yoko.bindings.corba.CorbaStreamable;
+import org.apache.yoko.bindings.corba.types.CorbaObjectHandler;
+
+import org.omg.CORBA.ORB;
+
+
+public class CorbaFaultInInterceptor extends AbstractPhaseInterceptor<Message> {
+        
+    private static final Logger LOG = LogUtils.getL7dLogger(CorbaFaultInInterceptor.class);
 
+    
+    public CorbaFaultInInterceptor() {
+        super();
+        setPhase(Phase.UNMARSHAL);        
+    }
+    
+    public void setOrb(ORB orb) {       
+    }
+
+    public void handleMessage(Message msg) {
+        CorbaMessage message = (CorbaMessage)msg;
+    
+        try {
+            Exchange exchange = msg.getExchange();
+            BindingOperationInfo boi = exchange.get(BindingOperationInfo.class);
+            OperationType opType = boi.getExtensor(OperationType.class);
+            if (opType == null) {
+                throw new CorbaBindingException("Unable to find operation definition");
+            }
+            List<RaisesType> raises = opType.getRaises();
+            //Method currentMethod = (Method)objContext.get(ObjectMessageContext.METHOD_OBJ);
+            //Class<?>[] methodExs = currentMethod.getExceptionTypes();
+
+            CorbaStreamable streamableEx = message.getStreamableException();
+            CorbaObjectHandler exObject = streamableEx.getObject();
+            String name = exObject.getName().getLocalPart();
+            
+            Class exWrapperCls = null;            
+            for (int i = 0; i < raises.size(); ++i) {
+                // Right now, this assumes that all exceptions will have unique simple names.
 REVISIT.
+                RaisesType type = raises.get(i);
+                if (name.equals(raises.get(i).getException().getLocalPart())) {
+                    //exWrapperCls = methodExs[i];
+                    break;
+                }
+            }
+
+            if (exWrapperCls == null) {
+                throw new CorbaBindingException("Unable to locate exception type in " 
+                                                + "declared exception list");
+            }
+
+            try {
+                Method faultInfoMethod = exWrapperCls.getMethod("getFaultInfo");
+                Class<?> exCls = faultInfoMethod.getReturnType();
+                Object yokoEx = exCls.newInstance();
+
+               // CorbaExceptionHandler.unmarshalCorbaException((CorbaExceptionHandler)exObject,
yokoEx);
+                
+                Constructor exWrapperCtr = exWrapperCls.getConstructor(String.class, exCls);
+                Object exWrapper = exWrapperCtr.newInstance("", yokoEx);
+                Exception exception = new Exception();                
+
+                // the wrapper should always be an instance of throwable
+                //message.setException((Exception)exWrapper);    
+
+                
+            } catch (java.lang.Exception ex) {
+                // rethrow to be caught below
+                throw ex;
+            }
+
+        } catch (java.lang.Exception ex) {
+            LOG.log(Level.SEVERE, "CORBA unmarshalFault exception", ex);
+            throw new CorbaBindingException("CORBA unmarshalFault exception", ex);
+        }
+
+    }
+}

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

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

Added: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaFaultOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaFaultOutInterceptor.java?view=auto&rev=483584
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaFaultOutInterceptor.java
(added)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaFaultOutInterceptor.java
Thu Dec  7 10:09:37 2006
@@ -0,0 +1,125 @@
+/**
+ * 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.interceptors;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.lang.reflect.Method;
+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.XMLEventReader;
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.ws.WebFault;
+
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.jaxb.io.EventDataWriter;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.schemas.yoko.bindings.corba.OperationType;
+import org.apache.schemas.yoko.bindings.corba.RaisesType;
+import org.apache.yoko.bindings.corba.ContextUtils;
+import org.apache.yoko.bindings.corba.CorbaBindingException;
+import org.apache.yoko.bindings.corba.CorbaMessage;
+import org.apache.yoko.bindings.corba.CorbaStaxObject;
+import org.apache.yoko.bindings.corba.CorbaStreamable;
+import org.apache.yoko.bindings.corba.types.CorbaObjectHandler;
+
+public class CorbaFaultOutInterceptor extends AbstractPhaseInterceptor<Message> {
+
+    private static final Logger LOG = LogUtils.getL7dLogger(CorbaFaultOutInterceptor.class);
+    protected CorbaStaxObject corbaStaxObject;    
+    
+    public CorbaFaultOutInterceptor() {
+        super();
+        setPhase(Phase.MARSHAL);
+        corbaStaxObject = new CorbaStaxObject();
+    }
+
+    public void handleMessage(Message msg) {
+        try {
+            CorbaMessage message = (CorbaMessage)msg;
+            EventDataWriter writer = (EventDataWriter)ContextUtils.getDataWriter(message);
+
+            // Get information about the operation being invoked from the WSDL
+            // definition.
+            // We need this to marshal data correctly
+            Exchange exchange = msg.getExchange();
+            BindingOperationInfo boi = exchange.get(BindingOperationInfo.class);
+            OperationType opType = boi.getExtensor(OperationType.class);
+            if (opType == null) {
+                throw new CorbaBindingException("Unable to find operation definition");
+            }
+
+            XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+            XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
+            outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+
+            Throwable except = new Throwable();
+            Method faultInfoMethod = except.getClass().getMethod("getFaultInfo");
+            Object faultInfo = faultInfoMethod.invoke(except);
+            WebFault wfAnnotation = except.getClass().getAnnotation(WebFault.class);
+            QName elName = new QName(wfAnnotation.targetNamespace(), except.getClass().getSimpleName());
+
+            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+            XMLEventWriter evtWriter = outputFactory.createXMLEventWriter(outStream);
+            writer.write(faultInfo, evtWriter);
+
+            QName exIdlType = null;
+            List<RaisesType> exList = opType.getRaises();
+            for (Iterator<RaisesType> i = exList.iterator(); i.hasNext();) {
+                // REVISIT: Note that this assumes that exception names need to
+                // be unique. We should make
+                // sure that this is really the case.
+                RaisesType raises = i.next();
+                if (raises.getException().getLocalPart().equals(elName.getLocalPart())) {
+                    exIdlType = raises.getException();
+                }
+            }
+            if (exIdlType == null) {
+                LOG.log(Level.INFO,
+                        "Could not find the exception in the raises list.  Must be a system
exception.");
+                // This could be a system exception?
+            } else {
+                LOG.log(Level.INFO, "Found exception in the raises list.  Marshalling.");
+                ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
+                XMLEventReader evtReader = inputFactory.createXMLEventReader(inStream);
+                CorbaObjectHandler obj = corbaStaxObject.readObjectFromStax(evtReader, exIdlType,
false);
+                CorbaStreamable streamable = new CorbaStreamable(obj, elName);
+                message.setStreamableException(streamable);
+            }
+
+        } catch (java.lang.Exception ex) {
+            LOG.log(Level.SEVERE, "CORBA marshalFault exception", ex);
+            // TODO: Throw a exception proper exception once implemented
+            throw new CorbaBindingException("Method unmarshalFault not implemented");
+        }
+
+    }                                
+    
+}

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

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

Added: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaInInterceptor.java?view=auto&rev=483584
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaInInterceptor.java
(added)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaInInterceptor.java
Thu Dec  7 10:09:37 2006
@@ -0,0 +1,444 @@
+/**
+ * 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.interceptors;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventFactory;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.ws.Holder;
+
+import org.apache.cxf.databinding.DataReader;
+import org.apache.cxf.databinding.DataReaderFactory;
+import org.apache.cxf.jaxb.io.EventDataReader;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.service.Service;
+import org.apache.cxf.service.model.BindingInfo;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.InterfaceInfo;
+import org.apache.cxf.service.model.MessageInfo;
+import org.apache.cxf.service.model.OperationInfo;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.service.model.ServiceModelUtil;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
+import org.apache.schemas.yoko.bindings.corba.ArgType;
+import org.apache.schemas.yoko.bindings.corba.ModeType;
+import org.apache.schemas.yoko.bindings.corba.OperationType;
+import org.apache.schemas.yoko.bindings.corba.ParamType;
+import org.apache.schemas.yoko.bindings.corba.TypeMappingType;
+import org.apache.yoko.bindings.corba.ContextUtils;
+import org.apache.yoko.bindings.corba.CorbaDestination;
+import org.apache.yoko.bindings.corba.CorbaMessage;
+import org.apache.yoko.bindings.corba.CorbaStaxObject;
+import org.apache.yoko.bindings.corba.CorbaStreamable;
+import org.apache.yoko.bindings.corba.CorbaTypeMap;
+import org.apache.yoko.bindings.corba.CorbaUtils;
+import org.apache.yoko.bindings.corba.types.CorbaHandlerUtils;
+import org.apache.yoko.bindings.corba.types.CorbaObjectHandler;
+import org.apache.yoko.orb.CORBA.ServerRequest;
+import org.apache.yoko.wsdl.CorbaConstants;
+import org.omg.CORBA.Any;
+import org.omg.CORBA.NVList;
+import org.omg.CORBA.ORB;
+
+public class CorbaInInterceptor extends AbstractPhaseInterceptor<Message> {
+    
+    protected static CorbaStaxObject corbaStaxObject;
+    private List<CorbaTypeMap> typeMaps;    
+    private XMLOutputFactory xof;
+    private XMLInputFactory xif;
+    private ORB orb;
+    
+    public CorbaInInterceptor() {
+        super();
+        setPhase(Phase.UNMARSHAL);
+        corbaStaxObject = new CorbaStaxObject();
+    }
+    
+    public void setOrb(ORB mOrb) {
+        this.orb = mOrb;
+    }
+
+    public void handleMessage(Message msg) {                  
+        CorbaMessage message = (CorbaMessage) msg;                
+        CorbaDestination destination = null;
+        if (message.getDestination() != null) {
+            destination = (CorbaDestination)message.getDestination();
+        } else {
+            destination = (CorbaDestination)message.getExchange().getDestination();
+        }
+        
+        typeMaps = new ArrayList<CorbaTypeMap>();                
+        ServiceInfo service = destination.getBindingInfo().getService();        
+        List<TypeMappingType> corbaTypes = service.getExtensors(TypeMappingType.class);
+        if (corbaTypes != null) {
+            CorbaUtils.createCorbaTypeMap(typeMaps, corbaTypes);
+            corbaStaxObject.setTypeMaps(typeMaps);
+        }
+        
+        // TODO: where does encoding constant go?
+        //String encoding = (String)message.get("Encoding");        
+                               
+        // check to see if we have an input or output message
+        if (!ContextUtils.isRequestor(msg)) {
+            handleNotRequestMessage(message, destination, service);                
+        } else {             
+            handleRequestMessage(message, destination, service);
+        } 
+    }
+            
+    protected void handleNotRequestMessage(CorbaMessage message, CorbaDestination destination,
+                                        ServiceInfo service) {
+        QName opQName = null;
+        OperationType opType = null;
+        BindingInfo bInfo = destination.getBindingInfo();              
+        InterfaceInfo info = bInfo.getInterface();        
+        EventDataReader reader = (EventDataReader)getDataReader(message);
+        
+        Exchange exchange = message.getExchange();
+        orb = (ORB)exchange.get(ORB.class);        
+        if (corbaStaxObject != null) {
+            corbaStaxObject.setOrb(orb);
+        } else {
+            corbaStaxObject = new CorbaStaxObject(orb);
+        }
+        String opName = message.getExchange().get(String.class);
+                
+        Iterator i = bInfo.getOperations().iterator();
+        while (i.hasNext()) {
+            BindingOperationInfo bOpType = (BindingOperationInfo)i.next();
+            if (bOpType.getName().getLocalPart().equals(opName)) {
+                opType = bOpType.getExtensor(OperationType.class);
+                opQName = bOpType.getName();
+                break;
+            }
+        }
+
+        ServerRequest request = (ServerRequest)exchange.get(org.omg.CORBA.ServerRequest.class);
+        NVList list = prepareArguments(message, destination, info, service, opType, opQName);
+        request.arguments(list);
+        message.setList(list);            
+    
+        // Handle the parameters that are given for the operation
+        List<ParamType> paramTypes = null;
+        if (opType != null) {
+            paramTypes = opType.getParam();             
+        }
+        addUnmarshalParams(message, message, 
+                           paramTypes, info,
+                           opType, reader);
+        
+    }
+    
+    protected void handleRequestMessage(CorbaMessage message, CorbaDestination destination,
+                                           ServiceInfo service) {
+        OperationType opType = null;
+                
+        orb = (org.omg.CORBA.ORB) message.get(CorbaConstants.ORB);  
+        if (corbaStaxObject != null) {
+            corbaStaxObject.setOrb(orb);
+        } else {
+            corbaStaxObject = new CorbaStaxObject(orb);
+        }        
+        EventDataReader reader;
+        reader = (EventDataReader)getDataReader(message);
+        BindingInfo bInfo = destination.getBindingInfo();              
+        InterfaceInfo info = bInfo.getInterface();
+        
+        Exchange exchange = message.getExchange();
+        BindingOperationInfo bopInfo = exchange.get(BindingOperationInfo.class);
+        opType = bopInfo.getExtensor(OperationType.class);
+
+        // Handle the parameters that are given for the operation
+        List<ParamType> paramTypes = null;     
+        ArgType argType = null;
+        
+        if (opType != null) {
+            paramTypes = opType.getParam();     
+            argType = opType.getReturn();
+        }
+        CorbaMessage outMessage = (CorbaMessage)exchange.getOutMessage();
+        
+        addUnmarshalParams(outMessage,
+                           message,
+                           paramTypes,
+                           info,
+                           opType,                         
+                           reader);
+        
+        writeReturnValue(message, outMessage, argType, reader);        
+    }
+    
+    protected void writeReturnValue(CorbaMessage message, 
+                                    CorbaMessage outMessage, 
+                                    ArgType argType, 
+                                    EventDataReader reader) {
+        Object retValue = null;
+        // Handle the parameters that are given for the operation
+        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+        XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
+        outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, 
+                                  Boolean.TRUE);        
+
+        try {
+            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+            XMLEventWriter evtWriter = outputFactory.createXMLEventWriter(outStream);
+            CorbaStreamable retVal = outMessage.getStreamableReturn();
+            corbaStaxObject.writeObjectToStax(retVal.getObject(), evtWriter, 
+                                              XMLEventFactory.newInstance(),
+                                              false);
+            evtWriter.flush();
+
+            ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
+            XMLEventReader evtReader = inputFactory.createXMLEventReader(inStream);     
      
+            if (argType.getName() != null) {
+                QName retName = new QName("", argType.getName(), "");
+                retValue = reader.read(retName, evtReader, String.class);
+            }
+            List<Object> args = new ArrayList<Object>();
+            args.add(retValue);
+            message.setContent(List.class, args);           
+        } catch (XMLStreamException ex) {
+            // NEED TO DO
+        }        
+    }
+    
+    protected void addUnmarshalParams(CorbaMessage msg,
+                                    CorbaMessage message,
+                                    List<ParamType> params,
+                                    InterfaceInfo info,
+                                    OperationType opType,                               
  
+                                    EventDataReader reader) {
+                      
+        
+        CorbaStreamable[] streamables = msg.getStreamableArguments();       
+        List<Object> args = msg.getContent(List.class);         
+                
+        for (int i = 0; i < params.size(); i++) {
+            Object obj = null;
+            ParamType param = params.get(i);                 
+
+            boolean skipRead = false;
+            if (!ContextUtils.isRequestor(msg)) {
+                if (param.getMode().equals(ModeType.OUT)) {
+                    skipRead = true;
+                }
+            } else if (param.getMode().equals(ModeType.IN)) {
+                skipRead = true;
+            }
+                       
+            if (!skipRead) {
+
+                XMLEventReader evtReader = getEventReader(streamables[i]);
+                if (param.getMode().equals(ModeType.OUT)) {                    
+                    obj = reader.read(evtReader);
+                    msg.setStreamableReturn(streamables[i]);
+                } else {
+                    QName elName2 = new QName("", param.getName(), "");
+                    obj = reader.read(elName2, evtReader, String.class);
+
+                    try {
+                        if (param.getMode().equals(ModeType.INOUT) || param.getMode().equals(ModeType.OUT))
{
+                            args.get(i).getClass().getField("value").set(i, obj);
+                        } else {
+                            args.add(obj);
+                        }
+                    } catch (IllegalAccessException ex) {
+                        ex.printStackTrace();
+                    } catch (NoSuchFieldException ex) {
+                        ex.printStackTrace();
+                    }
+                }
+
+            } else {
+                if (param.getMode().equals(ModeType.OUT)) {
+                    args.add(obj);
+                    message.setContent(List.class, args);
+                } else if (param.getMode().equals(ModeType.INOUT) || param.getMode().equals(ModeType.OUT))
{
+                    try {
+                        args.get(i).getClass().getField("value").set(i, obj);
+                    } catch (IllegalAccessException ex) {
+                        ex.printStackTrace();
+                    } catch (NoSuchFieldException ex) {
+                        ex.printStackTrace();
+                    } 
+                }                             
+            }
+            msg.setContent(List.class, args);
+        }
+    }   
+    
+    
+    protected XMLEventReader getEventReader(CorbaStreamable streamable) {
+        
+        XMLEventReader evtReader  = null;
+        XMLInputFactory inputFactory = getXMLInputFactory();
+        XMLOutputFactory outputFactory = getXMLOutputFactory();
+        try {
+            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+            XMLEventWriter evtWriter = outputFactory.createXMLEventWriter(outStream);
+            corbaStaxObject.writeObjectToStax(streamable.getObject(), evtWriter, XMLEventFactory
+                .newInstance(), false);
+            evtWriter.flush();
+
+            ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
+            evtReader = inputFactory.createXMLEventReader(inStream);
+        } catch (XMLStreamException ex) {
+            // NEED TO DO
+        }        
+        return evtReader;
+    }
+    
+    protected NVList prepareArguments(CorbaMessage corbaMsg, CorbaDestination destination,
+                                    InterfaceInfo info, ServiceInfo service, 
+                                    OperationType opType, QName opQName) {
+        
+        BindingInfo bInfo = destination.getBindingInfo();                              
+        EndpointInfo eptInfo = destination.getEndPointInfo();
+        BindingOperationInfo bOpInfo = bInfo.getOperation(opQName);
+        OperationInfo opInfo = bOpInfo.getOperationInfo();        
+        Exchange exg = corbaMsg.getExchange();
+        exg.put(BindingInfo.class, bInfo);
+        exg.put(InterfaceInfo.class, info);
+        exg.put(EndpointInfo.class, eptInfo);
+        exg.put(EndpointReferenceType.class, destination.getAddress());
+        exg.put(ServiceInfo.class, service);
+        exg.put(BindingOperationInfo.class, bOpInfo);        
+        exg.put(OperationInfo.class, opInfo);                
+        exg.put(MessageInfo.class, opInfo.getInput());
+        exg.put(String.class, opQName.getLocalPart());        
+        exg.setInMessage(corbaMsg);
+                       
+        List<ParamType> paramTypes = opType.getParam();       
+        CorbaStreamable[] arguments = new CorbaStreamable[paramTypes.size()];           
                   
+        NVList list = prepareDIIArgsList(corbaMsg, arguments, paramTypes, typeMaps);    
    
+        
+        return list;
+        
+    }
+    
+    protected NVList prepareDIIArgsList(CorbaMessage corbaMsg, 
+                                        CorbaStreamable[] streamables, 
+                                        List<ParamType> paramTypes,
+                                        List<CorbaTypeMap> maps) { 
+        
+        // Build the list of DII arguments, returns, and exceptions        
+        NVList list = orb.create_list(streamables.length);        
+        
+        prepareArgs(corbaMsg, paramTypes);
+        
+        for (int i = 0; i < paramTypes.size(); i++) {           
+            ParamType param = paramTypes.get(i);                                       
+            QName paramName = new QName("", param.getName(), "");
+            QName paramIdlType = param.getIdltype();
+            ModeType paramMode = param.getMode();
+ 
+            CorbaObjectHandler obj = 
+                CorbaHandlerUtils.initializeObjectHandler(orb, paramName, paramIdlType, maps);
+
+            streamables[i] = new CorbaStreamable(obj, paramName);
+            if (paramMode.value().equals("in")) {
+                streamables[i].setMode(org.omg.CORBA.ARG_IN.value);
+            } else if (paramMode.value().equals("out")) {
+                streamables[i].setMode(org.omg.CORBA.ARG_OUT.value);
+            } else {
+                streamables[i].setMode(org.omg.CORBA.ARG_INOUT.value);
+            }
+
+            Any value = orb.create_any();
+            value.insert_Streamable(streamables[i]);
+            list.add_value(streamables[i].getName(), value, streamables[i].getMode());
+            
+            corbaMsg.addStreamableArgument(streamables[i]);
+        }        
+        return list;
+    } 
+    
+    protected void prepareArgs(CorbaMessage corbaMsg, List<ParamType> paramTypes) {
+        List<Object> args = new ArrayList<Object>();
+        int idx = 0;
+        
+        try {
+            for (ParamType param : paramTypes) {
+                Class cls = param.getClass();
+                if (cls.isAssignableFrom(Holder.class)) {
+                    args.add(cls.newInstance());
+                } 
+                idx++;
+            }
+            corbaMsg.setContent(List.class, args);
+        } catch (InstantiationException ex) {
+            ex.printStackTrace();         
+        } catch (IllegalAccessException ex2) {
+            ex2.printStackTrace();
+        }
+    }
+    
+    protected XMLOutputFactory getXMLOutputFactory() {
+        if (xof == null) {
+            xof = XMLOutputFactory.newInstance();
+            xof.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+        }
+        return xof;
+    }
+
+    protected XMLInputFactory getXMLInputFactory() {
+        if (xif == null) {
+            xif = XMLInputFactory.newInstance();            
+        }
+        return xif;
+    }        
+    
+    protected DataReader<XMLEventReader> getDataReader(CorbaMessage message) {
+        Service service = ServiceModelUtil.getService(message.getExchange());
+        DataReaderFactory factory = service.getDataBinding().getDataReaderFactory();
+
+        DataReader<XMLEventReader> dataReader = null;
+        if (factory != null) {
+            for (Class<?> cls : factory.getSupportedFormats()) {
+                if (cls == XMLEventReader.class) {
+                    dataReader = factory.createReader(XMLEventReader.class);
+                    break;
+                }
+            }
+        }
+
+        if (dataReader == null) {
+            //throw a fault
+            //throw new Fault(new org.apache.cxf.common.i18n.Message("NO_DATAREADER", BUNDLE,
service
+            //    .getName()));
+        }
+
+        return dataReader;
+    }
+}

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

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

Added: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaOutInterceptor.java?view=auto&rev=483584
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaOutInterceptor.java
(added)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaOutInterceptor.java
Thu Dec  7 10:09:37 2006
@@ -0,0 +1,269 @@
+/**
+ * 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.interceptors;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.ws.Holder;
+
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.databinding.DataWriter;
+import org.apache.cxf.databinding.DataWriterFactory;
+import org.apache.cxf.jaxb.io.EventDataWriter;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.service.Service;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.MessageInfo;
+import org.apache.cxf.service.model.MessagePartInfo;
+import org.apache.cxf.service.model.OperationInfo;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.service.model.ServiceModelUtil;
+import org.apache.schemas.yoko.bindings.corba.ArgType;
+import org.apache.schemas.yoko.bindings.corba.ModeType;
+import org.apache.schemas.yoko.bindings.corba.OperationType;
+import org.apache.schemas.yoko.bindings.corba.ParamType;
+import org.apache.schemas.yoko.bindings.corba.TypeMappingType;
+import org.apache.yoko.bindings.corba.ContextUtils;
+import org.apache.yoko.bindings.corba.CorbaMessage;
+import org.apache.yoko.bindings.corba.CorbaStaxObject;
+import org.apache.yoko.bindings.corba.CorbaStreamable;
+import org.apache.yoko.bindings.corba.CorbaTypeMap;
+import org.apache.yoko.bindings.corba.CorbaUtils;
+import org.apache.yoko.bindings.corba.types.CorbaHandlerUtils;
+import org.apache.yoko.bindings.corba.types.CorbaObjectHandler;
+import org.apache.yoko.wsdl.CorbaConstants;
+import org.omg.CORBA.ORB;
+
+public class CorbaOutInterceptor extends AbstractPhaseInterceptor<Message> {
+
+    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";
+
+    protected CorbaStaxObject corbaStaxObject;
+    private List<CorbaTypeMap> typeMaps;
+    private ORB orb;
+    private XMLOutputFactory xof;
+    private XMLInputFactory xif;
+
+    public CorbaOutInterceptor() {
+        super();
+        setPhase(Phase.MARSHAL);
+    }
+
+    public void handleMessage(Message msg) {
+        CorbaMessage message = (CorbaMessage) msg;
+        orb = (org.omg.CORBA.ORB) message.get(CorbaConstants.ORB);
+        corbaStaxObject = new CorbaStaxObject(orb);
+        Exchange exchange = message.getExchange();
+        typeMaps = new ArrayList<CorbaTypeMap>();
+
+        ServiceInfo service = exchange.get(ServiceInfo.class);
+        List<TypeMappingType> corbaTypes = service.getExtensors(TypeMappingType.class);
+        CorbaUtils.createCorbaTypeMap(typeMaps, corbaTypes);
+        getXMLOutputFactory().setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+
+        // TODO: where does encoding constant go?
+        //String encoding = (String)message.get("Encoding");                
+        BindingOperationInfo boi = exchange.get(BindingOperationInfo.class);
+        OperationType opType = boi.getExtensor(OperationType.class);        
+        
+        if (ContextUtils.isRequestor(message)) {
+            handleOutBoundMessage(message, opType);           
+        } else {
+            handleInBoundMessage(message, opType);            
+        }
+    }
+    
+    
+    protected void handleOutBoundMessage(CorbaMessage message, OperationType opType) {
+        EventDataWriter writer = (EventDataWriter)getDataWriter(message);
+        List<ParamType> paramTypes = opType.getParam();
+        List<Object> args = message.getContent(List.class);
+        MessageInfo msgInfo = message.get(MessageInfo.class);
+        addMarshalParams(message, args, msgInfo, paramTypes, 
+                         getXMLInputFactory(), getXMLOutputFactory(), 
+                         writer);
+
+        ArgType returnParam = opType.getReturn();
+        QName retName = new QName("", returnParam.getName());
+        QName retIdlType = returnParam.getIdltype();
+        CorbaObjectHandler obj = CorbaHandlerUtils
+            .initializeObjectHandler(orb, retName, retIdlType, typeMaps);
+        CorbaStreamable streamable = new CorbaStreamable(obj, retName);
+        System.out.println("done outbound message");
+        message.setStreamableReturn(streamable);
+    }
+    
+    protected void handleInBoundMessage(CorbaMessage message, OperationType opType) {   
    
+        EventDataWriter writer = (EventDataWriter)getDataWriter(message);
+        List<ParamType> paramTypes = opType.getParam();
+        OperationInfo opInfo = message.getExchange().get(OperationInfo.class);
+        MessageInfo msgInInfo = opInfo.getInput();
+        List<Object> args = message.getExchange().getInMessage().getContent(List.class);
+        addMarshalParams(message, args, msgInInfo, paramTypes, getXMLInputFactory(), getXMLOutputFactory(),
+                         writer);
+
+        ArgType returnParam = opType.getReturn();
+        try {
+            List<Object> argsRet = message.getContent(List.class);
+            MessageInfo msgInfo = opInfo.getOutput();
+            MessagePartInfo part = getMessagePartInfo(msgInfo, returnParam.getName());
+
+            // for the server, write the result out.
+            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+            XMLEventWriter evtWriter = xof.createXMLEventWriter(outStream);
+            QName retName = new QName("", returnParam.getName());
+            writer.write(argsRet.get(0), part, evtWriter);
+            ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
+            XMLEventReader evtReader = xif.createXMLEventReader(inStream);
+            QName retIdlType = returnParam.getIdltype();
+            CorbaObjectHandler obj = corbaStaxObject.readObjectFromStax(evtReader, retIdlType,
false);
+            CorbaStreamable streamable = new CorbaStreamable(obj, retName);
+            message.setStreamableReturn(streamable);
+        } catch (XMLStreamException ex) {
+            // NEED TO DO
+            // throw
+        }
+
+    }
+    
+    protected void addMarshalParams(CorbaMessage message, List<Object> arguments, MessageInfo
msgInfo,
+                                    List<ParamType> params, XMLInputFactory inputFactory,
+                                    XMLOutputFactory outputFactory, EventDataWriter writer)
{
+        try {
+            if (writer != null) {
+                List<Object> args = arguments;
+                for (int i = 0; i < params.size(); i++) {
+                    Object partValue;
+                    ParamType param = params.get(i);
+                    if (param.getMode() != ModeType.IN) {
+                        partValue = ((Holder)args.get(i)).value;
+                    } else {
+                        partValue = args.get(i);
+                    }
+
+                    MessagePartInfo part = getMessagePartInfo(msgInfo, param.getName());
+                    QName elName = new QName("", param.getName());
+                    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+                    XMLEventWriter evtWriter = outputFactory.createXMLEventWriter(outStream);
+                    writer.write(partValue, part, evtWriter);
+
+                    ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
+                    XMLEventReader evtReader = inputFactory.createXMLEventReader(inStream);
+                    QName idlType = param.getIdltype();
+                    CorbaObjectHandler obj = null;
+                    boolean skipRead = false;
+                    if (!ContextUtils.isRequestor(message)) {
+                        if (param.getMode().equals(ModeType.IN)) {
+                            skipRead = true;
+                        }
+                    } else if (param.getMode().equals(ModeType.OUT)) {
+                        skipRead = true;
+                    }
+                    if (skipRead) {
+                        obj = CorbaHandlerUtils.initializeObjectHandler(orb, elName, idlType,
typeMaps);
+                    } else {
+                        obj = corbaStaxObject.readObjectFromStax(evtReader, idlType, false);
+                    }
+                    CorbaStreamable streamable = new CorbaStreamable(obj, elName);
+                    ModeType paramMode = param.getMode();
+                    if (paramMode.value().equals("in")) {
+                        streamable.setMode(org.omg.CORBA.ARG_IN.value);
+                    } else if (paramMode.value().equals("inout")) {
+                        streamable.setMode(org.omg.CORBA.ARG_INOUT.value);
+                    } else if (paramMode.value().equals("out")) {
+                        streamable.setMode(org.omg.CORBA.ARG_OUT.value);
+                    }
+                    message.addStreamableArgument(streamable);
+                }
+            }
+        } catch (java.lang.Exception ex) {
+            ex.printStackTrace();
+        }
+    }
+                
+    protected XMLOutputFactory getXMLOutputFactory() {
+        if (xof == null) {
+            xof = XMLOutputFactory.newInstance();
+            xof.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+        }
+        return xof;
+    }
+
+    protected XMLInputFactory getXMLInputFactory() {
+        if (xif == null) {
+            xif = XMLInputFactory.newInstance();
+        }
+        return xif;
+    }
+
+
+    protected MessagePartInfo getMessagePartInfo(MessageInfo msgInfo, String name) {
+        List<MessagePartInfo> parts = msgInfo.getMessageParts();
+        for (int i = 0; i < parts.size(); i++) {
+            MessagePartInfo part = parts.get(i);
+            if (part.getName().getLocalPart().equals(name)) {
+                return part;
+            }
+        }
+        return null;
+    }
+    
+    protected DataWriter<XMLEventWriter> getDataWriter(CorbaMessage message) {
+        Service service = ServiceModelUtil.getService(message.getExchange());
+        DataWriterFactory factory = service.getDataBinding().getDataWriterFactory();
+
+        DataWriter<XMLEventWriter> dataWriter = null;
+        if (factory != null) {
+            for (Class<?> cls : factory.getSupportedFormats()) {
+                if (cls == XMLEventWriter.class) {
+                    dataWriter = factory.createWriter(XMLEventWriter.class);
+                    break;
+                }
+            }
+        }
+
+        if (dataWriter == null) {
+            //throw a fault
+            //throw new Fault(new org.apache.cxf.common.i18n.Message("NO_DATAWRITER", BUNDLE,
service
+            //    .getName()));
+        }
+
+        return dataWriter;
+    }
+
+}

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

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

Added: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/Messages.properties?view=auto&rev=483584
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/Messages.properties
(added)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/Messages.properties
Thu Dec  7 10:09:37 2006
@@ -0,0 +1 @@
+// TODO: Add messages here for exceptions

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

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

Propchange: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/Messages.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message