O - the type of object to be build by the readerpublic abstract class AbstractXpp3Reader<O> extends Object implements Xpp3Reader<O>
PropertyMapper to set properties of
the objects to build.
To implements a new parser, just implements method initMappers() to
see authorized mapping from tag to pojo properties.
The logic of setting properties from xml (tag and attributes) is done in
The default implementation is to map tag text to a pojo's property.
If you want to do something more complex, override these methods.PropertyMapper,
Xpp3Reader| Modifier and Type | Field and Description |
|---|---|
protected boolean |
addDefaultEntities
If set the parser will be loaded with all single characters
from the XHTML specification.
|
protected Map<String,PropertyMapper> |
allMappers
the univers of mappers availables, initialized in
initMappers(). |
protected String |
arrayRootTagName
the root tag of an array of objets to retreave from xml streams.
|
protected String |
rootTagName
the root tag of an object to retreave from xml streams.
|
protected Class<O> |
type
the type of the object to produce from the xml streams.
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractXpp3Reader(Class<O> type,
String rootTagName) |
protected |
AbstractXpp3Reader(Class<O> type,
String arrayRootTagName,
String rootTagName) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addAttributeValueMappers(DataConverter type,
boolean onlyOne,
String... attributeNames) |
protected <O> void |
addTagContentMapper(Class<O> type,
boolean onlyOne,
Xpp3Reader<O> reader) |
protected <O> void |
addTagContentsMapper(Class<O> type,
boolean onlyOne,
Xpp3Reader<O> reader) |
protected void |
addTagTextContentMappers(DataConverter type,
boolean onlyOne,
String... tagNames) |
protected void |
checkEndOfXml(org.codehaus.plexus.util.xml.pull.XmlPullParser parser)
Checks that a given parser is at the end of the xml document.
|
protected void |
checkNotEndOfXml(org.codehaus.plexus.util.xml.pull.XmlPullParser parser,
String tagName)
Checks that a given parser is not at the end of the xml document.
|
String |
getArrayRootTagName() |
Map<String,PropertyMapper> |
getMappers(Class<?> srcType)
Obtain all mappers for a given type.
|
Map<String,PropertyMapper> |
getMappers(Class<?> srcType,
String tagName)
Obtain all mappers for a given type.
|
String |
getRootTagName() |
Class<O> |
getType() |
protected int |
gotoNextOpenTag(String tagName,
org.codehaus.plexus.util.xml.pull.XmlPullParser parser) |
protected abstract void |
initMappers() |
boolean |
isAddDefaultEntities() |
O |
read(Reader reader)
Read a single instance of the typed object and return it.
|
O |
read(Reader reader,
boolean strict)
Read a single instance of the typed object and return it.
|
<T> T |
read(String rootTagName,
Class<T> type,
org.codehaus.plexus.util.xml.pull.XmlPullParser parser,
boolean strict)
Parse the xml stream from the given parser and a build the associated
object.
|
O[] |
readArray(Reader reader)
Read some instances of the typed object and return it.
|
O[] |
readArray(Reader reader,
boolean strict)
Read some instances of the typed object and return it.
|
<T> T[] |
readArray(String parentRootTagName,
String rootTagName,
Class<T> type,
org.codehaus.plexus.util.xml.pull.XmlPullParser parser,
boolean strict)
Parse the xml stream from the given parser and a build an array of
associated object.
|
void |
setAddDefaultEntities(boolean addDefaultEntities)
Set the new value of the
defaultEntities flag. |
void |
setParentRootTagName(String parentRootTagName)
Set the name of the root tag for an array of object to read.
|
void |
setRootTagName(String rootTagName)
Set the name of the root tag of an object to read.
|
protected boolean addDefaultEntities
protected String rootTagName
protected String arrayRootTagName
protected Map<String,PropertyMapper> allMappers
initMappers().
Each mapper of the dictionary is associated to the fully qualified name
of the target class # the tag name or attribute name.
Example :
org.nuiton.util.MyPojo#my-tag org.nuiton.util.MyPojo#my-attribute
protected abstract void initMappers()
throws IntrospectionException
IntrospectionExceptionpublic Class<O> getType()
getType in interface Xpp3Reader<O>public String getRootTagName()
getRootTagName in interface Xpp3Reader<O>public void setRootTagName(String rootTagName)
Xpp3ReadersetRootTagName in interface Xpp3Reader<O>rootTagName - the name of the tagpublic String getArrayRootTagName()
getArrayRootTagName in interface Xpp3Reader<O>public void setParentRootTagName(String parentRootTagName)
Xpp3ReadersetParentRootTagName in interface Xpp3Reader<O>parentRootTagName - the name of the tagpublic boolean isAddDefaultEntities()
isAddDefaultEntities in interface Xpp3Reader<O>true if parser will load the default entities,
false otherwise.public void setAddDefaultEntities(boolean addDefaultEntities)
Xpp3ReaderdefaultEntities flag.setAddDefaultEntities in interface Xpp3Reader<O>addDefaultEntities - the new value.public O read(Reader reader) throws IOException, org.codehaus.plexus.util.xml.pull.XmlPullParserException
Xpp3ReaderXpp3Reader.read(Reader, boolean) in strict mode.
In the xml stream, the root tag must be the Xpp3Reader.getRootTagName().
Example :
<issue>:
...
</issue>:
read in interface Xpp3Reader<O>reader - the xml input readerIOException - if any io pborg.codehaus.plexus.util.xml.pull.XmlPullParserException - if parsing errorpublic O read(Reader reader, boolean strict) throws IOException, org.codehaus.plexus.util.xml.pull.XmlPullParserException
Xpp3ReaderXpp3Reader.getRootTagName().
Example :
<issue>:
...
</issue>:
read in interface Xpp3Reader<O>reader - the xml input readerstrict - flag to be strict while parsingIOException - if any io pborg.codehaus.plexus.util.xml.pull.XmlPullParserException - if any parsing pbpublic O[] readArray(Reader reader) throws IOException, org.codehaus.plexus.util.xml.pull.XmlPullParserException
Xpp3ReaderXpp3Reader.getArrayRootTagName().
Note : this is a convinient method to call :
Xpp3Reader.readArray(Reader, boolean) in stritc mode.
Example :
<issues>:
<issue>:
...
</issue>:
</issues>:
readArray in interface Xpp3Reader<O>reader - the xml input readerIOException - if any io pborg.codehaus.plexus.util.xml.pull.XmlPullParserException - if any parsing pbpublic O[] readArray(Reader reader, boolean strict) throws IOException, org.codehaus.plexus.util.xml.pull.XmlPullParserException
Xpp3ReaderXpp3Reader.getArrayRootTagName().
Example :
<issues>:
<issue>:
...
</issue>:
</issues>:
readArray in interface Xpp3Reader<O>reader - the xml input readerstrict - flag to be strict while parsingIOException - if any io pborg.codehaus.plexus.util.xml.pull.XmlPullParserException - if any parsing pbpublic Map<String,PropertyMapper> getMappers(Class<?> srcType)
my-tag my-attribute
srcType - the target type of the searched mapperspublic Map<String,PropertyMapper> getMappers(Class<?> srcType, String tagName)
my-tag my-attribute
srcType - the target type of the searched mapperstagName - the tag target of the searched mapperspublic <T> T read(String rootTagName, Class<T> type, org.codehaus.plexus.util.xml.pull.XmlPullParser parser, boolean strict) throws org.codehaus.plexus.util.xml.pull.XmlPullParserException, IOException
getRootTagName()
Example :
... <my-pojo> <my-property>myValue</my-property> </my-pojo>
read in interface Xpp3Reader<O>T - the type of object to buildrootTagName - the name of the root tag matching the object to buildtype - the type of object to buildparser - the xpp3 parserstrict - flag to indicate if should fail if a unknown tag
(or attribute ?) is scannedIOException - if any io pborg.codehaus.plexus.util.xml.pull.XmlPullParserException - if any parsing pbpublic <T> T[] readArray(String parentRootTagName, String rootTagName, Class<T> type, org.codehaus.plexus.util.xml.pull.XmlPullParser parser, boolean strict) throws org.codehaus.plexus.util.xml.pull.XmlPullParserException, IOException
parentRootTagName and sub nodes with names rootTagName.
Example :
...
<my-pojos>
<my-pojo>
<my-property>myValue</my-property>
</my-pojo>
<my-pojo>
<my-property>myValue2</my-property>
</my-pojo>
</my-pojos>
readArray in interface Xpp3Reader<O>T - the type of objects to buildparentRootTagName - the tag's name of the array containerrootTagName - the tag's name of each object to buildtype - the type of objects to buildparser - the xpp3 parserstrict - flag to indicate if should fail if a unknown
tag (or attribute ?) is scannedIOException - if any io pborg.codehaus.plexus.util.xml.pull.XmlPullParserException - if any parsing pbprotected int gotoNextOpenTag(String tagName, org.codehaus.plexus.util.xml.pull.XmlPullParser parser) throws org.codehaus.plexus.util.xml.pull.XmlPullParserException, IOException
org.codehaus.plexus.util.xml.pull.XmlPullParserExceptionIOExceptionprotected void checkNotEndOfXml(org.codehaus.plexus.util.xml.pull.XmlPullParser parser,
String tagName)
throws org.codehaus.plexus.util.xml.pull.XmlPullParserException
parser - the parser to checktagName - the endign tag's nameorg.codehaus.plexus.util.xml.pull.XmlPullParserException - if the parser is at the end of the xml
stream, instead of the tagName
ending tagprotected void checkEndOfXml(org.codehaus.plexus.util.xml.pull.XmlPullParser parser)
throws org.codehaus.plexus.util.xml.pull.XmlPullParserException
parser - the parser to checkorg.codehaus.plexus.util.xml.pull.XmlPullParserException - if the parser is not at the end of the
xml stream.protected void addTagTextContentMappers(DataConverter type, boolean onlyOne, String... tagNames) throws IntrospectionException
IntrospectionExceptionprotected void addAttributeValueMappers(DataConverter type, boolean onlyOne, String... attributeNames) throws IntrospectionException
IntrospectionExceptionprotected <O> void addTagContentMapper(Class<O> type, boolean onlyOne, Xpp3Reader<O> reader) throws IntrospectionException
IntrospectionExceptionprotected <O> void addTagContentsMapper(Class<O> type, boolean onlyOne, Xpp3Reader<O> reader) throws IntrospectionException
IntrospectionExceptionCopyright © 2009–2015 CodeLutin. All rights reserved.