org.formulacompiler.spreadsheet
Class SpreadsheetCompiler

java.lang.Object
  extended by org.formulacompiler.runtime.FormulaRuntime
      extended by org.formulacompiler.compiler.FormulaCompiler
          extended by org.formulacompiler.spreadsheet.SpreadsheetCompiler

public class SpreadsheetCompiler
extends FormulaCompiler

Static class defining factory methods for the various elements of AFC. This class is extends by FormulaCompiler which provides factory methods for the base model-compiler-only elements. You normally use newEngineBuilder() to get an engine builder with which to compile a new engine from a spreadsheet.

Author:
peo

Field Summary
 
Fields inherited from class org.formulacompiler.compiler.FormulaCompiler
BIGDECIMAL_SCALE8, BIGDECIMAL_SCALE9, BIGDECIMAL128, BIGDECIMAL32, BIGDECIMAL64, DEFAULT_NUMERIC_TYPE, DOUBLE, LONG, LONG_SCALE4, LONG_SCALE6
 
Fields inherited from class org.formulacompiler.runtime.FormulaRuntime
UNDEFINED_SCALE
 
Constructor Summary
SpreadsheetCompiler()
           
 
Method Summary
static SaveableEngine compileEngine(SpreadsheetBinding _binding, NumericType _numericType, boolean _fullCaching)
          Same as compileEngine(SpreadsheetBinding, NumericType, Class, Method, boolean), leaving the factory class and method unspecified.
static SaveableEngine compileEngine(SpreadsheetBinding _binding, NumericType _numericType, java.lang.Class _factoryClass, java.lang.reflect.Method _factoryMethod, boolean _fullCaching)
          Returns a new instance of a spreadsheet compiler, which is used to compile a spreadsheet representation, together with a binding associating cells with input and output methods, to an excecutable computation engine.
static Spreadsheet loadSpreadsheet(java.io.File _file)
          Loads a spreadsheet from a file and constructs an internal representation of it.
static Spreadsheet loadSpreadsheet(java.io.File _file, SpreadsheetLoader.Config _config)
          Loads a spreadsheet from a file and constructs an internal representation of it.
static Spreadsheet loadSpreadsheet(java.lang.String _originalFileName, java.io.InputStream _stream)
          Loads a spreadsheet from a file and constructs an internal representation of it.
static Spreadsheet loadSpreadsheet(java.lang.String _originalFileName, java.io.InputStream _stream, SpreadsheetLoader.Config _config)
          Loads a spreadsheet from a file and constructs an internal representation of it.
static EngineBuilder newEngineBuilder()
          Returns a new instance of an engine builder, which handles the most typical use-cases for compiling a spreadsheet to an computation engine.
static SpreadsheetBinder newSpreadsheetBinder(SpreadsheetBinder.Config _config)
          Returns a new instance of a spreadsheet binder, which is used to associate input and output cells of a spreadsheet with Java methods.
static SpreadsheetBinder newSpreadsheetBinder(Spreadsheet _spreadsheet, java.lang.Class _inputClass, java.lang.Class _outputClass)
          Returns a new instance of a spreadsheet binder, which is used to associate input and output cells of a spreadsheet with Java methods.
static SpreadsheetBuilder newSpreadsheetBuilder()
          Returns a new instance of a spreadsheet builder, which can be used to build a spreadsheet representation in memory from scratch.
static SpreadsheetByNameBinder newSpreadsheetByNameBinder(SpreadsheetBinder _binder)
          Returns a new instance of a spreadsheet binder utility class, which uses reflection and cell names defined in the spreadsheet to associate cells with methods.
static SpreadsheetByNameBinder newSpreadsheetByNameBinder(SpreadsheetByNameBinder.Config _config)
          Returns a new instance of a spreadsheet binder utility class, which uses reflection and cell names defined in the spreadsheet to associate cells with methods.
static SpreadsheetNameCreator newSpreadsheetCellNameCreator(Spreadsheet.Sheet _sheet)
          Returns a new instance of a spreadsheet cell name creator utility class, which names spreadsheet cells according to their row titles.
static SpreadsheetToEngineCompiler newSpreadsheetCompiler(SpreadsheetToEngineCompiler.Config _config)
          Returns a new instance of a spreadsheet compiler, which is used to compile a spreadsheet representation, together with a binding associating cells with input and output methods, to an excecutable computation engine.
static SpreadsheetSaver newSpreadsheetSaver(SpreadsheetSaver.Config _config)
          Returns a new instance of a spreadsheet saver, which is used to save a spreadsheet representation to a spreadsheet file (to give users a something to start with).
static void saveSpreadsheet(Spreadsheet _model, java.io.File _outputFile, java.io.File _templateFileOrNull)
          Saves a spreadsheet model to a new spreadsheet file.
 
Methods inherited from class org.formulacompiler.compiler.FormulaCompiler
getNumericType, getNumericType, getNumericType, getNumericType, newCallFrame
 
Methods inherited from class org.formulacompiler.runtime.FormulaRuntime
loadEngine, loadEngine
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpreadsheetCompiler

public SpreadsheetCompiler()
Method Detail

newEngineBuilder

public static EngineBuilder newEngineBuilder()
Returns a new instance of an engine builder, which handles the most typical use-cases for compiling a spreadsheet to an computation engine. You will rarely need any of the other factory methods of this class.

Returns:
the new instance.

loadSpreadsheet

public static Spreadsheet loadSpreadsheet(java.io.File _file)
                                   throws java.io.FileNotFoundException,
                                          java.io.IOException,
                                          SpreadsheetException
Loads a spreadsheet from a file and constructs an internal representation of it.

Parameters:
_file - is the file to load.
Returns:
the loaded spreadsheet representation.
Throws:
java.io.FileNotFoundException
java.io.IOException
SpreadsheetException

loadSpreadsheet

public static Spreadsheet loadSpreadsheet(java.io.File _file,
                                          SpreadsheetLoader.Config _config)
                                   throws java.io.FileNotFoundException,
                                          java.io.IOException,
                                          SpreadsheetException
Loads a spreadsheet from a file and constructs an internal representation of it.

Parameters:
_file - is the file to load.
_config - configures the loader; can be set to null.
Returns:
the loaded spreadsheet representation.
Throws:
java.io.FileNotFoundException
java.io.IOException
SpreadsheetException

loadSpreadsheet

public static Spreadsheet loadSpreadsheet(java.lang.String _originalFileName,
                                          java.io.InputStream _stream)
                                   throws java.io.IOException,
                                          SpreadsheetException
Loads a spreadsheet from a file and constructs an internal representation of it. Like loadSpreadsheet(String, InputStream, org.formulacompiler.spreadsheet.SpreadsheetLoader.Config) with _config set to null.

Parameters:
_originalFileName - is the name of the spreadsheet file to which the input stream corresponds.
_stream - is the stream from which to load the spreadsheet.
Returns:
the loaded spreadsheet representation.
Throws:
java.io.IOException
SpreadsheetException

loadSpreadsheet

public static Spreadsheet loadSpreadsheet(java.lang.String _originalFileName,
                                          java.io.InputStream _stream,
                                          SpreadsheetLoader.Config _config)
                                   throws java.io.IOException,
                                          SpreadsheetException
Loads a spreadsheet from a file and constructs an internal representation of it.

Parameters:
_originalFileName - is the name of the spreadsheet file to which the input stream corresponds.
_stream - is the stream from which to load the spreadsheet.
_config - configures the loader; can be set to null.
Returns:
the loaded spreadsheet representation.
Throws:
java.io.IOException
SpreadsheetException

newSpreadsheetBuilder

public static SpreadsheetBuilder newSpreadsheetBuilder()
Returns a new instance of a spreadsheet builder, which can be used to build a spreadsheet representation in memory from scratch.

Returns:
the new instance.

saveSpreadsheet

public static void saveSpreadsheet(Spreadsheet _model,
                                   java.io.File _outputFile,
                                   java.io.File _templateFileOrNull)
                            throws java.io.IOException,
                                   SpreadsheetException
Saves a spreadsheet model to a new spreadsheet file. Use this primarily to build an initial spreadsheet file for users wanting to customize a particular aspect of your application using AFC. See the tutorial for details.

Parameters:
_model - is the internal spreadsheet model that defines the file to be written. Use newSpreadsheetBuilder() to build this model.
_outputFile - is the spreadsheet file to be written. Its extension is used to determine the file format to write (.xls for Excel, etc.).
_templateFileOrNull - is an optional template file. If not null, AFC uses it to format the generated cells (again, see the tutorial for details).
Throws:
java.io.IOException
SpreadsheetException

newSpreadsheetSaver

public static SpreadsheetSaver newSpreadsheetSaver(SpreadsheetSaver.Config _config)
Returns a new instance of a spreadsheet saver, which is used to save a spreadsheet representation to a spreadsheet file (to give users a something to start with).

Parameters:
_config - contains the configuration for the new instance.
Returns:
the new instance.

newSpreadsheetBinder

public static SpreadsheetBinder newSpreadsheetBinder(Spreadsheet _spreadsheet,
                                                     java.lang.Class _inputClass,
                                                     java.lang.Class _outputClass)
Returns a new instance of a spreadsheet binder, which is used to associate input and output cells of a spreadsheet with Java methods.

Parameters:
_spreadsheet - see SpreadsheetBinder.Config.spreadsheet.
_inputClass - see SpreadsheetBinder.Config.inputClass.
_outputClass - see SpreadsheetBinder.Config.outputClass.
Returns:
the new instance.
See Also:
newSpreadsheetByNameBinder(SpreadsheetBinder)

newSpreadsheetBinder

public static SpreadsheetBinder newSpreadsheetBinder(SpreadsheetBinder.Config _config)
Returns a new instance of a spreadsheet binder, which is used to associate input and output cells of a spreadsheet with Java methods.

Parameters:
_config - contains the configuration data for the new instance.
Returns:
the new instance.
See Also:
newSpreadsheetByNameBinder(org.formulacompiler.spreadsheet.SpreadsheetByNameBinder.Config)

newSpreadsheetByNameBinder

public static SpreadsheetByNameBinder newSpreadsheetByNameBinder(SpreadsheetBinder _binder)
Returns a new instance of a spreadsheet binder utility class, which uses reflection and cell names defined in the spreadsheet to associate cells with methods.

Parameters:
_binder - see SpreadsheetByNameBinder.Config.binder.
Returns:
the new instance.

newSpreadsheetByNameBinder

public static SpreadsheetByNameBinder newSpreadsheetByNameBinder(SpreadsheetByNameBinder.Config _config)
Returns a new instance of a spreadsheet binder utility class, which uses reflection and cell names defined in the spreadsheet to associate cells with methods.

Parameters:
_config - contains the configuration for the new instance.
Returns:
the new instance.

newSpreadsheetCellNameCreator

public static SpreadsheetNameCreator newSpreadsheetCellNameCreator(Spreadsheet.Sheet _sheet)
Returns a new instance of a spreadsheet cell name creator utility class, which names spreadsheet cells according to their row titles. This is typically used before applying a SpreadsheetByNameBinder.

Parameters:
_sheet - is the single sheet of a spreadsheet representation in which to name cells.
Returns:
the new instance.

compileEngine

public static SaveableEngine compileEngine(SpreadsheetBinding _binding,
                                           NumericType _numericType,
                                           java.lang.Class _factoryClass,
                                           java.lang.reflect.Method _factoryMethod,
                                           boolean _fullCaching)
                                    throws CompilerException,
                                           EngineException
Returns a new instance of a spreadsheet compiler, which is used to compile a spreadsheet representation, together with a binding associating cells with input and output methods, to an excecutable computation engine.

Parameters:
_binding - see SpreadsheetToEngineCompiler.Config.binding.
_numericType - see SpreadsheetToEngineCompiler.Config.numericType.
_factoryClass - see SpreadsheetToEngineCompiler.Config.factoryClass.
_factoryMethod - see SpreadsheetToEngineCompiler.Config.factoryMethod.
_fullCaching - see SpreadsheetToEngineCompiler.Config.fullCaching.
Returns:
the new instance.
Throws:
CompilerException
EngineException

compileEngine

public static SaveableEngine compileEngine(SpreadsheetBinding _binding,
                                           NumericType _numericType,
                                           boolean _fullCaching)
                                    throws CompilerException,
                                           EngineException
Same as compileEngine(SpreadsheetBinding, NumericType, Class, Method, boolean), leaving the factory class and method unspecified.

Throws:
CompilerException
EngineException

newSpreadsheetCompiler

public static SpreadsheetToEngineCompiler newSpreadsheetCompiler(SpreadsheetToEngineCompiler.Config _config)
Returns a new instance of a spreadsheet compiler, which is used to compile a spreadsheet representation, together with a binding associating cells with input and output methods, to an excecutable computation engine.

Parameters:
_config - contains the configuration for the new instance.
Returns:
the new instance.