de.ispsoft.jaxme
Class JMAnyElement

java.lang.Object
  extended byde.ispsoft.jaxme.JMAnyElement
All Implemented Interfaces:
java.lang.Cloneable, JMNode, java.io.Serializable
Direct Known Subclasses:
JMJdbcElement

public class JMAnyElement
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable, JMNode

An implementation for an abstract element. This is used, for example, to implement the "any" type.

Author:
Jochen Wiedmann
See Also:
Serialized Form

Field Summary
protected static org.xml.sax.Attributes emptyAttributes
           
protected  java.lang.String localName
           
protected  java.lang.String namespaceURI
           
 
Constructor Summary
JMAnyElement()
          Creates a new JMAnyElement that needs to be intialized with setNamespaceURI() and setLocalName().
JMAnyElement(java.lang.String pNamespaceURI, java.lang.String pLocalName)
          Creates a new JMAnyElement with the given namespace URI and local name.
 
Method Summary
 void addChild(java.lang.Object pChild)
          Adds a single child to the list of childs.
protected  void childsToSAX(org.xml.sax.ContentHandler pContentHandler, NamespaceSupport pNamespaceSupport)
          Converts the elements childs into a stream of SAX events.
protected  void childToSAX(java.lang.String pNamespaceURI, java.lang.String pLocalName, java.lang.String pValue, org.xml.sax.ContentHandler pContentHandler, NamespaceSupport pNamespaceSupport)
          Converts a single, atomic element into a stream of SAX events.
 java.lang.Object clone()
          Returns a clone of this JMAnyElement.
static java.lang.String formatDate(java.util.Date pDate)
          Deprecated. Will be removed in JaxMe 2. Use a Marshaller and its property jaxme.format.datetime to achieve the same functionality.
 java.lang.String getAttribute(java.lang.String pNamespaceURI, java.lang.String pLocalName)
          Deprecated. Use getAttribute(String pNamespaceURI, String pLocalName, MarshallerImpl pMarshaller)
 java.lang.String getAttribute(java.lang.String pNamespaceURI, java.lang.String pLocalName, MarshallerImpl pMarshaller)
          Returns the value of a single attribute.
 org.xml.sax.helpers.AttributesImpl getAttributes(org.xml.sax.ContentHandler pContentHandler, NamespaceSupport pNamespaceSupport)
          Returns the elements attribute list suitable for a SAX ContentHandler.
 java.util.List getChilds()
          Returns the current list of childs.
protected  java.lang.String getContext(java.lang.String pContext, java.lang.String pElem)
           
static java.text.DateFormat getDefaultDateFormat()
          Deprecated. Will be removed in JaxMe 2. Use a Marshaller and its property jaxme.format.datetime to achieve the same functionality.
 java.lang.Object getElement(java.lang.String pNamespaceURI, java.lang.String pLocalName)
          Returns the value of a single Element.
 java.lang.String getLocalName()
          Returns the elements tag name, without any prefix.
 java.lang.String getNamespaceURI()
          Returns the elements namespace URI.
 java.lang.String[] getPrefixList()
          Returns an array of suggested prefix/namespace URI pairs to use for unmarshalling.
static java.util.Date parseDate(java.lang.String pDate)
          Deprecated. Will be removed in JaxMe 2. Use an Unmarshaller and its property jaxme.format.datetime to achieve the same functionality.
 void removeAttribute(java.lang.String pNamespaceURI, java.lang.String pLocalName)
          Removes a single attribute. by calling setAttribute(pNamespaceURI, pLocalName, null);
 void setAttribute(java.lang.String pNamespaceURI, java.lang.String pLocalName, java.lang.String pValue)
          Deprecated. Use setAttribute(pNamespaceURI, pLocalName, pValue, pUnmarshaller)
 void setAttribute(java.lang.String pNamespaceURI, java.lang.String pLocalName, java.lang.String pValue, UnmarshallerImpl pUnmarshaller)
          Sets a single attribute.
static void setDefaultDateFormat(java.text.DateFormat pFormat)
          Deprecated. Will be removed in JaxMe 2. Use a Marshaller and its property jaxme.format.datetime to achieve the same functionality.
 void setLocalName(java.lang.String pLocalName)
          Sets the elements tag name, without any prefix.
 void setNamespaceURI(java.lang.String pNamespaceURI)
          Sets the elements namespace URI.
 void toSAX(org.xml.sax.ContentHandler contentHandler)
          Converts the element into a stream of SAX events.
 void toSAX(org.xml.sax.ContentHandler pContentHandler, NamespaceSupport pNamespaceSupport)
          Converts the element into a stream of SAX events.
 void toSAX(org.xml.sax.ContentHandler pContentHandler, NamespaceSupport pNamespaceSupport, boolean pNamespaceInitialized)
          Converts the element into a stream of SAX events.
 void toWriter(java.io.Writer pWriter)
          Serializes the element into the given writer.
 void toWriter(java.io.Writer pWriter, NamespaceSupport pNamespaceSupport)
          Serializes the element into the given writer.
 java.lang.String toXML()
          Serializes the element into a String.
 java.lang.String toXML(NamespaceSupport pNamespaceSupport)
          Serializes the element into the given writer.
 void validate(java.lang.String pContext)
          Validates this elements contents.
protected  void validateMe(java.lang.String pContext, org.xml.sax.Locator pLocator)
          Validates this elements contents.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

emptyAttributes

protected static final org.xml.sax.Attributes emptyAttributes

localName

protected java.lang.String localName

namespaceURI

protected java.lang.String namespaceURI
Constructor Detail

JMAnyElement

public JMAnyElement(java.lang.String pNamespaceURI,
                    java.lang.String pLocalName)
Creates a new JMAnyElement with the given namespace URI and local name.


JMAnyElement

public JMAnyElement()
Creates a new JMAnyElement that needs to be intialized with setNamespaceURI() and setLocalName().

Method Detail

getLocalName

public java.lang.String getLocalName()

Returns the elements tag name, without any prefix.


getNamespaceURI

public java.lang.String getNamespaceURI()

Returns the elements namespace URI.


setLocalName

public void setLocalName(java.lang.String pLocalName)

Sets the elements tag name, without any prefix.


setNamespaceURI

public void setNamespaceURI(java.lang.String pNamespaceURI)

Sets the elements namespace URI.


setAttribute

public void setAttribute(java.lang.String pNamespaceURI,
                         java.lang.String pLocalName,
                         java.lang.String pValue)
                  throws org.xml.sax.SAXException
Deprecated. Use setAttribute(pNamespaceURI, pLocalName, pValue, pUnmarshaller)

Sets a single attribute.

Parameters:
pNamespaceURI - The attributes namespace URI
pLocalName - The attributes local name
pValue - The attributes value; null removes the attribute
Throws:
org.xml.sax.SAXException

setAttribute

public void setAttribute(java.lang.String pNamespaceURI,
                         java.lang.String pLocalName,
                         java.lang.String pValue,
                         UnmarshallerImpl pUnmarshaller)
                  throws org.xml.sax.SAXException

Sets a single attribute.

Parameters:
pNamespaceURI - The attributes namespace URI
pLocalName - The attributes local name
pValue - The attributes value; null removes the attribute
pUnmarshaller - A helper for the conversion of Strings in the actual values
Throws:
org.xml.sax.SAXException

removeAttribute

public void removeAttribute(java.lang.String pNamespaceURI,
                            java.lang.String pLocalName)
                     throws org.xml.sax.SAXException

Removes a single attribute. by calling

   setAttribute(pNamespaceURI, pLocalName, null);
 

Throws:
org.xml.sax.SAXException

getAttribute

public java.lang.String getAttribute(java.lang.String pNamespaceURI,
                                     java.lang.String pLocalName)
Deprecated. Use getAttribute(String pNamespaceURI, String pLocalName, MarshallerImpl pMarshaller)

Returns the value of a single attribute.


getAttribute

public java.lang.String getAttribute(java.lang.String pNamespaceURI,
                                     java.lang.String pLocalName,
                                     MarshallerImpl pMarshaller)

Returns the value of a single attribute.


getElement

public java.lang.Object getElement(java.lang.String pNamespaceURI,
                                   java.lang.String pLocalName)

Returns the value of a single Element.


addChild

public void addChild(java.lang.Object pChild)

Adds a single child to the list of childs. The child may be either of

The child is appended to the end of the list. If you want to insert it at another place, use the getChilds() method.


getChilds

public java.util.List getChilds()

Returns the current list of childs. This list is "live": Any modification to the list are modifying the element and vice versa.

Returns:
Current list of childs or null, if there are no childs. In the latter case you need to use addChild() to initialize the list.

toSAX

public void toSAX(org.xml.sax.ContentHandler contentHandler)
           throws org.xml.sax.SAXException

Converts the element into a stream of SAX events. The events are fired into the given ContentHandler. Default prefixes are used to handle the namespace URI's. If you wish to define your own prefixes, use the two arguments form of this method.

Throws:
org.xml.sax.SAXException

toSAX

public void toSAX(org.xml.sax.ContentHandler pContentHandler,
                  NamespaceSupport pNamespaceSupport)
           throws org.xml.sax.SAXException

Converts the element into a stream of SAX events. The events are fired into the given ContentHandler. Namespace URI's are resolved by looking into the given NamespaceSupport element. If the NamespaceSupport's method getPrefix() returns null for a given URL, then a default mapping is established.

Specified by:
toSAX in interface JMNode
Parameters:
pContentHandler - The SAX ContentHandler receiving SAX events.
pNamespaceSupport - A set of preconfigured mappings for prefixes; may be null, in which case default mappings are established.
Throws:
org.xml.sax.SAXException

toSAX

public void toSAX(org.xml.sax.ContentHandler pContentHandler,
                  NamespaceSupport pNamespaceSupport,
                  boolean pNamespaceInitialized)
           throws org.xml.sax.SAXException

Converts the element into a stream of SAX events. The events are fired into the given ContentHandler. Namespace URI's are resolved by looking into the given NamespaceSupport element. If the NamespaceSupport's method getPrefix() returns null for a given URL, then a default mapping is established.

Parameters:
pContentHandler - The SAX ContentHandler receiving SAX events.
pNamespaceSupport - A set of preconfigured mappings for prefixes; may be null, in which case default mappings are established.
pNamespaceInitialized - True, if initNamespaceSupport() has been called.
Throws:
org.xml.sax.SAXException

getAttributes

public org.xml.sax.helpers.AttributesImpl getAttributes(org.xml.sax.ContentHandler pContentHandler,
                                                        NamespaceSupport pNamespaceSupport)
                                                 throws org.xml.sax.SAXException

Returns the elements attribute list suitable for a SAX ContentHandler.

Throws:
org.xml.sax.SAXException

childToSAX

protected void childToSAX(java.lang.String pNamespaceURI,
                          java.lang.String pLocalName,
                          java.lang.String pValue,
                          org.xml.sax.ContentHandler pContentHandler,
                          NamespaceSupport pNamespaceSupport)
                   throws org.xml.sax.SAXException

Converts a single, atomic element into a stream of SAX events.

Throws:
org.xml.sax.SAXException

childsToSAX

protected void childsToSAX(org.xml.sax.ContentHandler pContentHandler,
                           NamespaceSupport pNamespaceSupport)
                    throws org.xml.sax.SAXException

Converts the elements childs into a stream of SAX events. The events are fired into the given ContentHandler. Namespace URI's are resolved by looking into the given NamespaceSupport element. If the NamespaceSupport's method getPrefix() returns null for a given URL, then a default mapping is established.

Throws:
org.xml.sax.SAXException

clone

public java.lang.Object clone()

Returns a clone of this JMAnyElement. A clone A of B is defined as follows:

Specified by:
clone in interface JMNode

toWriter

public void toWriter(java.io.Writer pWriter)
              throws org.xml.sax.SAXException,
                     java.io.IOException

Serializes the element into the given writer. Default mappings are established for namespace prefixes, as in

   toSAX(org.xml.sax.ContentHandler);
 
If you want to use your own mappings, create a NamespaceSupport and use the two arguments version of this method.

Throws:
org.xml.sax.SAXException
java.io.IOException

toWriter

public void toWriter(java.io.Writer pWriter,
                     NamespaceSupport pNamespaceSupport)
              throws org.xml.sax.SAXException,
                     java.io.IOException

Serializes the element into the given writer. The given NamespaceSupport is used to create prefix mappings.

Throws:
org.xml.sax.SAXException
java.io.IOException

toXML

public java.lang.String toXML()

Serializes the element into a String. Default mappings are established for namespace prefixes, as in

   toSAX(org.xml.sax.ContentHandler);
 
If you want to use your own mappings, create a NamespaceSupport and use the version of this method that takes an argument.


toXML

public java.lang.String toXML(NamespaceSupport pNamespaceSupport)

Serializes the element into the given writer. The given NamespaceSupport is used to create prefix mappings.


validateMe

protected void validateMe(java.lang.String pContext,
                          org.xml.sax.Locator pLocator)
                   throws ValidationException

Validates this elements contents. Doesn't work recursively.

Parameters:
pContext - A possible context to use in error messages or null
pLocator - A SAX locator to be used in error messages or null
Throws:
ValidationException - The element is invalid; details are specified in the error message

validate

public void validate(java.lang.String pContext)
              throws ValidationException

Validates this elements contents. Works recursively.

Parameters:
pContext - A possible context to use in error messages
Throws:
ValidationException - The element is invalid; details are specified in the error message

getContext

protected java.lang.String getContext(java.lang.String pContext,
                                      java.lang.String pElem)

parseDate

public static java.util.Date parseDate(java.lang.String pDate)
Deprecated. Will be removed in JaxMe 2. Use an Unmarshaller and its property jaxme.format.datetime to achieve the same functionality.


formatDate

public static java.lang.String formatDate(java.util.Date pDate)
Deprecated. Will be removed in JaxMe 2. Use a Marshaller and its property jaxme.format.datetime to achieve the same functionality.


setDefaultDateFormat

public static void setDefaultDateFormat(java.text.DateFormat pFormat)
Deprecated. Will be removed in JaxMe 2. Use a Marshaller and its property jaxme.format.datetime to achieve the same functionality.

Returns the DateFormat used to convert dateTime instances. The builtin default is new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm: ss. SSS z"). In multithreaded environments you have to synchronize on the returned DateFormat before actually using it. (Which is what formatDate(java.util.Date) and parseDate(String) are doing.


getDefaultDateFormat

public static java.text.DateFormat getDefaultDateFormat()
Deprecated. Will be removed in JaxMe 2. Use a Marshaller and its property jaxme.format.datetime to achieve the same functionality.

Returns the DateFormat used to convert dateTime instances. The builtin default is new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm: ss. SSS z"). In multithreaded environments you have to synchronize on the returned DateFormat before actually using it. (Which is what formatDate(java.util.Date) and parseDate(String) are doing.


getPrefixList

public java.lang.String[] getPrefixList()

Returns an array of suggested prefix/namespace URI pairs to use for unmarshalling. Usually these are the same as used in the defining schema.