Example #1
0
    /**
     * Processes the given ContentModelGroup
     * @param cmGroup the ContentModelGroup to process
     * @param sInfo the current source generator state information
    **/
    private void processContentModel(ContentModelGroup cmGroup, SGStateInfo sInfo) {


        Enumeration enum = cmGroup.enumerate();

        while (enum.hasMoreElements()) {

            Structure struct = (Structure)enum.nextElement();
            switch(struct.getStructureType()) {
                case Structure.ELEMENT:
                    ElementDecl eDecl = (ElementDecl)struct;
                    if (eDecl.isReference()) continue;
                    createClasses(eDecl, sInfo);
                    break;
                case Structure.GROUP:
                    processContentModel((Group)struct, sInfo);
                    //handle nested groups
                    if (!((cmGroup instanceof ComplexType) ||
                           (cmGroup instanceof ModelGroup)))
                    {
                        createClasses((Group)struct, sInfo);
                    }
                    break;
                default:
                    break;
            }
        }
    } //-- process
Example #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;
 }
Example #3
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
Example #4
0
  private static void getSchemaLocation(final Structure structure, final StringBuffer location) {
    if (structure == null) {
      throw new IllegalArgumentException("Structure cannot be null");
    }

    if (location == null) {
      throw new IllegalArgumentException("location cannot be null");
    }

    Structure parent = null;
    switch (structure.getStructureType()) {
      case Structure.ELEMENT:
        parent = ((ElementDecl) structure).getParent();
        if (parent.getStructureType() != Structure.SCHEMA) {
          getSchemaLocation(parent, location);
        }
        location.append(PATH_SEPARATOR);
        location.append(((ElementDecl) structure).getName());
        break;

      case Structure.COMPLEX_TYPE:
        ComplexType complexType = (ComplexType) structure;
        parent = (complexType).getParent();
        if (parent.getStructureType() != Structure.SCHEMA) {
          getSchemaLocation(parent, location);
        }
        if (complexType.getName() != null) {
          location.append(PATH_SEPARATOR);
          location.append(COMPLEXTYPE_ID);
          location.append(((ComplexType) structure).getName());
        }
        //                else {
        //                    location.append(PATH_SEPARATOR);
        //                    location.append(COMPLEXTYPE_ID);
        //                    location.append("anonymous");
        //                }
        break;

      case Structure.SIMPLE_TYPE:
        SimpleType simpleType = (SimpleType) structure;
        parent = simpleType.getParent();
        if (parent != null && parent.getStructureType() != Structure.SCHEMA)
          getSchemaLocation(parent, location);
        if (parent != null && simpleType.getName() != null) {
          location.append(PATH_SEPARATOR);
          location.append(ENUMTYPE_ID);
          location.append(((SimpleType) structure).getName());
        }
        //                else {
        //                    location.append(PATH_SEPARATOR);
        //                    location.append(ENUMTYPE_ID);
        //                    location.append("anonymous");
        //                }
        break;

      case Structure.MODELGROUP:
        ModelGroup group = (ModelGroup) structure;
        parent = group.getParent();
        if (parent.getStructureType() != Structure.SCHEMA) {
          getSchemaLocation(parent, location);
        }
        if (group.getName() != null) {
          location.append(GROUP_ID);
          location.append(group.getName());
        }
        break;

      case Structure.ATTRIBUTE:
        parent = ((AttributeDecl) structure).getParent();
        if (parent.getStructureType() != Structure.SCHEMA) {
          getSchemaLocation(parent, location);
        }
        location.append(PATH_SEPARATOR);
        location.append(ATTRIBUTE_PREFIX);
        location.append(((AttributeDecl) structure).getName());
        break;

      case Structure.GROUP:
        // --we are inside a complexType
        getSchemaLocation(((Group) structure).getParent(), location);
        break;

        //            case Structure.ATTRIBUTE_GROUP:
        //                //handle the real location

      default:
        break;
    }
  }
Example #5
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