org.writersforge.catalan.transform
Class ProcessorRegistry

java.lang.Object
  extended byorg.writersforge.catalan.transform.ProcessorRegistry

public class ProcessorRegistry
extends java.lang.Object

Central registry for connecting XML transform elements up to NodeProcessor implementations. The XML map has a simple format:

   <registry>
     <proc-one class="org.mystuff.processors.ProcOne"/>
     <proc-two class="org.mystuff.processors.ProcTwo"/>
   </registry>
 
Each child element represents an element in the Transform XML; the "class" attribute is the processor class that the Transform XML element should map to. In the example above, the element <proc-one> in Transform XML would map to the processor class org.mystuff.processors.ProcOne. Classes that don't exist in the current Java environment resolve to a null.

Author:
jsheets

Constructor Summary
ProcessorRegistry()
          Creates a new instance of ProcessorRegistry with the default Transform XML mapping.
ProcessorRegistry(org.writersforge.bellows.Datum baseMap)
          Creates a new instance of ProcessorRegistry.
 
Method Summary
 void addFallback(org.writersforge.bellows.Datum map)
          Adds a registry map to the front of the registry.
 void addOverride(org.writersforge.bellows.Datum map)
          Adds a registry map to the front of the registry.
 org.writersforge.bellows.traverse.NodeProcessor createProcessor(org.writersforge.bellows.Datum xmlOp)
          Instantiates a processor from the settings in the given Transform XML operation.
 java.lang.Class lookup(java.lang.String opName)
          Looks up a Transform XML element name in the registry and retrieves the corresponding NodeProcessor implementation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProcessorRegistry

public ProcessorRegistry()
Creates a new instance of ProcessorRegistry with the default Transform XML mapping.


ProcessorRegistry

public ProcessorRegistry(org.writersforge.bellows.Datum baseMap)
Creates a new instance of ProcessorRegistry.

Parameters:
baseMap - initial registry map
Method Detail

addOverride

public void addOverride(org.writersforge.bellows.Datum map)
Adds a registry map to the front of the registry. Will override any items in the new map that already exist in the registry.

Parameters:
map - override registry map

addFallback

public void addFallback(org.writersforge.bellows.Datum map)
Adds a registry map to the front of the registry. Will only register items that don't already exist in the registry.

Parameters:
map - fallback registry map

lookup

public java.lang.Class lookup(java.lang.String opName)
Looks up a Transform XML element name in the registry and retrieves the corresponding NodeProcessor implementation. Respects resolution ordering from overrides and fallbacks.

Parameters:
opName - the Transform XML name for the processor
Returns:
the class of the processor implementation, or null if class can't be found

createProcessor

public org.writersforge.bellows.traverse.NodeProcessor createProcessor(org.writersforge.bellows.Datum xmlOp)
Instantiates a processor from the settings in the given Transform XML operation. If the XML op does not exist in this registry, or if a valid constructor is not present in the processor class, returns a null. The processor must have a constructor with one of the following parameter lists; if a processor has more than one valid constructor overload, the registry will choose the first one it finds in the order below:
   MyProcessor (Datum xml, ProcessorRegistry registry)
   MyProcessor (Datum xml)
   MyProcessor ()
 

Parameters:
xmlOp - a Transform XML operation
Returns:
an instantiated processor or null if unable to instantiate