use of javax.naming.spi.ObjectFactory in project aries by apache.
the class ContextHelper method getURLObjectFactory.
public static ServicePair<ObjectFactory> getURLObjectFactory(final BundleContext ctx, String urlScheme, Hashtable<?, ?> environment) throws NamingException {
ServicePair<ObjectFactory> result = null;
ServiceReference<ObjectFactory> ref = Activator.getUrlFactory(urlScheme);
if (ref == null) {
Collection<ServiceReference<URLObjectFactoryFinder>> refs = Activator.getURLObjectFactoryFinderServices();
for (final ServiceReference<URLObjectFactoryFinder> finderRef : refs) {
URLObjectFactoryFinder finder = Activator.getService(ctx, finderRef);
if (finder != null) {
ObjectFactory f = finder.findFactory(urlScheme, environment);
if (f != null) {
result = new ServicePair<>(ctx, finderRef, f);
break;
}
}
}
} else {
result = new ServicePair<>(ctx, ref);
}
return result;
}
use of javax.naming.spi.ObjectFactory 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.spi.ObjectFactory in project Payara by payara.
the class EjbFactory method getObjectInstance.
// ----------------------------------------------------------- Constructors
// -------------------------------------------------------------- Constants
// ----------------------------------------------------- Instance Variables
// --------------------------------------------------------- Public Methods
// -------------------------------------------------- ObjectFactory Methods
/**
* Crete a new EJB 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 EjbRef) {
Reference ref = (Reference) obj;
// If ejb-link has been specified, resolving the link using JNDI
RefAddr linkRefAddr = ref.get(EjbRef.LINK);
if (linkRefAddr != null) {
// Retrieving the EJB link
String ejbLink = linkRefAddr.getContent().toString();
Object beanObj = (new InitialContext()).lookup(ejbLink);
/*
String homeClassName = ref.getClassName();
try {
Class home = Class.forName(homeClassName);
if (home.isInstance(beanObj)) {
if (log.isDebugEnabled())
log.debug("Bean of type "
+ beanObj.getClass().getName()
+ " implements home interface "
+ home.getName());
} else {
if (log.isDebugEnabled())
log.debug("Bean of type "
+ beanObj.getClass().getName()
+ " doesn't implement home interface "
+ home.getName());
throw new NamingException
("Bean of type " + beanObj.getClass().getName()
+ " doesn't implement home interface "
+ home.getName());
}
} catch (ClassNotFoundException e) {
log.warn("Couldn't load home interface "
+ homeClassName, e);
}
*/
return beanObj;
}
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) {
}
}
} else {
String javaxEjbFactoryClassName = System.getProperty("javax.ejb.Factory", Constants.OPENEJB_EJB_FACTORY);
try {
factory = (ObjectFactory) Class.forName(javaxEjbFactoryClassName).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.spi.ObjectFactory 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.spi.ObjectFactory 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;
}
Aggregations