Java Code Examples for javax.naming.Reference#getAll()
The following examples show how to use
javax.naming.Reference#getAll() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenericNamingResourcesFactory.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@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; }
Example 2
Source File: GenericNamingResourcesFactory.java From tomcatsrc with Apache License 2.0 | 6 votes |
@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; }
Example 3
Source File: ViburDBCPObjectFactory.java From vibur-dbcp with Apache License 2.0 | 6 votes |
@Override public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws ViburDBCPException { Reference reference = (Reference) obj; Enumeration<RefAddr> enumeration = reference.getAll(); Properties props = new Properties(); while (enumeration.hasMoreElements()) { RefAddr refAddr = enumeration.nextElement(); String pName = refAddr.getType(); String pValue = (String) refAddr.getContent(); props.setProperty(pName, pValue); } ViburDBCPDataSource dataSource = new ViburDBCPDataSource(props); dataSource.start(); return dataSource; }
Example 4
Source File: JtdsObjectFactory.java From jTDS with GNU Lesser General Public License v2.1 | 6 votes |
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] ); value = value == null && props[i] != JtdsDataSource.DESCRIPTION ? (String) values.get( Messages.get( props[i] ).toLowerCase() ) : value; if( value != null ) { config.put( props[i], value ); } } return config; }
Example 5
Source File: JNDIReferenceFactory.java From qpid-jms with Apache License 2.0 | 6 votes |
/** * This will be called by a JNDIprovider when a Reference is retrieved from * a JNDI store - and generates the original instance * * @param object * the Reference object * @param name * the JNDI name * @param nameCtx * the context * @param environment * the environment settings used by JNDI * * @return the instance built from the Reference object * * @throws Exception * if building the instance from Reference fails (usually class not found) */ @Override public Object getObjectInstance(Object object, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { Object result = null; if (object instanceof Reference) { Reference reference = (Reference) object; Class<?> theClass = loadClass(this, reference.getClassName()); if (JNDIStorable.class.isAssignableFrom(theClass)) { JNDIStorable store = (JNDIStorable) theClass.getDeclaredConstructor().newInstance(); Map<String, String> properties = new HashMap<String, String>(); for (Enumeration<RefAddr> iter = reference.getAll(); iter.hasMoreElements();) { StringRefAddr addr = (StringRefAddr) iter.nextElement(); properties.put(addr.getType(), (addr.getContent() == null) ? "" : addr.getContent().toString()); } store.setProperties(properties); result = store; } } else { throw new RuntimeException("Object " + object + " is not a reference"); } return result; }
Example 6
Source File: GenericNamingResourcesFactory.java From Tomcat8-Source-Read with MIT License | 5 votes |
@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 = ClassLoaderUtil.loadClass( type, GenericNamingResourcesFactory.class.getClassLoader(), Thread.currentThread().getContextClassLoader()).getConstructor().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)) { } else { log.debug("Property not configured["+param+"]. No setter found on["+o+"]."); } } return o; }
Example 7
Source File: ClientDataSourceFactory.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Set the Java bean properties for an object from its Reference. The * Reference contains a set of StringRefAddr values with the key being the * bean name and the value a String representation of the bean's value. This * code looks for setXXX() method where the set method corresponds to the * standard bean naming scheme and has a single parameter of type String, * int, boolean or short. */ private static void setBeanProperties(Object ds, Reference ref) throws Exception { for (Enumeration e = ref.getAll(); e.hasMoreElements();) { RefAddr attribute = (RefAddr) e.nextElement(); String propertyName = attribute.getType(); String value = (String) attribute.getContent(); String methodName = "set" + propertyName.substring(0, 1).toUpperCase( java.util.Locale.ENGLISH) + propertyName.substring(1); Method m; Object argValue; try { m = ds.getClass().getMethod(methodName, STRING_ARG); argValue = value; } catch (NoSuchMethodException nsme) { try { m = ds.getClass().getMethod(methodName, INT_ARG); argValue = Integer.valueOf(value); } catch (NoSuchMethodException nsme2) { try { m = ds.getClass().getMethod(methodName, BOOLEAN_ARG); argValue = Boolean.valueOf(value); } catch (NoSuchMethodException nsme3) { m = ds.getClass().getMethod(methodName, SHORT_ARG); argValue = Short.valueOf(value); } } } m.invoke(ds, new Object[] { argValue }); } }
Example 8
Source File: ClientDataSourceFactory.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Set the Java bean properties for an object from its Reference. The * Reference contains a set of StringRefAddr values with the key being the * bean name and the value a String representation of the bean's value. This * code looks for setXXX() method where the set method corresponds to the * standard bean naming scheme and has a single parameter of type String, * int, boolean or short. */ private static void setBeanProperties(Object ds, Reference ref) throws Exception { for (Enumeration e = ref.getAll(); e.hasMoreElements();) { RefAddr attribute = (RefAddr) e.nextElement(); String propertyName = attribute.getType(); String value = (String) attribute.getContent(); String methodName = "set" + propertyName.substring(0, 1).toUpperCase( java.util.Locale.ENGLISH) + propertyName.substring(1); Method m; Object argValue; try { m = ds.getClass().getMethod(methodName, STRING_ARG); argValue = value; } catch (NoSuchMethodException nsme) { try { m = ds.getClass().getMethod(methodName, INT_ARG); argValue = Integer.valueOf(value); } catch (NoSuchMethodException nsme2) { try { m = ds.getClass().getMethod(methodName, BOOLEAN_ARG); argValue = Boolean.valueOf(value); } catch (NoSuchMethodException nsme3) { m = ds.getClass().getMethod(methodName, SHORT_ARG); argValue = Short.valueOf(value); } } } m.invoke(ds, new Object[] { argValue }); } }
Example 9
Source File: JNDIReferenceFactory.java From activemq-artemis with Apache License 2.0 | 5 votes |
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; }
Example 10
Source File: ClientDataSourceFactory.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
/** * Set the Java bean properties for an object from its Reference. The * Reference contains a set of StringRefAddr values with the key being the * bean name and the value a String representation of the bean's value. This * code looks for setXXX() method where the set method corresponds to the * standard bean naming scheme and has a single parameter of type String, * int, boolean or short. */ private static void setBeanProperties(Object ds, Reference ref) throws Exception { for (Enumeration e = ref.getAll(); e.hasMoreElements();) { RefAddr attribute = (RefAddr) e.nextElement(); String propertyName = attribute.getType(); String value = (String) attribute.getContent(); String methodName = "set" + propertyName.substring(0, 1).toUpperCase( java.util.Locale.ENGLISH) + propertyName.substring(1); Method m; Object argValue; try { m = ds.getClass().getMethod(methodName, STRING_ARG); argValue = value; } catch (NoSuchMethodException nsme) { try { m = ds.getClass().getMethod(methodName, INT_ARG); argValue = Integer.valueOf(value); } catch (NoSuchMethodException nsme2) { try { m = ds.getClass().getMethod(methodName, BOOLEAN_ARG); argValue = Boolean.valueOf(value); } catch (NoSuchMethodException nsme3) { m = ds.getClass().getMethod(methodName, SHORT_ARG); argValue = Short.valueOf(value); } } } m.invoke(ds, new Object[] { argValue }); } }
Example 11
Source File: DecryptingDataSourceFactory.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private int find( final String addrType, final Reference ref ) { final Enumeration enu = ref.getAll(); for ( int i = 0; enu.hasMoreElements(); i++ ) { final RefAddr addr = (RefAddr) enu.nextElement(); if ( addr.getType().compareTo( addrType ) == 0 ) { return i; } } throw new IllegalArgumentException( "The '" + addrType + "' name/value pair was not found in the Reference object. The reference Object is" + " " + ref.toString() ); }
Example 12
Source File: ReferenceableDataSource.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** Re-Create Derby datasource given a reference. @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 nameCtx, or null if no name is specified. @param nameCtx The context relative to which the name parameter is specified, or null if name is relative to the default initial context. @param environment The possibly null environment that is used in creating the object. @return One of the Derby datasource object created; null if an object cannot be created. @exception Exception if this object factory encountered an exception while attempting to create an object, and no other object factories are to be tried. */ public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception { Reference ref = (Reference)obj; String classname = ref.getClassName(); Object ds = Class.forName(classname).newInstance(); for (Enumeration e = ref.getAll(); e.hasMoreElements(); ) { RefAddr attribute = (RefAddr) e.nextElement(); String propertyName = attribute.getType(); String value = (String) attribute.getContent(); String methodName = "set" + propertyName.substring(0,1).toUpperCase(java.util.Locale.ENGLISH) + propertyName.substring(1); Method m; Object argValue; try { m = ds.getClass().getMethod(methodName, STRING_ARG); argValue = value; } catch (NoSuchMethodException nsme) { try { m = ds.getClass().getMethod(methodName, INT_ARG); argValue = Integer.valueOf(value); } catch (NoSuchMethodException nsme2) { m = ds.getClass().getMethod(methodName, BOOLEAN_ARG); argValue = Boolean.valueOf(value); } } m.invoke(ds, new Object[] { argValue }); } return ds; }
Example 13
Source File: ReferenceableDataSource.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** Re-Create Derby datasource given a reference. @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 nameCtx, or null if no name is specified. @param nameCtx The context relative to which the name parameter is specified, or null if name is relative to the default initial context. @param environment The possibly null environment that is used in creating the object. @return One of the Derby datasource object created; null if an object cannot be created. @exception Exception if this object factory encountered an exception while attempting to create an object, and no other object factories are to be tried. */ public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception { Reference ref = (Reference)obj; String classname = ref.getClassName(); Object ds = Class.forName(classname).newInstance(); for (Enumeration e = ref.getAll(); e.hasMoreElements(); ) { RefAddr attribute = (RefAddr) e.nextElement(); String propertyName = attribute.getType(); String value = (String) attribute.getContent(); String methodName = "set" + propertyName.substring(0,1).toUpperCase(java.util.Locale.ENGLISH) + propertyName.substring(1); Method m; Object argValue; try { m = ds.getClass().getMethod(methodName, STRING_ARG); argValue = value; } catch (NoSuchMethodException nsme) { try { m = ds.getClass().getMethod(methodName, INT_ARG); argValue = Integer.valueOf(value); } catch (NoSuchMethodException nsme2) { m = ds.getClass().getMethod(methodName, BOOLEAN_ARG); argValue = Boolean.valueOf(value); } } m.invoke(ds, new Object[] { argValue }); } return ds; }
Example 14
Source File: ReferenceableDataSource.java From spliceengine with GNU Affero General Public License v3.0 | 4 votes |
/** Re-Create Derby datasource given a reference. @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 nameCtx, or null if no name is specified. @param nameCtx The context relative to which the name parameter is specified, or null if name is relative to the default initial context. @param environment The possibly null environment that is used in creating the object. @return One of the Derby datasource object created; null if an object cannot be created. @exception Exception if this object factory encountered an exception while attempting to create an object, and no other object factories are to be tried. */ public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception { Reference ref = (Reference)obj; String classname = ref.getClassName(); Object ds = Class.forName(classname).newInstance(); for (Enumeration e = ref.getAll(); e.hasMoreElements(); ) { RefAddr attribute = (RefAddr) e.nextElement(); String propertyName = attribute.getType(); String value = (String) attribute.getContent(); String methodName = "set" + propertyName.substring(0,1).toUpperCase(java.util.Locale.ENGLISH) + propertyName.substring(1); Method m; Object argValue; try { m = ds.getClass().getMethod(methodName, STRING_ARG); argValue = value; } catch (NoSuchMethodException nsme) { try { m = ds.getClass().getMethod(methodName, INT_ARG); argValue = Integer.valueOf(value); } catch (NoSuchMethodException nsme2) { m = ds.getClass().getMethod(methodName, BOOLEAN_ARG); argValue = Boolean.valueOf(value); } } m.invoke(ds, new Object[] { argValue }); } return ds; }