001: package murlen.util.fscript;
002:
003: import java.util.ArrayList;
004: import java.util.Hashtable;
005:
006: /**
007: * <p>FastExtension - general extension in which other (simple) extensions
008: * can be plugged.
009: * </p>
010: * <p>
011: * <I>Copyright (C) 2002 </I></p>
012: * <p>
013: * This library is free software; you can redistribute it and/or
014: * modify it under the terms of the GNU Library General Public
015: * License as published by the Free Software Foundation; either
016: * version 2 of the License, or (at your option) any later version.</p>
017: * <p>
018: * This library is distributed in the hope that it will be useful,
019: * but WITHOUT ANY WARRANTY; without even the implied warranty of
020: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
021: * Library General Public License for more details.</p>
022: *
023: * <p>You should have received a copy of the GNU Library General Public
024: * License along with this library; if not, write to the Free
025: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA </p>
026: *
027: * @author Joachim Van der Auwera
028: *
029: * modifications by Joachim Van der Auwera
030: * 02.08.2002 started
031: *
032: * 11.08.2002 (murlen) Changed function names to add<X>Extension + java doc
033: */
034: public class FSFastExtension implements FSExtension {
035: Hashtable variables = new Hashtable();
036: Hashtable functions = new Hashtable();
037: Hashtable arrays = new Hashtable();
038:
039: /**
040: * Add new FSVarExtension to this FastExtension
041: * @param name - the name of the variable (must be unique amongst varables)
042: * @param var - the FSVarExtension object implementing the varaible
043: */
044: public void addVarExtension(String name, FSVarExtension var) {
045: variables.put(name, var);
046: }
047:
048: /**
049: * Add new FSArrayExtension to this FastExtension
050: * @param name - the name of the array (must be unique amongst arrays)
051: * @param array - the FSArrayExtension object implementing the array
052: */
053: public void addArrayExtension(String name, FSArrayExtension array) {
054: arrays.put(name, array);
055: }
056:
057: /**
058: * Add new FSFunctionExtension to this FastExtension
059: * @param name - the name of the function (must be unique amongs functions)
060: * @param fnc - the FSFunctionExtension object implementing the function
061: */
062: public void addFunctionExtension(String name,
063: FSFunctionExtension fnc) {
064: functions.put(name, fnc);
065: }
066:
067: public Object getVar(String name) throws FSException {
068: FSVarExtension var = (FSVarExtension) variables.get(name);
069: if (var != null)
070: return var.getVar(name);
071: throw new FSUnsupportedException();
072: }
073:
074: //FSExtension implementation code below here.
075:
076: public void setVar(String name, Object value) throws FSException {
077: FSVarExtension var = (FSVarExtension) variables.get(name);
078: if (var != null) {
079: var.setVar(name, value);
080: return;
081: }
082: throw new FSUnsupportedException();
083: }
084:
085: public Object getVar(String name, Object index) throws FSException {
086: FSArrayExtension var = (FSArrayExtension) arrays.get(name);
087: if (var != null)
088: return var.getVar(name, index);
089: throw new FSUnsupportedException();
090: }
091:
092: public void setVar(String name, Object index, Object value)
093: throws FSException {
094: FSArrayExtension var = (FSArrayExtension) arrays.get(name);
095: if (var != null) {
096: var.setVar(name, index, value);
097: return;
098: }
099: throw new FSUnsupportedException();
100: }
101:
102: public Object callFunction(String name, ArrayList params)
103: throws FSException {
104: FSFunctionExtension var = (FSFunctionExtension) functions
105: .get(name);
106: if (var != null)
107: return var.callFunction(name, params);
108: throw new FSUnsupportedException();
109: }
110:
111: }
|