List of usage examples for javax.naming RefAddr getContent
public abstract Object getContent();
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 ww w . j a v a 2 s . c o m*/ } } return null; }
From source file:it.infn.ct.futuregateway.apiserver.utils.MonitorQueueFactory.java
@Override public final Object getObjectInstance(final Object obj, final Name name, final Context ctx, final Hashtable<?, ?> env) throws Exception { Reference ref = (Reference) obj; Enumeration<RefAddr> addrs = ref.getAll(); int threadPoolSize = Constants.DEFAULTTHREADPOOLSIZE; int bufferSize = Constants.MONITORBUFFERSIZE; int checkInterval = Constants.MONITORCHECKINTERVAL; while (addrs.hasMoreElements()) { RefAddr addr = (RefAddr) addrs.nextElement(); String addrName = addr.getType(); String addrValue = (String) addr.getContent(); switch (addrName) { case "poolSize": try { threadPoolSize = Integer.parseInt(addrValue); } catch (NumberFormatException nfe) { log.warn("Attribute poolSize format not correct." + " Default value (" + threadPoolSize + ") applied."); }/* w ww. j av a2 s . c o m*/ break; case "bufferSize": try { bufferSize = Integer.parseInt(addrValue); } catch (NumberFormatException nfe) { log.warn("Attribute bufferSize format not correct." + " Default value (" + bufferSize + ") applied."); } break; case "checkInterval": try { checkInterval = Integer.parseInt(addrValue); } catch (NumberFormatException nfe) { log.warn("Attribute checkInterval format not correct." + " Default value (" + checkInterval + ") applied."); } default: } } return new MonitorQueue(bufferSize, threadPoolSize, checkInterval); }
From source file:it.infn.ct.futuregateway.apiserver.utils.ThreadPoolFactory.java
@Override public final Object getObjectInstance(final Object obj, final Name name, final Context ctx, final Hashtable<?, ?> env) throws Exception { Reference ref = (Reference) obj; Enumeration<RefAddr> addrs = ref.getAll(); int threadPoolSize = Constants.DEFAULTTHREADPOOLSIZE; int maxThreadPoolSize = Constants.MAXTHREADPOOLSIZETIMES * threadPoolSize; int maxThreadIdleTime = Constants.MAXTHREADPOOLSIZETIMES; while (addrs.hasMoreElements()) { RefAddr addr = (RefAddr) addrs.nextElement(); String addrName = addr.getType(); String addrValue = (String) addr.getContent(); switch (addrName) { case "poolSize": try { threadPoolSize = Integer.parseInt(addrValue); } catch (NumberFormatException nfe) { log.warn("Attribute poolSize format not correct." + " Default value applied."); }// w ww. ja v a 2 s. com break; case "maxPoolSize": try { maxThreadPoolSize = Integer.parseInt(addrValue); } catch (NumberFormatException nfe) { log.warn("Attribute maxPoolSize format not correct." + " Default value applied."); } break; case "maxThreadIdleTimeMills": try { maxThreadIdleTime = Integer.parseInt(addrValue); } catch (NumberFormatException nfe) { log.warn("Attribute maxThreadIdleTimeMills format not" + " correct. Default value applied."); } break; default: } } log.info("A new thread pool created with name: " + name.toString()); return (ThreadPoolFactory.getThreadPool(threadPoolSize, maxThreadPoolSize, maxThreadIdleTime)); }
From source file:com.mysoft.b2b.event.util.MysoftBoneCPDataSource.java
public Object getObjectInstance(Object object, Name name, Context context, Hashtable<?, ?> table) throws Exception { Reference ref = (Reference) object; Enumeration<RefAddr> addrs = ref.getAll(); Properties props = new Properties(); while (addrs.hasMoreElements()) { RefAddr addr = addrs.nextElement(); if (addr.getType().equals("driverClassName")) { Class.forName((String) addr.getContent()); } else {/*from w w w . j a v a 2 s . c om*/ props.put(addr.getType(), addr.getContent()); } } BoneCPConfig config = new BoneCPConfig(props); return new BoneCPDataSource(config); }
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 w w . j ava 2 s .com*/ * * @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:NonSerializableFactory.java
/** Transform the obj Reference bound into the JNDI namespace into the actual non-Serializable object./*from w w w . j av a2 s. co m*/ @param obj the object bound in the JNDI namespace. This must be an implementation of javax.naming.Reference with a javax.naming.RefAddr of type "nns" whose content is the String key used to location the non-Serializable object in the NonSerializableFactory map. @param name ignored. @param nameCtx ignored. @param env ignored. @return the non-Serializable object associated with the obj Reference if one exists, null if one does not. */ public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable env) throws Exception { // Get the nns value from the Reference obj and use it as the map key Reference ref = (Reference) obj; RefAddr addr = ref.get("nns"); String key = (String) addr.getContent(); Object target = wrapperMap.get(key); return target; }
From source file:com.frameworkset.commons.dbcp2.BasicDataSourceFactory.java
/** * Collects warnings and info messages. Warnings are generated when an obsolete * property is set. Unknown properties generate info messages. * * @param ref Reference to check properties of * @param name Name provided to getObject * @param warnings container for warning messages * @param infoMessages container for info messages *//* w w w .j a v a 2s . c o m*/ private void validatePropertyNames(Reference ref, Name name, List<String> warnings, List<String> infoMessages) { final List<String> allPropsAsList = Arrays.asList(ALL_PROPERTIES); final String nameString = name != null ? "Name = " + name.toString() + " " : ""; if (NUPROP_WARNTEXT != null && !NUPROP_WARNTEXT.keySet().isEmpty()) { for (String propertyName : NUPROP_WARNTEXT.keySet()) { final RefAddr ra = ref.get(propertyName); if (ra != null && !allPropsAsList.contains(ra.getType())) { final StringBuilder stringBuilder = new StringBuilder(nameString); final String propertyValue = ra.getContent().toString(); stringBuilder.append(NUPROP_WARNTEXT.get(propertyName)).append(" You have set value of \"") .append(propertyValue).append("\" for \"").append(propertyName) .append("\" property, which is being ignored."); warnings.add(stringBuilder.toString()); } } } final Enumeration<RefAddr> allRefAddrs = ref.getAll(); while (allRefAddrs.hasMoreElements()) { final RefAddr ra = allRefAddrs.nextElement(); final String propertyName = ra.getType(); // If property name is not in the properties list, we haven't warned on it // and it is not in the "silent" list, tell user we are ignoring it. if (!(allPropsAsList.contains(propertyName) || NUPROP_WARNTEXT.keySet().contains(propertyName) || SILENT_PROPERTIES.contains(propertyName))) { final String propertyValue = ra.getContent().toString(); final StringBuilder stringBuilder = new StringBuilder(nameString); stringBuilder.append("Ignoring unknown property: ").append("value of \"").append(propertyValue) .append("\" for \"").append(propertyName).append("\" property"); infoMessages.add(stringBuilder.toString()); } } }
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; }//from www .ja va2s.c om 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; }/*from ww w .j a va 2 s.c om*/ 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.exoplatform.services.jcr.impl.jndi.BindableRepositoryFactory.java
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception { if (obj instanceof Reference) { Reference ref = (Reference) obj; synchronized (cache) { if (cache.containsKey(ref)) { return cache.get(ref); }/* w w w. j a v a2s .com*/ RefAddr containerConfig = ref.get(CONTAINERCONFIG_ADDRTYPE); String repositoryName = (String) ref.get(REPOSITORYNAME_ADDRTYPE).getContent(); ExoContainer container = ExoContainerContext.getCurrentContainerIfPresent(); if (containerConfig != null) { // here the code will work properly only when no StandaloneContainer instance created yet if (container == null) { StandaloneContainer.setConfigurationURL((String) containerConfig.getContent()); container = StandaloneContainer.getInstance(); } } ManageableRepository rep = ((RepositoryService) container .getComponentInstanceOfType(RepositoryService.class)).getRepository(repositoryName); // BindableRepositoryImpl brep = new BindableRepositoryImpl(rep); cache.put(ref, rep); return rep; } } return null; }