org.inria.ns.reflex.xml
Class XFactory

java.lang.Object
  extended by org.inria.ns.reflex.xml.XFactory
Direct Known Subclasses:
XFactory.Impl

public abstract class XFactory
extends Object

A factory that provides basic XML features related to XPath.

A concrete implementation of this class will be able to parse XPath expressions and provides adapters that will be compliant with this implementation. Adapters are provided for X-operable objects and XPath contexts in order to process them safely when a cooperation of such objects is needed, for example when executing an XPath expression on an X-operable object.

The same factory may be used safely many times, even simultaneously. Each concrete implementation of a factory is registered after its first invokation, and reused when invoked several times.

Author:
Philippe Poulard

Nested Class Summary
static class XFactory.Impl
          A partial implementation of an XFactory that provides a support of the XPointer framework.
 
Method Summary
abstract  PatternContext getContextAdapter(PatternContext context)
          Adapt the given context for a specific implementation.
abstract  XPathContext getContextAdapter(XPathContext context)
          Adapt the given context for a specific implementation.
static XFactory newInstance()
          Provide the built-in implentation of a factory, based on Jaxen.
static XFactory newInstance(String propertyName)
          Provide a factory whose class name is given by a system property.
abstract  Pattern parsePattern(String pattern)
          Parse the XPath pattern to a compiled pattern.
abstract  XPath parseXPath(String expression)
          Parse the XPath expression to a compiled expression.
abstract  XPointer parseXPointer(String expression, NamespaceContext namespaceContext)
          Parse the XPointer expression to a compiled expression.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newInstance

public static final XFactory newInstance()
Provide the built-in implentation of a factory, based on Jaxen.

Returns:
The singleton default factory.
See Also:
JaxenXFactory

newInstance

public static final XFactory newInstance(String propertyName)
                                  throws XFactoryConfigurationException
Provide a factory whose class name is given by a system property.

Parameters:
propertyName - The name of the property.
Returns:
The factory bound to the given name, or the default factory if not found.
Throws:
XFactoryConfigurationException - If the factory can't be instanciated.

parseXPath

public abstract XPath parseXPath(String expression)
                          throws XPathSyntaxException
Parse the XPath expression to a compiled expression.

Parameters:
expression - The XPath expression to parse.
Returns:
The compiled XPath expression.
Throws:
XPathSyntaxException - If the XPath expression can't be parsed.

parsePattern

public abstract Pattern parsePattern(String pattern)
                              throws BadPatternException
Parse the XPath pattern to a compiled pattern.

Parameters:
pattern - The pattern to compile.
Returns:
The compiled pattern.
Throws:
BadPatternException - If the pattern can't be parsed.

parseXPointer

public abstract XPointer parseXPointer(String expression,
                                       NamespaceContext namespaceContext)
                                throws XPointerSyntaxException
Parse the XPointer expression to a compiled expression.

Parameters:
expression - The XPointer expression to parse.
namespaceContext - The namespace context used to resolve prefixes. If a namespace binding context is encountered, it is added to the namespace context to use. The namespace context given is restored to its original bindings.
Returns:
The compiled XPointer expression.
Throws:
XPointerSyntaxException - If the XPointer expression can't be parsed.

getContextAdapter

public abstract XPathContext getContextAdapter(XPathContext context)
Adapt the given context for a specific implementation. A context is needed when executing an XPath expression to provide functions, variables, etc. A concrete implementation should provide a wrapper of the context.

Parameters:
context - The context used when the XPath expression will be evaluated.

getContextAdapter

public abstract PatternContext getContextAdapter(PatternContext context)
Adapt the given context for a specific implementation. A context is needed when executing an XPath expression to provide functions, variables, etc. A concrete implementation should provide a wrapper of the context.

Parameters:
context - The context used when the XPath expression will be evaluated.