Exemplo n.º 1
0
  /* package */ void ensureConstraints(List<Child> children) {
    Set<String> nullElements = new HashSet<String>(model.getElementNames());
    for (Child child : children) {
      nullElements.remove(child.name);
    }

    for (String s : nullElements) {
      ConfigModel.Property p = model.getElement(s);
      for (String annotation : p.getAnnotations()) {
        if (annotation.equals(NotNull.class.getName())) {
          if (p instanceof ConfigModel.Node) {
            ConfigModel childModel = ((ConfigModel.Node) p).model;
            Dom child = document.make(getHabitat(), null, this, childModel);
            child.register();

            children.add(new Dom.NodeChild(s, child));

            // recursive call to ensure the children constraints are also respected
            List<Child> grandChildren = new ArrayList<Child>();
            child.ensureConstraints(grandChildren);
            if (!grandChildren.isEmpty()) {
              child.setChildren(grandChildren);
            }

            child.initializationCompleted();
          }
        }
      }
    }
  }
Exemplo n.º 2
0
 /**
  * Locates the DOM that serves as the symbol space root.
  *
  * @return always non-null.
  */
 public Dom getSymbolSpaceRoot(String typeName) {
   Dom dom = this;
   while (!dom.model.symbolSpaces.contains(typeName)) {
     Dom p = dom.parent();
     if (p == null) return dom; // root
     dom = p;
   }
   return dom;
 }
Exemplo n.º 3
0
 /**
  * Copy constructor, used to get a deep copy of the passed instance
  *
  * @param source the instance to copy
  */
 public Dom(Dom source, Dom parent) {
   this(source.getHabitat(), source.document, parent, source.model);
   List<Child> newChildren = new ArrayList<Child>();
   for (Child child : source.children) {
     newChildren.add(child.deepCopy(this));
   }
   setChildren(newChildren);
   attributes.putAll(source.attributes);
 }
Exemplo n.º 4
0
  /**
   * Replaces an existing {@link NodeChild} with another one.
   *
   * @see #insertAfter(Dom, String, Dom)
   */
  public synchronized void replaceChild(Dom reference, String name, Dom newNode) {
    ListIterator<Child> itr = children.listIterator();
    while (itr.hasNext()) {
      Child child = itr.next();
      if (child instanceof NodeChild) {
        NodeChild nc = (NodeChild) child;
        if (nc.dom == reference) {
          reference.release();
          newNode.domDescriptor =
              addWithAlias(getHabitat(), newNode, newNode.getProxyType(), newNode.getKey());

          itr.set(new NodeChild(name, newNode));
          return;
        }
      }
    }
    throw new IllegalArgumentException(
        reference + " is not a valid child of " + this + ". Children=" + children);
  }
Exemplo n.º 5
0
  /**
   * Inserts a new {@link Dom} node right after the given DOM element.
   *
   * @param reference If null, the new element will be inserted at the very beginning.
   * @param name The element name of the newly inserted item. "*" to indicate that the element name
   *     be determined by the model of the new node.
   */
  public synchronized void insertAfter(Dom reference, String name, Dom newNode) {
    // TODO: reparent newNode
    if (name.equals("*")) name = newNode.model.tagName;
    NodeChild newChild = new NodeChild(name, newNode);

    if (children.size() == 0) {
      children = new ArrayList<Child>();
    }
    if (reference == null) {
      children.add(0, newChild);
      newNode.domDescriptor =
          addWithAlias(getHabitat(), newNode, newNode.getProxyType(), newNode.getKey());
      return;
    }

    ListIterator<Child> itr = children.listIterator();
    while (itr.hasNext()) {
      Child child = itr.next();
      if (child instanceof NodeChild) {
        NodeChild nc = (NodeChild) child;
        if (nc.dom == reference) {
          itr.add(newChild);
          newNode.domDescriptor =
              addWithAlias(getHabitat(), newNode, newNode.getProxyType(), newNode.getKey());

          return;
        }
      }
    }
    throw new IllegalArgumentException(
        reference + " is not a valid child of " + this + ". Children=" + children);
  }
Exemplo n.º 6
0
 /** Removes an existing {@link NodeChild} */
 public synchronized void removeChild(final Dom reference) {
   ListIterator<Child> itr = children.listIterator();
   while (itr.hasNext()) {
     Child child = itr.next();
     if (child instanceof NodeChild) {
       NodeChild nc = (NodeChild) child;
       if (nc.dom == reference) {
         itr.remove();
         reference.release();
         return;
       }
     }
   }
   throw new IllegalArgumentException(
       reference + " is not a valid child of " + this + ". Children=" + children);
 }
Exemplo n.º 7
0
 @Override
 public String toString() {
   return "Dom.NodeChild(" + dom.getImplementation() + "," + super.toString() + ")";
 }
Exemplo n.º 8
0
 @Override
 protected boolean isEmpty() {
   return dom.isEmpty();
 }
Exemplo n.º 9
0
    @Override
    protected Child deepCopy(Dom parent) {

      return new NodeChild(name, dom.copy(parent));
    }
Exemplo n.º 10
0
 protected void writeTo(XMLStreamWriter w) throws XMLStreamException {
   dom.writeTo(name, w);
 }