001: /* Copyright 2005-2006 David N. Welton
002:
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014: */
015:
016: /* $Id: ObjectThing.java 426 2007-09-03 21:10:18Z davidw $ */
017:
018: package org.hecl;
019:
020: /**
021: * The <code>ObjectThing</code> class provides a wrapper for objects
022: * that are not directly representable as strings. FIXME - I am
023: * uncertain if this will actually work or not.
024: *
025: * @author <a href="mailto:davidw@dedasys.com">David N. Welton </a>
026: * @version 1.0
027: */
028: public class ObjectThing implements RealThing {
029: private Object val;
030:
031: /**
032: * Creates a new <code>ObjectThing</code> instance equal to 0.
033: *
034: */
035: public ObjectThing() {
036: // val = new Object();
037: }
038:
039: /**
040: * Creates a new <code>ObjectThing</code> instance with value i.
041: *
042: * @param o
043: * an <code>Object</code>.
044: */
045: public ObjectThing(Object o) {
046: val = o;
047: }
048:
049: public String thingclass() {
050: return "object";
051: }
052:
053: /**
054: * Retrieve the object associated with this instance.
055: */
056: public Object get() {
057: return this .val;
058: }
059:
060: /**
061: * The <code>create</code> method creates and returns a newly allocated
062: * Thing with an ObjectThing internal representation.
063: *
064: * @param o
065: * an <code>Object</code>
066: * @return a <code>Thing</code> value
067: */
068: public static Thing create(Object o) {
069: return new Thing(new ObjectThing(o));
070: }
071:
072: /**
073: * <code>get</code> attempts to fetch an Object from the Thing.
074: *
075: * @param thing a <code>Thing</code> value
076: * @return an <code>Object</code> value
077: * @exception HeclException if an error occurs
078: */
079: public static Object get(Thing thing) throws HeclException {
080: RealThing realthing = thing.getVal();
081:
082: if (!(realthing instanceof ObjectThing)) {
083: throw new HeclException("cannot transform "
084: + thing.toString() + " into an ObjectThing");
085: }
086: return ((ObjectThing) realthing).val;
087: }
088:
089: /**
090: * <code>deepcopy</code> makes a copy.
091: *
092: * @return a <code>RealThing</code> value
093: */
094: public RealThing deepcopy() {
095: return new ObjectThing(val);
096: }
097:
098: /**
099: * <code>getStringRep</code> creates a string representation of the
100: * ObjectThing.
101: *
102: * @return a <code>String</code> value
103: */
104: public String getStringRep() {
105: /* FIXME! */
106: return val != null ? val.toString() : "null";
107: //return val.toString();
108: }
109: }
|