use of javax.naming.Reference in project Payara by payara.
the class ResourceEnvFactory method getObjectInstance.
// ----------------------------------------------------------- Constructors
// -------------------------------------------------------------- Constants
// ----------------------------------------------------- Instance Variables
// --------------------------------------------------------- Public Methods
// -------------------------------------------------- ObjectFactory Methods
/**
* Crete a new Resource env instance.
*
* @param obj The reference object describing the DataSource
*/
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
if (obj instanceof ResourceEnvRef) {
Reference ref = (Reference) obj;
ObjectFactory factory = null;
RefAddr factoryRefAddr = ref.get(Constants.FACTORY);
if (factoryRefAddr != null) {
// Using the specified factory
String factoryClassName = factoryRefAddr.getContent().toString();
// Loading factory
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
Class<?> factoryClass = null;
if (tcl != null) {
try {
factoryClass = tcl.loadClass(factoryClassName);
} catch (ClassNotFoundException e) {
}
} else {
try {
factoryClass = Class.forName(factoryClassName);
} catch (ClassNotFoundException e) {
}
}
if (factoryClass != null) {
try {
factory = (ObjectFactory) factoryClass.newInstance();
} catch (Throwable t) {
}
}
}
// Note: No defaults here
if (factory != null) {
return factory.getObjectInstance(obj, name, nameCtx, environment);
} else {
throw new NamingException("Cannot create resource instance");
}
}
return null;
}
use of javax.naming.Reference in project Payara by payara.
the class ResourceFactory method getObjectInstance.
// ----------------------------------------------------------- Constructors
// -------------------------------------------------------------- Constants
// ----------------------------------------------------- Instance Variables
// --------------------------------------------------------- Public Methods
// -------------------------------------------------- ObjectFactory Methods
/**
* Crete a new DataSource instance.
*
* @param obj The reference object describing the DataSource
*/
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
if (obj instanceof ResourceRef) {
Reference ref = (Reference) obj;
ObjectFactory factory = null;
RefAddr factoryRefAddr = ref.get(Constants.FACTORY);
if (factoryRefAddr != null) {
// Using the specified factory
String factoryClassName = factoryRefAddr.getContent().toString();
// Loading factory
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
Class<?> factoryClass = null;
if (tcl != null) {
try {
factoryClass = tcl.loadClass(factoryClassName);
} catch (ClassNotFoundException e) {
throw new NamingException("Could not create resource factory, ClassNotFoundException:" + e.getMessage());
}
} else {
try {
factoryClass = Class.forName(factoryClassName);
} catch (ClassNotFoundException e) {
throw new NamingException("Could not create resource factory, ClassNotFoundException:" + e.getMessage());
}
}
if (factoryClass != null) {
try {
factory = (ObjectFactory) factoryClass.newInstance();
} catch (Throwable t) {
if (t instanceof NamingException)
throw (NamingException) t;
throw new NamingException("Could not create resource factory instance, " + t.getMessage());
}
}
} else {
if (ref.getClassName().equals("javax.sql.DataSource")) {
String javaxSqlDataSourceFactoryClassName = System.getProperty("javax.sql.DataSource.Factory", Constants.DBCP_DATASOURCE_FACTORY);
try {
factory = (ObjectFactory) Class.forName(javaxSqlDataSourceFactoryClassName).newInstance();
} catch (Throwable t) {
}
} else if (ref.getClassName().equals("javax.mail.Session")) {
String javaxMailSessionFactoryClassName = System.getProperty("javax.mail.Session.Factory", "org.apache.naming.factory.MailSessionFactory");
try {
factory = (ObjectFactory) Class.forName(javaxMailSessionFactoryClassName).newInstance();
} catch (Throwable t) {
}
}
}
if (factory != null) {
return factory.getObjectInstance(obj, name, nameCtx, environment);
} else {
throw new NamingException("Cannot create resource instance");
}
}
return null;
}
use of javax.naming.Reference in project Payara by payara.
the class ResourceLinkFactory method getObjectInstance.
// -------------------------------------------------- ObjectFactory Methods
/**
* Create a new DataSource instance.
*
* @param obj The reference object describing the DataSource
*/
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws NamingException {
if (!(obj instanceof ResourceLinkRef))
return null;
// Can we process this request?
Reference ref = (Reference) obj;
// Read the global ref addr
String globalName = null;
RefAddr refAddr = ref.get(ResourceLinkRef.GLOBALNAME);
if (refAddr != null) {
globalName = refAddr.getContent().toString();
Object result = null;
result = globalContext.lookup(globalName);
// FIXME: Check type
return result;
}
return (null);
}
use of javax.naming.Reference in project Payara by payara.
the class TransactionFactory method getObjectInstance.
// ----------------------------------------------------------- Constructors
// -------------------------------------------------------------- Constants
// ----------------------------------------------------- Instance Variables
// --------------------------------------------------------- Public Methods
// -------------------------------------------------- ObjectFactory Methods
/**
* Crete a new User transaction instance.
*
* @param obj The reference object describing the DataSource
*/
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
if (obj instanceof TransactionRef) {
Reference ref = (Reference) obj;
ObjectFactory factory = null;
RefAddr factoryRefAddr = ref.get(Constants.FACTORY);
if (factoryRefAddr != null) {
// Using the specified factory
String factoryClassName = factoryRefAddr.getContent().toString();
// Loading factory
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
Class<?> factoryClass = null;
if (tcl != null) {
try {
factoryClass = tcl.loadClass(factoryClassName);
} catch (ClassNotFoundException e) {
}
} else {
try {
factoryClass = Class.forName(factoryClassName);
} catch (ClassNotFoundException e) {
}
}
if (factoryClass != null) {
try {
factory = (ObjectFactory) factoryClass.newInstance();
} catch (Throwable t) {
}
}
}
if (factory != null) {
return factory.getObjectInstance(obj, name, nameCtx, environment);
} else {
throw new NamingException("Cannot create resource instance");
}
}
return null;
}
use of javax.naming.Reference in project Payara by payara.
the class NamingContextListener method addEjb.
/**
* Set the specified EJBs in the naming context.
*/
public void addEjb(ContextEjb ejb) {
// Create a reference to the EJB.
Reference ref = new EjbRef(ejb.getType(), ejb.getHome(), ejb.getRemote(), ejb.getLink());
// Adding the additional parameters, if any
addAdditionalParameters(ejb.getNamingResources(), ref, ejb.getName());
try {
createSubcontexts(envCtx, ejb.getName());
envCtx.bind(ejb.getName(), ref);
} catch (NamingException e) {
String msg = MessageFormat.format(rb.getString(LogFacade.BIND_OBJECT_FAILED), e);
log(msg);
}
}
Aggregations