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;
}
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);
}
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;
}
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);
}
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;
}
}
Aggregations