org.xmlpull.v1
Class XmlPullParserFactory

java.lang.Object
  |
  +--org.xmlpull.v1.XmlPullParserFactory

public abstract class XmlPullParserFactory
extends java.lang.Object

This class is used to create implementations of XML Pull Parser defined in XMPULL V1 API. The name of actual facotry class will be determied based on several parameters. It works similar to JAXP but tailored to work in J2ME environments (no access to system properties or file system) so name of parser class factory to use and its class used for loading (no classloader - on J2ME no access to context class loaders) must be passed explicitly. If no name of parser factory was passed (or is null) it will try to find name by searching in CLASSPATH for META-INF/services/org.xmlpull.v1.XmlPullParserFactory resource that should contain the name of parser facotry class. If none found it will try to create a default parser factory (if available) or throw exception.

NOTE:In J2SE or J2EE environments to get best results use newInstance(property, classLoaderCtx) where first argument is System.getProperty(XmlPullParserFactory.DEFAULT_PROPERTY_NAME) and second is Thread.getContextClassLoader().getClas() .

Author:
Aleksander Slominski [http://www.extreme.indiana.edu/~aslom/]
See Also:
XmlPullParser

Field Summary
static java.lang.String DEFAULT_PROPERTY_NAME
          name of parser factory property that should be used for system property or in general to retrieve parser factory clas sname from configuration (currently name of peroperty is org.xmlpull.v1.XmlPullParserFactory)
 
Method Summary
 boolean getFeature(java.lang.String name)
          Return the current value of the feature with given name.
 boolean isNamespaceAware()
          Indicates whether or not the factory is configured to produce parsers which are namespace aware.
 boolean isValidating()
          Indicates whether or not the factory is configured to produce parsers which validate the XML content during parse.
static XmlPullParserFactory newInstance()
          Create a new instance of a PullParserFactory used to create XML pull parser (see description of class for more details).
static XmlPullParserFactory newInstance(java.lang.Class classLoaderCtx)
          Get a new instance of a PullParserFactory used to create XML Pull Parser.
static XmlPullParserFactory newInstance(java.lang.Class classLoaderCtx, java.lang.String factoryClassName)
          Get instance of XML pull parser factiry.
static XmlPullParserFactory newInstance(java.lang.String factoryClassName)
          Get a new instance of a PullParserFactory from given class name.
abstract  XmlPullParser newPullParser()
          Creates a new instance of a XML Pull Parser using the currently configured factory parameters.
 void setFeature(java.lang.String name, boolean state)
          Set the features to be set when XML Pull Parser is created by this factory.
 void setNamespaceAware(boolean awareness)
          Specifies that the parser produced by this factory will provide support for XML namespaces.
 void setValidating(boolean validating)
          Specifies that the parser produced by this factory will be validating By default the value of this is set to false.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PROPERTY_NAME

public static final java.lang.String DEFAULT_PROPERTY_NAME
name of parser factory property that should be used for system property or in general to retrieve parser factory clas sname from configuration (currently name of peroperty is org.xmlpull.v1.XmlPullParserFactory)
Method Detail

newInstance

public static XmlPullParserFactory newInstance()
                                        throws XmlPullParserException
Create a new instance of a PullParserFactory used to create XML pull parser (see description of class for more details).
Returns:
result of call to newInstance(null, null)

newInstance

public static XmlPullParserFactory newInstance(java.lang.String factoryClassName)
                                        throws XmlPullParserException
Get a new instance of a PullParserFactory from given class name.
Parameters:
factoryClassName - use specified factory class if not null
Returns:
result of call to newInstance(null, factoryClassName)

newInstance

public static XmlPullParserFactory newInstance(java.lang.Class classLoaderCtx)
                                        throws XmlPullParserException
Get a new instance of a PullParserFactory used to create XML Pull Parser.

NOTE: passing classLoaderCtx is not very useful in ME but can be useful in J2SE, J2EE or in container environments (such as servlets) where multiple class loaders are used (it is using Class as ClassLoader is not in ME profile).

Parameters:
classLoaderCtx - if not null it is used to find default factory and to create instance
Returns:
result of call to newInstance(classLoaderCtx, null)

newInstance

public static XmlPullParserFactory newInstance(java.lang.Class classLoaderCtx,
                                               java.lang.String factoryClassName)
                                        throws XmlPullParserException
Get instance of XML pull parser factiry.

NOTE: this allows to use -D system properties indirectly and still to support flexible configuration in J2ME environments..

Parameters:
classLoaderCtx - if null Class.forName will be used instead - simple way to use class loaders and still have ME compatibility!
hint - with name of parser factory to use - it is a hint and is ignored if factory is not available.

setFeature

public void setFeature(java.lang.String name,
                       boolean state)
                throws XmlPullParserException
Set the features to be set when XML Pull Parser is created by this factory.
Parameters:
name - string with URI identifying feature
state - if true feature will be set; if false will be ignored

getFeature

public boolean getFeature(java.lang.String name)
Return the current value of the feature with given name.
Parameters:
name - The name of feature to be retrieved.
Returns:
The value of named feature. Unknown features are always returned as false

setNamespaceAware

public void setNamespaceAware(boolean awareness)
                       throws XmlPullParserException
Specifies that the parser produced by this factory will provide support for XML namespaces. By default the value of this is set to false.
Parameters:
awareness - true if the parser produced by this code will provide support for XML namespaces; false otherwise.

isNamespaceAware

public boolean isNamespaceAware()
Indicates whether or not the factory is configured to produce parsers which are namespace aware.
Returns:
true if the factory is configured to produce parsers which are namespace aware; false otherwise.

setValidating

public void setValidating(boolean validating)
                   throws XmlPullParserException
Specifies that the parser produced by this factory will be validating By default the value of this is set to false.
Parameters:
validating - - if true the parsers created by this factory must be validating.

isValidating

public boolean isValidating()
Indicates whether or not the factory is configured to produce parsers which validate the XML content during parse.
Returns:
true if the factory is configured to produce parsers which validate the XML content during parse; false otherwise.

newPullParser

public abstract XmlPullParser newPullParser()
                                     throws XmlPullParserException
Creates a new instance of a XML Pull Parser using the currently configured factory parameters.
Returns:
A new instance of a XML Pull Parser.
Throws:
XmlPullParserException - if a parser cannot be created which satisfies the requested configuration.


This XMLPULL V1 API is free, enjoy! http://www.xmlpull.org/