org.nuiton.io.xpp3
Class Xpp3Helper

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

public class Xpp3Helper
extends 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 Map<Class<?>,Xpp3Reader<?>> readers
          les readers enregistres via un ServiceLoader sur le contrat Xpp3Reader.
 
Constructor Summary
Xpp3Helper()
           
 
Method Summary
static void addAttributeValueMappers(Class<?> containerType, DataConverter type, boolean onlyOne, Map<String,PropertyMapper> allMappers, 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(Class<? extends PropertyMapper> mapperClass, Class<?> containerType, DataConverter type, boolean onlyOne, Map<String,PropertyMapper> allMappers, String... tagNames)
           
static void addTagTextContentMappers(Class<?> containerType, DataConverter type, boolean onlyOne, Map<String,PropertyMapper> allMappers, String... tagNames)
           
static void clearReaders()
          Clean all the registred readers.
static
<T> Xpp3Reader<T>
getReader(Class<T> klass)
          Obtain the loaded reader which match his Xpp3Reader.getType() whith the given type.
static Iterator<Xpp3Reader<?>> getReaderItetator()
           
protected static Map<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(Class<O> klass, Reader reader)
          Read a single object from a xml stream.
static
<O> O[]
readObjects(Class<O> klass, 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 Map<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(Class<O> klass,
                               Reader reader)
                    throws 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:
IOException - if any io pb
org.codehaus.plexus.util.xml.pull.XmlPullParserException - if any parsing pb

readObjects

public static <O> O[] readObjects(Class<O> klass,
                                  Reader reader)
                       throws 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:
IOException - if any io pb
org.codehaus.plexus.util.xml.pull.XmlPullParserException - if any parsing pb

getReaderItetator

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

getReader

public static <T> Xpp3Reader<T> getReader(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(Class<?> containerType,
                                            DataConverter type,
                                            boolean onlyOne,
                                            Map<String,PropertyMapper> allMappers,
                                            String... tagNames)
                                     throws IntrospectionException
Throws:
IntrospectionException

addAttributeValueMappers

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

addMappers

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

getReaders

protected static Map<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 CodeLutin. All Rights Reserved.