| java.lang.Object biz.hammurapi.config.DomConfigFactory
DomConfigFactory | public class DomConfigFactory (Code) | | Creates and configures objects from DOM
org.w3c.dom.Element (XML file).
DOM Element can be read from InputStream, File or URL.
Instantiation and configuration happens as follows:
Instantiation
- If there is no
'type' attribute then type defaults to
java.lang.String and text of the element will be returned.
E.g. <name>Pavel</name> will yield string 'Pavel'. 'type'
attribute name can be changed through
biz.hammurapi.config.DomConfigInfo.setCodeExpression(String) method. Create
biz.hammurapi.config.DomConfigInfo , change code expression and then
use
DomConfigFactory.DomConfigFactory(DomConfigInfo) to instantiate DomConfigFactory.
- Otherwise class specified in
'type' attribute will be loaded and
verified by classAcceptor (if any)
- If there is no nested
'constructor' ' element and element text is blank then default
constructor will be used
- If there is no nested
'constructor' ' element and element text is not blank then constructor which takes a single argument of type
java.lang.String will be used
- If there is nested
'constructor' element then 'arg' elements of
'constructor' element are iterated to create a list of arguments.
Arguments are constructed in the same way as described here. 'arg' element
also supports 'context-ref' attribute. If this attribute is set argument
value will be taken from context entry set by
DomConfigFactory.setContextEntry(StringObject) method
Configuration
Examples
<name>Pavel</name> will yield java.lang.String with value 'Pavel'
<age type="java.lang.Integer">33</age> will yield java.lang.Integer with value '33'
<config type="org.myself.myproject.MyConfig" url="http://myproject.myself.org/MyConfig.xml"/> will load
configuration from URL and configure MyConfig object
<config type="org.myself.myproject.MyParameterizableConfig">
<parameter name="pi" type="java.lang.Double">3.14159</parameter>
</config> will create MyParameterizableConfig object and then invoke its setParameter() method if MyParameterizableConfig
implements
biz.hammurapi.config.Parameterizable or invoke setPi() method if there is such method. In lenient mode
nothing will happen if there is no setPi() method. Otherwise exception will be thrown.
<config type="org.myself.myproject.MyParameterizableConfig">
<pi type="java.lang.Double">3.14159</pi>
</config> same as above.
author: Pavel Vlasov version: $Revision: 1.12 $ |
Method Summary | |
public Object | create(Node node) Creates object. | public Object | create(File file, String xPath) Parses file and returns object. | public Object | create(File file, String xPath, ClassAcceptor classAcceptor, ObjectAcceptor objectAcceptor) Parses file and returns object
Parameters: file - XML configuration file Parameters: xPath - XPath expression, can be null Parameters: classAcceptor - Class acceptor, validates that class about to be instantiated is 'the right one' Parameters: objectAcceptor - Object acceptor, validates instantiated object. | public Object | create(InputStream in, String xPath) | public Object | create(InputStream in, String xPath, ClassAcceptor classAcceptor, ObjectAcceptor objectAcceptor) | public Object | create(Reader in, String xPath) | public Object | create(Reader in, String xPath, ClassAcceptor classAcceptor, ObjectAcceptor objectAcceptor) | public Object | create(URL url, String xPath) | public Object | create(URL url, String xPath, ClassAcceptor classAcceptor, ObjectAcceptor objectAcceptor) | public Object | create(Node node, ClassAcceptor classAcceptor, ObjectAcceptor objectAcceptor) | protected Object | create(Node node, ClassAcceptor classAcceptor, ObjectAcceptor objectAcceptor, CachedXPathAPI cxpa) Creates and configures object
Parameters: node - Parameters: classAcceptor - Parameters: objectAcceptor - Parameters: cxpa - Cached XPath API to accelerate XPath expressions evaluation. | public static void | inject(Object instance, Context context) | public static void | main(String[] args) |
CODE_EXPRESSION | final public static String CODE_EXPRESSION(Code) | | |
MAP_KEY_EXPRESSION | final public static String MAP_KEY_EXPRESSION(Code) | | |
MAP_VALUE_EXPRESSION | final public static String MAP_VALUE_EXPRESSION(Code) | | |
PRIMITIVES | final public static Map PRIMITIVES(Code) | | |
DomConfigFactory | public DomConfigFactory()(Code) | | Default constructor
|
DomConfigFactory | public DomConfigFactory(Context context)(Code) | | Default constructor
|
create | public Object create(File file, String xPath) throws ConfigurationException, IOException(Code) | | Parses file and returns object. Same as create(file, xPath, null, null)
Parameters: file - XML configuration file Parameters: xPath - XPath expression, can be null configured object |
create | public Object create(File file, String xPath, ClassAcceptor classAcceptor, ObjectAcceptor objectAcceptor) throws ConfigurationException, IOException(Code) | | Parses file and returns object
Parameters: file - XML configuration file Parameters: xPath - XPath expression, can be null Parameters: classAcceptor - Class acceptor, validates that class about to be instantiated is 'the right one' Parameters: objectAcceptor - Object acceptor, validates instantiated object. Configured object |
inject | public static void inject(Object instance, Context context) throws ConfigurationException(Code) | | Sets property (field or through setter) using reflection
Parameters: instance - Parameters: lenient - If false then inject throws ConfigurationException if property does not exists Parameters: string - Parameters: object - |
|
|