001: /*=============================================================================
002: * Copyright Texas Instruments 2000-2004. All Rights Reserved.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: * $ProjectHeader: OSCRIPT 0.155 Fri, 20 Dec 2002 18:34:22 -0800 rclark $
019: */
020:
021: package oscript.data;
022:
023: import oscript.exceptions.*;
024: import oscript.classwrap.ClassWrapGen;
025: import oscript.syntaxtree.FunctionCallExpressionList;
026: import oscript.OscriptInterpreter;
027: import oscript.NodeEvaluator;
028:
029: import java.util.Enumeration;
030:
031: /**
032: * The built-in type <i>Object</i>, which is the type that implements the
033: * root of the inheritance hierarchy of all language types. All types
034: * either directly or indirectly inherit from this class.
035: * <p>
036: * Some of the class hierarchy should be re-thought... perhaps the methods
037: * that are implemented in <code>Value</code> should be moved to this
038: * class?
039: *
040: * @author Rob Clark (rob@ti.com)
041: */
042: public class OObject extends Value {
043: /**
044: * The type object for an instance of Object.
045: */
046: public final static Value TYPE = BuiltinType
047: .makeBuiltinType("oscript.data.OObject");
048: public final static String PARENT_TYPE_NAME = null;
049: public final static String TYPE_NAME = "Object";
050: public final static String[] MEMBER_NAMES = new String[] {
051: "unhand", "getType", "castToJavaObject", "castToString",
052: "bopInstanceOf", "bopInstanceOfR", "bopEquals",
053: "bopNotEquals", "memberSet",
054: // from java.lang.Object:
055: "hashCode", "equals", "toString", "notify", "notifyAll",
056: "wait", "getMember" };
057:
058: /**
059: * When a script function doesn't explicitly extend another type, it
060: * implicitly subclasses <i>Object</i>, and uses this expression-list
061: * when calling the super-class constructor.
062: */
063: public final static NodeEvaluator EMPTY_EXPR_LIST_EVALUATOR = OscriptInterpreter.EMPTY_EXPR_LIST_EVALUATOR;
064:
065: /*=======================================================================*/
066: /**
067: * Class Constructor.
068: */
069: public OObject() {
070: super ();
071: }
072:
073: /*=======================================================================*/
074: /**
075: * Class Constructor. This is the constructor that gets called via an
076: * BuiltinType instance.
077: *
078: * @param args arguments to this constructor
079: * @throws PackagedScriptObjectException(Exception) if wrong number of args
080: */
081: public OObject(oscript.util.MemberTable args) {
082: super ();
083:
084: if (args.length() != 0)
085: throw PackagedScriptObjectException
086: .makeExceptionWrapper(new OIllegalArgumentException(
087: "wrong number of args!"));
088: }
089:
090: /*=======================================================================*/
091: /**
092: * Get the type of this object. The returned type doesn't have to take
093: * into account the possibility of a script type extending a built-in
094: * type, since that is handled by {@link #getType}.
095: *
096: * @return the object's type
097: */
098: protected Value getTypeImpl() {
099: return TYPE;
100: }
101:
102: /*=======================================================================*/
103: /**
104: * Convert this object to a native java <code>String</code> value.
105: *
106: * @return a String value
107: * @throws PackagedObjectException(NoSuchMethodException)
108: */
109: public String castToString() throws PackagedScriptObjectException {
110: return "[object]";
111: }
112:
113: /*=======================================================================*/
114: /**
115: * Get a member of this object.
116: *
117: * @param name the name of the member
118: * @return a reference to the member
119: * @throws PackagedScriptObjectException(NoSuchMemberException)
120: */
121: public Value getMember(int id, boolean exception)
122: throws PackagedScriptObjectException {
123: Value val = null;
124: Value scriptObject = ClassWrapGen.getScriptObject(this );
125: if (scriptObject != null)
126: val = scriptObject.getMember(id, false);
127: if (val != null)
128: return val;
129: return super .getMember(id, exception);
130: }
131:
132: // public Value getMember( Value name )
133: // throws PackagedScriptObjectException
134: // {
135: // Value val = null;
136: // Value scriptObject = ClassWrapGen.getScriptObject(this);
137: // if( scriptObject != null )
138: // val = scriptObject.getMember( name, false );
139: // if( val != null )
140: // return val;
141: // return super.getMember(name);
142: // }
143:
144: /*=======================================================================*/
145: /**
146: * Derived classes that implement {@link #getMember} should also
147: * implement this.
148: *
149: * @param s the set to populate
150: * @param debugger <code>true</code> if being used by debugger, in
151: * which case both public and private/protected field names should
152: * be returned
153: * @see #getMember
154: */
155: protected void populateMemberSet(java.util.Set s, boolean debugger) {
156: Value scriptObject = ClassWrapGen.getScriptObject(this );
157: if (scriptObject != null)
158: scriptObject.populateMemberSet(s, debugger);
159: super .populateMemberSet(s, debugger);
160: }
161: }
162:
163: /*
164: * Local Variables:
165: * tab-width: 2
166: * indent-tabs-mode: nil
167: * mode: java
168: * c-indentation-style: java
169: * c-basic-offset: 2
170: * eval: (c-set-offset 'substatement-open '0)
171: * eval: (c-set-offset 'case-label '+)
172: * eval: (c-set-offset 'inclass '+)
173: * eval: (c-set-offset 'inline-open '0)
174: * End:
175: */
|