001: /*=============================================================================
002: * Copyright Texas Instruments 2003-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:
025: /**
026: * An XML-RPC object.
027: *
028: * @author Rob Clark (rob@ti.com)
029: */
030: public class XmlRpcObject extends OObject {
031: /**
032: * The type object for an instance of XmlRpcObject.
033: */
034: public final static Value TYPE = BuiltinType
035: .makeBuiltinType("oscript.data.XmlRpcObject");
036: public final static String PARENT_TYPE_NAME = "oscript.data.OObject";
037: public final static String TYPE_NAME = "XmlRpcObject";
038: public final static String[] MEMBER_NAMES = new String[] {
039: "getType", "castToJavaObject", "castToString",
040: "bopInstanceOf", "bopEquals", "bopNotEquals", "getMember", };
041:
042: /**
043: * The client object used to access the server
044: */
045: private org.apache.xmlrpc.XmlRpcClient client;
046:
047: /**
048: * The name of the object.
049: */
050: private String objectName;
051:
052: public static void init() {
053: oscript.OscriptInterpreter.getGlobalScope().createMember(
054: "XmlRpcObject", 0).opAssign(TYPE);
055: }
056:
057: /*=======================================================================*/
058: /**
059: * Class Constructor.
060: *
061: * @param client the client object
062: * @param objectName the name of the object
063: */
064: XmlRpcObject(org.apache.xmlrpc.XmlRpcClient client,
065: String objectName) {
066: super ();
067:
068: this .client = client;
069: this .objectName = objectName;
070: }
071:
072: /*=======================================================================*/
073: /**
074: * For benefit of <code>BuiltinType</code>... always throws an exception because
075: * script code should not be allowed to directly create an instance...
076: *
077: * @param args arguments to this constructor
078: * @throws PackagedScriptObjectException(Exception) if wrong number of args
079: */
080: public XmlRpcObject(oscript.util.MemberTable args) {
081: throw PackagedScriptObjectException
082: .makeExceptionWrapper(new OIllegalArgumentException(
083: "wrong number of args!"));
084: }
085:
086: /*=======================================================================*/
087: /**
088: * Get the type of this object. The returned type doesn't have to take
089: * into account the possibility of a script type extending a built-in
090: * type, since that is handled by {@link #getType}.
091: *
092: * @return the object's type
093: */
094: protected Value getTypeImpl() {
095: return TYPE;
096: }
097:
098: /*=======================================================================*/
099: /**
100: * Get a member of this object.
101: *
102: * @param id the id of the symbol that maps to the member
103: * @param exception whether an exception should be thrown if the
104: * member object is not resolved
105: * @return a reference to the member
106: * @throws PackagedScriptObjectException(NoSuchMemberException)
107: */
108: public Value getMember(int id, boolean exception)
109: throws PackagedScriptObjectException {
110: Value member = super .getMember(id, false);
111:
112: if (member != null)
113: return member;
114:
115: return new XmlRpcMethod(client, objectName, Symbol
116: .getSymbol(id).castToString());
117: }
118: }
119:
120: /*
121: * Local Variables:
122: * tab-width: 2
123: * indent-tabs-mode: nil
124: * mode: java
125: * c-indentation-style: java
126: * c-basic-offset: 2
127: * eval: (c-set-offset 'substatement-open '0)
128: * eval: (c-set-offset 'case-label '+)
129: * eval: (c-set-offset 'inclass '+)
130: * eval: (c-set-offset 'inline-open '0)
131: * End:
132: */
|