org.nuiton.io.xpp3
Class Xpp3Helper

java.lang.Object
  extended by org.nuiton.io.xpp3.Xpp3Helper

public class Xpp3Helper
extends java.lang.Object

A Helper to read some data stored in xml with a Xpp3Reader.

In this class, there is some methods to obtain a discovered Xpp3Reader registred by a ServiceLoader mecanism.

Since:
1.0.3
Author:
chemit
See Also:
Xpp3Reader

Field Summary
protected static java.util.Map<java.lang.Class<?>,Xpp3Reader<?>> readers
          les readers enregistres via un ServiceLoader sur le contrat Xpp3Reader.
 
Constructor Summary
Xpp3Helper()
           
 
Method Summary
static void addAttributeValueMappers(java.lang.Class<?> containerType, DataConverter type, boolean onlyOne, java.util.Map<java.lang.String,PropertyMapper> allMappers, java.lang.String... tagNames)
           
static void addDefaultEntities(org.codehaus.plexus.util.xml.pull.XmlPullParser parser)
          Add to the parser, the default replacers for all single characters from the XHTML specification.
protected static void addMappers(java.lang.Class<? extends PropertyMapper> mapperClass, java.lang.Class<?> containerType, DataConverter type, boolean onlyOne, java.util.Map<java.lang.String,PropertyMapper> allMappers, java.lang.String... tagNames)
           
static void addTagTextContentMappers(java.lang.Class<?> containerType, DataConverter type, boolean onlyOne, java.util.Map<java.lang.String,PropertyMapper> allMappers, java.lang.String... tagNames)
           
static void clearReaders()
          Clean all the registred readers.
static
<T> Xpp3Reader<T>
getReader(java.lang.Class<T> klass)
          Obtain the loaded reader which match his Xpp3Reader.getType() whith the given type.
static java.util.Iterator<Xpp3Reader<?>> getReaderItetator()
           
protected static java.util.Map<java.lang.Class<?>,Xpp3Reader<?>> getReaders()
          Load (if readers is null the readers via a ServiceLoader of contract Xpp3Reader and returns the dictionnary of discovered associated to their type (Xpp3Reader.getType()).
static
<O> O
readObject(java.lang.Class<O> klass, java.io.Reader reader)
          Read a single object from a xml stream.
static
<O> O[]
readObjects(java.lang.Class<O> klass, java.io.Reader reader)
          Read an array of objects from a xml stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

readers

protected static java.util.Map<java.lang.Class<?>,Xpp3Reader<?>> readers
les readers enregistres via un ServiceLoader sur le contrat Xpp3Reader.

Constructor Detail

Xpp3Helper

public Xpp3Helper()
Method Detail

readObject

public static <O> O readObject(java.lang.Class<O> klass,
                               java.io.Reader reader)
                    throws java.io.IOException,
                           org.codehaus.plexus.util.xml.pull.XmlPullParserException
Read a single object from a xml stream.

Type Parameters:
O - the type of object to read
Parameters:
klass - the type of object to read
reader - the reader where to parse the xml
Returns:
the loaded object
Throws:
java.io.IOException - if any io pb
org.codehaus.plexus.util.xml.pull.XmlPullParserException - if any parsing pb

readObjects

public static <O> O[] readObjects(java.lang.Class<O> klass,
                                  java.io.Reader reader)
                       throws java.io.IOException,
                              org.codehaus.plexus.util.xml.pull.XmlPullParserException
Read an array of objects from a xml stream.

Type Parameters:
O - the type of objects to return
Parameters:
klass - the type of object to read
reader - the reader where to parse the xml
Returns:
the loaded objects
Throws:
java.io.IOException - if any io pb
org.codehaus.plexus.util.xml.pull.XmlPullParserException - if any parsing pb

getReaderItetator

public static java.util.Iterator<Xpp3Reader<?>> getReaderItetator()
Returns:
an iterator on all registred Xpp3Reader.

getReader

public static <T> Xpp3Reader<T> getReader(java.lang.Class<T> klass)
Obtain the loaded reader which match his Xpp3Reader.getType() whith the given type.

Type Parameters:
T - the type of the data which should be parsed by the researched parser
Parameters:
klass - the type of the data which should be parsed by the researched parser
Returns:
the parser for the given type

clearReaders

public static void clearReaders()
Clean all the registred readers.

To reload them, just call a getReader(java.lang.Class).


addDefaultEntities

public static void addDefaultEntities(org.codehaus.plexus.util.xml.pull.XmlPullParser parser)
                               throws org.codehaus.plexus.util.xml.pull.XmlPullParserException
Add to the parser, the default replacers for all single characters from the XHTML specification. The entities used:

Parameters:
parser - the parser to configure
Throws:
org.codehaus.plexus.util.xml.pull.XmlPullParserException - if any pb

addTagTextContentMappers

public static void addTagTextContentMappers(java.lang.Class<?> containerType,
                                            DataConverter type,
                                            boolean onlyOne,
                                            java.util.Map<java.lang.String,PropertyMapper> allMappers,
                                            java.lang.String... tagNames)
                                     throws java.beans.IntrospectionException
Throws:
java.beans.IntrospectionException

addAttributeValueMappers

public static void addAttributeValueMappers(java.lang.Class<?> containerType,
                                            DataConverter type,
                                            boolean onlyOne,
                                            java.util.Map<java.lang.String,PropertyMapper> allMappers,
                                            java.lang.String... tagNames)
                                     throws java.beans.IntrospectionException
Throws:
java.beans.IntrospectionException

addMappers

protected static void addMappers(java.lang.Class<? extends PropertyMapper> mapperClass,
                                 java.lang.Class<?> containerType,
                                 DataConverter type,
                                 boolean onlyOne,
                                 java.util.Map<java.lang.String,PropertyMapper> allMappers,
                                 java.lang.String... tagNames)
                          throws java.beans.IntrospectionException,
                                 java.lang.NoSuchMethodException,
                                 java.lang.InstantiationException,
                                 java.lang.IllegalAccessException,
                                 java.lang.IllegalArgumentException,
                                 java.lang.reflect.InvocationTargetException
Throws:
java.beans.IntrospectionException
java.lang.NoSuchMethodException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException

getReaders

protected static java.util.Map<java.lang.Class<?>,Xpp3Reader<?>> getReaders()
Load (if readers is null the readers via a ServiceLoader of contract Xpp3Reader and returns the dictionnary of discovered associated to their type (Xpp3Reader.getType()).

Returns:
all the Xpp3Reader registred via a ServiceLoader on the contract Xpp3Reader associated to their type (Xpp3Reader.getType()).


Copyright © 2009-2010 CodeLutin. All Rights Reserved.