List of usage examples for javax.naming Reference getClassName
public String getClassName()
From source file:Rebind.java
public Object getObjectInstance(Object obj, Name name, Context ctx, Hashtable<?, ?> env) throws Exception { if (obj instanceof Reference) { Reference ref = (Reference) obj; if (ref.getClassName().equals(Fruit.class.getName())) { RefAddr addr = ref.get("fruit"); if (addr != null) { return new Fruit((String) addr.getContent()); }//from www .ja v a 2 s . c o m } } return null; }
From source file:jndi.view.JndiView.java
/** * @param ctx//from www .j av a2 s .co m * the Context we're examining * @param path * the path to examine * @param bindings * the {@link NamingEnumeration} of {@link Binding}s * @return List of {@link JndiEntry} * @throws NamingException * on exception */ private List<JndiEntry> examineBindings(final Context ctx, final String path, final NamingEnumeration<Binding> bindings) throws NamingException { if (null == bindings) { throw new NullPointerException("bindings is null!"); } final List<JndiEntry> entries = new ArrayList<JndiEntry>(); while (bindings.hasMore()) { final Binding binding = bindings.next(); final String name = binding.getName(); final String className = binding.getClassName(); logger.finest("name: " + name + " [" + className + "]"); final JndiEntry entry = new JndiEntry(name, className); final Object obj = binding.getObject(); if (obj instanceof Context) { entry.setContext(true); String link = name; if (!path.isEmpty()) { link = path + "/" + name; } entry.setLink(link); } else if (obj instanceof Reference) { final Reference ref = (Reference) obj; entry.setTargetClassName(ref.getClassName()); } else if ("org.glassfish.javaee.services.ResourceProxy".equals(className)) { // SUPPRESS CHECKSTYLE AvoidInlineConditionals final Object lookup = ctx.lookup(path.isEmpty() ? name : path + "/" + name); if (lookup != null) { final String lookedUpClassName = lookup.getClass().getName(); logger.finest("lookup(\"" + name + "\") returned " + lookedUpClassName); entry.setTargetClassName(lookedUpClassName); } } else if ("com.sun.ejb.containers.JavaGlobalJndiNamingObjectProxy".equals(className)) { inspectJndiNamingObjectProxy(entry, obj); } entries.add(entry); } return entries; }
From source file:com.frameworkset.commons.dbcp2.BasicDataSourceFactory.java
/** * <p>Create and return a new <code>BasicDataSource</code> instance. If no * instance can be created, return <code>null</code> instead.</p> * * @param obj The possibly null object containing location or * reference information that can be used in creating an object * @param name The name of this object relative to <code>nameCtx</code> * @param nameCtx The context relative to which the <code>name</code> * parameter is specified, or <code>null</code> if <code>name</code> * is relative to the default initial context * @param environment The possibly null environment that is used in * creating this object//from w ww . j av a2 s.c o m * * @exception Exception if an exception occurs creating the instance */ @Override public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { // We only know how to deal with <code>javax.naming.Reference</code>s // that specify a class name of "javax.sql.DataSource" if (obj == null || !(obj instanceof Reference)) { return null; } Reference ref = (Reference) obj; if (!"javax.sql.DataSource".equals(ref.getClassName())) { return null; } // Check property names and log warnings about obsolete and / or unknown properties final List<String> warnings = new ArrayList<String>(); final List<String> infoMessages = new ArrayList<String>(); validatePropertyNames(ref, name, warnings, infoMessages); for (String warning : warnings) { log.warn(warning); } for (String infoMessage : infoMessages) { log.info(infoMessage); } Properties properties = new Properties(); for (String propertyName : ALL_PROPERTIES) { RefAddr ra = ref.get(propertyName); if (ra != null) { String propertyValue = ra.getContent().toString(); properties.setProperty(propertyName, propertyValue); } } return createDataSource(properties); }
From source file:org.eclipse.ecr.runtime.jtajca.NuxeoConnectionManagerFactory.java
@Override public Object getObjectInstance(Object obj, Name objName, Context nameCtx, Hashtable<?, ?> env) throws Exception { Reference ref = (Reference) obj; if (!ConnectionManager.class.getName().equals(ref.getClassName())) { return null; }//w w w.ja va 2 s. c o m if (NuxeoContainer.getConnectionManager() == null) { // initialize ConnectionManagerConfiguration config = new ConnectionManagerConfiguration(); for (RefAddr addr : Collections.list(ref.getAll())) { String name = addr.getType(); String value = (String) addr.getContent(); try { BeanUtils.setProperty(config, name, value); } catch (Exception e) { log.error(String.format("NuxeoConnectionManagerFactory cannot set %s = %s", name, value)); } } NuxeoContainer.initConnectionManager(config); } return NuxeoContainer.getConnectionManager(); }
From source file:org.eclipse.ecr.runtime.jtajca.NuxeoTransactionManagerFactory.java
@Override public Object getObjectInstance(Object obj, Name objName, Context nameCtx, Hashtable<?, ?> env) throws Exception { Reference ref = (Reference) obj; if (!TransactionManager.class.getName().equals(ref.getClassName())) { return null; }/* www . j ava 2s. c o m*/ if (NuxeoContainer.getTransactionManager() == null) { // initialize TransactionManagerConfiguration config = new TransactionManagerConfiguration(); for (RefAddr addr : Collections.list(ref.getAll())) { String name = addr.getType(); String value = (String) addr.getContent(); try { BeanUtils.setProperty(config, name, value); } catch (Exception e) { log.error(String.format("NuxeoTransactionManagerFactory cannot set %s = %s", name, value)); } } NuxeoContainer.initTransactionManager(config); } return NuxeoContainer.getTransactionManager(); }
From source file:org.nuxeo.runtime.datasource.BasicManagedDataSourceFactory.java
/** * Create and return a new <code>BasicManagedDataSource</code> instance. If * no instance can be created, return <code>null</code> instead. * * @param obj The possibly null object containing location or reference * information that can be used in creating an object * @param name The name of this object relative to <code>nameCtx</code> * @param nameCtx The context relative to which the <code>name</code> * parameter is specified, or <code>null</code> if * <code>name</code> is relative to the default initial context * @param environment The possibly null environment that is used in creating * this object/*from ww w . j a v a2s . c o m*/ * * @exception Exception if an exception occurs creating the instance */ @Override public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { // We only know how to deal with <code>javax.naming.Reference</code>s // that specify a class name of "javax.sql.DataSource" if ((obj == null) || !(obj instanceof Reference)) { return null; } Reference ref = (Reference) obj; if (!"javax.sql.DataSource".equals(ref.getClassName())) { return null; } Properties properties = new Properties(); for (String propertyName : ALL_PROPERTIES) { RefAddr ra = ref.get(propertyName); if (ra != null) { String propertyValue = ra.getContent().toString(); properties.setProperty(propertyName, propertyValue); } } return createDataSource(properties); }
From source file:org.nuxeo.runtime.datasource.DataSourceFactory.java
@Override public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> env) throws Exception { Reference ref = (Reference) obj; if (!DataSource.class.getName().equals(ref.getClassName())) { return null; }// www .j av a 2 s . c om TransactionManager transactionManager; try { transactionManager = TransactionHelper.lookupTransactionManager(); } catch (NamingException e) { transactionManager = null; } boolean xa = ref.get(BasicManagedDataSourceFactory.PROP_XADATASOURCE) != null; log.info(String.format("Creating pooled %s datasource: %s/%s", xa ? "XA" : "non-XA", nameCtx.getNameInNamespace(), name)); if (xa && transactionManager == null) { throw new RuntimeException( "Cannot configure XA datasource " + name + " without an available transaction manager"); } // extract properties from Reference Map<String, String> properties = new HashMap<String, String>(); Enumeration<RefAddr> refAddrs = ref.getAll(); while (refAddrs.hasMoreElements()) { RefAddr ra = refAddrs.nextElement(); String key = ra.getType(); String value = ra.getContent().toString(); if (key.startsWith(DataSourceDescriptor.PROP_PREFIX)) { key = key.substring(DataSourceDescriptor.PROP_PREFIX.length()); properties.put(key, value); } } DataSource ds; if (!xa) { // fetch url from properties for (Entry<String, String> en : properties.entrySet()) { // often misspelled, thus the ignore case if (URL_LOWER.equalsIgnoreCase(en.getKey())) { ref.add(new StringRefAddr(URL_LOWER, en.getValue())); } } ObjectFactory factory = new BasicDataSourceFactory(); ds = (DataSource) factory.getObjectInstance(ref, name, nameCtx, env); BasicDataSource bds = (BasicDataSource) ds; // set properties for (Entry<String, String> en : properties.entrySet()) { String key = en.getKey(); if (URL_LOWER.equalsIgnoreCase(key)) { continue; } bds.addConnectionProperty(key, en.getValue()); } } else { ObjectFactory factory = new BasicManagedDataSourceFactory(); ds = (DataSource) factory.getObjectInstance(obj, name, nameCtx, env); if (ds == null) { return null; } BasicManagedDataSource bmds = (BasicManagedDataSource) ds; // set transaction manager bmds.setTransactionManager(transactionManager); // set properties XADataSource xaDataSource = bmds.getXaDataSourceInstance(); if (xaDataSource == null) { return null; } for (Entry<String, String> en : properties.entrySet()) { String key = en.getKey(); // proper JavaBean convention for initial cap if (Character.isLowerCase(key.charAt(1))) { key = Character.toLowerCase(key.charAt(0)) + key.substring(1); } String value = en.getValue(); boolean ok = false; try { BeanUtils.setProperty(xaDataSource, key, value); ok = true; } catch (Exception e) { if (URL_LOWER.equals(key)) { // commonly misspelled try { BeanUtils.setProperty(xaDataSource, URL_UPPER, value); ok = true; } catch (Exception ee) { // log error below } } } if (!ok) { log.error(String.format("Cannot set %s = %s on %s", key, value, xaDataSource.getClass().getName())); } } } return ds; }
From source file:org.nuxeo.runtime.datasource.PooledDataSourceFactory.java
protected ConnectionManagerWrapper createManager(Reference ref, Context ctx) throws ResourceException { NuxeoConnectionManagerConfiguration config = NuxeoConnectionManagerFactory.getConfig(ref); String className = ref.getClassName(); config.setXAMode(XADataSource.class.getName().equals(className)); return NuxeoContainer.initConnectionManager(config); }
From source file:org.nuxeo.runtime.datasource.PooledDataSourceFactory.java
protected ManagedConnectionFactory createFactory(Reference ref, Context ctx) throws NamingException, InvalidPropertyException { String className = ref.getClassName(); if (XADataSource.class.getName().equals(className)) { String user = refAttribute(ref, "User", ""); String password = refAttribute(ref, "Password", ""); String name = refAttribute(ref, "dataSourceJNDI", null); XADataSource ds = NuxeoContainer.lookup(name, XADataSource.class); XADataSourceWrapper wrapper = new XADataSourceWrapper(ds); wrapper.setUserName(user);//w w w .j a v a 2 s . c om wrapper.setPassword(password); return wrapper; } if (javax.sql.DataSource.class.getName().equals(className)) { String user = refAttribute(ref, "username", ""); if (user.isEmpty()) { user = refAttribute(ref, "user", ""); if (!user.isEmpty()) { LogFactory.getLog(PooledDataSourceFactory.class) .warn("wrong attribute 'user' in datasource descriptor, should use 'username' instead"); } } String password = refAttribute(ref, "password", ""); String dsname = refAttribute(ref, "dataSourceJNDI", ""); if (!dsname.isEmpty()) { javax.sql.DataSource ds = NuxeoContainer.lookup(dsname, DataSource.class); LocalDataSourceWrapper wrapper = new LocalDataSourceWrapper(ds); wrapper.setUserName(user); wrapper.setPassword(password); return wrapper; } String name = refAttribute(ref, "driverClassName", null); String url = refAttribute(ref, "url", null); String sqlExceptionSorter = refAttribute(ref, "sqlExceptionSorter", DatasourceExceptionSorter.class.getName()); boolean commitBeforeAutocommit = Boolean.valueOf(refAttribute(ref, "commitBeforeAutocommit", "true")) .booleanValue(); JdbcConnectionFactory factory = new JdbcConnectionFactory(); factory.setDriver(name); factory.setUserName(user); factory.setPassword(password); factory.setConnectionURL(url); factory.setExceptionSorterClass(sqlExceptionSorter); factory.setCommitBeforeAutocommit(commitBeforeAutocommit); return factory; } throw new IllegalArgumentException("unsupported class " + className); }
From source file:org.nuxeo.runtime.jtajca.NuxeoConnectionManagerFactory.java
@Override public Object getObjectInstance(Object obj, Name objName, Context nameCtx, Hashtable<?, ?> env) { Reference ref = (Reference) obj; if (!ConnectionManager.class.getName().equals(ref.getClassName())) { return null; }/*w w w . j ava 2 s . c o m*/ String name; int size = objName.size(); if (size == 1) { name = "default"; } else { name = objName.get(size - 1); } final ConnectionManager cm = NuxeoContainer.connectionManagers.get(name); if (cm != null) { return cm; } NuxeoConnectionManagerConfiguration config = new NuxeoConnectionManagerConfiguration(); for (RefAddr addr : Collections.list(ref.getAll())) { String type = addr.getType(); String content = (String) addr.getContent(); try { BeanUtils.setProperty(config, type, content); } catch (ReflectiveOperationException e) { log.error(String.format("NuxeoConnectionManagerFactory cannot set %s = %s", type, content)); } } return NuxeoContainer.initConnectionManager(config); }