コード例 #1
0
ファイル: PathMarshal.java プロジェクト: phektus/quercus-gae
 @Override
 protected int getMarshalingCostImpl(Value argValue) {
   if (argValue instanceof JavaValue
       && Path.class.isAssignableFrom(argValue.toJavaObject().getClass())) return Marshal.ZERO;
   else if (argValue.isString()) return Marshal.THREE;
   else return Marshal.FOUR;
 }
コード例 #2
0
ファイル: SimpleXMLElement.java プロジェクト: dlitz/resin
  /** Implementation for getting the indices of this class. i.e. <code>$a->foo[0]</code> */
  public Value __get(Env env, Value indexV) {
    if (indexV.isString()) {
      String name = indexV.toString();

      SimpleXMLElement attr = getAttribute(name);

      if (attr == null) return NullValue.NULL;
      else return wrapJava(env, _cls, attr);
    } else if (indexV.isLongConvertible()) {
      int i = indexV.toInt();

      if (i == 0) return wrapJava(env, _cls, getOwner());
      else if (_parent == null) return NullValue.NULL;

      ArrayList<SimpleXMLElement> children = _parent._children;

      if (children != null) {
        int size = children.size();

        for (int j = 0; j < size; j++) {
          SimpleXMLElement child = children.get(j);

          if (child.getName().equals(getName()) && i-- == 0) return wrapJava(env, _cls, child);
        }
      }

      return NullValue.NULL;
    } else return NullValue.NULL;
  }
コード例 #3
0
  /**
   * Converts node tree to a valid xml string.
   *
   * @return xml string
   */
  public final Value asXML(Env env, @Optional Value filename) {
    Value value = toXML(env);

    if (!value.isString()) {
      return value;
    }

    StringValue str = value.toStringValue(env);

    if (filename.isDefault()) {
      return str;
    } else {
      Path path = env.lookupPwd(filename);

      OutputStream os = null;

      try {
        os = path.openWrite();

        str.writeTo(os);

        return BooleanValue.TRUE;
      } catch (IOException e) {
        env.warning(e);

        return BooleanValue.FALSE;
      } finally {
        if (os != null) {
          IoUtil.close(os);
        }
      }
    }
  }
  private boolean setLobParameter(Env env, int index, Value value) {
    if (_preparedStmt == null) {
      return false;
    }

    try {
      if (value == null || value.isNull()) {
        _preparedStmt.setObject(index, null);
      } else if (value.isString()) {
        _preparedStmt.setBinaryStream(index, value.toInputStream(), value.length());
      } else {
        InputStream inputStream = value.toInputStream();

        if (inputStream == null) {
          env.warning(
              L.l(
                  "type {0} ({1}) for parameter index {2} cannot be used for lob",
                  value.getType(), value.getClass(), index));
          return false;
        }

        int length = -1;

        if (value instanceof FileReadValue) {
          length = (int) ((FileReadValue) value).getLength();

          if (length <= 0) length = -1;
        }

        if (length < 0) {
          TempBuffer tempBuffer = TempBuffer.allocate();

          try {
            byte[] bytes = new byte[1024];

            int len;

            while ((len = inputStream.read(bytes, 0, 1024)) != -1) tempBuffer.write(bytes, 0, len);
          } catch (IOException e) {
            env.warning(e);
            return false;
          }

          TempReadStream tempReadStream = new TempReadStream(tempBuffer);
          tempReadStream.setFreeWhenDone(true);

          _preparedStmt.setBinaryStream(
              index, new ReadStream(tempReadStream), tempBuffer.getLength());
        } else {
          _preparedStmt.setBinaryStream(index, inputStream, length);
        }
      }
    } catch (SQLException e) {
      setError(env, e);
      return false;
    }

    return true;
  }
コード例 #5
0
  /** Implementation for getting the indices of this class. i.e. <code>$a->foo[0]</code> */
  public Value __get(Env env, Value indexV) {
    if (indexV.isString()) {
      String name = indexV.toString();

      SimpleXMLElement attr = getAttribute(name);

      if (attr != null) return wrapJava(env, _cls, attr);
      else return NullValue.NULL;
    } else if (indexV.isLongConvertible()) {
      int i = indexV.toInt();

      if (i < _attributes.size()) return wrapJava(env, _cls, _attributes.get(i));

      return NullValue.NULL;
    } else return NullValue.NULL;
  }
コード例 #6
0
 @Override
 protected int getMarshalingCostImpl(Value argValue) {
   if (argValue.isArray()) return Marshal.ZERO;
   else if (argValue.isString()) return Marshal.ONE;
   else return Marshal.MAX;
 }