Ejemplo n.º 1
0
  /**
   * Adds the given attribute group definition to this Schema definition.
   *
   * @param attrGroup the AttributeGroupDecl to add
   * @exception SchemaException if an AttributeGroupDecl already exisits with the same name
   */
  public void addAttributeGroup(AttributeGroupDecl attrGroup) throws SchemaException {
    if (attrGroup == null) return;

    String name = attrGroup.getName();

    // -- handle namespace prefix, if necessary
    int idx = name.indexOf(':');
    if (idx >= 0) {
      String nsPrefix = name.substring(0, idx);
      name = name.substring(idx + 1);
      String ns = (String) namespaces.get(nsPrefix);
      if (ns == null) {
        String err = "addAttributeGroup: ";
        err += "Namespace prefix not recognized '" + nsPrefix + "'";
        throw new IllegalArgumentException(err);
      }
      if (!ns.equals(targetNS)) {
        String err = "AttributeGroup has different namespace " + "than this Schema definition.";
        throw new IllegalArgumentException(err);
      }
    }

    if (attrGroup.getSchema() != this) {
      String err = "invalid attempt to add an AttributeGroup which ";
      err += "belongs to a different Schema; " + name;
      throw new SchemaException(err);
    }

    Object obj = attributeGroups.get(name);

    if (obj == attrGroup) return;

    if (obj != null) {
      String err =
          "Error attempting to add an AttributeGroup to this "
              + "Schema definition, an AttributeGroup already exists with "
              + "the given name: ";
      throw new SchemaException(err + name);
    }

    attributeGroups.put(name, attrGroup);
  } // -- addAttributeGroup