Пример #1
0
  public StringValue toXML(Env env) {
    StringValue sb = env.createBinaryBuilder();

    toXMLImpl(sb);

    return sb;
  }
  /** Reads into a binary builder. */
  @Override
  public StringValue read(int length) throws IOException {
    if (_is == null) return null;

    StringValue bb = _env.createBinaryBuilder();

    if (bb.appendRead(_is, length) > 0) return bb;
    else return null;
  }
Пример #3
0
  public Value receive(Env env, @Optional("1") long timeout) throws JMSException {
    Message message = _consumer.receive(timeout);

    if (message == null) return BooleanValue.FALSE;

    if (message instanceof ObjectMessage) {
      Object object = ((ObjectMessage) message).getObject();

      return env.wrapJava(object);
    } else if (message instanceof TextMessage) {
      return env.createString(((TextMessage) message).getText());
    } else if (message instanceof StreamMessage) {
      Object object = ((StreamMessage) message).readObject();

      return env.wrapJava(object);
    } else if (message instanceof BytesMessage) {
      BytesMessage bytesMessage = (BytesMessage) message;
      int length = (int) bytesMessage.getBodyLength();

      StringValue bb = env.createBinaryBuilder(length);

      TempBuffer tempBuffer = TempBuffer.allocate();
      int sublen;

      while (true) {
        sublen = bytesMessage.readBytes(tempBuffer.getBuffer());

        if (sublen > 0) bb.append(tempBuffer.getBuffer(), 0, sublen);
        else break;
      }

      TempBuffer.free(tempBuffer);

      return bb;
    } else if (message instanceof MapMessage) {
      MapMessage mapMessage = (MapMessage) message;

      Enumeration mapNames = mapMessage.getMapNames();

      ArrayValue array = new ArrayValueImpl();

      while (mapNames.hasMoreElements()) {
        String name = mapNames.nextElement().toString();

        Object object = mapMessage.getObject(name);

        array.put(env.createString(name), env.wrapJava(object));
      }

      return array;
    } else {
      return BooleanValue.FALSE;
    }
  }
Пример #4
0
  /**
   * Converts node tree to a valid xml string.
   *
   * @return xml string
   */
  @ReturnNullAsFalse
  public StringValue asXML(Env env) {
    if (_parent == null) {
      StringValue sb = env.createBinaryBuilder();

      sb.append("<?xml version=\"1.0\"?>\n");
      toXMLImpl(sb);
      sb.append("\n");

      return sb;
    } else return toXML(env);
  }
  protected Value toXML(Env env) {
    StringValue sb = env.createBinaryBuilder();

    if (_parent == null) {
      sb.append("<?xml version=\"1.0\"?>\n");
    }

    toXMLImpl(sb);

    if (_parent == null) {
      sb.append("\n");
    }

    return sb;
  }
Пример #6
0
 private static StringValue format(Env env,
                             StringValue msg,
                             Value []args)
 {
   if (args.length == 0)
     return msg;
   
   StringValue sb;
   
   if (msg.isUnicode())
     sb = env.createUnicodeBuilder();
   else
     sb = env.createBinaryBuilder();
   
   return formatImpl(env, msg, args, sb);
 }