Exemplo n.º 1
0
  /**
   * Check and add the <code>Attribute</code> to this list at the given index. Note: does not check
   * for duplicate attributes.
   *
   * @param index index where to add <code>Attribute</code>
   * @param attribute <code>Attribute</code> to add
   */
  void add(int index, Attribute attribute) {
    if (attribute.getParent() != null) {
      throw new IllegalAddException(
          "The attribute already has an existing parent \""
              + attribute.getParent().getQualifiedName()
              + "\"");
    }

    String reason = Verifier.checkNamespaceCollision(attribute, parent);
    if (reason != null) {
      throw new IllegalAddException(parent, attribute, reason);
    }

    if (index < 0 || index > size) {
      throw new IndexOutOfBoundsException("Index: " + index + " Size: " + size());
    }

    attribute.setParent(parent);

    ensureCapacity(size + 1);
    if (index == size) {
      elementData[size++] = attribute;
    } else {
      System.arraycopy(elementData, index, elementData, index + 1, size - index);
      elementData[index] = attribute;
      size++;
    }
    modCount++;
  }
Exemplo n.º 2
0
  /**
   * Set the object at the specified location to the supplied object. Note: does not check for
   * duplicate attributes.
   *
   * @param index The location to set the value to.
   * @param attribute The attribute to set.
   * @return The object which was replaced. throws IndexOutOfBoundsException if index < 0 || index
   *     >= size()
   */
  Object set(int index, Attribute attribute) {
    if (index < 0 || index >= size)
      throw new IndexOutOfBoundsException("Index: " + index + " Size: " + size());

    if (attribute.getParent() != null) {
      throw new IllegalAddException(
          "The attribute already has an existing parent \""
              + attribute.getParent().getQualifiedName()
              + "\"");
    }

    String reason = Verifier.checkNamespaceCollision(attribute, parent);
    if (reason != null) {
      throw new IllegalAddException(parent, attribute, reason);
    }

    Attribute old = (Attribute) elementData[index];
    old.setParent(null);

    elementData[index] = attribute;
    attribute.setParent(parent);
    return old;
  }
Exemplo n.º 3
0
  /**
   * Adds the given attribute to the list, possibly replacing an existing attribute matching the new
   * attribute's name and namespace URI.
   */
  public void addAttribute(Attribute attr) {
    if (null != attr.getParent()) {
      throw new PublicException(BpmRuntimeError.SDT_ATTRIBUTE_MUST_BE_DETACHED.raise());
    }

    if (attribs.isEmpty()) {
      this.attribs = newArrayList();
    }

    for (int i = 0; i < attribs.size(); ++i) {
      Attribute attrib = attribs.get(i);
      if (areEqual(attrib.getLocalName(), attr.getLocalName())
          && areEqual(attrib.getNamespaceURI(), attr.getNamespaceURI())) {
        attrib.setParent(null);
        attribs.set(i, attr);
        attr.setParent(this);
        return;
      }
    }
    attribs.add(attr);
    attr.setParent(this);
  }