|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface EngineBuilder
Simplified interface to AFC's spreadsheet compiler functionality for the most typical use-cases. Typical example:
private RebateComputationFactory compileFactoryFromSpreadsheet( File _sheetFile ) throws Exception { EngineBuilder builder = SpreadsheetCompiler.newEngineBuilder(); builder.loadSpreadsheet( _sheetFile ); builder.setFactoryClass( RebateComputationFactory.class ); builder.bindAllByName(); builder.failIfByNameBindingLeftNamedCellsUnbound(); Engine engine = builder.compile(); return (RebateComputationFactory) engine.getComputationFactory(); }
Please refer to the tutorial for details.
This interface is an API only. Do not implement it yourself.
Nested Class Summary | |
---|---|
static interface |
EngineBuilder.Factory
Factory interface for ImplementationLocator.getInstance(Class) . |
Method Summary | |
---|---|
boolean |
areAnyNamesDefined()
Checks whether the spreadsheet contains any named cells or ranges. |
void |
bindAllByName()
Uses reflection to bind all named cells in the spreadsheet to corresponding methods on the input and output types. |
void |
bindAllByName(java.lang.String _inputPrefix,
java.lang.String _outputPrefix)
Uses reflection to bind all named cells in the spreadsheet to corresponding methods on the input and output types, provided the cell names have the specified prefixes. |
SaveableEngine |
compile()
Compiles an executable computation engine from the inputs to this builder. |
void |
createCellNamesFromRowTitles()
Uses a SpreadsheetNameCreator to create cell names from row titles in the first sheet
of the spreadsheet. |
void |
failIfByNameBindingLeftNamedCellsUnbound()
Raises an exception if there are named cells that were not bound. |
void |
failIfByNameBindingLeftNamedCellsUnbound(java.lang.String _inputPrefix,
java.lang.String _outputPrefix)
Raises an exception if there are named cells with one of the given prefixes that were not bound. |
SpreadsheetByNameBinder |
getByNameBinder()
Returns the SpreadsheetByNameBinder used by this engine builder to associate cells
with Java methods. |
Computation.Config |
getCompileTimeConfig()
Let's you control the compile-time locale and timezone configuration by setting fields of the returned object. |
boolean |
getCompileToReadableCode()
Controls whether AFC should attempt to compile more readable code (when decompiled), possibly at the expense of engine size and performance. |
boolean |
getComputationListenerEnabled()
Controls whether AFC should compile the computation with support for CellComputationListener . |
ComputationMode |
getComputationMode()
Returns the computation mode to be used for compiled engines. |
ConstantExpressionOptimizationListener |
getConstantExpressionOptimizationListener()
Returns a listener that receives notifications about events during compilation process, if any. |
java.lang.Class |
getFactoryClass()
Returns the application-specific type to be used for the generated factory. |
java.lang.reflect.Method |
getFactoryMethod()
Returns the application-specific factory method. |
boolean |
getFullCaching()
Indicates whether AFC should compile the computation with full internal caching of values, or only (usually minimal) caching at its own discretion. |
java.lang.Class |
getInputClass()
Returns the application-specific type defining the methods which input cells can call. |
NumericType |
getNumericType()
Returns the numeric type used by computations compiled by this builder. |
java.lang.Class |
getOutputClass()
Returns the application-specific type defining the methods which output cells can implement. |
java.lang.ClassLoader |
getParentClassLoaderForEngine()
Returns the parent class loader used for the compiled engine (which is itself class loader). |
SpreadsheetBinder.Section |
getRootBinder()
Returns the root of the SpreadsheetBinder used by this engine builder to associate
cells with Java methods. |
Spreadsheet |
getSpreadsheet()
Gets the spreadsheet representation that this builder compiles. |
void |
loadSpreadsheet(java.io.File _file)
Loads the input spreadsheet from a file. |
CallFrame |
newCallFrame(java.lang.reflect.Method _method,
java.lang.Object... _args)
Constructs a call, possibly the initial call in a chain of calls. |
void |
setCompileTimeConfig(Computation.Config _value)
Let's you replace the entire compile-time configuration in one go. |
void |
setCompileToReadableCode(boolean _value)
Controls whether AFC should attempt to compile more readable code (when decompiled), possibly at the expense of engine size and performance. |
void |
setComputationListenerEnabled(boolean _enabled)
Controls whether AFC should compile the computation with support for CellComputationListener . |
void |
setComputationMode(ComputationMode _computationMode)
Tells AFC to calculate expressions as for example Excel or OpenOffice does. |
void |
setConstantExpressionOptimizationListener(ConstantExpressionOptimizationListener _listener)
Sets a listener that receives notifications about events during compilation process. |
void |
setFactoryClass(java.lang.Class _class)
Sets either an application-specific class from which to descend the generated computation factory, or an application-specific interface which the generated factory should implement. |
void |
setFactoryMethod(java.lang.reflect.Method _factoryMethod)
Sets the application-specific method of the given factory type, setFactoryClass(Class) , which AFC should implement to return new computation
instances. |
void |
setFullCaching(boolean _enabled)
Controls whether AFC should compile the computation with full internal caching of values, or only (usually minimal) caching at its own discretion. |
void |
setInputClass(java.lang.Class _inputClass)
Sets the application-specific type defining the methods which input cells can call. |
void |
setLoadAllCellValues(boolean _value)
Controls whether Spreadsheet.Cell.getValue() should return valid values instead of null
for computed cells. |
void |
setNumericType(NumericType _type)
Sets the numeric type to be used by computations compiled by this builder. |
void |
setOutputClass(java.lang.Class _outputClass)
Sets the application-specific type defining the methods output cells can implement. |
void |
setParentClassLoaderForEngine(java.lang.ClassLoader _value)
Sets the parent class loader to be used for the compiled engine (which is itself a class loader). |
void |
setSpreadsheet(Spreadsheet _sheet)
Sets the spreadsheet representation that this builder compiles. |
Method Detail |
---|
NumericType getNumericType()
void setNumericType(NumericType _type)
See the tutorial for details.
ComputationMode getComputationMode()
null
then a default computation mode for a spreadsheet source will be used.
null
otherwise.void setComputationMode(ComputationMode _computationMode)
_computationMode
- the computation mode to be used for compiled engines.Spreadsheet getSpreadsheet()
loadSpreadsheet(File)
.
void setSpreadsheet(Spreadsheet _sheet)
SpreadsheetCompiler
,
or after having constructed the spreadsheet in-memory using a SpreadsheetBuilder
.
_sheet
- is the spreadsheet representation to use as input for spreadsheet compilation.loadSpreadsheet(File)
void loadSpreadsheet(java.io.File _file) throws java.io.FileNotFoundException, java.io.IOException, SpreadsheetException
_file
- is the spreadsheet file to load.
java.io.FileNotFoundException
java.io.IOException
SpreadsheetException
setSpreadsheet(Spreadsheet)
,
setLoadAllCellValues(boolean)
void setLoadAllCellValues(boolean _value)
Spreadsheet.Cell.getValue()
should return valid values instead of null
for computed cells. The default is false
.
loadSpreadsheet(File)
java.lang.Class getInputClass()
setInputClass(Class)
void setInputClass(java.lang.Class _inputClass)
public
. Can only be left null
if a factory type is provided (see
setFactoryClass(Class)
), from which it is then inferred. If the factory method is
provided, then this class must be assignable from the factory method's single argument.
See the tutorial for details.
setFactoryMethod(Method)
java.lang.Class getOutputClass()
setOutputClass(Class)
void setOutputClass(java.lang.Class _outputClass)
public
. Can only be left null
if a factory type is provided (see setFactoryClass(Class)
), from which it is then
inferred. If the factory method is set, then the factory method's return type must be
assignable from this class.
See the tutorial for details.
setFactoryMethod(Method)
java.lang.Class getFactoryClass()
setFactoryClass(Class)
void setFactoryClass(java.lang.Class _class)
public
. Can be left null
. If set, it must be public
and have
at most a single abstract method.
If you don't specify the factory method, setFactoryMethod(Method)
, then AFC infers
it as the sole abstract method, or else the first overridable method of the type that has the
proper application-specific computation factory signature.
See the tutorial for details.
java.lang.reflect.Method getFactoryMethod()
setFactoryMethod(Method)
void setFactoryMethod(java.lang.reflect.Method _factoryMethod)
setFactoryClass(Class)
, which AFC should implement to return new computation
instances. Must be public
and have a single parameter of the input type of the
spreadsheet binding, and return the output type of the spreadsheet binding.
If you specify the factory type, then this must be a method of it. If not, then the factory type is taken to be the declaring type of this method.
If you don't specify the input and output types, then they are inferred from this factory method. If you do, then they must be compatible with the type of the single argument and the return type of this factory method, respectively. More precisely, the input type must be assignable from the type of the single argument, and the return type must be assignable from the output type.
See the tutorial for details.
boolean getFullCaching()
setFullCaching(boolean)
void setFullCaching(boolean _enabled)
getFullCaching()
boolean areAnyNamesDefined()
void createCellNamesFromRowTitles()
SpreadsheetNameCreator
to create cell names from row titles in the first sheet
of the spreadsheet. This method is called by bindAllByName()
automatically if
areAnyNamesDefined()
returns false
.
See the tutorial for details.
SpreadsheetBinder.Section getRootBinder() throws CompilerException
SpreadsheetBinder
used by this engine builder to associate
cells with Java methods. You only need to access it if neither the behaviour of
bindAllByName()
, nor that of the getByNameBinder()
is sufficient for you.
CompilerException
CallFrame newCallFrame(java.lang.reflect.Method _method, java.lang.Object... _args)
_method
- is the method to be called._args
- is the list of arguments for the method's parameters.FormulaCompiler.newCallFrame(Method, Object...)
SpreadsheetByNameBinder getByNameBinder() throws CompilerException
SpreadsheetByNameBinder
used by this engine builder to associate cells
with Java methods. You only need to access it if the behaviour of bindAllByName()
is
not sufficient for you.
CompilerException
void bindAllByName() throws CompilerException
xy()
).getXY()
and xy()
to cell "XY").See the tutorial for details.
Here's what this method does:
if (!areAnyNamesDefined()) { createCellNamesFromRowTitles(); } SpreadsheetByNameBinder bn = getByNameBinder(); bn.outputs().bindAllMethodsToNamedCells(); bn.inputs().bindAllNamedCellsToMethods();
CompilerException
bindAllByName(String, String)
,
failIfByNameBindingLeftNamedCellsUnbound()
void bindAllByName(java.lang.String _inputPrefix, java.lang.String _outputPrefix) throws CompilerException
See the tutorial for details.
Here's what this method does:
if (!areAnyNamesDefined()) { createCellNamesFromRowTitles(); } SpreadsheetByNameBinder bn = getByNameBinder(); bn.outputs().bindAllMethodsToPrefixedNamedCells( _outputPrefix ); bn.inputs().bindAllPrefixedNamedCellsToMethods( _inputPrefix );
_inputPrefix
- is what cell names used for input methods must start with._outputPrefix
- is what cell names used for output methods must start with.
CompilerException
bindAllByName()
,
failIfByNameBindingLeftNamedCellsUnbound()
void failIfByNameBindingLeftNamedCellsUnbound() throws CompilerException
SpreadsheetException.NameNotFound
- if there is an unbound name.
CompilerException
bindAllByName()
,
getByNameBinder()
void failIfByNameBindingLeftNamedCellsUnbound(java.lang.String _inputPrefix, java.lang.String _outputPrefix) throws CompilerException
_inputPrefix
- is what cell names used for input methods must start with._outputPrefix
- is what cell names used for output methods must start with.
SpreadsheetException.NameNotFound
- if there is an unbound name.
CompilerException
bindAllByName()
,
getByNameBinder()
java.lang.ClassLoader getParentClassLoaderForEngine()
ClassLoader.getSystemClassLoader()
if the value was never modified, or else
the value you have last set.setParentClassLoaderForEngine(ClassLoader)
,
compile()
void setParentClassLoaderForEngine(java.lang.ClassLoader _value)
_value
- is the new parent class loader. It probably never makes sense to pass
null
here.getParentClassLoaderForEngine()
,
compile()
Computation.Config getCompileTimeConfig()
Please refer to the tutorial for details.
null
.setCompileTimeConfig(Computation.Config)
void setCompileTimeConfig(Computation.Config _value)
_value
- is the new configuration; must not be null
.getCompileTimeConfig()
boolean getCompileToReadableCode()
true
means make more readable, false
means make more efficient
(default).void setCompileToReadableCode(boolean _value)
_value
- : true
means make more readable, false
means make more efficient
(default).boolean getComputationListenerEnabled()
CellComputationListener
.
true
if CellComputationListener
will be supported.
The default is false
.CellComputationListener
,
Computation.Config.cellComputationListener
void setComputationListenerEnabled(boolean _enabled)
CellComputationListener
.
_enabled
- if true
then CellComputationListener
will be supported. The default is false
.CellComputationListener
,
Computation.Config.cellComputationListener
ConstantExpressionOptimizationListener getConstantExpressionOptimizationListener()
void setConstantExpressionOptimizationListener(ConstantExpressionOptimizationListener _listener)
_listener
- compilation events listewner.SaveableEngine compile() throws CompilerException, EngineException
See the tutorial for details.
CompilerException
EngineException
loadSpreadsheet(File)
,
setInputClass(Class)
,
setOutputClass(Class)
,
setFactoryClass(Class)
,
setFullCaching(boolean)
,
bindAllByName()
,
setParentClassLoaderForEngine(ClassLoader)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |