Ejemplo n.º 1
0
  @EntrySet
  public Set<Map.Entry<Value, Value>> entrySet() {
    LinkedHashMap<Value, Value> map = new LinkedHashMap<Value, Value>();

    if (_attributes != null) {
      ArrayValue array = new ArrayValueImpl();

      for (SimpleXMLElement attr : _attributes) {
        StringValue value = attr._text;

        array.put(_env.createString(attr._name), value);
      }

      map.put(_env.createString("@attributes"), array);
    }

    boolean hasElement = false;
    if (_children != null) {
      for (SimpleXMLElement child : _children) {
        if (!child.isElement()) continue;

        hasElement = true;

        StringValue name = _env.createString(child.getName());
        Value oldChild = map.get(name);
        Value childValue;

        if (child._text != null) childValue = child._text;
        else childValue = wrapJava(_env, _cls, child);

        if (oldChild == null) {
          map.put(name, childValue);
        } else if (oldChild.isArray()) {
          ArrayValue array = (ArrayValue) oldChild;

          array.append(childValue);
        } else {
          ArrayValue array = new ArrayValueImpl();
          array.append(oldChild);
          array.append(childValue);

          map.put(name, array);
        }
      }
    }

    if (!hasElement && _text != null) {
      map.put(LongValue.ZERO, _text);
    }

    return map.entrySet();
  }
Ejemplo n.º 2
0
  private void getNamespaces(Env env, ArrayValue array) {
    if (_namespaceMap != null) {
      for (Map.Entry<String, String> entry : _namespaceMap.entrySet()) {
        StringValue name = env.createString(entry.getKey());
        StringValue uri = env.createString(entry.getValue());

        SimpleXMLAttribute attr = new SimpleXMLAttribute(env, _cls, this, entry.getKey());
        attr.setText(uri);

        array.append(name, env.wrapJava(attr));
      }
    }
  }