Search in sources :

Example 96 with Reference

use of javax.naming.Reference in project tomee by apache.

the class WsFactory method getObjectInstance.

@Override
public Object getObjectInstance(final Object object, final Name name, final Context context, final Hashtable environment) throws Exception {
    // ignore non resource-refs
    if (!(object instanceof ResourceRef)) {
        return null;
    }
    final Reference ref = (Reference) object;
    final Object value;
    if (NamingUtil.getProperty(ref, NamingUtil.JNDI_NAME) != null) {
        // lookup the value in JNDI
        value = super.getObjectInstance(object, name, context, environment);
    } else {
        // load service class which is used to construct the port
        final String serviceClassName = NamingUtil.getProperty(ref, NamingUtil.WS_CLASS);
        Class<? extends Service> serviceClass = Service.class;
        if (serviceClassName != null) {
            serviceClass = NamingUtil.loadClass(serviceClassName).asSubclass(Service.class);
            if (serviceClass == null) {
                throw new NamingException("Could not load service type class " + serviceClassName);
            }
        }
        // load the reference class which is the ultimate type of the port
        final Class<?> referenceClass = NamingUtil.loadClass(ref.getClassName());
        // if ref class is a subclass of Service, use it for the service class
        if (referenceClass != null && Service.class.isAssignableFrom(referenceClass)) {
            serviceClass = referenceClass.asSubclass(Service.class);
        }
        // PORT ID
        final String serviceId = NamingUtil.getProperty(ref, NamingUtil.WS_ID);
        // Service QName
        QName serviceQName = null;
        if (NamingUtil.getProperty(ref, NamingUtil.WS_QNAME) != null) {
            serviceQName = QName.valueOf(NamingUtil.getProperty(ref, NamingUtil.WS_QNAME));
        }
        // WSDL URL
        URL wsdlUrl = null;
        if (NamingUtil.getProperty(ref, NamingUtil.WSDL_URL) != null) {
            wsdlUrl = new URL(NamingUtil.getProperty(ref, NamingUtil.WSDL_URL));
        }
        // Port QName
        QName portQName = null;
        if (NamingUtil.getProperty(ref, NamingUtil.WS_PORT_QNAME) != null) {
            portQName = QName.valueOf(NamingUtil.getProperty(ref, NamingUtil.WS_PORT_QNAME));
        }
        // port refs
        List<PortRefData> portRefs = NamingUtil.getStaticValue(ref, "port-refs");
        if (portRefs == null) {
            portRefs = Collections.emptyList();
        }
        // HandlerChain
        List<HandlerChainData> handlerChains = NamingUtil.getStaticValue(ref, "handler-chains");
        if (handlerChains == null) {
            handlerChains = Collections.emptyList();
        }
        Collection<Injection> injections = NamingUtil.getStaticValue(ref, "injections");
        if (injections == null) {
            injections = Collections.emptyList();
        }
        final Properties properties = new Properties();
        properties.putAll(environment);
        final JaxWsServiceReference serviceReference = new JaxWsServiceReference(serviceId, serviceQName, serviceClass, portQName, referenceClass, wsdlUrl, portRefs, handlerChains, injections, properties);
        value = serviceReference.getObject();
    }
    return value;
}
Also used : HandlerChainData(org.apache.openejb.core.webservices.HandlerChainData) Reference(javax.naming.Reference) JaxWsServiceReference(org.apache.openejb.core.ivm.naming.JaxWsServiceReference) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) Injection(org.apache.openejb.Injection) Properties(java.util.Properties) URL(java.net.URL) JaxWsServiceReference(org.apache.openejb.core.ivm.naming.JaxWsServiceReference) ResourceRef(org.apache.naming.ResourceRef) NamingException(javax.naming.NamingException) PortRefData(org.apache.openejb.core.webservices.PortRefData)

Example 97 with Reference

use of javax.naming.Reference in project tomee by apache.

the class EnumFactory method getObjectInstance.

@Override
public Object getObjectInstance(final Object object, final Name name, final Context context, final Hashtable environment) throws Exception {
    if (!(object instanceof Reference)) {
        return null;
    }
    final Reference reference = ((Reference) object);
    final String typeName = reference.getClassName();
    final ClassLoader loader = Thread.currentThread().getContextClassLoader();
    final Class<?> type = loader.loadClass(typeName);
    final String value = NamingUtil.getProperty(reference, ENUM_VALUE);
    return Enum.valueOf((Class<Enum>) type, value);
}
Also used : Reference(javax.naming.Reference)

Example 98 with Reference

use of javax.naming.Reference in project tomee by apache.

the class PersistenceContextFactory method getObjectInstance.

@Override
public Object getObjectInstance(final Object object, final Name name, final Context context, final Hashtable environment) throws Exception {
    // ignore non resource-refs
    if (!(object instanceof ResourceRef)) {
        return null;
    }
    final Reference ref = (Reference) object;
    final Object value;
    if (getProperty(ref, JNDI_NAME) != null) {
        // lookup the value in JNDI
        value = super.getObjectInstance(object, name, context, environment);
    } else {
        // value is hard hard coded in the properties
        value = getStaticValue(ref);
    }
    return value;
}
Also used : Reference(javax.naming.Reference) ResourceRef(org.apache.naming.ResourceRef)

Example 99 with Reference

use of javax.naming.Reference in project tomee by apache.

the class ResourceFactory method getObjectInstance.

@Override
public Object getObjectInstance(final Object object, final Name name, final Context context, final Hashtable environment) throws Exception {
    final Reference reference = ((Reference) object);
    final String type = reference.getClassName();
    if ("java.net.URL".equals(type)) {
        final String resourceId = getProperty(reference, RESOURCE_ID);
        return new URL(resourceId);
    }
    if ("java.lang.Class".equals(type)) {
        final ClassLoader loader = Thread.currentThread().getContextClassLoader();
        final String resourceId = getProperty(reference, RESOURCE_ID);
        return loader.loadClass(resourceId);
    }
    return super.getObjectInstance(object, name, context, environment);
}
Also used : Reference(javax.naming.Reference) URL(java.net.URL)

Example 100 with Reference

use of javax.naming.Reference in project tomee by apache.

the class JNDIResponse method writeExternal.

@Override
public void writeExternal(final ObjectOutput out) throws IOException {
    // write out the version of the serialized data for future use
    out.writeByte(1);
    if (null != server) {
        out.writeBoolean(true);
        server.setMetaData(metaData);
        server.writeExternal(out);
    } else {
        out.writeBoolean(false);
    }
    out.writeByte((byte) responseCode);
    switch(responseCode) {
        case ResponseCodes.JNDI_BUSINESS_OBJECT:
        case ResponseCodes.JNDI_OK:
        case ResponseCodes.JNDI_NAMING_EXCEPTION:
        case ResponseCodes.JNDI_RUNTIME_EXCEPTION:
        case ResponseCodes.JNDI_ERROR:
        case ResponseCodes.JNDI_RESOURCE:
            out.writeObject(result);
            break;
        case ResponseCodes.JNDI_CONTEXT:
        case ResponseCodes.JNDI_NOT_FOUND:
            break;
        case ResponseCodes.JNDI_EJBHOME:
            final EJBMetaDataImpl m = (EJBMetaDataImpl) result;
            m.setMetaData(metaData);
            m.writeExternal(out);
            break;
        case ResponseCodes.JNDI_DATA_SOURCE:
            final DataSourceMetaData ds = (DataSourceMetaData) result;
            ds.setMetaData(metaData);
            ds.writeExternal(out);
            break;
        case ResponseCodes.JNDI_INJECTIONS:
            final InjectionMetaData imd = (InjectionMetaData) result;
            imd.setMetaData(metaData);
            imd.writeExternal(out);
            break;
        case ResponseCodes.JNDI_WEBSERVICE:
            final WsMetaData ws = (WsMetaData) result;
            out.writeObject(ws);
            break;
        case ResponseCodes.JNDI_ENUMERATION:
            final NameClassPairEnumeration ncpe = (NameClassPairEnumeration) result;
            ncpe.setMetaData(metaData);
            ncpe.writeExternal(out);
            break;
        case ResponseCodes.JNDI_REFERENCE:
            final Reference ref = (Reference) result;
            out.writeObject(ref);
            break;
    }
}
Also used : Reference(javax.naming.Reference)

Aggregations

Reference (javax.naming.Reference)226 NamingException (javax.naming.NamingException)79 RefAddr (javax.naming.RefAddr)59 StringRefAddr (javax.naming.StringRefAddr)54 Context (javax.naming.Context)41 NameNotFoundException (javax.naming.NameNotFoundException)40 InitialContext (javax.naming.InitialContext)37 Test (org.junit.Test)33 Name (javax.naming.Name)30 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)28 Properties (java.util.Properties)26 OperationNotSupportedException (javax.naming.OperationNotSupportedException)25 NotContextException (javax.naming.NotContextException)24 ObjectFactory (javax.naming.spi.ObjectFactory)23 CompositeName (javax.naming.CompositeName)21 Referenceable (javax.naming.Referenceable)18 Binding (javax.naming.Binding)17 CompoundName (javax.naming.CompoundName)16 LinkRef (javax.naming.LinkRef)15 Hashtable (java.util.Hashtable)12