001: /*=============================================================================
002: * Copyright Texas Instruments 2000. 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: * A <code>ComMethod</code> object is a wrapper for a property of a COM
027: * object
028: *
029: * @author Rob Clark (rob@ti.com)
030: * <!--$Format: " * @version $Revision$"$-->
031: * @version 1.15
032: */
033: public class ComProperty extends AbstractReference {
034: /**
035: * The dispatch-pointer object is our handle to the COM object.
036: */
037: private org.jawin.DispatchPtr dptr;
038:
039: /**
040: * The name of the method.
041: */
042: private String name;
043:
044: private Object val;
045:
046: /**
047: * Class Constructor.
048: *
049: * @param dptr the dispatch-ptr object
050: * @param name the name of the method
051: * @param val the initial value, or <code>null</code> (in which
052: * case the constructor looks-up the value)... the purpose of passing
053: * this as an argument is to avoid re-looking up the value that
054: * {@link ComObject#getMember} has already looked up
055: * @throws org.jawin.COMException if COM error
056: */
057: ComProperty(org.jawin.DispatchPtr dptr, String name, Object val)
058: throws org.jawin.COMException {
059: super ();
060:
061: this .dptr = dptr;
062: this .name = name;
063: this .val = val;
064: }
065:
066: /**
067: * Perform assignment. Set the value of this reference to the specified
068: * value.
069: *
070: * @param val the value to set this reference to
071: * @throws PackagedScriptObjectException(NoSuchMemberException)
072: */
073: public void opAssign(Value val)
074: throws PackagedScriptObjectException {
075: Object[] javaArgs = new Object[1];
076:
077: OArray args = new OArray(1);
078: args.push1(val);
079: if (JavaBridge.convertArgs(new Class[] { Object.class },
080: javaArgs, args) < 0)
081: throw PackagedScriptObjectException
082: .makeExceptionWrapper(new OIllegalArgumentException(
083: "wrong arg types!"));
084:
085: try {
086: dptr.put(name, javaArgs[0]);
087: } catch (org.jawin.COMException e) {
088: throw OJavaException.makeJavaExceptionWrapper(e);
089: }
090: }
091:
092: protected Value get() {
093: if (val == null) {
094: try {
095: val = dptr.get(name);
096: } catch (org.jawin.COMException e) {
097: throw OJavaException.makeJavaExceptionWrapper(e);
098: }
099: }
100:
101: return JavaBridge.convertToScriptObject(val);
102: }
103: }
104:
105: /*
106: * Local Variables:
107: * tab-width: 2
108: * indent-tabs-mode: nil
109: * mode: java
110: * c-indentation-style: java
111: * c-basic-offset: 2
112: * eval: (c-set-offset 'substatement-open '0)
113: * eval: (c-set-offset 'case-label '+)
114: * eval: (c-set-offset 'inclass '+)
115: * eval: (c-set-offset 'inline-open '0)
116: * End:
117: */
|