Пример #1
0
 /**
  * Sets the parent for this ComplexType
  *
  * @param parent the parent Structure for this ComplexType
  */
 protected void setParent(Structure parent) {
   if (parent != null) {
     switch (parent.getStructureType()) {
       case Structure.SCHEMA:
       case Structure.ELEMENT:
         break;
       default:
         String error = "Invalid parent for ComplexType";
         throw new IllegalArgumentException(error);
     }
   }
   _parent = parent;
 } // -- setParent
Пример #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