Exemple #1
0
  /**
   * Given an XSD Complex Type Definition, return the model group containing its child elements.
   *
   * @param cType
   * @return the model group
   */
  public static XSDModelGroup getModelGroup(XSDComplexTypeDefinition cType) {

    XSDParticle particle = cType.getComplexType();

    // In cases where cType doesn't have a model group AND cType has a parent with a modelgroup, the
    // call above will rather unexpectedly give us cType's PARENT's model group, rather than the
    // null we
    // might expect.  We don't want that here, if the model group returned is null or belongs to
    // someone
    // other than us, return null
    if (particle == null || particle.eContainer() != cType) {
      return null;
    }

    // get the model group
    Object particleContent = particle.getContent();
    XSDModelGroup group = null;

    if (particleContent instanceof XSDModelGroupDefinition) {
      group =
          ((XSDModelGroupDefinition) particleContent)
              .getResolvedModelGroupDefinition()
              .getModelGroup();
    } else if (particleContent instanceof XSDModelGroup) {
      group = (XSDModelGroup) particleContent;
    }

    if (group == null) {
      return null;
    }

    // if the content of the complex type is empty then the content
    // must be in the complexContent, ie. we're extending another BO.
    // if the group and the type are not in the same resource then
    // we are extending another BO and we don't want to show inherited
    // attributes.
    if (group.getContents().isEmpty() || group.eResource() != cType.eResource()) {
      // if we are extending another BO then get the elements
      // we are adding
      if (cType.getBaseType() != null) {
        XSDComplexTypeContent content = cType.getContent();

        if (content instanceof XSDParticle) {
          particleContent = ((XSDParticle) content).getContent();
          if (particleContent instanceof XSDModelGroupDefinition) {
            group =
                ((XSDModelGroupDefinition) particleContent)
                    .getResolvedModelGroupDefinition()
                    .getModelGroup();
          } else if (particleContent instanceof XSDModelGroup) {
            group = (XSDModelGroup) particleContent;
          }
        }
      }
    }

    return group;
  }
Exemple #2
0
  /**
   * Given a Model group, return a list of the XSDFeatures declared within.
   *
   * @param group
   * @return the child elements.
   */
  public static List<XSDParticleContent> getChildElements(XSDModelGroup group) {
    if (group == null) {
      return new ArrayList<XSDParticleContent>();
    }

    List<XSDParticleContent> children = new ArrayList<XSDParticleContent>();

    for (XSDParticle next : group.getContents()) {
      if (next.getContent() instanceof XSDFeature) {
        children.add(next.getContent());
      } else if (next.getTerm() instanceof XSDModelGroup) {
        children.addAll(getChildElements((XSDModelGroup) next.getTerm()));
      }
    }
    return children;
  }
 protected Object[] getXSDModelGroupChildren(XSDModelGroup parent) {
   return parent.getContents().toArray(new Object[parent.getContents().size()]);
 }