Class GenericNamingResourcesFactory

  • All Implemented Interfaces:
    javax.naming.spi.ObjectFactory

    public class GenericNamingResourcesFactory
    extends java.lang.Object
    implements javax.naming.spi.ObjectFactory
    Simple 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-managed ResourceRef that 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, description and forceString) 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, char and boolean - each in its primitive and boxed form - and java.net.InetAddress. Booleans accept only true or false, ignoring case and surrounding whitespace - not the anything-but-true-is-false coercion of org.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 no setFoo setter exists at all, a two-argument setProperty(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 a false answer 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.

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String capitalize​(java.lang.String name)
      Capitalizes the first character of the given string.
      java.lang.Object getObjectInstance​(java.lang.Object obj, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable<?,​?> environment)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GenericNamingResourcesFactory

        public GenericNamingResourcesFactory()
        Default constructor.
    • 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:
        getObjectInstance in interface javax.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