Package org.apache.yoko.bindings.corba

Source Code of org.apache.yoko.bindings.corba.CorbaObjectReferenceHelper

/**
* 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.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.wsdl.Binding;
import javax.wsdl.Definition;
import javax.wsdl.Port;
import javax.wsdl.Service;
import javax.xml.namespace.QName;

import org.apache.cxf.common.logging.LogUtils;
import org.apache.schemas.yoko.bindings.corba.BindingType;

public class CorbaObjectReferenceHelper {

    public static final String WSDLI_NAMESPACE_URI = "http://www.w3.org/2006/01/wsdl-instance";
    public static final String ADDRESSING_NAMESPACE_URI = "http://www.w3.org/2005/08/addressing";
    public static final String ADDRESSING_WSDL_NAMESPACE_URI = "http://www.w3.org/2005/08/addressing/wsdl";
   
    private static final Logger LOG = LogUtils.getL7dLogger(CorbaObjectReferenceHelper.class);

    //  We need to keep a list of all object references that we have used in the binding.
    //  This helps us in two ways:
    //    1. When we receive a CORBA object reference in Yoko, we can make sure that
    //       when Yoko makes any invocation on that reference, the binding selects the
    //       correct target to send the request to.
    //    2. When we want to send a Yoko reference to a CORBA target, we make sure that
    //       we provide the correct DSI servant to the request so that the CORBA target
    //       can correctly call the corresponding Yoko object.
    private static Map<String, org.omg.CORBA.Object> objectReferences =
        new HashMap<String, org.omg.CORBA.Object>();

    public static void addReference(String id, org.omg.CORBA.Object reference) {
        LOG.log(Level.INFO, "Registering object with id " + id);
        objectReferences.put(id, reference);
    }

    public static org.omg.CORBA.Object getReferenceById(String id) {
        LOG.log(Level.INFO, "Retrieving object with id " + id);
        return objectReferences.get(id);
    }
   
    public static String getWSDLLocation(Definition wsdlDef) {
        return wsdlDef.getDocumentBaseURI();
    }
   
    public static QName getServiceName(Binding binding, Definition wsdlDef) {
        Collection services = wsdlDef.getServices().values();
        for (Iterator iter = services.iterator(); iter.hasNext();) {
            Service serv = (Service)iter.next();
            Collection ports = serv.getPorts().values();
            for (Iterator portIter = ports.iterator(); portIter.hasNext();) {
                Port pt = (Port)portIter.next();
                if (pt.getBinding().equals(binding)) {
                    return serv.getQName();
                }
            }
        }
        return null;
    }
   
    public static String getEndpointName(Binding binding, Definition wsdlDef) {
        Collection services = wsdlDef.getServices().values();
        for (Iterator iter = services.iterator(); iter.hasNext();) {
            Service serv = (Service)iter.next();
            Collection ports = serv.getPorts().values();
            for (Iterator portIter = ports.iterator(); portIter.hasNext();) {
                Port pt = (Port)portIter.next();
                if (pt.getBinding().equals(binding)) {
                    return pt.getName();
                }
            }
        }
        return null;
    }
   
    public static Binding getDefaultBinding(org.omg.CORBA.Object obj, Definition wsdlDef) {
        Collection bindings = wsdlDef.getBindings().values();
        for (Iterator iter = bindings.iterator(); iter.hasNext();) {
            Binding b = (Binding)iter.next();
            List extElements = b.getExtensibilityElements();
           
            // Get the list of all extensibility elements
            for (Iterator extIter = extElements.iterator(); extIter.hasNext();) {
                Object element = extIter.next();

                // Find a binding type so we can check against its repository ID
                if (element instanceof BindingType) {
                    BindingType type = (BindingType)element;
                    if (obj._is_a(type.getRepositoryID())) {
                        return b;
                    }
                }
            }
        }
       
        return null;
    }
}
TOP

Related Classes of org.apache.yoko.bindings.corba.CorbaObjectReferenceHelper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.