예제 #1
0
파일: Dom.java 프로젝트: hk2-project/hk2
  /* 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();
          }
        }
      }
    }
  }
예제 #2
0
파일: Dom.java 프로젝트: hk2-project/hk2
 /**
  * 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;
 }
예제 #3
0
파일: Dom.java 프로젝트: hk2-project/hk2
 /**
  * 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);
 }
예제 #4
0
파일: Dom.java 프로젝트: hk2-project/hk2
  /**
   * 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);
  }
예제 #5
0
파일: Dom.java 프로젝트: hk2-project/hk2
  /**
   * 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);
  }
예제 #6
0
파일: Dom.java 프로젝트: hk2-project/hk2
 /** 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);
 }
예제 #7
0
파일: Dom.java 프로젝트: hk2-project/hk2
 @Override
 public String toString() {
   return "Dom.NodeChild(" + dom.getImplementation() + "," + super.toString() + ")";
 }
예제 #8
0
파일: Dom.java 프로젝트: hk2-project/hk2
 @Override
 protected boolean isEmpty() {
   return dom.isEmpty();
 }
예제 #9
0
파일: Dom.java 프로젝트: hk2-project/hk2
    @Override
    protected Child deepCopy(Dom parent) {

      return new NodeChild(name, dom.copy(parent));
    }
예제 #10
0
파일: Dom.java 프로젝트: hk2-project/hk2
 protected void writeTo(XMLStreamWriter w) throws XMLStreamException {
   dom.writeTo(name, w);
 }