Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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.cxf.binding.corba.interceptors;
 
 import java.util.List;
 
 
 
 
 
 
     public CorbaStreamInInterceptor() {
         super(.);
     }   
 
     public void handleMessage(Message messagethrows Fault {
         if (ContextUtils.isRequestor(message)) {
             handleReply(message);
         } else {
             handleRequest(message);
         }
     }
 
     private void handleReply(Message msg) {
         ORB orb;
         ServiceInfo service;
         CorbaDestination destination;
         if (msg.getDestination() != null) {
             destination = (CorbaDestination)msg.getDestination();
         } else {
             destination = (CorbaDestination)msg.getExchange().getDestination();
         }
         service = destination.getBindingInfo().getService();
 
         CorbaMessage message = (CorbaMessage)msg;
         if (message.getStreamableException() != null || message.getSystemException() != null) {
             message.setContent(Exception.class
                                message.getExchange().getOutMessage().getContent(Exception.class));
 
             Endpoint ep = message.getExchange().get(Endpoint.class);
             message.getInterceptorChain().abort();
             if (ep.getInFaultObserver() != null) {
                ep.getInFaultObserver().onMessage(message);
                return;
            }
        }
        CorbaMessage outMessage = (CorbaMessage)message.getExchange().getOutMessage();
        orb = message.getExchange().get(ORB.class);
        HandlerIterator paramIterator = new HandlerIterator(outMessagefalse);
        CorbaTypeEventProducer eventProducer = null;
        Exchange exchange = message.getExchange();
        BindingOperationInfo bindingOpInfo = exchange.get(BindingOperationInfo.class);  
        BindingMessageInfo msgInfo = bindingOpInfo.getOutput();
        boolean wrap = false;
        if (bindingOpInfo.isUnwrappedCapable()) {
            wrap = true;
        }
        if (wrap) {
            // wrapper element around our args
            // REVISIT, bravi, message name same as the element name
            QName wrapperElementQName = msgInfo.getMessageInfo().getName();
            eventProducer = new WrappedParameterSequenceEventProducer(wrapperElementQName,
                                                                      paramIterator,
                                                                      service,
                                                                      orb);
        } else {
            eventProducer = new ParameterEventProducer(paramIterator,
                                                       service,
                                                       orb);
        }
        CorbaStreamReader reader = new CorbaStreamReader(eventProducer);
        message.setContent(XMLStreamReader.classreader);
    }
    private void handleRequest(Message msg) {
        ORB orb;
        ServiceInfo service;
        CorbaDestination destination;
        if (msg.getDestination() != null) {
            destination = (CorbaDestination)msg.getDestination();
        } else {
            destination = (CorbaDestination)msg.getExchange().getDestination();
        }
        service = destination.getBindingInfo().getService();
        CorbaMessage message = (CorbaMessagemsg;
        Exchange exchange = message.getExchange();
        CorbaTypeMap typeMap = message.getCorbaTypeMap();
        BindingInfo bInfo = destination.getBindingInfo();              
        InterfaceInfo info = bInfo.getInterface();
        String opName = exchange.get(String.class);
        Iterator<BindingOperationInfoi = bInfo.getOperations().iterator();
        OperationType opType = null;
        BindingOperationInfo bopInfo = null;
        QName opQName = null;
        while (i.hasNext()) {
            bopInfo = i.next();
            if (bopInfo.getName().getLocalPart().equals(opName)) {
                opType = bopInfo.getExtensor(OperationType.class);
                opQName = bopInfo.getName();
                break;
            }
        }
        if (opType == null) {
            throw new RuntimeException("Couldn't find the binding operation for " + opName);
        }
        orb = exchange.get(ORB.class);
        ServerRequest request = exchange.get(ServerRequest.class);
        NVList list = prepareArguments(messageinfoopType
                                       opQNametypeMap,
                                       destinationservice);
        request.arguments(list);
        message.setList(list);
        HandlerIterator paramIterator = new HandlerIterator(messagetrue);
        CorbaTypeEventProducer eventProducer = null;
        BindingMessageInfo msgInfo = bopInfo.getInput();
        boolean wrap = false;
        if (bopInfo.isUnwrappedCapable()) {
            wrap = true;
        }
        if (wrap) {
            // wrapper element around our args
            QName wrapperElementQName = msgInfo.getMessageInfo().getName();
            eventProducer = new WrappedParameterSequenceEventProducer(wrapperElementQName,
                                                                      paramIterator,
                                                                      service,
                                                                      orb);
        } else {
            eventProducer = new ParameterEventProducer(paramIterator,
                                                       service,
                                                       orb);
        }
        CorbaStreamReader reader = new CorbaStreamReader(eventProducer);
        message.setContent(XMLStreamReader.classreader);
    }
    protected NVList prepareArguments(CorbaMessage corbaMsg,
                                      InterfaceInfo info,
                                      OperationType opType,
                                      QName opQName,
                                      CorbaTypeMap typeMap,
                                      CorbaDestination destination,
                                      ServiceInfo service) {        
        BindingInfo bInfo = destination.getBindingInfo();                              
        EndpointInfo eptInfo = destination.getEndPointInfo();
        BindingOperationInfo bOpInfo = bInfo.getOperation(opQName);
        OperationInfo opInfo = bOpInfo.getOperationInfo();        
        Exchange exg = corbaMsg.getExchange();
        exg.put(BindingInfo.classbInfo);
        exg.put(InterfaceInfo.classinfo);
        exg.put(EndpointInfo.classeptInfo);
        exg.put(EndpointReferenceType.classdestination.getAddress());
        exg.put(ServiceInfo.classservice);
        exg.put(BindingOperationInfo.classbOpInfo);        
        exg.put(OperationInfo.classopInfo);
        exg.put(MessageInfo.classopInfo.getInput());
        exg.put(String.classopQName.getLocalPart());        
        exg.setInMessage(corbaMsg);
        corbaMsg.put(MessageInfo.classopInfo.getInput());
                       
        List<ParamTypeparamTypes = opType.getParam();       
        CorbaStreamable[] arguments = new CorbaStreamable[paramTypes.size()];                               
        NVList list = prepareDIIArgsList(corbaMsgbOpInfo
                                         argumentsparamTypes
                                         typeMap,
                                         exg.get(ORB.class), service);         
        
        return list;
        
    }
    
    protected NVList prepareDIIArgsList(CorbaMessage corbaMsg,
                                        BindingOperationInfo boi,
                                        CorbaStreamable[] streamables
                                        List<ParamTypeparamTypes,
                                        CorbaTypeMap map,
                                        ORB orb,
                                        ServiceInfo service) {
        try {
            // Build the list of DII arguments, returns, and exceptions        
            NVList list = orb.create_list(streamables.length);        
            OperationInfo opInfo = boi.getOperationInfo();
            MessageInfo input = opInfo.getInput();          
            MessageInfo output = opInfo.getOutput();
        
            String inWrapNSUri = null;
            String outWrapNSUri = null;
            boolean wrap = false;
            if (boi.isUnwrappedCapable()) {
                wrap = true;
                if (input != null) {
                    inWrapNSUri = getWrappedParamNamespace(input);
                    if (!CorbaUtils.isElementFormQualified(serviceinWrapNSUri)) {
                        inWrapNSUri = "";
                    }
                }
                if (output != null) {
                    outWrapNSUri = getWrappedParamNamespace(output);
                    if (!CorbaUtils.isElementFormQualified(serviceoutWrapNSUri)) {
                        outWrapNSUri = "";
                    }
                }
            }
            int inMsgIndex = 0;
            int outMsgIndex = 0;
            for (int i = 0; i < paramTypes.size(); i++) {
                ParamType param = paramTypes.get(i);
                QName paramIdlType = param.getIdltype();
                QName paramName;
                ModeType paramMode = param.getMode();
                if (paramMode.value().equals("in")) {
                    if (wrap) {
                        paramName = new QName(inWrapNSUriparam.getName());
                    } else {
                        paramName = getMessageParamQName(inputparam.getName(), inMsgIndex);
                        inMsgIndex++;
                    }
                } else {
                    if (wrap) {
                        paramName = new QName(outWrapNSUriparam.getName());
                    } else {
                        paramName = getMessageParamQName(outputparam.getName(), outMsgIndex);
                        outMsgIndex++;
                    }
                }
                CorbaObjectHandler obj = 
                    CorbaHandlerUtils.initializeObjectHandler(orbparamNameparamIdlTypemapservice);
                streamables[i] = corbaMsg.createStreamableObject(objparamName);
                Any value = CorbaAnyHelper.createAny(orb);
                if (paramMode.value().equals("in")) {
                    streamables[i].setMode(....);
                    streamables[i].getObject().setIntoAny(valuestreamables[i], false);
                } else if (paramMode.value().equals("out")) {
                    streamables[i].setMode(....);
                    streamables[i].getObject().setIntoAny(valuestreamables[i], true);
                } else {
                    streamables[i].setMode(....);
                    streamables[i].getObject().setIntoAny(valuestreamables[i], false);
                }
                list.add_value(streamables[i].getName(), valuestreamables[i].getMode());              
                corbaMsg.addStreamableArgument(streamables[i]);
            }
            return list;
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
    protected QName getMessageParamQName(MessageInfo msgInfo,
                                         String paramName,
                                         int index) {
        QName paramQName = null;
        MessagePartInfo part = msgInfo.getMessageParts().get(index);
        if (part != null && part.isElement()) {
            paramQName = part.getElementQName();
        } else if (part != null) {
            paramQName = part.getName();
        }
        return paramQName;
    }
    protected String getWrappedParamNamespace(MessageInfo msgInfo) {
        MessagePartInfo part = msgInfo.getMessageParts().get(0);
        if (part.isElement()) {
            return part.getElementQName().getNamespaceURI();
        } else {
            return part.getName().getNamespaceURI();
        }
    }
New to GrepCode? Check out our FAQ X