Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.cayenne.xml
Class XMLEncoder

    java.lang.Object
      org.apache.cayenne.xml.XMLEncoder

    public class XMLEncoder

extends Object

A helper class to encode objects to XML.

Since:
  1.2

Constructor Summary
`XMLEncoder()` Creates new XMLEncoder.
`XMLEncoder(String mappingUrl)` Creates new XMLEncoder that will use a mapping descriptor loaded via provided URL.

Method Summary
`String` | `encode(Object object)` Encodes an object using "root" as a root tag.
`String` | `encode(String rootTag, Object object)` Encodes using provided root XML tag.
`protected void` | `encodeCollection(String xmlTag, Collection<Object> c, boolean useType)` Encodes a collection of objects, attaching them to the current root.
`void` | `encodeProperty(String xmlTag, Object value)` A callback method for XMLSerializable objects to encode an object property.
`protected void` | `encodeProperty(String xmlTag, Object value, boolean useType)`
`protected void` | `encodeSerializable(String xmlTag, XMLSerializable object)`
`protected void` | `encodeSimple(String xmlTag, Object object, boolean useType)`
`protected Node` | `getRootNode(boolean forceSyntheticRoot)` Returns a root DOM node of the encoder.
`protected void` | `initDocument(String rootTag, String type)` Resets the encoder to process a new object tree.
`protected String` | `nodeToString(Node rootNode)`
`void` | `setRoot(String xmlTag, String type)` A callback for XMLSerializable objects to add a node to an encoding tree.
`protected void` | `setRoot(String xmlTag, String type, boolean push)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### XMLEncoder

    public XMLEncoder()

  Creates new XMLEncoder.

### XMLEncoder

    public XMLEncoder(String mappingUrl)

  Creates new XMLEncoder that will use a mapping descriptor loaded via provided URL.

Method Detail

### setRoot

    public void setRoot(String xmlTag,
                        String type)

  A callback for XMLSerializable objects to add a node to an encoding tree.

### encodeProperty

    public void encodeProperty(String xmlTag,
                               Object value)

  A callback method for XMLSerializable objects to encode an object property. Note that the object must call "setRoot" prior to encoding its properties.

  Parameters:
    `xmlTag` - The name of the XML element used to represent the property.
    `value` - The object's property value to encode.

### encode

    public String encode(Object object)
                  throws CayenneRuntimeException

  Encodes an object using "root" as a root tag.

  Throws:
    `CayenneRuntimeException`

### encode

    public String encode(String rootTag,
                         Object object)
                  throws CayenneRuntimeException

  Encodes using provided root XML tag.

  Throws:
    `CayenneRuntimeException`

### initDocument

    protected void initDocument(String rootTag,
                                String type)

  Resets the encoder to process a new object tree.

### getRootNode

    protected Node getRootNode(boolean forceSyntheticRoot)

  Returns a root DOM node of the encoder.

### nodeToString

    protected String nodeToString(Node rootNode)

### setRoot

    protected void setRoot(String xmlTag,
                           String type,
                           boolean push)

### encodeProperty

    protected void encodeProperty(String xmlTag,
                                  Object value,
                                  boolean useType)

### encodeSimple

    protected void encodeSimple(String xmlTag,
                                Object object,
                                boolean useType)

### encodeSerializable

    protected void encodeSerializable(String xmlTag,
                                      XMLSerializable object)

### encodeCollection

    protected void encodeCollection(String xmlTag,
                                    Collection<Object> c,
                                    boolean useType)

  Encodes a collection of objects, attaching them to the current root.

  Parameters:
    `xmlTag` - The name of the root XML element for the encoded collection.
    `c` - The collection to encode.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2010 Apache Cayenne. All Rights Reserved.