예제 #1
0
 /**
  * Returns the minimum number of occurances that this ContentModelGroup must appear
  *
  * @return the minimum number of occurances that this ContentModelGroup must appear A negative (n
  *     < 0) value indicates that the value is unspecified.
  */
 public int getMinOccurs() {
   if (_contentModel.getParticleCount() > 0) {
     Particle particle = _contentModel.getParticle(0);
     if (particle instanceof ContentModelGroup) {
       return particle.getMinOccurs();
     }
   }
   return _contentModel.getMinOccurs();
 } // -- getMinOccurs
예제 #2
0
 /**
  * A helper method that returns true if this complexType contains an <any> element.
  *
  * @return method that returns true if this complexType contains an <any> element.
  */
 public boolean hasAny() {
   boolean result = false;
   Enumeration enumeration = _contentModel.enumerate();
   while (enumeration.hasMoreElements() && !result) {
     Structure struct = (Structure) enumeration.nextElement();
     switch (struct.getStructureType()) {
       case Structure.ELEMENT:
         break;
       case Structure.GROUP:
       case Structure.MODELGROUP:
         result = ((Group) struct).hasAny();
         break;
       case Structure.WILDCARD:
         result = true;
         break;
       default:
         break;
     }
   }
   return result;
 }
예제 #3
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
예제 #4
0
 /**
  * Returns the number of particles contained within this ContentModelGroup
  *
  * @return the number of particles
  */
 public int getParticleCount() {
   return _contentModel.getParticleCount();
 } // -- getParticleCount
예제 #5
0
 /**
  * Returns the Particle at the specified index
  *
  * @param index the index of the particle to return
  * @returns the CMParticle at the specified index
  */
 public Particle getParticle(int index) {
   Particle result = _contentModel.getParticle(index);
   return result;
 } // -- getParticle
예제 #6
0
 /**
  * Returns the element declaration with the given name, or null if no element declaration with
  * that name exists in this ContentModelGroup.
  *
  * @param name the name of the element.
  * @return the ElementDecl with the given name, or null if no ElementDecl exists in this
  *     ContentModelGroup.
  */
 public ElementDecl getElementDecl(String name) {
   ElementDecl result = _contentModel.getElementDecl(name);
   return result;
 } // -- getElementDecl
예제 #7
0
 /**
  * Returns an enumeration of all the Particles of this ContentModelGroup
  *
  * @return an enumeration of the Particles contained within this ContentModelGroup
  */
 public Enumeration enumerate() {
   return _contentModel.enumerate();
 } // -- enumerate
예제 #8
0
 /**
  * Removes the given ModelGroup Definition from this ContentModelGroup.
  *
  * @param group the ModelGroup Definition to remove.
  * @return true if the group has been successfully removed, false otherwise.
  */
 public boolean removeGroup(ModelGroup group) {
   boolean result = _contentModel.removeGroup(group);
   group.setParent(null);
   return result;
 }
예제 #9
0
  /**
   * Adds the given ModelGroup Definition to this ContentModelGroup
   *
   * @param group the ModelGroup to add
   * @exception SchemaException when a group with the same name as the specified group already
   *     exists in the current scope
   */
  public void addGroup(ModelGroup group) throws SchemaException {
    _contentModel.addGroup(group);

    // -- set reference to parent
    group.setParent(this);
  } // -- addGroup
예제 #10
0
 /**
  * Removes the given ElementDecl from this ContentModelGroup.
  *
  * @param elementDecl the ElementDecl to remove.
  * @return true if the element has been successfully removed, false otherwise.
  */
 public boolean removeElementDecl(ElementDecl element) {
   return _contentModel.removeElementDecl(element);
 }
예제 #11
0
  /**
   * Adds the given ElementDecl to this ContentModelGroup
   *
   * @param elementDecl the ElementDecl to add
   * @exception SchemaException when an ElementDecl already exists with the same name as the given
   *     ElementDecl
   */
  public void addElementDecl(ElementDecl elementDecl) throws SchemaException {
    _contentModel.addElementDecl(elementDecl);

    // --set the parent
    elementDecl.setParent(this);
  } // -- addElementDecl