|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbiz.c24.io.api.presentation.Source
biz.c24.io.api.presentation.SAXSource
public class SAXSource
A source for generating data objects from a series of SAX events.
Since the generation of SAX events is an asynchronous process the readObject(biz.c24.io.api.data.Element)
method of this class will always immediatley return null
without blocking for the incoming events. After
calling this method, and once the events have been sent to this object you should call getRootObject()
to
return the parsed object. Thus a common usage of this class would be:
SAXSource src = new SAXSource(); src.readObject(myElement); // should still call this method to initialise the src // The following is dependent on the actual SAX event source in use saxEvenntSource = // initialize the source of the SAX events saxEventSource.setContentHandler(src.getContentHandler()); saxEventSource.setLexicalHandler(src.getLexicalHandler()); saxEventSource.setEntityResolver(src.getEntityResolver()); saxEventSource.setErrorHandler(src.getErrorHandler()); saxEventSource.start(); // dependent on the actual SAX event source in use ComplexDataObject myObj = src.getRootObject();
Please note this class does not use the inherited Source.getInputStream()
or Source.getReader()
methods.
Note that this implementation is not synchronized. If multiple threads use an instance concurrently, it must be synchronized externally.
Note. Internal parts of this built up on the "Thread Local pattern". So, before processing of XML is stopped is not allowed the using of other SAXSource instances in scope of onethread
. But there is options,
for details see the binding context
.
Source
,
DefaultContext
,
Serialized FormField Summary | |
---|---|
static String |
DEFAULT_LOG_NAME
Default logger used when reading an object with no defining element. |
Constructor Summary | |
---|---|
SAXSource()
Constructs a new instance. |
|
SAXSource(SAXSource clone)
Constructs a new instance cloned from clone . |
Method Summary | |
---|---|
Object |
clone()
|
ContentHandler |
getContentHandler()
Returns the content handler from which SAX events will be read. |
EntityResolver |
getEntityResolver()
Returns the entity resolver. |
ErrorHandler |
getErrorHandler()
Returns the error handler. |
LexicalHandler |
getLexicalHandler()
Returns the lexical handler from which SAX events will be read. |
String[] |
getRegisteredRemoteComponents()
Deprecated. please use Document Root instead |
File |
getRootDir()
Returns the root directory to which all relative filenames will be resolved. |
Element |
getRootElement()
Returns the root element set up via the readObject(biz.c24.io.api.data.Element) method. |
Logger |
getRootLogger()
Returns the logger for the root element is one has been specified, otherwise the logger called DEFAULT_LOG_NAME . |
ComplexDataObject |
getRootObject()
Returns the parsed object or null if insufficent SAX events have been received to create the object. |
boolean |
isElementOrderValidationEnabled()
Returns whether element order validation are allowed in the incoming XML. |
boolean |
isPopulateOptionalDefaultValues()
Returns wether the default values be populated to the elements/attributes if they are empty/absent respectively. |
boolean |
isPopulateOptionalFixedValues()
Returns wether the fixed values be populated to the elements/attributes if they are empty/absent respectively. |
boolean |
isSkipWrongData()
Returns wether skipping of non-bindable elements are allowed in the incoming XML. |
boolean |
isStrictNamespaces()
Returns whether instance documents in namespaces (including the default namespace) other than that defined by the argument supplied to the readObject(biz.c24.io.api.data.Element) method will be accepted. |
boolean |
isUnknownComponentsAllowed()
Returns whether unknown components are allowed to appear in the incoming XML. |
void |
readObject(ComplexDataObject object)
Unsupported operation, use readObject(biz.c24.io.api.data.Element) instead. |
ComplexDataObject |
readObject(Element element)
Initialises this source to read data against the specified element declaration. |
void |
registerRemoteComponent(DataComponent element)
Deprecated. please use Document Root instead |
void |
setElementOrderValidationEnabled(boolean enable)
Sets whether element order validation are allowed. |
void |
setPopulateOptionalDefaultValues(boolean enable)
Sets whether the default values be populated to the elements/attributes. |
void |
setPopulateOptionalFixedValues(boolean enable)
Sets whether the fixed values be populated to the elements/attributes. |
void |
setRootDir(File rootDir)
Sets the root directory to which all relative filenames will be resolved. |
void |
setSkipWrongData(boolean enable)
Sets whether skipping of non-bindable elements are allowed. |
void |
setStrictNamespaces(boolean strictNamespaces)
Sets whether instance documents in namespaces (including the default namespace) other than that defined by the argument supplied to the readObject(biz.c24.io.api.data.Element) method will be accepted. |
void |
setUnknownComponentsAllowed(boolean unknownComponentsAllowed)
Sets whether unknown components are allowed to appear in the incoming XML. |
void |
unregisterRemoteComponent(DataComponent element)
Deprecated. please use Document Root instead |
Methods inherited from class biz.c24.io.api.presentation.Source |
---|
checkInit, getEncoding, getInputStream, getMarkableInputStream, getParseListener, getReader, getSystemId, reader, ready, setEncoding, setInputStream, setInputStream, setParseListener, setReader, setReader, setSystemId, stream |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String DEFAULT_LOG_NAME
Constructor Detail |
---|
public SAXSource()
public SAXSource(SAXSource clone)
clone
.
clone
- The instance to clone.Method Detail |
---|
public ContentHandler getContentHandler()
The handler can be used with a SAX event source - a producer of SAX events (or possibly a SAXSink
).
public LexicalHandler getLexicalHandler()
The handler can be used with a SAX event source - a producer of SAX events (or possibly a SAXSink
).
public EntityResolver getEntityResolver()
public ErrorHandler getErrorHandler()
public void readObject(ComplexDataObject object) throws IOException
readObject(biz.c24.io.api.data.Element)
instead.
XML instance documents often consist of a root element whose name is different from it's type or which use the
xsi:type attribute. In both these cases the object which is to be produced by the parse process may not be
compatible with that which is passed in. A pointer to the root element is required so that the correct instance
can be created, populated and returned, it is therefore neccesary to use the alternative readObject
method.
readObject
in class Source
object
- The object into which the input data should be parsed.
IOException
- If the complete object could not be read for any reason.public ComplexDataObject readObject(Element element) throws IOException
If element == null
, a new object will be created on the fly from the SAX event data, in a similar fashion to a DOM.
In this case, logging output will be sent to DEFAULT_LOG_NAME
.
This method will always return null
since parsing the incoming SAX events is an asynchronous process.
To get access to the parsed object call getRootObject()
after firing all SAX events.
readObject
in class Source
element
- The element declaration to which the input data is expected to adhere.
null
- the parsed object can be retrieved via getRootObject()
after the events have been fired.
IOException
- If an error occours reading the data.public Element getRootElement()
readObject(biz.c24.io.api.data.Element)
method.
public ComplexDataObject getRootObject()
null
if insufficent SAX events have been received to create the object.This method should be called synchronously after all SAX events have been fired.
null
.public Logger getRootLogger()
DEFAULT_LOG_NAME
.
public File getRootDir()
public void setRootDir(File rootDir)
rootDir
- The new value.public boolean isStrictNamespaces()
readObject(biz.c24.io.api.data.Element)
method will be accepted.
public void setStrictNamespaces(boolean strictNamespaces)
readObject(biz.c24.io.api.data.Element)
method will be accepted.
strictNamespaces
- The new value.public boolean isUnknownComponentsAllowed()
Unknown components are remote to the structure being parsed, e.g. those that might appear in place of an 'any'.
This property is set to true
by default to give maximum flexibility..
public void setUnknownComponentsAllowed(boolean unknownComponentsAllowed)
Unknown components are remote to the structure being parsed, e.g. those that might appear in place of an 'any'.
You should consider setting this property to false
if you have registered remote components via the
registerRemoteComponent(biz.c24.io.api.data.DataComponent)
method and want to be alerted when an XML document
contains an unregistered component.
unknownComponentsAllowed
- The new value.public boolean isElementOrderValidationEnabled()
This property is set to true
by default to give maximum flexibility..
public void setElementOrderValidationEnabled(boolean enable)
enable
- The new value.public boolean isSkipWrongData()
This property is set to false by default to give the working the batch processing. If this property is true, batch processing has the unexpected results.
public void setSkipWrongData(boolean enable)
enable
- The new value.isSkipWrongData()
public boolean isPopulateOptionalDefaultValues()
public void setPopulateOptionalDefaultValues(boolean enable)
enable
- The new value.isPopulateOptionalDefaultValues()
public boolean isPopulateOptionalFixedValues()
public void setPopulateOptionalFixedValues(boolean enable)
enable
- The new value.isPopulateOptionalFixedValues()
public void registerRemoteComponent(DataComponent element)
Document Root
instead
This method provides the parser with possible elements which can be parsed against, e.g. those that might appear in place of an 'any'
or as part of a model which is loaded without a defining element declaration, i.e. as a result of a call to
readObject(biz.c24.io.api.data.Element)
with a null
argument.
element
- The data component (element or attribute) to register.public void unregisterRemoteComponent(DataComponent element)
Document Root
instead
element
- The (element or attribute) to unregister.public String[] getRegisteredRemoteComponents()
Document Root
instead
public Object clone()
clone
in class Source
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |