Class GenericNamingResourcesFactory

java.lang.Object
org.apache.tomcat.jdbc.naming.GenericNamingResourcesFactory
All Implemented Interfaces:
ObjectFactory

public class GenericNamingResourcesFactory extends Object implements 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.

  • Constructor Details

    • GenericNamingResourcesFactory

      public GenericNamingResourcesFactory()
      Default constructor.
  • Method Details