Esempio 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.getNamespaceURI(nsPrefix);
            if (ns == null)  {
                String err = "addAttributeGroup: ";
                err += "Namespace prefix not recognized '"+nsPrefix+"'";
                throw new IllegalArgumentException(err);
            }
            if (!ns.equals(_targetNamespace)) {
                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
Esempio n. 2
0
  /**
   * Checks the validity of this ComplexType defintion.
   *
   * @throws ValidationException when this ComplexType definition is invalid.
   */
  public void validate() throws ValidationException {
    // -- check name
    if (_parent != null && _parent.getStructureType() != Structure.SCHEMA) {
      if (getName() != null) {
        String err = "Only top-level complexTypes can be named.";
        err += getName() + "is not a valid complexType.";
        throw new ValidationException(err);
      }
    }
    // -- check attributes
    _attributes.validate();

    // -- check content model
    Enumeration enumeration = _contentModel.enumerate();
    while (enumeration.hasMoreElements()) {
      ((Structure) enumeration.nextElement()).validate();
    }

    // -- make sure baseType is accessible
    XMLType type = getBaseType();
    if ((type == null) && (_baseType != null)) {
      String error = "The base type '" + _baseType + "' was not found.";
      throw new ValidationException(error);
    }
    if (type != null) {
      if (type.getStructureType() == Structure.SIMPLE_TYPE) {
        if (_restricted) {
          String name = getName();
          if (name == null) {
            name = "anonymous-complexType-for-element: ";
            if (_parent != null) {
              // -- parent should be an element if name is null, but
              // -- we'll check the type to be on the safe side
              if (_parent.getStructureType() == Structure.ELEMENT)
                name += ((ElementDecl) _parent).getName();
              else name += _parent.toString();
            }
          }
          String err = "complexType: " + name;
          err += "; A complex type cannot be a restriction" + " of a simpleType:";
          err += type.getName();
          throw new ValidationException(err);
        }
      } else if (type.getStructureType() == Structure.COMPLEX_TYPE) {

        if (!_complexContent) {
          // we are now sure that the base is a ComplexType
          // but is the base of this complexType a simpleType? (see 4.3.3->simpleContent->content
          // type)
          if (((ComplexType) type).getContentType().getType() != ContentType.SIMPLE) {
            String name = getName();
            if (name == null) {
              name = "anonymous-complexType-for-element: ";
              if (_parent != null) {
                // -- parent should be an element if name is null, but
                // -- we'll check the type to be on the safe side
                if (_parent.getStructureType() == Structure.ELEMENT)
                  name += ((ElementDecl) _parent).getName();
                else name += _parent.toString();
              }
            }
            String err = "complexType: " + name;
            err +=
                "; When a complexType is a restriction of simpleContent the base type"
                    + " must be a complexType whose base is also simpleContent.";
            throw new ValidationException(err);
          }
        }
      }
    }
  } // -- validate
Esempio n. 3
0
 /**
  * Returns an Enumeration of all the AttributeGroup that are referenced within this ComplexType.
  *
  * @return an Enumeration of all the AttributeGroup that are referenced within this ComplexType.
  */
 public Enumeration getAttributeGroupReferences() {
   return _attributes.getLocalAttributeGroupReferences();
 }
Esempio n. 4
0
 /**
  * Returns an Enumeration of *all* locally defined AttributeDecl declared within this ComplexType.
  * The Enumeration will not contain any AttributeDecl from AttributeGroup references.
  *
  * @return an Enumeration of all locally declared AttributeDecl.
  */
 public Enumeration getLocalAttributeDecls() {
   return _attributes.getLocalAttributes();
 } // -- getLocalAttributeDecls
Esempio n. 5
0
 /**
  * Returns the AttributeDecl associated with the given name
  *
  * @return the AttributeDecl associated with the given name, or null if no AttributeDecl with the
  *     given name was found.
  */
 public AttributeDecl getAttributeDecl(String name) {
   AttributeDecl result = _attributes.getAttribute(name);
   return result;
 } // -- getAttributeDecl
Esempio n. 6
0
 /**
  * Removes the given AttributeGroupReference from this ComplexType
  *
  * @param attrGroupRef the AttributeGroupReference to remove.
  */
 public void removeAttributeGroupReference(AttributeGroupReference attrGroupRef) {
   _attributes.removeReference(attrGroupRef);
 }
Esempio n. 7
0
 /**
  * Adds the given AttributeGroupReference to this ComplexType
  *
  * @param attrGroupRef the AttributeGroupReference to add to this ComplexType
  */
 public void addAttributeGroupReference(AttributeGroupReference attrGroupRef) {
   _attributes.addReference(attrGroupRef);
 } // -- addAttributeGroupReference
Esempio n. 8
0
 /**
  * Removes the given AttributeDecl from this ComplexType
  *
  * @param attrDecl the AttributeDecl to remove.
  */
 public void removeAttributeDecl(AttributeDecl attrDecl) {
   _attributes.removeAttribute(attrDecl);
 }
Esempio n. 9
0
  /**
   * Adds the given AttributeDecl to this ComplexType
   *
   * @param attrDecl the AttributeDecl to add to this ComplexType
   * @exception SchemaException when an AttributeDecl already exists with the same name as the given
   *     AttributeDecl
   */
  public void addAttributeDecl(AttributeDecl attrDecl) throws SchemaException {
    _attributes.addAttribute(attrDecl);

    // --set the parent
    attrDecl.setParent(this);
  } // -- addAttributeDecl