public static Properties getProperties(Reference reference) { Properties properties = new Properties(); for (Enumeration iter = reference.getAll(); iter.hasMoreElements();) { StringRefAddr addr = (StringRefAddr)iter.nextElement(); properties.put(addr.getType(), (addr.getContent() == null) ? "" : addr.getContent()); } return properties; }
@Override synchronized 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> that specify a class name of "javax.sql.DataSource" if (obj instanceof Reference && "javax.sql.DataSource".equals(((Reference) obj).getClassName())) { Reference ref = (Reference) obj; Set<String> hikariPropSet = PropertyElf.getPropertyNames(HikariConfig.class); Properties properties = new Properties(); Enumeration<RefAddr> enumeration = ref.getAll(); while (enumeration.hasMoreElements()) { RefAddr element = enumeration.nextElement(); String type = element.getType(); if (type.startsWith("dataSource.") || hikariPropSet.contains(type)) { properties.setProperty(type, element.getContent().toString()); } } return createDataSource(properties, nameCtx); } return null; }
/** * Testing code. * @param args Command line arguments. * @throws NullPointerException * @throws MalformedObjectNameException * @throws NamingException * @throws InvalidNameException */ public static void main(String[] args) throws MalformedObjectNameException, NullPointerException, InvalidNameException, NamingException { final ObjectName on = new ObjectName("org.archive.crawler:" + "type=Service,name=Heritrix00,host=debord.archive.org"); Context c = getSubContext(getCompoundName(on.getDomain())); CompoundName key = bindObjectName(c, on); Reference r = (Reference)c.lookup(key); for (Enumeration<RefAddr> e = r.getAll(); e.hasMoreElements();) { System.out.println(e.nextElement()); } unbindObjectName(c, on); } }
Enumeration<RefAddr> props = ((Reference) obj).getAll();
Enumeration<RefAddr> props = ((Reference) obj).getAll();
for (Enumeration iter = reference.getAll(); iter.hasMoreElements();) {
@Override public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { if ((obj == null) || !(obj instanceof Reference)) { return null; } Reference ref = (Reference) obj; Enumeration<RefAddr> refs = ref.getAll(); String type = ref.getClassName(); Object o = Class.forName(type).newInstance(); while (refs.hasMoreElements()) { RefAddr addr = refs.nextElement(); String param = addr.getType(); String value = null; if (addr.getContent()!=null) { value = addr.getContent().toString(); } if (setProperty(o, param, value,false)) { } else { log.debug("Property not configured["+param+"]. No setter found on["+o+"]."); } } return o; }
private Map<String, String> getConfigurationMap(Reference ref) { Map<String, String> configMap = new HashMap<String, String>(); if (ref != null) { Enumeration<RefAddr> addrs = ref.getAll(); while (addrs.hasMoreElements()) { RefAddr addr = (RefAddr) addrs.nextElement(); String type = addr.getType(); String value = (String) addr.getContent(); configMap.put(type, value); } } return configMap; }
public static Properties getProperties(Reference reference) { Properties properties = new Properties(); for (Enumeration iter = reference.getAll(); iter.hasMoreElements();) { StringRefAddr addr = (StringRefAddr)iter.nextElement(); properties.put(addr.getType(), (addr.getContent() == null) ? "" : addr.getContent()); } return properties; }
public static Properties getProperties(Reference reference) { Properties properties = new Properties(); for (Enumeration iter = reference.getAll(); iter.hasMoreElements();) { StringRefAddr addr = (StringRefAddr)iter.nextElement(); properties.put(addr.getType(), (addr.getContent() == null) ? "" : addr.getContent()); } return properties; }
public static Properties getProperties(Reference reference) { Properties properties = new Properties(); for (Enumeration iter = reference.getAll(); iter.hasMoreElements();) { StringRefAddr addr = (StringRefAddr)iter.nextElement(); properties.put(addr.getType(), (addr.getContent() == null) ? "" : addr.getContent()); } return properties; }
public static Properties getProperties(Reference reference) { Properties properties = new Properties(); for (Enumeration iter = reference.getAll(); iter.hasMoreElements();) { StringRefAddr addr = (StringRefAddr)iter.nextElement(); properties.put(addr.getType(), (addr.getContent() == null) ? "" : addr.getContent()); } return properties; }
private HashMap loadProps( Reference ref, String[] props ) { HashMap config = new HashMap(); HashMap values = new HashMap(); Enumeration c = ref.getAll(); while( c.hasMoreElements() ) { RefAddr ra = (RefAddr) c.nextElement(); values.put( ra.getType().toLowerCase(), ra.getContent() ); } for( int i = 0; i < props.length; i ++ ) { String value = (String) values.get( props[i].toLowerCase() ); value = value == null ? (String) values.get( Messages.get( props[i].toLowerCase() ) ) : value; if( value != null ) { config.put( props[i], value ); } } return config; }
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 { props.put(addr.getType(), addr.getContent()); } } BoneCPConfig config = new BoneCPConfig(props); return new BoneCPDataSource(config); }
@Override public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) { final Reference ref = (Reference) obj; if (!ref.getClassName().equals("javax.mail.Session")) return (null); final Properties properties = toProperties(ref.getAll()); return AccessController.doPrivileged((PrivilegedAction<Session>) () -> EmailHelper.newSession(properties)); }
/** * {@inheritDoc} * */ @Override public Object getObjectInstance(Object object, Name name, Context context, Hashtable<?, ?> table) throws Exception { final Reference ref = (Reference) object; final Enumeration<RefAddr> addrs = ref.getAll(); final Properties props = new Properties(); while (addrs.hasMoreElements()) { final RefAddr addr = addrs.nextElement(); if (addr.getType().equals("driverClassName")) { Class.forName((String) addr.getContent()); } else { props.put(addr.getType(), addr.getContent()); } } final BoneCPConfig config = new BoneCPConfig(props); return new BoneCPDataSource(config); }
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { if ((obj == null) || !(obj instanceof Reference)) { return null; } Reference ref = (Reference) obj; Enumeration<RefAddr> refs = ref.getAll(); String type = ref.getClassName(); Object o = Class.forName(type).newInstance(); while (refs.hasMoreElements()) { RefAddr addr = refs.nextElement(); String param = addr.getType(); String value = null; if (addr.getContent()!=null) { value = addr.getContent().toString(); } if (setProperty(o, param, value,false)) { } else { log.debug("Property not configured["+param+"]. No setter found on["+o+"]."); } } return o; }
@Override synchronized 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> that specify a class name of "javax.sql.DataSource" if (!(obj instanceof Reference)) { return null; } Reference ref = (Reference) obj; if (!"javax.sql.DataSource".equals(ref.getClassName())) { throw new NamingException(ref.getClassName() + " is not a valid class name/type for this JNDI factory."); } Set<String> hikariPropSet = PropertyElf.getPropertyNames(HikariConfig.class); Properties properties = new Properties(); Enumeration<RefAddr> enumeration = ref.getAll(); while (enumeration.hasMoreElements()) { RefAddr element = enumeration.nextElement(); String type = element.getType(); if (type.startsWith("dataSource.") || hikariPropSet.contains(type)) { properties.setProperty(type, element.getContent().toString()); } } return createDataSource(properties, nameCtx); }
public Object getObjectInstance(Object refObj, Name name, Context nameCtx, Hashtable env) throws Exception { if (refObj instanceof Reference) { Reference ref = (Reference) refObj; Map refAddrsMap = new HashMap(); for (Enumeration e = ref.getAll(); e.hasMoreElements(); ) { RefAddr addr = (RefAddr) e.nextElement(); refAddrsMap.put( addr.getType(), addr ); } Class beanClass = Class.forName( ref.getClassName() ); Set refProps = null; RefAddr refPropsRefAddr = (BinaryRefAddr) refAddrsMap.remove( JavaBeanReferenceMaker.REF_PROPS_KEY ); if ( refPropsRefAddr != null ) refProps = (Set) SerializableUtils.fromByteArray( (byte[]) refPropsRefAddr.getContent() ); Map propMap = createPropertyMap( beanClass, refAddrsMap ); return findBean( beanClass, propMap, refProps ); } else return null; }
public Object getObjectInstance(Object refObj, Name name, Context nameCtx, Hashtable env) throws Exception { if (refObj instanceof Reference) { Reference ref = (Reference) refObj; Map refAddrsMap = new HashMap(); for (Enumeration e = ref.getAll(); e.hasMoreElements(); ) { RefAddr addr = (RefAddr) e.nextElement(); refAddrsMap.put( addr.getType(), addr ); } Class beanClass = Class.forName( ref.getClassName() ); Set refProps = null; RefAddr refPropsRefAddr = (BinaryRefAddr) refAddrsMap.remove( JavaBeanReferenceMaker.REF_PROPS_KEY ); if ( refPropsRefAddr != null ) refProps = (Set) SerializableUtils.fromByteArray( (byte[]) refPropsRefAddr.getContent() ); Map propMap = createPropertyMap( beanClass, refAddrsMap ); return findBean( beanClass, propMap, refProps ); } else return null; }