001: /*
002: * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.es;
030:
031: import com.caucho.util.IntMap;
032:
033: import java.util.HashMap;
034:
035: /**
036: * JavaScript object
037: */
038: class ESJavaWrapper extends ESObject {
039: public Object value;
040:
041: public ESString toStr() throws Throwable {
042: return ESString.create(value == null ? "null" : value
043: .toString());
044: }
045:
046: public ESString toSource(IntMap map, boolean isLoopPath)
047: throws Throwable {
048: if (isLoopPath)
049: return null;
050: else
051: return toStr();
052: }
053:
054: public ESBase toPrimitive(int hint) throws Throwable {
055: if (value instanceof ESBase)
056: return (ESBase) value;
057: else
058: return toStr();
059: }
060:
061: public Object toJavaObject() {
062: return value;
063: }
064:
065: public ESJavaWrapper wrap(Object value) {
066: if (value == null)
067: throw new NullPointerException();
068:
069: ESJavaWrapper child = (ESJavaWrapper) dup();
070: child.value = value;
071: child.init(className, prototype);
072:
073: return child;
074: }
075:
076: public boolean ecmaEquals(ESBase b) {
077: if (!(b instanceof ESJavaWrapper))
078: return false;
079: else
080: return value == ((ESJavaWrapper) b).value;
081: }
082:
083: protected ESJavaWrapper() {
084: }
085:
086: protected ESObject dup() {
087: return new ESJavaWrapper();
088: }
089:
090: protected void copy(HashMap refs, Object newObj) {
091: ESJavaWrapper obj = (ESJavaWrapper) newObj;
092:
093: super .copy(refs, obj);
094:
095: obj.value = value;
096: }
097:
098: protected ESJavaWrapper(ESBase proto, Object value) {
099: super ("javaWrapper", proto);
100:
101: this.value = value;
102: }
103: }
|