示例#1
0
文件: Dom.java 项目: hk2-project/hk2
  /**
   * Returns true if this element is empty meaning all their attributes have default values and it
   * has no descendants.
   *
   * @return true if the element is empty, false otherwise
   */
  private boolean isEmpty() {
    Map<String, String> attributesToWrite = attributesToWrite();

    if (!attributesToWrite.isEmpty()) {
      return false;
    }

    // if we have children, we are not empty.
    return children.isEmpty();
  }
示例#2
0
文件: Dom.java 项目: hk2-project/hk2
 /**
  * Updates the attribute value.
  *
  * <p>This would trigger the re-injection of the value.
  */
 public void attribute(String name, String value) {
   if (value == null) {
     attributes.remove(name);
   } else {
     attributes.put(name, value);
     // TODO:
     // this re-injection has two problems. First, it forces an instantiation
     // even if that hasn't happened yet. Second, if the component is scoped,
     // this won't work correctly (but then, there's no way to make that work,
     // since we can't enumerate all scope instances.)
     getInjector().injectAttribute(this, name, get());
   }
 }
示例#3
0
文件: Dom.java 项目: hk2-project/hk2
  /**
   * Returns the map of attributes names and values for attributes which value is neither null or
   * the default value. These attributes are considered having a non default value and must be
   * written out.
   *
   * @return map of attributes indexed by name that must be persisted
   */
  private Map<String, String> attributesToWrite() {

    Map<String, String> attributesToWrite = new HashMap<String, String>();
    Map<String, String> localAttr = new HashMap<String, String>(attributes);
    for (Map.Entry<String, String> a : localAttr.entrySet()) {
      ConfigModel.AttributeLeaf am = model.attributes.get(a.getKey());
      String dv = am.getDefaultValue();
      if (dv == null || !dv.equals(a.getValue())) {
        attributesToWrite.put(a.getKey(), a.getValue());
      }
    }
    return attributesToWrite;
  }
示例#4
0
文件: Dom.java 项目: hk2-project/hk2
 /**
  * Obtians the attribute value without variable expansion.
  *
  * @return null if the attribute is not found.
  */
 public String rawAttribute(String name) {
   String value = attributes.get(name);
   if (value == null && model.attributes.containsKey(name)) {
     value = model.attributes.get(name).getDefaultValue();
   }
   return value;
 }
示例#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
 /*package*/ void fillAttributes(XMLStreamReader in) {
   for (int i = in.getAttributeCount() - 1; i >= 0; i--) {
     String n = in.getAttributeLocalName(i);
     if (model.attributes.containsKey(n)) {
       if (attributes == null) attributes = new HashMap<String, String>();
       attributes.put(n, in.getAttributeValue(i));
     }
   }
   if (attributes == null) attributes = Collections.emptyMap();
 }
示例#7
0
文件: Dom.java 项目: hk2-project/hk2
 /**
  * Returns the list of attributes with a value on this config instance. This is by definition a
  * subset of the attributes names as known to the model {@see ConfigModel.getAttributeNames}.
  *
  * @return list of attributes names which have values on this config instance
  */
 public Set<String> getAttributeNames() {
   return Collections.unmodifiableSet(attributes.keySet());
 }