コード例 #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
ファイル: DefaultValueTest.java プロジェクト: winsx/Payara
  @Test
  public void rawAttributeTest() throws NoSuchMethodException {

    String address = listener.getAddress();

    Dom raw = Dom.unwrap(listener);
    Attribute attr = raw.getProxyType().getMethod("getAddress").getAnnotation(Attribute.class);
    assertEquals(attr.defaultValue(), address);

    assertEquals(raw.attribute("address"), address);
    assertEquals(raw.rawAttribute("address"), address);
  }
コード例 #4
0
  @GET
  @Produces({"text/plain"})
  public String get(@QueryParam("outputDir") String outputDir) {
    if (outputDir == null) {
      outputDir = DEFAULT_OUTPUT_DIR;
    }
    String retVal = "Code Generation done at : " + outputDir;

    try {
      Domain entity = habitat.getComponent(Domain.class);
      Dom dom = Dom.unwrap(entity);
      DomDocument document = dom.document;
      ConfigModel rootModel = dom.document.getRoot().model;

      ResourcesGenerator resourcesGenerator = new TextResourcesGenerator(outputDir, habitat);
      resourcesGenerator.generateSingle(rootModel, document);
      resourcesGenerator.endGeneration();
    } catch (Exception ex) {
      Logger.getLogger(GeneratorResource.class.getName()).log(Level.SEVERE, null, ex);
      retVal =
          "Exception encountered during generation process: "
              + ex.toString()
              + "\nPlease look at server.log for more information.";
    }
    return retVal;
  }
コード例 #5
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);
 }
コード例 #6
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);
  }
コード例 #7
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);
  }
コード例 #8
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);
 }
コード例 #9
0
ファイル: StatusGenerator.java プロジェクト: phan-pivotal/OSS
  @GET
  @Produces({"text/plain"})
  public String get() {
    //        status.append("\n------------------------");
    //        status.append("Status of Command usage\n");
    try {
      Domain entity = habitat.getComponent(Domain.class);
      Dom dom = Dom.unwrap(entity);
      DomDocument document = dom.document;
      ConfigModel rootModel = dom.document.getRoot().model;

      ResourcesGenerator resourcesGenerator = new NOOPResourcesGenerator(habitat);
      resourcesGenerator.generateSingle(rootModel, document);
      resourcesGenerator.endGeneration();
    } catch (Exception ex) {
      Logger.getLogger(GeneratorResource.class.getName()).log(Level.SEVERE, null, ex);
      // retVal = "Exception encountered during generation process: " + ex.toString() + "\nPlease
      // look at server.log for more information.";
    }

    status.append("\n------------------------");
    status.append("All Commands used in REST Admin:\n");
    for (String ss : commandsUsed) {
      status.append(ss + "\n");
    }

    listOfCommands();
    for (String ss : commandsUsed) {
      allCommands.remove(ss);
    }

    status.append("\n------------------------");
    status.append("Missing Commands not used in REST Admin:\n");

    for (String ss : allCommands) {
      if (hasTargetParam(ss)) {
        status.append(ss + "          has a target param " + "\n");
      } else {
        status.append(ss + "\n");
      }
    }
    status.append("\n------------------------");
    status.append("REST-REDIRECT Commands defined on ConfigBeans:\n");

    for (String ss : restRedirectCommands) {
      status.append(ss + "\n");
    }

    status.append("\n------------------------");
    status.append("Commands to Resources Mapping Usage in REST Admin:\n");

    for (String ss : commandsToResources.keySet()) {
      if (hasTargetParam(ss)) {
        status.append(ss + "   :::target:::   " + commandsToResources.get(ss) + "\n");
      } else {
        status.append(ss + "      :::      " + commandsToResources.get(ss) + "\n");
      }
    }
    status.append("\n------------------------");
    status.append("Resources with Delete Commands in REST Admin (not counting RESTREDIRECT:\n");
    for (String ss : resourcesToDeleteCommands.keySet()) {
      status.append(ss + "      :::      " + resourcesToDeleteCommands.get(ss) + "\n");
    }

    FileOutputStream f;
    try {
      f = new FileOutputStream(System.getProperty("user.home") + "/GlassFishI18NData.properties");
      propsI18N.store(f, "");
      f.close();

    } catch (Exception ex) {
      Logger.getLogger(StatusGenerator.class.getName()).log(Level.SEVERE, null, ex);
    }
    return status.toString();
  }
コード例 #10
0
ファイル: Dom.java プロジェクト: hk2-project/hk2
 @Override
 public String toString() {
   return "Dom.NodeChild(" + dom.getImplementation() + "," + super.toString() + ")";
 }
コード例 #11
0
ファイル: Dom.java プロジェクト: hk2-project/hk2
 @Override
 protected boolean isEmpty() {
   return dom.isEmpty();
 }
コード例 #12
0
ファイル: Dom.java プロジェクト: hk2-project/hk2
    @Override
    protected Child deepCopy(Dom parent) {

      return new NodeChild(name, dom.copy(parent));
    }
コード例 #13
0
ファイル: Dom.java プロジェクト: hk2-project/hk2
 protected void writeTo(XMLStreamWriter w) throws XMLStreamException {
   dom.writeTo(name, w);
 }