net.sf.joost.stx
Class TransformerHandlerResolverImpl

java.lang.Object
  extended by net.sf.joost.stx.TransformerHandlerResolverImpl
All Implemented Interfaces:
Constants, TransformerHandlerResolver

public final class TransformerHandlerResolverImpl
extends Object
implements TransformerHandlerResolver, Constants

The default implementation of an TransformerHandlerResolver. It supports pluggable TransformerHandlerResolver implementations. Plugin mechanism is based on Jakarta's Discovery library. During instantiation it will scan for available handlers and cache them if this was behavior was configured. Upon calling resolve(String, String, String, URIResolver, ErrorListener, Hashtable) or resolve(String, XMLReader, URIResolver, ErrorListener, Hashtable) it will look for a handler supporting the given method URI and will delegate the call to it.

Version:
$Revision: 2.19 $ $Date: 2009/09/26 13:48:04 $
Author:
fikin

Field Summary
 TransformerHandlerResolver customResolver
          Custom handler provided via {link @Processor} interface
private static int FLAG_FAIL
           
private static int FLAG_IGNORE
           
private static int FLAG_REPLACE
           
private static String flgName
          Defines plugin factory behaviour when duplicated method implementations are discovered.
private static org.apache.commons.logging.Log log
          logging object
private static boolean notInitializedYet
          indicate whether plugins has been initialized or not
private static Hashtable plugins
          hashtable with available methods and their plugin implementations
 
Fields inherited from interface net.sf.joost.Constants
DEBUG, DEFAULT_ENCODING, FEAT_NS, FEAT_NSPREFIX, FEATURE_URI_PREFIX, FUNC_NS, JOOST_EXT_NS, PR_ATTRIBUTES, PR_BUFFER, PR_CHILDREN, PR_CONTINUE, PR_ERROR, PR_SELF, PR_SIBLINGS, STX_NS
 
Constructor Summary
TransformerHandlerResolverImpl()
           
 
Method Summary
 boolean available(String method)
          Lookup given method via searching for a plugin providing implementation for it.
private  Hashtable createExternalParameters(Hashtable params)
          Creates a new Hashtable with String resp.
private static void init()
          Initialize the object It scans plugins directories and create a hashtable of all implemented filter-methods and their factories.
 TransformerHandler resolve(String method, String href, String base, URIResolver uriResolver, ErrorListener errorListener, Hashtable params)
          Resolve given method via searching for a plugin providing implementation for it.
 TransformerHandler resolve(String method, XMLReader reader, URIResolver uriResolver, ErrorListener errorListener, Hashtable params)
          This is essentially same method as common resolve but it assumes that params are already "parsed" via createExternalParameters(Hashtable)
 String[] resolves()
          Return all supported filter-method URIs Each one must return true when checked against available(String).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log
logging object


plugins

private static Hashtable plugins
hashtable with available methods and their plugin implementations


flgName

private static final String flgName
Defines plugin factory behaviour when duplicated method implementations are discovered. One of following values:
(undefined)
use last found implementation and print warning messages each time
replace
see (undefined)
fail
throw exception if duplicate encountered
ignore
ignore that duplicate and print warning message only

See Also:
Constant Field Values

FLAG_FAIL

private static final int FLAG_FAIL
See Also:
Constant Field Values

FLAG_IGNORE

private static final int FLAG_IGNORE
See Also:
Constant Field Values

FLAG_REPLACE

private static final int FLAG_REPLACE
See Also:
Constant Field Values

notInitializedYet

private static boolean notInitializedYet
indicate whether plugins has been initialized or not


customResolver

public TransformerHandlerResolver customResolver
Custom handler provided via {link @Processor} interface

Constructor Detail

TransformerHandlerResolverImpl

public TransformerHandlerResolverImpl()
Method Detail

init

private static void init()
                  throws SAXException
Initialize the object It scans plugins directories and create a hashtable of all implemented filter-methods and their factories. In case of duplicated method implementations its behaviour is defined by {link @flgName} system property.

Throws:
SAXException - when duplicated method implementation is found and has been asked to raise an exception

createExternalParameters

private Hashtable createExternalParameters(Hashtable params)
Creates a new Hashtable with String resp. Object values


resolve

public TransformerHandler resolve(String method,
                                  String href,
                                  String base,
                                  URIResolver uriResolver,
                                  ErrorListener errorListener,
                                  Hashtable params)
                           throws SAXException
Resolve given method via searching for a plugin providing implementation for it.

Specified by:
resolve in interface TransformerHandlerResolver
Parameters:
method - an URI string provided in the filter-method attribute, identifying the type of the requested filter
href - the location of the source for the filter provided in the filter-src attribute (as pseudo-argument of the url(...) notation); null if the filter-src attribute is missing
base - the base URI of the transformation sheet
uriResolver - the optional URIResolver configured for Joost
errorListener - the optional ErrorListener configured for Joost
params - the set of parameters specified using stx:with-param elements, all values are Strings
Returns:
TransformerHandler for that method or throws exception.
Throws:
SAXException - if an error occurs during the creation or initialization

resolve

public TransformerHandler resolve(String method,
                                  XMLReader reader,
                                  URIResolver uriResolver,
                                  ErrorListener errorListener,
                                  Hashtable params)
                           throws SAXException
This is essentially same method as common resolve but it assumes that params are already "parsed" via createExternalParameters(Hashtable)

Specified by:
resolve in interface TransformerHandlerResolver
Parameters:
method - an URI string provided in the filter-method attribute, identifying the type of the requested filter
reader - an XMLReader object that provides the source for the transformation as a stream of SAX events (the contents of an stx:buffer). Either parse method may be used, the required parameters systemId or input respectively will be ignored by this reader.
uriResolver - the optional URIResolver configured for Joost
errorListener - the optional ErrorListener configured for Joost
params - the set of parameters specified using stx:with-param elements, all values are Strings
Returns:
a TransformerHandler object that transforms a SAX stream, or null if the STX processor should try to resolve the handler itself
Throws:
SAXException - if an error occurs during the creation or initialization

available

public boolean available(String method)
Lookup given method via searching for a plugin providing implementation for it. Returns TransformerHandler for that method or throws exception.

Specified by:
available in interface TransformerHandlerResolver
Parameters:
method - an URI string identifying the type of the requested filter
Returns:
true if this resolver will return a TransformerHandler object for this filter

resolves

public String[] resolves()
Return all supported filter-method URIs Each one must return true when checked against available(String).

Specified by:
resolves in interface TransformerHandlerResolver
Returns:
array of supported URIs