Package anvil.core

Examples of anvil.core.Any


    public void setAttribute(String name, Object value)
    {
      synchronized(_lock) {
        openConnection();
        writeLine("store,"+_id+","+Conversions.URLEncode(name));
        Any data = Any.create(value);
        try {
          Serialization.serialize(null, data, _output);
          flush();
        } catch (IOException e) {
          closeConnection();
View Full Code Here


  private static final int append(StringBuffer result, int type, byte flags,
      int width, int precision, Any[] arguments, int index, int max)
  {

    Any value = (index < max) ? arguments[index++] : Any.NULL;

    if (width == -1) {
      width = (index < max) ? arguments[index++].toInt() : 0;
      if (width < 0) {
        width = 0;
      }
    }

    if (precision == -1) {
      precision = (index < max) ? arguments[index++].toInt() : 0;
      if (precision < 0) {
        precision = 0;
      }
    }
   
    switch(type) {
    case TYPE_CHAR:
      if (width > 0) {
        if ((flags & FLAG_ADJUST_LEFT) != 0) {
          appendChar(result, value);
          while(--width > 0) {
            result.append(' ');
          }
        } else {
          while(width-- > 1) {
            result.append(' ');
          }
          appendChar(result, value);
        }
      } else {
        appendChar(result, value);
      }
      break;
   
    case TYPE_BOOLEAN:
    case TYPE_STRING:
      appendString(result, flags, width, value.toString());
      break;

    case TYPE_LONG:
      appendLong(result, flags, width, value.toLong());
      break;

    case TYPE_DOUBLE:
      appendFloat(result, flags, width, precision, value.toDouble(), false);
      break;

    case TYPE_DOUBLE_SIGNIFICANT:
      appendFloat(result, flags, width, precision, value.toDouble(), true);
      break;
     
    }
   
    return index;
View Full Code Here

  public Any m_write(Context context, Any[] parameters)
  {
    int n = parameters.length;
    try {
      for(int i=0; i<n; i++) {
        Any value = parameters[i];
        switch(value.typeOf()) {
        case IS_NULL:
        case IS_UNDEFINED:
          break;
        case IS_INT:
          _output.write(value.toInt());
          break;
        case IS_BINARY:
          int len = value.sizeOf();
          if (n > 0) {
            _output.write(value.toBinary(), 0, len);
          }
          break;
        default:
          String buffer = value.toString();
          if (buffer.length()>0) {
            _output.write(anvil.util.Conversions.getBytes(buffer));
          }
        }
      }
View Full Code Here

  {
    try {
      File source = toFile(file);
      context.checkRead(source.getPath());
      FileInputStream in = new FileInputStream(source);
      Any struct = Serialization.unserialize(context, in);
      in.close();
      return struct;
    } catch (UnserializationException e) {
      throw context.CorruptedSerialization();
    } catch (IOException e) {
View Full Code Here

      if (parameters.length == 0) {
        queryString = query;
      } else {
        queryString = SQLUtil.buildQueryString(query, parameters, 0);
      }
      Any returnValue;
      if (stmt.execute(queryString)) {
        returnValue = new AnyResultSet(stmt.getResultSet(), stmt);
      } else {
        returnValue = Any.create(stmt.getUpdateCount());
        stmt.close();
View Full Code Here

    case StreamUtils.TYPE_BINARY:
      return StreamUtils.streamToAnyByteArray((new URL(url)).openStream());

    case StreamUtils.TYPE_DATA:
      InputStream inputStream = (new URL(url)).openStream();
      Any data = Serialization.unserialize(context, inputStream);
      inputStream.close();
      return data;

    default:
      return Any.NULL;
View Full Code Here

        code.dup();
        code.invokespecial(hashlistctor);
        int c = 0;
        Enumeration keys = (Enumeration)_switches.elementAt(i);
        while(keys.hasMoreElements()) {
          Any key = (Any)keys.nextElement();
          if (key != SwitchStatement.DEFAULT_MARKER) {
            key.toCode(code);
            code.anew(intclazz);
            code.dup();
            code.iconst(c++);
            code.invokespecial(intclazzctor);
            code.invokevirtual(hashlistadd);
View Full Code Here

    ConstantPool pool = getPool();
    int max = (parameters != null) ? parameters.length : 0;
    int c = 0;
    int n = function.getParameterCount();
    for(int i=0; i<n; i++) {
      Any defaultValue = function.getParameterDefault(i);
      switch(function.getParameterType(i)) {
      case CompilableFunction.PARAMETER_ANY:
        if (c<max) {
          parameters[c++].compile(this, Node.GET);
        } else {
          if (defaultValue != null) {
            constant(defaultValue, true);
          } else {
            code.aconst_null();
          }
        }
        break;

      case CompilableFunction.PARAMETER_OBJECT:
        if (c<max) {
          parameters[c++].compile(this, Node.GET);
          code.invokevirtual(pool.addMethodRef(TYPE_ANY,
            "toObject", "()Ljava/lang/Object;"));
        } else {
          if (defaultValue != null) {
            constant(defaultValue, true);
            code.invokevirtual(pool.addMethodRef(TYPE_ANY,
              "toObject", "()Ljava/lang/Object;"));
          } else {
            code.aconst_null();
          }
        }
        break;

      case CompilableFunction.PARAMETER_BOOLEAN:
        if (c<max) {
          Node node = parameters[c++];
          if (node.isConstant()) {
            code.iconst(node.eval().toBoolean());
          } else {
            node.compile(this, Node.GET_BOOLEAN);
          }
        } else {
          if (defaultValue != null) {
            code.iconst(defaultValue.toBoolean());
          } else {
            code.iconst(false);
          }
        }
        break;

      case CompilableFunction.PARAMETER_INT:
        if (c<max) {
          Node node = parameters[c++];
          if (node.isConstant()) {
            code.iconst(node.eval().toInt());
          } else {
            node.compile(this, Node.GET);
            code.invokevirtual(pool.addMethodRef(TYPE_ANY,
              "toInt", "()I"));           
          }
        } else {
          if (defaultValue != null) {
            code.iconst(defaultValue.toInt());
          } else {
            code.iconst(0);
          }
        }
        break;

      case CompilableFunction.PARAMETER_LONG:
        if (c<max) {
          Node node = parameters[c++];
          if (node.isConstant()) {
            code.lconst(node.eval().toLong());
          } else {
            node.compile(this, Node.GET);
            code.invokevirtual(pool.addMethodRef(TYPE_ANY,
              "toLong", "()J"))
          }
        } else {
          if (defaultValue != null) {
            code.lconst(defaultValue.toLong());
          } else {
            code.lconst(0);
          }
        }
        break;

      case CompilableFunction.PARAMETER_DOUBLE:
        if (c<max) {
          Node node = parameters[c++];
          if (node.isConstant()) {
            code.dconst(node.eval().toDouble());
          } else {
            node.compile(this, Node.GET);
            code.invokevirtual(pool.addMethodRef(TYPE_ANY,
              "toDouble", "()D"));
          }
        } else {
          if (defaultValue != null) {
            code.dconst(defaultValue.toDouble());
          } else {
            code.dconst(0.0);
          }
        }
        break;

      case CompilableFunction.PARAMETER_STRING:
        if (c<max) {
          Node node = parameters[c++];
          if (node.isConstant()) {
            code.astring(node.eval().toString());
          } else {
            node.compile(this, Node.GET);
            code.invokevirtual(pool.addMethodRef(TYPE_OBJECT,
              "toString", "()Ljava/lang/String;"));
          }
        } else {
          if (defaultValue != null) {
            code.astring(defaultValue.toString());
          } else {
            code.aconst_null();
          }
        }
        break;
View Full Code Here

  }


  private Any getFunction(Context context, Any struct, String name)
  {
    Any value = struct.checkAttribute(context, name);
    if (!value.isNull()) {
      return value;
    }
    return null;
  }
View Full Code Here


  public boolean hasMoreElements()
  {
    if (_hasmore) {
      Any next = _next;
      if (next == null) {
        return getNextElement();
      } else {
        return true;
      }
View Full Code Here

TOP

Related Classes of anvil.core.Any

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.