terp - the Codemesh Modular
Template Interpreter v1.3.304

com.codemesh.terp.api
Interface Executor<T>

All Known Implementing Classes:
Ant.AntExecutor, ApplyExecutor, Ar.ArExecutor, BatchExecutor, Bc.BcExecutor, BooleanAnd, BooleanNot, BooleanOr, BuiltinRange, Builtins.Size, CodegenExecutor, CollectionAdder, CollectionSubtracter, ComparableComparator, Conditional, Cpp.AccExecutor, Cpp.CppExecutor, Cpp.GccExecutor, Cpp.IccExecutor, Cpp.MsvcExecutor, Cpp.QccExecutor, Cpp.SunccExecutor, Cpp.XlcExecutor, Csharp.CsharpExecutor, DPAnalysis.DPAnalysisExecutor, Dummy, Emitter, Equals, EvalExecutor, Executor.AbstractExecutor, Executor.ForMethod, Expander, Exporter, FileContentsGetter, FileContentsSetter, FirstGetter, FirstSetter, Gprof.GprofExecutor, HelpExecutor, Importer, IndexOperatorGetter, IndexOperatorSetter, IsFileTypeExecutor, JarExecutor, JavacExecutor, JavadocExecutor, JavaExecutor, JavaToolExecutor, LastGetter, LastSetter, Lib.LibExecutor, LvalueAssignment, LvalueDecrement, LvalueDivideAssignment, LvalueIncrement, LvalueMinusAssignment, LvalueModuloAssignment, LvalueMultiplyAssignment, LvaluePlusAssignment, ManifestTool.ManifestToolExecutor, MapAdder, NotEquals, NumericAdder, NumericBitwiseAnd, NumericBitwiseNot, NumericBitwiseOr, NumericComparator, NumericDivider, NumericModulo, NumericMultiplier, NumericNegator, NumericSubtracter, ProcessExecutor, Reg.RegExecutor, Reg.RegQueryValue, ShellExecutor, StringMatcher, StringPlusAnythingAdder, TextMultiplier, VersionComparator, VisualBasic.VbExecutor, Xargs.XargsExecutor

public interface Executor<T>

The interface implemented by all executors that take 0 to n arguments.

Executors are the primary abstraction for active or executable terp elements (member functions, terp global functions, terp operators, external tools). While nothing prevents you from instantiating an executor and then directly calling one of its execute() methods, execution within the terp framework is handled a bit differently.

Executors representing functions or operators have to be registered with the terp framework via a TerpRegistrar. The framework performs this registration step for you for the built-in operators and types. Registered xecutors are maintained in a hashtable that maps each executor name to a list of executors. That's right, one name can have multiple executors registered to it. When figuring out what to do when a function or an operator is invoked with a set of arguments, the following steps take place.

  1. the function's or operator's name is used as the primary key to look up the list of registered executors.
  2. the list is traversed in natural order until the invocation of matches(List) returns true for the invocation arguments.
  3. if an executor was found, its execute(List) method is invoked, otherwise nothing happens and the operation results in null.
In essence, this means that the terp framework gives you the ability to overload functions and operators based on argument types.

The executors themselves are not named because each executor might be known under more than one name and this allows us to reuse the same instance in these cases.

Since:
1.0.0
Author:
Alexander R Krapf

Nested Class Summary
static class Executor.AbstractExecutor<T>
          A convenient base class for your own custom executors.
static class Executor.ForMethod
           
 
Method Summary
 T execute(java.util.List<java.lang.Object> args)
          Performs the executor's action on the given arguments.
 T execute(java.util.List<java.lang.Object> args, TerpEvaluator eval, TerpContext ctx)
          Performs the executor's action on the given arguments in the given context.
 boolean matches(java.util.List<java.lang.Object> args)
          Returns true if the executor applies to the given arguments.
 

Method Detail

matches

boolean matches(java.util.List<java.lang.Object> args)
Returns true if the executor applies to the given arguments. Typically, your custom executor will implement this method to check for the proper number of arguments and the proper argument types.

Parameters:
args - the arguments passed to the executor.
Returns:
true if the executor knows how to handle the given arguments, false otherwise.

execute

T execute(java.util.List<java.lang.Object> args)
Performs the executor's action on the given arguments. Typically, this method is implemented in terms of execute(List,TerpEvaluator,TerpContext).

Parameters:
args - the arguments.
Returns:
the execution result.

execute

T execute(java.util.List<java.lang.Object> args,
          TerpEvaluator eval,
          TerpContext ctx)
Performs the executor's action on the given arguments in the given context. Typically, your custom executor will implement this method to provide its core functionality.

Parameters:
args - the arguments.
eval - the evaluator to use. Can frequently be null.
ctx - the context in which the execution occurs. Can frequently be null.
Returns:
the execution result.

terp - the Codemesh Modular
Template Interpreter v1.3.304

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