Oracle Fusion Middleware
Java API Reference for Oracle PDK Java
11g Release 1 (11.1.1)
E10691-01

oracle.portal.utils.xml.v2
Class DefaultNodeHandler

java.lang.Object
  extended by oracle.portal.utils.xml.v2.DefaultNodeHandler
All Implemented Interfaces:
NodeHandler
Direct Known Subclasses:
LiteralXML.Handler

public class DefaultNodeHandler
extends java.lang.Object
implements NodeHandler

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:

In this default implementation, the following restrictions are placed on complex elements and the classes of the objects they describe: In the example XML below:
    <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

DefaultNodeHandler

public DefaultNodeHandler(java.lang.ClassLoader classLoader)
Constructs a DefaultNodeHandler which uses the given ClassLoader.

Parameters:
classLoader - the class loader to use when resolving class names.

DefaultNodeHandler

public DefaultNodeHandler()
Constructs a 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

processNode

public void processNode(org.w3c.dom.Node n,
                        java.lang.Object o)
                 throws NodeHandlerException
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.

Specified by:
processNode in interface NodeHandler
Parameters:
n - current node whose children will be processed to populate the context application object.
o - the context application object.
Throws:
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.

getApplicationObjectForElement

public java.lang.Object getApplicationObjectForElement(org.w3c.dom.Element e)
                                                throws NodeHandlerException
For a given 'complex' element, returns an instance of the type of object it represents. In this default implementation, the method simply attempts to create an instance of the class named in the element's 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.

Parameters:
e - the 'complex' element for which a corresponing object is to be created
Returns:
an object of the class corresponding to the element, or null if no corresponding class can be determined for the element
Throws:
NodeHandlerException - if an error occurs while trying to create an appropriate object.

getHandlerForElement

public NodeHandler getHandlerForElement(org.w3c.dom.Element e)
                                 throws NodeHandlerException
For a given 'complex' element, returns the 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.

Parameters:
e - the 'complex' element whose handler is to be determined
Returns:
a handler for the element
Throws:
NodeHandlerException - if an error occurs while trying to create an appropriate handler object.

handleSimpleElement

public void handleSimpleElement(org.w3c.dom.Element e,
                                java.lang.Object o)
                         throws NodeHandlerException
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. In this default implementation, the method looks for a method on the application object with a name prefixed by "set" or "add" and suffixed by the tag name of the simple element (with initial captital letter), taking a single String parameter. If such a method is found, it is called with the String value of the simple element's first child text node as an argument. Users should override if application object properties should be set in a different way.

Parameters:
e - a 'simple' element corresponding to a property of the application object
o - the application object on which the property is to be set
Throws:
NodeHandlerException - if an error occurs while trying to locate and set the property on the application object

invokePreInitialize

public void invokePreInitialize(java.lang.Object o,
                                java.lang.Object parent)
                         throws NodeHandlerException
Performs any steps required to initialize an application object after it has been created, perhaps relating the new object to its parent. In this default implementation, the method simply calls the object's 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.

Parameters:
o - the application object to be initialized
parent - the application object that will become this object's parent
Throws:
NodeHandlerException - if an error occurs while initializing the application object

invokePostInitialize

public void invokePostInitialize(java.lang.Object o)
                          throws NodeHandlerException
Performs any extra steps required to initialize and validate an application object once its child application objects have been created. In this default implementation, the method simply calls the object's postInitialize method, if it implements InitializableXMLObject. Users should override if there are further post-initialization steps to be performed on their application objects.

Parameters:
o - the application object to be initialized
Throws:
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

Copyright (c) 1999, 2009, Oracle and/or its affiliates. All rights reserved.