org.ow2.jonas.migration.jboss
Class Transformer

java.lang.Object
  extended by org.ow2.jonas.migration.jboss.Transformer
Direct Known Subclasses:
Migrate

public class Transformer
extends Object

The Transformer class contains methods for querying one or more input documents and building a new output document. Transformation tasks such as these can also be programmed in XSL and performed by an XSLT engine, however, for certain kinds of transformations it may be useful to perform them in Java by extending the Transformer class.

Author:
Rafael H. Schloming <rhs@mit.edu>

Nested Class Summary
protected static class Transformer.Mapper
           
protected static interface Transformer.NodeFilter
          Interface used to filter nodes when querying an input document.
 
Field Summary
protected static Transformer.NodeFilter ALL
          A predefined Transformer.NodeFilter that accepts all nodes.
protected static String LINE
          A predefined String containing the line seperator for this system.
 
Constructor Summary
protected Transformer()
          Constructs a new Transformer ready to output to an empty document.
 
Method Summary
protected  void close()
          Adds a text node with the appropriate amount of whitespace and restores the previous current node.
protected  void close(boolean indent)
          Restores the previous current node.
protected  void comment(String comment)
          Adds a comment to the current node.
protected  void get(Node node, String name, Collection result, Transformer.NodeFilter filter)
          Queries a node for child elements with a given name and filters the result based on a given Transformer.NodeFilter.
protected  Document getDocument()
          Returns the output document.
protected  boolean isEmpty(String str)
           
protected  Node node(Node node, String path)
          Queries a node for a single descedent element at a given path.
protected  List nodes(Node node, String path)
          Queries a node for all descendent elements at a given path.
protected  void open(String name)
          Creates a new child element of the current node with the given name and makes the new element the current node.
protected  void open(String name, boolean indent)
          Creates a new child element of the current node with the given name and makes the new element the current node.
protected  void query(Node node, String path, Collection result)
          Queries the given node for all elements at a given path.
protected  void query(Node node, String path, Collection result, Transformer.NodeFilter filter)
          Queries the given node for all elements at a given path and filters the result.
protected  void rename(Collection nodes, Map substitutions)
           
protected  void rename(Node node, Map substitutions)
           
protected  void set(String name, String value)
          Sets an attribute on the current element.
protected  Node singleton(Collection c)
           
protected  void tag(String name, String value)
          Creates an element with the given name that contains a single text node with the given value and adds it as a child to the current node.
protected  void text(String text)
          Adds the given text to the current node.
protected  String value(Node node, String path)
          Queries a node for a string value at a given path.
protected  List values(Node node, String path)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALL

protected static final Transformer.NodeFilter ALL
A predefined Transformer.NodeFilter that accepts all nodes.


LINE

protected static final String LINE
A predefined String containing the line seperator for this system.

Constructor Detail

Transformer

protected Transformer()
Constructs a new Transformer ready to output to an empty document.

Method Detail

getDocument

protected Document getDocument()
Returns the output document.

Returns:
the output document

open

protected void open(String name)
Creates a new child element of the current node with the given name and makes the new element the current node. A text node is added with an appropriate amount of indenting whitespace before the new element is added.

Parameters:
name - the name of the new element
See Also:
open(String, boolean)

open

protected void open(String name,
                    boolean indent)
Creates a new child element of the current node with the given name and makes the new element the current node. If indent is true then a text node with the appropriate amount of whitespace is added before the new element is created.

Parameters:
name - the name of the new node
indent - a flag indicating whether or not to indent

close

protected void close()
Adds a text node with the appropriate amount of whitespace and restores the previous current node.

See Also:
close(boolean)

close

protected void close(boolean indent)
Restores the previous current node. If indent is true an appropriate amount of indenting whitespace is added before restoring the previous current node.

Parameters:
indent - a flag indicating whether or not to indent

set

protected void set(String name,
                   String value)
Sets an attribute on the current element.

Parameters:
name - the attribute name
value - the attribute value
Throws:
IllegalStateException - if the current node is not an element

text

protected void text(String text)
Adds the given text to the current node.

Parameters:
text - the text to add

comment

protected void comment(String comment)
Adds a comment to the current node.

Parameters:
comment - the text of the comment

tag

protected void tag(String name,
                   String value)
Creates an element with the given name that contains a single text node with the given value and adds it as a child to the current node.

Parameters:
name - the name of the element
value - the value of the text node

get

protected void get(Node node,
                   String name,
                   Collection result,
                   Transformer.NodeFilter filter)
Queries a node for child elements with a given name and filters the result based on a given Transformer.NodeFilter.

Parameters:
node - the node to query
name - the name of the child elements to get
result - the collection to add the results to
filter - the result filter

query

protected void query(Node node,
                     String path,
                     Collection result)
Queries the given node for all elements at a given path.

Parameters:
node - the node to query
path - the path
result - the collection to add results to

query

protected void query(Node node,
                     String path,
                     Collection result,
                     Transformer.NodeFilter filter)
Queries the given node for all elements at a given path and filters the result.

Parameters:
node - the node to query
the - path
result - the collection to add results to
filter - the Transformer.NodeFilter used to filter the results

nodes

protected List nodes(Node node,
                     String path)
Queries a node for all descendent elements at a given path.

Parameters:
node - the node to query
path - the path
Returns:
the resulting list of nodes

node

protected Node node(Node node,
                    String path)
Queries a node for a single descedent element at a given path.

Parameters:
node - the node to query
path - the path
Returns:
the node or null if none is found
Throws:
IllegalStateException - if more than one node is found

value

protected String value(Node node,
                       String path)
Queries a node for a string value at a given path.

Parameters:
node - the node to query
path - the path
Returns:
the value or null if there is none
Throws:
IllegalStateException - if the node exists but has no value

values

protected List values(Node node,
                      String path)

singleton

protected Node singleton(Collection c)

isEmpty

protected boolean isEmpty(String str)

rename

protected void rename(Collection nodes,
                      Map substitutions)

rename

protected void rename(Node node,
                      Map substitutions)


Copyright © 2010 OW2 Consortium. All Rights Reserved.