|
Oracle Fusion Middleware Java API Reference for Oracle PDK Java 11g Release 1 (11.1.1) E10691-01 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object oracle.portal.utils.xml.v2.DefaultNodeHandler
public class DefaultNodeHandler
A DefaultNodeHandler
is capable of translating an XML DOM
object tree into an analogous hierarchy of application objects, whose
classes, attributes and associations all reflect the configuration of the
nodes in the XML tree. The class therefore provides an extensible mechanism
for configuring a potentially complex system of Java objects through an XML
document.
The main entry point is the processNode(Node,Object)
method, which
recursively processes the nodes in the XML document and builds up a
corresponding tree of application objects. Each call to the method processes
all the children of a given XML node in the context of a particular
application object represented by that node. For each of the given node's
child nodes in turn, the method proceeds as follows:
getApplicationObjectForElement(Element)
method, which returns a new
instance of an appropriate application object class. Given this new object,
processNode
records a parent-child association between the
context application object and the new object. Finally, a recursive call to
<processNode> is made in order to process the child node in the context of
the new application object. However, this call may actually be redirected to
the processNode
method of a different NodeHandler
object, depending on the value the overridable getHandlerForElement(Element)
method returns for the complex element. This
mechanism is designed to allow the 'delegation' of the processing of certain
complex elements to customized NodeHandler
s.handleSimpleElement(Element,Object)
method is used to set a corresponding
property on the context application object to the 'value' of the simple
element (derived from the String value of the element's first text node
child).class
attribute,
containing the fully qualified name of the corresponding application
object class.InitializableXMLObject
interface. Initialization to be
performed when the object is first created, perhaps relating the new
object to its parent, should be placed in a
preInitialize(Object)
method, and any extra initialization
and validation to be performed once the object's own children have been
initialized should be placed in a postInitialize()
method.NodeHandler
other
than the current one, then it should have a handler
attribute, containing the fully qualified name of a class implementing
NodeHandler
.complex1
and complex2
are complex elements.
complex1
describes an object of class
oracle.portal.ApplicationClass
, while complex2
describes an object of class my.custom.ApplicationClass
.complex1
has no handler
attribute, so will
be processed by the same NodeHandler
that processed its
parent (the root document element). complex2
specifies
my.custom.HandlerClass
in its handler
attribute,
so its processing will be delegated to a NodeHandler
object
of the specified class.simple1
and simple2
are simple elements.
simple1
controls a single property in the
oracle.portal.ApplicationClass
object, while
simple2
controls a collection of values in the same object. A
corresponding method of oracle.portal.ApplicationClass
,
setSimple1(String)
might set a single member variable to the
given string value, while another method addSimple2(String)
might add the given value to list of values held within the object.
<complex1 class="oracle.portal.ApplicationClass">
<simple1>value</simple1>
<simple2>value1</item>
<simple2>value2</item>
<simple2>value3</item>
<complex2 class="my.custom.ApplicationClass" handler="my.custom.HandlerClass"/>
</complex1>
Constructor Summary | |
---|---|
DefaultNodeHandler()
Constructs a DefaultNodeHandler which uses the
ClassLoader that loaded its own class. |
|
DefaultNodeHandler(java.lang.ClassLoader classLoader)
Constructs a DefaultNodeHandler which uses the given
ClassLoader . |
Method Summary | |
---|---|
java.lang.Object |
getApplicationObjectForElement(org.w3c.dom.Element e)
For a given 'complex' element, returns an instance of the type of object it represents. |
NodeHandler |
getHandlerForElement(org.w3c.dom.Element e)
For a given 'complex' element, returns the NodeHandler that
should be used to process it. |
void |
handleSimpleElement(org.w3c.dom.Element e,
java.lang.Object o)
For a given 'simple' element, and the current context application object, performs the steps necessary to set the value of a property of the application object corresponding to the simple element, to the value held by the element. |
void |
invokePostInitialize(java.lang.Object o)
Performs any extra steps required to initialize and validate an application object once its child application objects have been created. |
void |
invokePreInitialize(java.lang.Object o,
java.lang.Object parent)
Performs any steps required to initialize an application object after it has been created, perhaps relating the new object to its parent. |
void |
processNode(org.w3c.dom.Node n,
java.lang.Object o)
Recursively processes all the children of a given XML node in the context of an application object represented by that node, in order to populate the application object and create and populate other 'child' application objects. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DefaultNodeHandler(java.lang.ClassLoader classLoader)
DefaultNodeHandler
which uses the given
ClassLoader
.
classLoader
- the class loader to use when resolving class names.public DefaultNodeHandler()
DefaultNodeHandler
which uses the
ClassLoader
that loaded its own class. Note: if you have
pdkjava.jar in you global classpath, using this constructor means that
you will not be able to load classes specific to a particular web app.
Method Detail |
---|
public void processNode(org.w3c.dom.Node n, java.lang.Object o) throws NodeHandlerException
processNode
in interface NodeHandler
n
- current node whose children will be processed to populate the
context application object.o
- the context application object.
NodeHandlerException
- if unable to instantiate a child object
or handler object, find a method corresponding to a simple element, or
an exception occurs while calling a method on a child object.public java.lang.Object getApplicationObjectForElement(org.w3c.dom.Element e) throws NodeHandlerException
class
attribute, if it has one. Users should override if
the type of object corresponding to a particular complex element can be
determined in a different way.
e
- the 'complex' element for which a corresponing object is to be
created
null
if no corresponding class can be determined for the
element
NodeHandlerException
- if an error occurs while trying to
create an appropriate object.public NodeHandler getHandlerForElement(org.w3c.dom.Element e) throws NodeHandlerException
NodeHandler
that
should be used to process it. In this default implementation, the method
simply returns an instance of the class named in the element's
handler
attribute, if it has one, or the current
DefaultNodeHandler
otherwise. Users should override if the
handler for a particular complex element can be determined in a
different way.
e
- the 'complex' element whose handler is to be determined
NodeHandlerException
- if an error occurs while trying to
create an appropriate handler object.public void handleSimpleElement(org.w3c.dom.Element e, java.lang.Object o) throws NodeHandlerException
e
- a 'simple' element corresponding to a property of the
application objecto
- the application object on which the property is to be set
NodeHandlerException
- if an error occurs while trying to
locate and set the property on the application objectpublic void invokePreInitialize(java.lang.Object o, java.lang.Object parent) throws NodeHandlerException
preInitialize
method with the parent object as an argument,
if it implements InitializableXMLObject
. Users should override
if there are further actions to be performed on their application
objects.
o
- the application object to be initializedparent
- the application object that will become this object's parent
NodeHandlerException
- if an error occurs while initializing
the application objectpublic void invokePostInitialize(java.lang.Object o) throws NodeHandlerException
postInitialize
method, if it implements InitializableXMLObject
. Users should override if there are further
post-initialization steps to be performed on their application objects.
o
- the application object to be initialized
NodeHandlerException
- if an error occurs while initializing or
validating the application object
|
Oracle Fusion Middleware Java API Reference for Oracle PDK Java 11g Release 1 (11.1.1) E10691-01 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |