Source for org.jfree.formula.typing.DefaultType

   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: DefaultType.java 3521 2007-10-16 10:55:14Z tmorgner $
  28:  * ------------
  29:  * (C) Copyright 2006-2007, by Pentaho Corporation.
  30:  */
  31: package org.jfree.formula.typing;
  32: 
  33: import java.util.HashMap;
  34: import java.util.HashSet;
  35: 
  36: /**
  37:  * Creation-Date: 02.11.2006, 09:37:54
  38:  *
  39:  * @author Thomas Morgner
  40:  */
  41: public abstract class DefaultType implements Type
  42: {
  43:   private HashSet flags;
  44:   private HashMap properties;
  45:   private boolean locked;
  46: 
  47:   protected DefaultType()
  48:   {
  49:   }
  50: 
  51:   public boolean isLocked()
  52:   {
  53:     return locked;
  54:   }
  55: 
  56:   public void lock()
  57:   {
  58:     this.locked = true;
  59:   }
  60: 
  61:   public void addFlag(final String name)
  62:   {
  63:     if (locked)
  64:     {
  65:       throw new IllegalStateException();
  66:     }
  67:     if (flags == null)
  68:     {
  69:       flags = new HashSet();
  70:     }
  71:     flags.add(name);
  72:   }
  73: 
  74:   public boolean isFlagSet(final String name)
  75:   {
  76:     if (flags == null)
  77:     {
  78:       return false;
  79:     }
  80:     return flags.contains(name);
  81:   }
  82: 
  83:   public void setProperty(final String name, final Object value)
  84:   {
  85:     if (locked)
  86:     {
  87:       throw new IllegalStateException();
  88:     }
  89:     if (properties == null)
  90:     {
  91:       properties = new HashMap();
  92:     }
  93:     properties.put(name, value);
  94:   }
  95: 
  96:   public Object getProperty(final String name)
  97:   {
  98:     // The type system has no properties yet. This is done later, when we
  99:     // deal with real meta-data
 100:     if (properties == null)
 101:     {
 102:       return null;
 103:     }
 104:     return properties.get(name);
 105:   }
 106: }