001: /*
002: * Copyright (c) 1998-2008 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: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.quercus.env;
031:
032: import com.caucho.quercus.Location;
033: import com.caucho.quercus.expr.Expr;
034: import com.caucho.quercus.expr.StringLiteralExpr;
035: import com.caucho.quercus.program.AbstractFunction;
036: import com.caucho.quercus.program.JavaClassDef;
037: import com.caucho.vfs.WriteStream;
038:
039: import java.io.IOException;
040: import java.io.ObjectInputStream;
041: import java.io.ObjectOutputStream;
042: import java.io.Serializable;
043: import java.util.AbstractSet;
044: import java.util.IdentityHashMap;
045: import java.util.Iterator;
046: import java.util.Map;
047: import java.util.Set;
048: import java.util.TreeSet;
049:
050: /**
051: * Represents a PHP object which extends a Java value.
052: */
053: public class ObjectExtJavaValue extends ObjectExtValue implements
054: Serializable {
055: private final Object _object;
056: private final JavaClassDef _javaClassDef;
057:
058: public ObjectExtJavaValue(QuercusClass cl, Object object,
059: JavaClassDef javaClassDef) {
060: super (cl);
061:
062: _object = object;
063: _javaClassDef = javaClassDef;
064: }
065:
066: //
067: // field
068: //
069:
070: /**
071: * Returns fields not specified by the value.
072: */
073: protected Value getFieldExt(Env env, StringValue name) {
074: Value value = _javaClassDef.getField(env, this , name);
075:
076: if (value != null)
077: return value;
078: else
079: return _quercusClass.getField(env, this , name);
080: }
081:
082: /**
083: * Sets fields not specified by the value.
084: */
085: protected Value putFieldExt(Env env, StringValue name, Value value) {
086: return _javaClassDef.putField(env, this , name, value);
087: }
088:
089: /**
090: * Returns the java object.
091: */
092: @Override
093: public Object toJavaObject() {
094: return _object;
095: }
096:
097: public void varDumpImpl(Env env, WriteStream out, int depth,
098: IdentityHashMap<Value, String> valueSet) throws IOException {
099: if (!_javaClassDef.varDumpImpl(env, _object, out, depth,
100: valueSet))
101: super .varDumpImpl(env, out, depth, valueSet);
102: }
103:
104: @Override
105: protected void printRImpl(Env env, WriteStream out, int depth,
106: IdentityHashMap<Value, String> valueSet) throws IOException {
107: _javaClassDef.printRImpl(env, _object, out, depth, valueSet);
108: }
109: }
|