|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbiz.c24.io.api.presentation.CDOStreamReader
public class CDOStreamReader
Lowest level StAX cursor based reader implementation to read Complex Data Objects.
Represents theStAX cursor based reader
implementation that allows cursor based, read-only access to
Complex Data Objects
in the most efficiencent way.
It is designed to create events from a Complex
Data Object
using hasNext()
and next()
like on usual XML.
The data can be accessed using methods such as getEventType()
,
getNamespaceURI()
, getLocalName()
, getText()
and
so on, according to the contract on StAX cursor based
reader
. Its behaviour is defined by the
JSR-173
specification.
If used with Java 1.5 or 1.4, then please ensure that the JSR-173 API library
added to your classpath (jsr173_api.jar).
The next()
method causes the reader to read the next cursor event
for an underliying Complex Data Object
like it is
just "plain old XML". The returned event represented by an primitive integer
identifies the type of event just read. At any time the current event
type can be determined using getEventType()
method. Just after
construction of the reader, its state is undefined (zero 0 value).
Note. Unlike the XML Stream reader
some events
that are defined there (DTD
,
entity
declaration
, entity reference
,white
space
, attributes
and
namespaces
) will never
happen due to their inapplicability for a ComplexDataObject
.
The typical usage of the reader is following:
ComplexDataObject cdo = ... CDOStreamReader reader = new CDOStreamReader(cdo); while (reader.hasNext()) { event = reader.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: // handle start of element ... break; case XMLStreamConstants.CHARACTERS: // handle characters ... break; case XMLStreamConstants.CDATA: // handle characters incapsulated into <![CDATA[...]]> ... break; case XMLStreamConstants.COMMENT: // handle comments ... break; case XMLStreamConstants.END_ELEMENT: // handle end of element ... break; case XMLStreamConstants.START_DOCUMENT: // handle start of document ... break; case XMLStreamConstants.END_DOCUMENT: // handle end of document ... break; case XMLStreamConstants.PROCESSING_INSTRUCTION: // handle processing instructions ... break; } }
stream.events.XMLEvent
,
CDOStreamWriter
Field Summary |
---|
Fields inherited from interface javax.xml.stream.XMLStreamConstants |
---|
ATTRIBUTE, CDATA, CHARACTERS, COMMENT, DTD, END_DOCUMENT, END_ELEMENT, ENTITY_DECLARATION, ENTITY_REFERENCE, NAMESPACE, NOTATION_DECLARATION, PROCESSING_INSTRUCTION, SPACE, START_DOCUMENT, START_ELEMENT |
Constructor Summary | |
---|---|
CDOStreamReader(ComplexDataObject object)
Constructor with the Complex Data Object. |
Method Summary | |
---|---|
protected void |
allocateScanner(biz.c24.io.api.presentation.Scanner scanner)
The underlied CDO scanner setter. |
void |
close()
Frees any resources associated with this Reader. |
int |
getAttributeCount()
Gets the attribute count. |
String |
getAttributeLocalName(int index)
Returns the local name of the attribute at the provided index. |
QName |
getAttributeName(int index)
Returns the QName of the attribute at the provided index. |
String |
getAttributeNamespace(int index)
Returns the namespace of the attribute at the provided index. |
String |
getAttributePrefix(int index)
Returns the prefix of this attribute at the provided index. |
String |
getAttributeType(int index)
Returns the XML type of the attribute at the provided index. |
String |
getAttributeValue(int index)
Returns the value of the attribute at the index. |
String |
getAttributeValue(String namespace,
String name)
Returns the value of the attribute with the specified namespace and local name. |
String |
getCharacterEncodingScheme()
The XML charachter encoding getter. |
String |
getElementText()
Returns the text of current element. |
String |
getEncoding()
Input encoding getter. |
int |
getEventType()
Gets the current event. |
String |
getLocalName()
Returns the (local) name of the current event. |
javax.xml.stream.Location |
getLocation()
Return the current location of the processor. |
QName |
getName()
Returns a QName for the current START_ELEMENT or END_ELEMENT event |
NamespaceContext |
getNamespaceContext()
Returns a read only namespace context for the current position. |
int |
getNamespaceCount()
Gets the namespace count. |
String |
getNamespacePrefix(int index)
Returns the prefix for the namespace declared at the index or null if this is the default namespace declaration. |
String |
getNamespaceURI()
Returns the URI of the prefix or the default namespace if the current event is a START_ELEMENT or END_ELEMENT, returns null if the event does not have a prefix or haven't name. |
String |
getNamespaceURI(int index)
Returns the URI for the namespace declared at the index. |
String |
getNamespaceURI(String prefix)
Return the URI for the given prefix. |
String |
getPIData()
Get the data section of a processing instruction. |
String |
getPITarget()
Get the target of a processing instruction. |
String |
getPrefix()
Returns the prefix of the current event or null if the event does not have a prefix. |
Object |
getProperty(String name)
Get the value of a feature/property from the underlying implementation |
String |
getText()
Returns the current value of the event as a string. |
char[] |
getTextCharacters()
Returns an array which contains the characters from this event. |
int |
getTextCharacters(int sourceStart,
char[] target,
int targetStart,
int length)
Gets the the text associated with a CHARACTERS, SPACE or CDATA event. |
int |
getTextLength()
Returns the length of the sequence of characters for this event. |
int |
getTextStart()
Returns the offset into the text character array where the first character (of this text event) is stored. |
String |
getVersion()
The XML version getter. |
boolean |
hasName()
Returns true if the current event has a name (i.e. a START_ELEMENT or END_ELEMENT), returns false otherwise. |
boolean |
hasNext()
Checks weather there is any event or not. |
boolean |
hasText()
Return true if the current event has a text, false otherwise. |
boolean |
isAttribute()
Returns true if the cursor points to a attribute event, false - otherwise. |
boolean |
isAttributeSpecified(int index)
Returns a boolean which indicates if this attribute was created by default or not. |
boolean |
isCDATA()
Returns true if the cursor points to a character data in CDATA section event, false - otherwise. |
boolean |
isCharacters()
Returns true if the cursor points to a character data event, false - otherwise. |
boolean |
isComment()
Returns true if the cursor points to a comment event, false - otherwise. |
boolean |
isEndElement()
Returns true if the cursor points to an end tag event, false - otherwise. |
boolean |
isNamespace()
Returns true if the cursor points to a namespace event, false - otherwise. |
boolean |
isPI()
Returns true if the cursor points to a processing instruction event, false - otherwise. |
boolean |
isStandalone()
Get the standalone declaration from the Complex Data Object. |
boolean |
isStartElement()
Returns true if the cursor points to a start tag event, false - otherwise. |
boolean |
isWhiteSpace()
Returns true if the cursor points to a white spaces event, false - otherwise. |
int |
next()
Next event in iteration getter. |
int |
nextTag()
Seeks the cursor on next element. |
void |
require(int type,
String namespace,
String name)
Checks the current state against the specified conditions. |
boolean |
standaloneSet()
Checks if standalone was set in the Complex Data Object. |
static String |
textualizeState(int state)
Returns the textual representation of specified state. |
String |
toString()
Returns a string representation of the reader. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public CDOStreamReader(ComplexDataObject object)
object
- the Complex Data Object instance just scanned over.Method Detail |
---|
public int getEventType()
getEventType
in interface javax.xml.stream.XMLStreamReader
hasNext()
public boolean hasNext() throws javax.xml.stream.XMLStreamException
END_DOCUMENT
.
hasNext
in interface javax.xml.stream.XMLStreamReader
javax.xml.stream.XMLStreamException
- if there is a fatal error
detecting the next state.public int next() throws javax.xml.stream.XMLStreamException
START_DOCUMENT
,
END_DOCUMENT
, START_ELEMENT
,
END_ELEMENT
, COMMENT
and
PROCESSING_INSTRUCTION
with the same
expectations as during the XML events iteration. The events related to
character processing (CHARACTERS
and CDATA
) occured on any contiguous character data with the differences
described in textual data representation for an
complex
and
simple
data types. However
due the specific of an object that is scanned, this will not return the
XML specific events like ENTITY_DECLARATION
and ENTITY_DECLARATION
. Also there is never
happend the whitespace events
, the human friendly
formatting is under client application responsibility.
Given the Complex Data Object that has a following XML representation:
hasNext()
returns false.
next
in interface javax.xml.stream.XMLStreamReader
NoSuchElementException
- if this is called when hasNext()
returns false
javax.xml.stream.XMLStreamException
- if there is an error
scanning the underlying Complex Data object.hasNext()
public void require(int type, String namespace, String name) throws javax.xml.stream.XMLStreamException
require
in interface javax.xml.stream.XMLStreamReader
type
- the expected event typenamespace
- the expected URI of the event, may be null.name
- the local name of the event, may be null.
javax.xml.stream.XMLStreamException
- if the required values are not matched to
current state.public int nextTag() throws javax.xml.stream.XMLStreamException
white space
, comment
or processing instructions
until a START_ELEMENT
or END_ELEMENT is reached. If other than white space characters, comment,
processing instructions, START_ELEMENT, END_ELEMENT are encountered, an
exception is thrown. This method should be used when processing
element-only content seperated by white space.
Precondition: none
nextTag
in interface javax.xml.stream.XMLStreamReader
javax.xml.stream.XMLStreamException
- if the current event is not
white space, PROCESSING_INSTRUCTION, START_ELEMENT or END_ELEMENT
NoSuchElementException
- if this is called when hasNext() returns
falsepublic String getElementText() throws javax.xml.stream.XMLStreamException
getElementText
in interface javax.xml.stream.XMLStreamReader
javax.xml.stream.XMLStreamException
- if the current event is not a
START_ELEMENT or if a non text element is encounteredpublic boolean hasName()
hasName
in interface javax.xml.stream.XMLStreamReader
public String getNamespaceURI()
getNamespaceURI
in interface javax.xml.stream.XMLStreamReader
public String getPrefix()
getPrefix
in interface javax.xml.stream.XMLStreamReader
public String getLocalName()
getLocalName
in interface javax.xml.stream.XMLStreamReader
IllegalStateException
- if this not a START_ELEMENT or END_ELEMENT.public QName getName()
getName
in interface javax.xml.stream.XMLStreamReader
IllegalStateException
- if this not a START_ELEMENT or END_ELEMENT.public int getAttributeCount()
getAttributeCount
in interface javax.xml.stream.XMLStreamReader
IllegalStateException
- if this not a START_ELEMENT or ATTRIBUTE.public boolean isAttributeSpecified(int index)
isAttributeSpecified
in interface javax.xml.stream.XMLStreamReader
index
- the position of the attribute.
IllegalStateException
- if this not a START_ELEMENT or ATTRIBUTE.
NoSuchElementException
- if there is no such attribute.public String getAttributeLocalName(int index)
getAttributeLocalName
in interface javax.xml.stream.XMLStreamReader
index
- the position of the attribute.
IllegalStateException
- if this not a START_ELEMENT or ATTRIBUTE.
NoSuchElementException
- if there is no such attribute.public String getAttributeNamespace(int index)
getAttributeNamespace
in interface javax.xml.stream.XMLStreamReader
index
- the position of the attribute.
IllegalStateException
- if this not a START_ELEMENT or ATTRIBUTE.
NoSuchElementException
- if there is no such attribute.public String getAttributePrefix(int index)
getAttributePrefix
in interface javax.xml.stream.XMLStreamReader
index
- the position of the attribute.
IllegalStateException
- if this not a START_ELEMENT or ATTRIBUTE.
NoSuchElementException
- if there is no such attribute.public String getAttributeType(int index)
getAttributeType
in interface javax.xml.stream.XMLStreamReader
index
- the position of the attribute.
IllegalStateException
- if this not a START_ELEMENT or ATTRIBUTE.
NoSuchElementException
- if there is no such attribute.public String getAttributeValue(int index)
getAttributeValue
in interface javax.xml.stream.XMLStreamReader
index
- the position of the attribute.
IllegalStateException
- if this not a START_ELEMENT or ATTRIBUTE.
NoSuchElementException
- if there is no such attribute.public String getAttributeValue(String namespace, String name)
getAttributeValue
in interface javax.xml.stream.XMLStreamReader
namespace
- the namespace of the attribute.name
- the local name of the attribute, cannot be null.
IllegalStateException
- if this is not a START_ELEMENT or ATTRIBUTE
IllegalArgumentException
- if the name is null.public QName getAttributeName(int index)
getAttributeName
in interface javax.xml.stream.XMLStreamReader
index
- the position of the attribute.
IllegalStateException
- if this not a START_ELEMENT or ATTRIBUTE.public int getNamespaceCount()
getNamespaceCount
in interface javax.xml.stream.XMLStreamReader
IllegalStateException
- if this not a START_ELEMEN or END_ELEMENT.public String getNamespacePrefix(int index)
getNamespacePrefix
in interface javax.xml.stream.XMLStreamReader
index
- the position of the namespace declaration.
IllegalStateException
- if this not a START_ELEMENT, END_ELEMENT or
NAMESPACE.public String getNamespaceURI(int index)
getNamespaceURI
in interface javax.xml.stream.XMLStreamReader
index
- the position of the namespace declaration.
IllegalStateException
- if this not a START_ELEMENT, END_ELEMENT or
NAMESPACE.public String getNamespaceURI(String prefix)
getNamespaceURI
in interface javax.xml.stream.XMLStreamReader
prefix
- the prefix to lookup, may not be null.
IllegalArgumentException
- if the prefix is
null.public NamespaceContext getNamespaceContext()
getNamespaceContext
in interface javax.xml.stream.XMLStreamReader
public boolean hasText()
hasText
in interface javax.xml.stream.XMLStreamReader
public String getText()
getText
in interface javax.xml.stream.XMLStreamReader
IllegalStateException
- if this state is not a valid text state.public int getTextLength()
getTextLength
in interface javax.xml.stream.XMLStreamReader
IllegalStateException
- if this state is not a valid text state.public int getTextStart()
getTextStart
in interface javax.xml.stream.XMLStreamReader
IllegalStateException
- if this state is not a valid text state.public char[] getTextCharacters()
getTextCharacters
in interface javax.xml.stream.XMLStreamReader
IllegalStateException
- if this state is not a valid text state.public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length) throws javax.xml.stream.XMLStreamException
getTextCharacters
in interface javax.xml.stream.XMLStreamReader
sourceStart
- the index of the first character in the source array to
copy.target
- the destination array.targetStart
- the start offset in the target array.length
- the number of characters to copy.
IndexOutOfBoundsException
- if targetStart < 0 or > than the
length of target or if length < 0 or
targetStart + length > length of
target.
UnsupportedOperationException
- if this method is not supported.
NullPointerException
- is if target is null.
javax.xml.stream.XMLStreamException
public String getPITarget()
getPITarget
in interface javax.xml.stream.XMLStreamReader
IllegalStateException
- if the current event is not a XMLStreamConstants.PROCESSING_INSTRUCTION
public String getPIData()
getPIData
in interface javax.xml.stream.XMLStreamReader
IllegalStateException
- if the current event is not a XMLStreamConstants.PROCESSING_INSTRUCTION
public boolean isStartElement()
isStartElement
in interface javax.xml.stream.XMLStreamReader
public boolean isNamespace()
public boolean isAttribute()
public boolean isCharacters()
isCharacters
in interface javax.xml.stream.XMLStreamReader
public boolean isCDATA()
public boolean isWhiteSpace()
isWhiteSpace
in interface javax.xml.stream.XMLStreamReader
public boolean isEndElement()
isEndElement
in interface javax.xml.stream.XMLStreamReader
public boolean isPI()
public boolean isComment()
public String getEncoding()
Complex Data Object
responsibility.
getEncoding
in interface javax.xml.stream.XMLStreamReader
public String getCharacterEncodingScheme()
Complex Data Object
responsibility.
getCharacterEncodingScheme
in interface javax.xml.stream.XMLStreamReader
public String getVersion()
Complex Data Object
responsibility.
getVersion
in interface javax.xml.stream.XMLStreamReader
public boolean standaloneSet()
Complex Data Object
responsibility.
standaloneSet
in interface javax.xml.stream.XMLStreamReader
public boolean isStandalone()
Complex Data Object
responsibility.
isStandalone
in interface javax.xml.stream.XMLStreamReader
public javax.xml.stream.Location getLocation()
getLocation
in interface javax.xml.stream.XMLStreamReader
public Object getProperty(String name) throws IllegalArgumentException
getProperty
in interface javax.xml.stream.XMLStreamReader
name
- The name of the property, may not be null
IllegalArgumentException
- if name is nullpublic void close() throws javax.xml.stream.XMLStreamException
close
in interface javax.xml.stream.XMLStreamReader
javax.xml.stream.XMLStreamException
- if there are errors freeing
associated resourcespublic String toString()
toString
in class Object
public static String textualizeState(int state)
state
- The event type which textualize.
protected void allocateScanner(biz.c24.io.api.presentation.Scanner scanner)
scanner
- the new CDO scanner instance.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |