terp - the Codemesh Modular
Template Interpreter v1.3.309

com.codemesh.terp.eval
Class TerpRegistrarImpl

java.lang.Object
  extended by com.codemesh.terp.eval.TerpRegistrarImpl
All Implemented Interfaces:
TerpRegistrar
Direct Known Subclasses:
TerpEvaluatorImpl

public class TerpRegistrarImpl
extends java.lang.Object
implements TerpRegistrar

The default implementation of a registrar for the terp framework.


Field Summary
static TerpRegistrar GLOBAL_REGISTRAR
          The global registrar instance used by the terp framework.
protected  java.util.Map<java.lang.String,Converter> instanceConverters
           
protected  java.util.Map<java.lang.String,java.util.List<Executor<Lvalue>>> instanceLvalFactories
           
protected  java.util.Map<java.lang.String,java.util.List<Executor>> instanceOps
           
protected  java.util.Map<java.lang.String,java.util.List<Executor<Rvalue>>> instanceRvalFactories
           
protected  java.util.Map<java.lang.String,Selector> instanceSelectors
           
protected  java.util.Map<java.lang.String,Sorter> instanceSorters
           
protected  java.util.Map<java.lang.String,Transformer> instanceTransformers
           
 
Constructor Summary
TerpRegistrarImpl()
           
 
Method Summary
 TerpRegistrar getGlobalRegistrar()
          Returns the global registrar.
 Converter lookupConverter(java.lang.String name)
           
 Executor<Lvalue> lookupLvalueResolver(java.lang.String name, java.util.List<java.lang.Object> args)
          Looks up a resolver.
 Executor<Rvalue> lookupRvalueResolver(java.lang.String name, java.util.List<java.lang.Object> args)
          Looks up a resolver.
 Selector lookupSelector(java.lang.String name)
           
 Sorter lookupSorter(java.lang.String name)
           
 Transformer lookupTransformer(java.lang.String name)
           
 void registerConverter(java.lang.String name, Converter conv)
          Unregisters a previously bound variable.
 void registerExecutor(java.lang.String op, Executor exec)
          Register a custom executor with the evaluator.
 void registerLvalueResolver(java.lang.String name, Executor<Lvalue> exec)
          Register an Lvalue resolver for a specific name.
 void registerRvalueResolver(java.lang.String name, Executor<Rvalue> exec)
          Register an Rvalue resolver for a specific name.
 void registerSelector(java.lang.String name, Selector selector)
           
 void registerSorter(java.lang.String name, Sorter sorter)
           
 void registerTransformer(java.lang.String name, Transformer tx)
           
 Executor resolveExecutor(java.lang.String op, java.util.List<java.lang.Object> args)
          Locates an executor matching the given name and suitable for the given arguments.
 void unregisterConverter(java.lang.String name, Converter conv)
           
 void unregisterExecutor(java.lang.String op, Executor exec)
          Unregisters a registered executor.
 void unregisterLvalueResolver(java.lang.String op, Executor<Lvalue> exec)
          Unregister the provided Lvalue resolver.
 void unregisterRvalueResolver(java.lang.String op, Executor<Rvalue> exec)
          Unregister the provided Rvalue resolver.
 void unregisterSelector(java.lang.String name, Selector selector)
           
 void unregisterSorter(java.lang.String name, Sorter sorter)
           
 void unregisterTransformer(java.lang.String name, Transformer tx)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instanceOps

protected final java.util.Map<java.lang.String,java.util.List<Executor>> instanceOps

instanceConverters

protected final java.util.Map<java.lang.String,Converter> instanceConverters

instanceSelectors

protected final java.util.Map<java.lang.String,Selector> instanceSelectors

instanceSorters

protected final java.util.Map<java.lang.String,Sorter> instanceSorters

instanceTransformers

protected final java.util.Map<java.lang.String,Transformer> instanceTransformers

instanceLvalFactories

protected final java.util.Map<java.lang.String,java.util.List<Executor<Lvalue>>> instanceLvalFactories

instanceRvalFactories

protected final java.util.Map<java.lang.String,java.util.List<Executor<Rvalue>>> instanceRvalFactories

GLOBAL_REGISTRAR

public static final TerpRegistrar GLOBAL_REGISTRAR
The global registrar instance used by the terp framework.

Constructor Detail

TerpRegistrarImpl

public TerpRegistrarImpl()
Method Detail

getGlobalRegistrar

public TerpRegistrar getGlobalRegistrar()
Returns the global registrar. Changes to the global registrar affect all instances that resolve via the terp registry.

Specified by:
getGlobalRegistrar in interface TerpRegistrar
Returns:
the global registrar, one instance per classloader hierarchy.

registerExecutor

public void registerExecutor(java.lang.String op,
                             Executor exec)
Register a custom executor with the evaluator. Evaluators are expected to be long-lived objects that are reused for as long as the application is in need of them. Making the evaluator rather than the context the registration point for custom functionality improves overall performance.

This function might for example get invoked by an OSGi bundle registration method to register executors for operators acting on custom types.

Specified by:
registerExecutor in interface TerpRegistrar
Parameters:
op - the executor's name.
exec - the executor.

unregisterExecutor

public void unregisterExecutor(java.lang.String op,
                               Executor exec)
Unregisters a registered executor. No exception is thrown if the executor was not registered at the time this method is being called.

Specified by:
unregisterExecutor in interface TerpRegistrar
Parameters:
op - the executor's registered name.
exec - the executor.

resolveExecutor

public Executor resolveExecutor(java.lang.String op,
                                java.util.List<java.lang.Object> args)
Description copied from interface: TerpRegistrar
Locates an executor matching the given name and suitable for the given arguments.

Specified by:
resolveExecutor in interface TerpRegistrar
Parameters:
op - the executor's name.
args - the arguments passed to it.
Returns:
an executor or null if no matching executor is found.

registerLvalueResolver

public void registerLvalueResolver(java.lang.String name,
                                   Executor<Lvalue> exec)
Description copied from interface: TerpRegistrar
Register an Lvalue resolver for a specific name. An Lvalue can be used as the target for assignment operations. An Lvalue resolver is an executor that has an Lvalue as a result. It is the basic extension mechanism that allows you to extend types' capabilities with writable properties.

Specified by:
registerLvalueResolver in interface TerpRegistrar
Parameters:
name - the extension property or function name.
exec - the executor returning the Lvalue.

unregisterLvalueResolver

public void unregisterLvalueResolver(java.lang.String op,
                                     Executor<Lvalue> exec)
Description copied from interface: TerpRegistrar
Unregister the provided Lvalue resolver.

Specified by:
unregisterLvalueResolver in interface TerpRegistrar
Parameters:
op - the extension property or function name.
exec - the executor.

lookupLvalueResolver

public Executor<Lvalue> lookupLvalueResolver(java.lang.String name,
                                             java.util.List<java.lang.Object> args)
Description copied from interface: TerpRegistrar
Looks up a resolver.

Specified by:
lookupLvalueResolver in interface TerpRegistrar
Parameters:
name - the property name.
args - the arguments being passed.
Returns:
an Lvalue resolver or null.

registerRvalueResolver

public void registerRvalueResolver(java.lang.String name,
                                   Executor<Rvalue> exec)
Description copied from interface: TerpRegistrar
Register an Rvalue resolver for a specific name. An Rvalue can be dereferenced to get its value. An Rvalue resolver is an executor that has an Rvalue as a result. It is the basic extension mechanism that allows you to extend types' capabilities with readable properties or functions.

Specified by:
registerRvalueResolver in interface TerpRegistrar
Parameters:
name - the extension property or function name.
exec - the executor returning the Rvalue.

unregisterRvalueResolver

public void unregisterRvalueResolver(java.lang.String op,
                                     Executor<Rvalue> exec)
Description copied from interface: TerpRegistrar
Unregister the provided Rvalue resolver.

Specified by:
unregisterRvalueResolver in interface TerpRegistrar
Parameters:
op - the extension property or function name.
exec - the executor.

lookupRvalueResolver

public Executor<Rvalue> lookupRvalueResolver(java.lang.String name,
                                             java.util.List<java.lang.Object> args)
Description copied from interface: TerpRegistrar
Looks up a resolver.

Specified by:
lookupRvalueResolver in interface TerpRegistrar
Parameters:
name - the property name.
args - the arguments being passed.
Returns:
an Rvalue resolver or null.

registerConverter

public void registerConverter(java.lang.String name,
                              Converter conv)
Description copied from interface: TerpRegistrar
Unregisters a previously bound variable.

Specified by:
registerConverter in interface TerpRegistrar
Parameters:
name - the variable name.

unregisterConverter

public void unregisterConverter(java.lang.String name,
                                Converter conv)
Specified by:
unregisterConverter in interface TerpRegistrar

lookupConverter

public Converter lookupConverter(java.lang.String name)
Specified by:
lookupConverter in interface TerpRegistrar

registerSelector

public void registerSelector(java.lang.String name,
                             Selector selector)
Specified by:
registerSelector in interface TerpRegistrar

unregisterSelector

public void unregisterSelector(java.lang.String name,
                               Selector selector)
Specified by:
unregisterSelector in interface TerpRegistrar

lookupSelector

public Selector lookupSelector(java.lang.String name)
Specified by:
lookupSelector in interface TerpRegistrar

registerSorter

public void registerSorter(java.lang.String name,
                           Sorter sorter)
Specified by:
registerSorter in interface TerpRegistrar

unregisterSorter

public void unregisterSorter(java.lang.String name,
                             Sorter sorter)
Specified by:
unregisterSorter in interface TerpRegistrar

lookupSorter

public Sorter lookupSorter(java.lang.String name)
Specified by:
lookupSorter in interface TerpRegistrar

registerTransformer

public void registerTransformer(java.lang.String name,
                                Transformer tx)
Specified by:
registerTransformer in interface TerpRegistrar

unregisterTransformer

public void unregisterTransformer(java.lang.String name,
                                  Transformer tx)
Specified by:
unregisterTransformer in interface TerpRegistrar

lookupTransformer

public Transformer lookupTransformer(java.lang.String name)
Specified by:
lookupTransformer in interface TerpRegistrar

terp - the Codemesh Modular
Template Interpreter v1.3.309

Copyright © 2008-2012 by Codemesh, Inc. All Rights Reserved.