com.arsdigita.domain
Class DomainObjectXMLRenderer

java.lang.Object
  extended bycom.arsdigita.domain.DomainObjectTraversal
      extended bycom.arsdigita.domain.DomainObjectXMLRenderer
Direct Known Subclasses:
FormBuilderXMLRenderer

public class DomainObjectXMLRenderer
extends DomainObjectTraversal

An implementation of DomainObjectTraversal that generates an XML tree representing the DomainObject. The output format of the XML can be controlled using the various setWrapXXX methods detailed below.

Version:
$Id: //core-platform/dev/src/com/arsdigita/domain/DomainObjectXMLRenderer.java#10 $

Nested Class Summary
 
Nested classes inherited from class com.arsdigita.domain.DomainObjectTraversal
DomainObjectTraversal.AdapterKey
 
Field Summary
 
Fields inherited from class com.arsdigita.domain.DomainObjectTraversal
LINK_NAME
 
Constructor Summary
DomainObjectXMLRenderer(Element root)
          Creates a new DomainObject XML renderer that outputs XML into the element passed into the constructor.
 
Method Summary
protected  void beginAssociation(DomainObject obj, String path, Property property)
          Method called when the processing of an association starts
protected  void beginObject(DomainObject obj, String path)
          Method called when the processing of an object starts
protected  void beginRole(DomainObject obj, String path, Property property)
          Method called when the processing of a role starts
protected  void endAssociation(DomainObject obj, String path, Property property)
          Method called when the procesing of an association completes
protected  void endObject(DomainObject obj, String path)
          Method called when the procesing of an object completes
protected  void endRole(DomainObject obj, String path, Property property)
          Method called when the procesing of a role completes
static DomainObjectXMLFormatter findFormatter(ObjectType type, String context)
          Retrieves the closest matching traversal formatter for an object type in a given context.
protected  String format(DomainObject obj, String path, Property prop, Object value)
           
protected  Element getCurrentElement()
           
static DomainObjectXMLFormatter getFormatter(ObjectType type, String context)
          Retrieves the traversal formatter for an object type in a given context.
protected  void handleAttribute(DomainObject obj, String path, Property property)
          Method called when an attribute is encountered
 boolean isWrappingAttributes()
           
 boolean isWrappingObjects()
           
 boolean isWrappingRoot()
           
protected  Element newElement(Element parent, String name)
           
protected  Element newElement(Element parent, String name, Element copy)
           
static void registerFormatter(ObjectType type, DomainObjectXMLFormatter formatter, String context)
          Registers a traversal formatter for an object type in a given context.
static void registerFormatter(String type, DomainObjectXMLFormatter formatter, String context)
          Registers a traversal formatter for an object type in a given context.
protected  void revisitObject(DomainObject obj, String path)
          Method called when a previously visited object is encountered for a second time.
 void setNamespace(String prefix, String uri)
           
 void setRevisitFullObject(boolean value)
          Determines XML output used for objects.
 void setWrapAttributes(boolean value)
          Determines XML output used for scalar attributes.
 void setWrapObjects(boolean value)
          Determines XML output used for objects.
 void setWrapRoot(boolean value)
          Determines XML output for root object.
static void unregisterFormatter(ObjectType type, String context)
          Unregisteres a traversal formatter for an object type in a given context
static void unregisterFormatter(String type, String context)
          Unregisteres a traversal formatter for an object type in a given context
protected  void walk(DomainObject obj, String context, DomainObjectTraversalAdapter adapter)
           
 
Methods inherited from class com.arsdigita.domain.DomainObjectTraversal
appendToPath, beginLink, endLink, findAdapter, lookupAdapter, nameFromPath, parentFromPath, registerAdapter, registerAdapter, unregisterAdapter, unregisterAdapter, walk
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DomainObjectXMLRenderer

public DomainObjectXMLRenderer(Element root)
Creates a new DomainObject XML renderer that outputs XML into the element passed into the constructor.

Parameters:
root - the XML element in which to output children
Method Detail

registerFormatter

public static void registerFormatter(ObjectType type,
                                     DomainObjectXMLFormatter formatter,
                                     String context)
Registers a traversal formatter for an object type in a given context.

Parameters:
type - the object type whose items will be traversed
formatter - the formatter for controlling object traversal
context - the context in which the formatter should be used

unregisterFormatter

public static void unregisterFormatter(ObjectType type,
                                       String context)
Unregisteres a traversal formatter for an object type in a given context

Parameters:
type - the object type whose items will be traversed
context - the context in which the formatter should be used

registerFormatter

public static void registerFormatter(String type,
                                     DomainObjectXMLFormatter formatter,
                                     String context)
Registers a traversal formatter for an object type in a given context.

Parameters:
type - the object type whose items will be traversed
formatter - the formatter for controlling object traversal
context - the context in which the formatter should be used

unregisterFormatter

public static void unregisterFormatter(String type,
                                       String context)
Unregisteres a traversal formatter for an object type in a given context

Parameters:
type - the object type whose items will be traversed
context - the context in which the formatter should be used

getFormatter

public static DomainObjectXMLFormatter getFormatter(ObjectType type,
                                                    String context)
Retrieves the traversal formatter for an object type in a given context.

Parameters:
type - the object type to lookup
context - the formatter context

findFormatter

public static DomainObjectXMLFormatter findFormatter(ObjectType type,
                                                     String context)
Retrieves the closest matching traversal formatter for an object type in a given context. The algorithm looks for an exact match, then considers the supertype, and the supertype's supertype. If no match could be found at all, returns null

Parameters:
type - the object type to search for
context - the formatter context

setNamespace

public void setNamespace(String prefix,
                         String uri)

format

protected String format(DomainObject obj,
                        String path,
                        Property prop,
                        Object value)

walk

protected void walk(DomainObject obj,
                    String context,
                    DomainObjectTraversalAdapter adapter)
Overrides:
walk in class DomainObjectTraversal

setWrapRoot

public void setWrapRoot(boolean value)
Determines XML output for root object. If set to true a separate element will be output for the root object, if false, then the element passed into the constructor will be used.


setWrapObjects

public void setWrapObjects(boolean value)
Determines XML output used for objects. If set to true, then a wrapper XML element will be generated for the association, and then individual elements generated for each object. If false then no wrapper XML element will be produced.


setWrapAttributes

public void setWrapAttributes(boolean value)
Determines XML output used for scalar attributes. If set to true, then each attribute is output as a separate element, otherwise, attributes are output as simple attributes.


setRevisitFullObject

public void setRevisitFullObject(boolean value)
Determines XML output used for objects. If set to true, then repeated objects will generate full xml. If false then only the OID will be printed.


isWrappingAttributes

public boolean isWrappingAttributes()

isWrappingObjects

public boolean isWrappingObjects()

isWrappingRoot

public boolean isWrappingRoot()

beginObject

protected void beginObject(DomainObject obj,
                           String path)
Description copied from class: DomainObjectTraversal
Method called when the processing of an object starts

Specified by:
beginObject in class DomainObjectTraversal

endObject

protected void endObject(DomainObject obj,
                         String path)
Description copied from class: DomainObjectTraversal
Method called when the procesing of an object completes

Specified by:
endObject in class DomainObjectTraversal

revisitObject

protected void revisitObject(DomainObject obj,
                             String path)
Description copied from class: DomainObjectTraversal
Method called when a previously visited object is encountered for a second time.

Specified by:
revisitObject in class DomainObjectTraversal

handleAttribute

protected void handleAttribute(DomainObject obj,
                               String path,
                               Property property)
Description copied from class: DomainObjectTraversal
Method called when an attribute is encountered

Specified by:
handleAttribute in class DomainObjectTraversal

beginRole

protected void beginRole(DomainObject obj,
                         String path,
                         Property property)
Description copied from class: DomainObjectTraversal
Method called when the processing of a role starts

Specified by:
beginRole in class DomainObjectTraversal

endRole

protected void endRole(DomainObject obj,
                       String path,
                       Property property)
Description copied from class: DomainObjectTraversal
Method called when the procesing of a role completes

Specified by:
endRole in class DomainObjectTraversal

beginAssociation

protected void beginAssociation(DomainObject obj,
                                String path,
                                Property property)
Description copied from class: DomainObjectTraversal
Method called when the processing of an association starts

Specified by:
beginAssociation in class DomainObjectTraversal

endAssociation

protected void endAssociation(DomainObject obj,
                              String path,
                              Property property)
Description copied from class: DomainObjectTraversal
Method called when the procesing of an association completes

Specified by:
endAssociation in class DomainObjectTraversal

getCurrentElement

protected Element getCurrentElement()

newElement

protected Element newElement(Element parent,
                             String name)

newElement

protected Element newElement(Element parent,
                             String name,
                             Element copy)


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 21 2004:2337 UTC