Пример #1
0
 /**
  * Adds given attribute into this container. Checks duplicities in attribute's names.
  *
  * @param attribute given attribute
  * @throws QtiAttributeException if container already contains attribute with same name
  */
 public void add(final Attribute<?> attribute) {
   for (final Attribute<?> child : attributes) {
     if (child.getLocalName().equals(attribute.getLocalName())
         && child.getNamespaceUri().equals(attribute.getNamespaceUri())) {
       throw new QtiAttributeException("Duplicate attribute name: " + attribute.computeXPath());
     }
   }
   attributes.add(attribute);
 }
Пример #2
0
  /**
   * Gets attribute with given local name and namespace URI or null (if attribute is not found).
   * Silent parameter is useful for support of unknown attributes.
   *
   * @param localName name of requested attribute
   * @param silent if exception should be thrown in case attribute is not found
   * @return attribute with given name
   * @throws QtiAttributeException if silent is false and if attribute is not found
   */
  private Attribute<?> get(
      final String localName, final String namespaceUri, final boolean silent) {
    Assert.notNull(localName, "localName");
    Assert.notNull(namespaceUri, "namespaceUri");
    for (final Attribute<?> attribute : attributes) {
      if (attribute.getLocalName().equals(localName)
          && attribute.getNamespaceUri().equals(namespaceUri)) {
        return attribute;
      }
    }

    if (silent) {
      return null;
    }
    throw new QtiAttributeException(
        "Cannot find attribute with namespace '"
            + namespaceUri
            + "' and local name '"
            + localName
            + "' in Node with XPath "
            + owner.computeXPath());
  }