Source for org.jfree.formula.DefaultFormulaContext

   1: /**
   2:  * =========================================
   3:  * LibFormula : a free Java formula library
   4:  * =========================================
   5:  *
   6:  * Project Info:  http://reporting.pentaho.org/libformula/
   7:  *
   8:  * (C) Copyright 2006-2007, by Pentaho Corporation and Contributors.
   9:  *
  10:  * This library is free software; you can redistribute it and/or modify it under the terms
  11:  * of the GNU Lesser General Public License as published by the Free Software Foundation;
  12:  * either version 2.1 of the License, or (at your option) any later version.
  13:  *
  14:  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  15:  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16:  * See the GNU Lesser General Public License for more details.
  17:  *
  18:  * You should have received a copy of the GNU Lesser General Public License along with this
  19:  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  20:  * Boston, MA 02111-1307, USA.
  21:  *
  22:  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  23:  * in the United States and other countries.]
  24:  *
  25:  *
  26:  * ------------
  27:  * $Id: DefaultFormulaContext.java 3521 2007-10-16 10:55:14Z tmorgner $
  28:  * ------------
  29:  * (C) Copyright 2006-2007, by Pentaho Corporation.
  30:  */
  31: package org.jfree.formula;
  32: 
  33: import java.util.HashMap;
  34: 
  35: import org.jfree.formula.function.DefaultFunctionRegistry;
  36: import org.jfree.formula.function.FunctionRegistry;
  37: import org.jfree.formula.operators.DefaultOperatorFactory;
  38: import org.jfree.formula.operators.OperatorFactory;
  39: import org.jfree.formula.typing.DefaultTypeRegistry;
  40: import org.jfree.formula.typing.Type;
  41: import org.jfree.formula.typing.TypeRegistry;
  42: import org.jfree.formula.typing.coretypes.AnyType;
  43: import org.jfree.util.Configuration;
  44: 
  45: /**
  46:  * Creation-Date: 31.10.2006, 16:32:32
  47:  *
  48:  * @author Thomas Morgner
  49:  */
  50: public class DefaultFormulaContext implements FormulaContext
  51: {
  52:   private DefaultTypeRegistry typeRegistry;
  53:   private DefaultFunctionRegistry functionRegistry;
  54:   private OperatorFactory operatorFactory;
  55:   private DefaultLocalizationContext localizationContext;
  56:   private Configuration config;
  57:   private HashMap references;
  58: 
  59:   public DefaultFormulaContext()
  60:   {
  61:     this(LibFormulaBoot.getInstance().getGlobalConfig());
  62:   }
  63: 
  64:   public DefaultFormulaContext(final Configuration config)
  65:   {
  66:     this.config = config;
  67:     localizationContext = new DefaultLocalizationContext();
  68:     localizationContext.initialize(config);
  69:     typeRegistry = new DefaultTypeRegistry();
  70:     typeRegistry.initialize(config, this);
  71:     functionRegistry = new DefaultFunctionRegistry();
  72:     functionRegistry.initialize(config);
  73:     operatorFactory = new DefaultOperatorFactory();
  74:     operatorFactory.initalize(config);
  75:   }
  76: 
  77:   public OperatorFactory getOperatorFactory()
  78:   {
  79:     return operatorFactory;
  80:   }
  81: 
  82:   public void defineReference(final Object name, final Object value)
  83:   {
  84:     if (references == null)
  85:     {
  86:       references = new HashMap();
  87:     }
  88:     references.put(name, value);
  89:   }
  90: 
  91:   public Object resolveReference(final Object name)
  92:   {
  93:     if (references == null)
  94:     {
  95:       return null;
  96:     }
  97:     return references.get(name);
  98:   }
  99: 
 100:   public Configuration getConfiguration()
 101:   {
 102:     return config;
 103:   }
 104: 
 105:   public FunctionRegistry getFunctionRegistry()
 106:   {
 107:     return functionRegistry;
 108:   }
 109: 
 110:   public Type resolveReferenceType(final Object name)
 111:   {
 112:     return AnyType.TYPE;
 113:   }
 114: 
 115:   public TypeRegistry getTypeRegistry()
 116:   {
 117:     return typeRegistry;
 118:   }
 119: 
 120:   public LocalizationContext getLocalizationContext()
 121:   {
 122:     return localizationContext;
 123:   }
 124: 
 125:   public boolean isReferenceDirty(final Object name)
 126:   {
 127:     return true;
 128:   }
 129: }