Class GenericNamingResourcesFactory
- java.lang.Object
-
- org.apache.tomcat.jdbc.naming.GenericNamingResourcesFactory
-
- All Implemented Interfaces:
javax.naming.spi.ObjectFactory
public class GenericNamingResourcesFactory extends java.lang.Object implements javax.naming.spi.ObjectFactorySimple way of configuring generic resources by using reflection. Example usage:<Resource factory="org.apache.tomcat.jdbc.naming.GenericNamingResourcesFactory" name="jdbc/test" type="org.apache.derby.jdbc.ClientXADataSource" databaseName="sample" createDatabase="create" serverName="localhost" port="1527"/>The factory accepts any
Reference, not only the container-managedResourceRefthat a<Resource>element produces. The referenced class is loaded with the factory's own class loader first and the thread context class loader second, and a new instance built by its public no-argument constructor is created for every lookup. Reference metadata the container attaches (factory,singleton,scope,auth,descriptionandforceString) is skipped; every other address is treated as a bean property.A property is applied through a
setFoo(String)setter when one exists, otherwise through a single-argument setter whose parameter type the configured value can be built from:int,long,short,byte,float,double,charandboolean- each in its primitive and boxed form - andjava.net.InetAddress. Booleans accept onlytrueorfalse, ignoring case and surrounding whitespace - not the anything-but-true-is-falsecoercion oforg.apache.naming.factory.BeanFactory- and an address carrying no content is applied to nothing: missing content is not a configured value and, like any other property that cannot be applied, it fails the lookup. When nosetFoosetter exists at all, a two-argumentsetProperty(name, value)property bag is consulted; when one exists but its type cannot be built from the configured value, the bag is not consulted - what the bean's own setter rejects must not be silently absorbed there. If the bean has both a boolean-returning and a void-returning bag, the boolean one is tried first and afalseanswer means the property was not applied; the void bag is not consulted in that case.A property that cannot be applied - no usable setter, a value the setter type cannot be built from, or a setter that throws - fails the lookup with a
NamingException, so a partially configured resource never reaches a caller and, in particular, is never cached by the container for a singleton resource.
-
-
Constructor Summary
Constructors Constructor Description GenericNamingResourcesFactory()Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.Stringcapitalize(java.lang.String name)Capitalizes the first character of the given string.java.lang.ObjectgetObjectInstance(java.lang.Object obj, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable<?,?> environment)
-
-
-
Method Detail
-
getObjectInstance
public java.lang.Object getObjectInstance(java.lang.Object obj, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable<?,?> environment) throws java.lang.Exception- Specified by:
getObjectInstancein interfacejavax.naming.spi.ObjectFactory- Throws:
java.lang.Exception
-
capitalize
public static java.lang.String capitalize(java.lang.String name)
Capitalizes the first character of the given string.- Parameters:
name- The string to capitalize- Returns:
- The capitalized string, or the original if null or empty
-
-