Ejemplo n.º 1
0
  @Override
  protected void printRImpl(
      Env env, WriteStream out, int depth, IdentityHashMap<Value, String> valueSet)
      throws IOException {
    if (_classDef.printRImpl(env, _object, out, depth, valueSet)) {
      return;
    }

    Set<? extends Map.Entry<Value, Value>> entrySet = entrySet();

    if (entrySet == null) {
      out.print("resource(" + toString(env) + ")"); // XXX:
      return;
    }

    out.print(_classDef.getSimpleName());
    out.println(" Object");
    printRDepth(out, depth);
    out.print("(");

    for (Map.Entry<Value, Value> entry : entrySet) {
      out.println();
      printRDepth(out, depth);
      out.print("    [" + entry.getKey() + "] => ");

      entry.getValue().printRImpl(env, out, depth + 1, valueSet);
    }

    out.println();
    printRDepth(out, depth);
    out.println(")");
  }
Ejemplo n.º 2
0
  /** Adds a java class */
  public JavaClassDef getJavaClassDefinition(String className) {
    JavaClassDef def;

    if (_classNotFoundCache.get(className) != null) return null;

    def = _javaClassWrappers.get(className);

    if (def == null) {
      try {
        def = getModuleContext().getJavaClassDefinition(className);

        _javaClassWrappers.put(className, def);
      } catch (RuntimeException e) {
        _classNotFoundCache.put(className, className);

        throw e;
      } catch (Exception e) {
        throw new QuercusRuntimeException(e);
      }
    }

    def.init();

    return def;
  }
  /**
   * Converts to a string.
   *
   * @param env
   */
  @Override
  public StringValue toString(Env env) {
    AbstractFunction toString = _quercusClass.getToString();

    if (toString != null) {
      return toString.callMethod(env, _quercusClass, this).toStringValue();
    } else if (_javaClassDef.getToString() != null) {
      JavaValue value = new JavaValue(env, _object, _javaClassDef);

      return _javaClassDef.toString(env, value);
    } else {
      return env.createString(_className + "[]");
    }
  }
Ejemplo n.º 4
0
  /** Sets the field value. */
  @Override
  public Value putField(Env env, StringValue name, Value value) {
    Value oldValue = _classDef.putField(env, this, name, value);

    if (oldValue != null) return oldValue;
    else return NullValue.NULL;
  }
  /** Sets fields not specified by the value. */
  protected Value putFieldExt(Env env, StringValue name, Value value) {
    if (_object == null) {
      createJavaObject(env);
    }

    return _javaClassDef.putField(env, this, name, value);
  }
Ejemplo n.º 6
0
  @Override
  public Value clone(Env env) {
    Object obj = null;

    if (_object != null) {
      if (!(_object instanceof Cloneable)) {
        return env.error(
            L.l("Java class {0} does not implement Cloneable", _object.getClass().getName()));
      }

      Class<?> cls = _classDef.getType();

      try {
        Method method = cls.getMethod("clone", new Class[0]);
        method.setAccessible(true);

        obj = method.invoke(_object);
      } catch (NoSuchMethodException e) {
        throw new QuercusException(e);
      } catch (InvocationTargetException e) {
        throw new QuercusException(e.getCause());
      } catch (IllegalAccessException e) {
        throw new QuercusException(e);
      }
    }

    return new JavaValue(env, obj, _classDef, getQuercusClass());
  }
Ejemplo n.º 7
0
 /** Converts to a string. */
 public String toString() {
   if (_object != null) {
     return String.valueOf(_object);
   } else {
     return String.valueOf(_classDef.getName());
   }
 }
Ejemplo n.º 8
0
  /** Returns the field value. */
  @Override
  public Value getField(Env env, StringValue name) {
    Value value = _classDef.getField(env, this, name);

    if (value != null) return value;
    else return UnsetValue.NULL;
  }
Ejemplo n.º 9
0
  @Override
  protected int getMarshalingCostImpl(Value argValue) {
    Class type = _def.getType();

    if (argValue instanceof JavaValue && type.isAssignableFrom(argValue.toJavaObject().getClass()))
      return Marshal.ZERO;
    else return Marshal.FOUR;
  }
  public void varDumpImpl(
      Env env, WriteStream out, int depth, IdentityHashMap<Value, String> valueSet)
      throws IOException {
    if (_object == null) {
      _object = createJavaObject(Env.getInstance());
    }

    if (!_javaClassDef.varDumpImpl(env, this, _object, out, depth, valueSet))
      super.varDumpImpl(env, out, depth, valueSet);
  }
  @Override
  protected void printRImpl(
      Env env, WriteStream out, int depth, IdentityHashMap<Value, String> valueSet)
      throws IOException {
    if (_object == null) {
      _object = createJavaObject(Env.getInstance());
    }

    _javaClassDef.printRImpl(env, _object, out, depth, valueSet);
  }
Ejemplo n.º 12
0
  @Override
  public StringValue toString(Env env) {
    StringValue value = _classDef.toString(env, this);

    if (value == null) {
      value = env.createString(toString());
    }

    return value;
  }
Ejemplo n.º 13
0
  private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException {
    _env = Env.getInstance();

    _classDef = _env.getJavaClassDefinition((String) in.readObject());

    int id = _env.getQuercus().getClassId(_classDef.getName());

    setQuercusClass(_env.createQuercusClass(id, _classDef, null));

    _object = in.readObject();
  }
Ejemplo n.º 14
0
  @Override
  public int cmpObject(ObjectValue rValue) {
    // php/172z

    if (rValue == this) return 0;

    if (!(rValue instanceof JavaValue)) return -1;

    Object rObject = rValue.toJavaObject();

    return _classDef.cmpObject(_object, rObject, ((JavaValue) rValue)._classDef);
  }
Ejemplo n.º 15
0
  @Override
  protected void varDumpImpl(
      Env env, WriteStream out, int depth, IdentityHashMap<Value, String> valueSet)
      throws IOException {
    Value oldThis = env.setThis(this);

    try {
      if (!_classDef.varDumpImpl(env, this, _object, out, depth, valueSet))
        out.print("resource(" + toString(env) + ")"); // XXX:
    } finally {
      env.setThis(oldThis);
    }
  }
  /** Returns fields not explicitly specified by this value. */
  @Override
  protected Value getFieldExt(Env env, StringValue name) {
    if (_object == null) {
      _object = createJavaObject(env);
    }

    Value parentValue = super.getFieldExt(env, name);
    if (parentValue != NullValue.NULL && parentValue != UnsetValue.UNSET) return parentValue;

    Value value = _javaClassDef.getField(env, this, name);
    Value quercusValue = _quercusClass.getField(env, this, name);

    if (quercusValue != null
        && quercusValue != UnsetValue.UNSET
        && quercusValue != NullValue.NULL) {
      return quercusValue;
    }

    if (value != null) return value;
    else return super.getFieldExt(env, name);
  }
Ejemplo n.º 17
0
  /** Serializes the value. */
  @Override
  public void serialize(Env env, StringBuilder sb, SerializeMap serializeMap) {
    Integer index = serializeMap.get(this);

    if (index != null) {
      sb.append("r:");
      sb.append(index);
      sb.append(";");

      serializeMap.incrementIndex();

      return;
    }

    serializeMap.put(this);
    serializeMap.incrementIndex();
    String name = _classDef.getSimpleName();

    Set<? extends Map.Entry<Value, Value>> entrySet = entrySet();

    if (entrySet != null) {
      sb.append("O:");
      sb.append(name.length());
      sb.append(":\"");
      sb.append(name);
      sb.append("\":");
      sb.append(entrySet.size());
      sb.append(":{");

      for (Map.Entry<Value, Value> entry : entrySet) {
        entry.getKey().serialize(env, sb);
        entry.getValue().serialize(env, sb, serializeMap);
      }

      sb.append("}");
    } else {
      // php/121f
      sb.append("i:0;");
    }
  }
Ejemplo n.º 18
0
 @Override
 public String getClassName() {
   return _classDef.getName();
 }
Ejemplo n.º 19
0
  private void writeObject(ObjectOutputStream out) throws IOException {
    out.writeObject(_classDef.getType().getCanonicalName());

    out.writeObject(_object);
  }
Ejemplo n.º 20
0
 /** Encodes the value in JSON. */
 @Override
 public void jsonEncode(Env env, JsonEncodeContext context, StringValue sb) {
   if (_classDef.jsonEncode(env, _object, context, sb)) return;
   else super.jsonEncode(env, context, sb);
 }
Ejemplo n.º 21
0
 /** Evaluates a method. */
 @Override
 public Value callMethodRef(
     Env env, StringValue methodName, int hash, Value a1, Value a2, Value a3, Value a4, Value a5) {
   return _classDef.callMethod(env, this, methodName, hash, a1, a2, a3, a4, a5);
 }
Ejemplo n.º 22
0
 /** Evaluates a method. */
 @Override
 public Value callMethodRef(Env env, StringValue methodName, int hash, Value a1) {
   return _classDef.callMethod(env, this, methodName, hash, a1);
 }
Ejemplo n.º 23
0
 @Override
 public final Class getExpectedClass() {
   return _def.getType();
 }
Ejemplo n.º 24
0
 public Set<? extends Map.Entry<Value, Value>> entrySet() {
   return _classDef.entrySet(_object);
 }
Ejemplo n.º 25
0
  /** Evaluates a method. */
  @Override
  public Value callMethodRef(Env env, StringValue methodName, int hash) {
    Value value = _classDef.callMethod(env, this, methodName, hash);

    return value;
  }
 /** Creats a backing Java object for this php object. */
 private Object createJavaObject(Env env) {
   Value javaWrapper = _javaClassDef.callNew(env, Value.NULL_ARGS);
   return javaWrapper.toJavaObject();
 }