List of usage examples for javax.naming RefAddr getType
public String getType()
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 w w .jav 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."); }/*from w ww.j av a 2 s . c om*/ 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 ww w.ja 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
/** * 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 *//*www . j a va 2 s.c om*/ 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; }/*w ww . ja va 2 s . co 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; }// w w w.j a v a 2s.com 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.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; }//ww w . j a va 2 s. co m 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.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; }//from w ww . j a v a2s . c om 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); }
From source file:org.nuxeo.runtime.jtajca.NuxeoConnectionManagerFactory.java
public static NuxeoConnectionManagerConfiguration getConfig(Reference ref) { NuxeoConnectionManagerConfiguration config = new NuxeoConnectionManagerConfiguration(); IllegalArgumentException errors = new IllegalArgumentException("wrong naming config"); for (RefAddr addr : Collections.list(ref.getAll())) { String name = addr.getType(); String value = (String) addr.getContent(); try {/* w ww . j a v a 2 s . c o m*/ BeanUtils.setProperty(config, name, value); } catch (ReflectiveOperationException cause) { errors.addSuppressed(cause); } } if (errors.getSuppressed().length > 0) { throw errors; } return config; }
From source file:org.nuxeo.runtime.jtajca.NuxeoTransactionManagerFactory.java
@Override public Object getObjectInstance(Object obj, Name objName, Context nameCtx, Hashtable<?, ?> env) { Reference ref = (Reference) obj; if (!TransactionManager.class.getName().equals(ref.getClassName())) { return null; }/*from w w w. jav a 2 s . c o m*/ if (NuxeoContainer.tm != null) { return NuxeoContainer.tm; } // 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 (ReflectiveOperationException e) { log.error(String.format("NuxeoTransactionManagerFactory cannot set %s = %s", name, value)); } } return NuxeoContainer.initTransactionManager(config); }