extendedMetaData.setContentKind(eClass, isMixed ? ExtendedMetaData.MIXED_CONTENT : ExtendedMetaData.ELEMENT_ONLY_CONTENT);
extendedMetaData.setContentKind (eClass, isMixed ? ExtendedMetaData.MIXED_CONTENT : xsdComplexTypeDefinition.getContentTypeCategory() == XSDContentTypeCategory.EMPTY_LITERAL ? ExtendedMetaData.EMPTY_CONTENT : ExtendedMetaData.ELEMENT_ONLY_CONTENT);
  public EClass computeEClass(XSDComplexTypeDefinition xsdComplexTypeDefinition)  {    if (xsdComplexTypeDefinition == null)    {      return (EClass)getBuiltInEClassifier(rootSchema.getSchemaForSchemaNamespace(), "anyType");    }    else if (XSDConstants.isSchemaForSchemaNamespace(xsdComplexTypeDefinition.getTargetNamespace()))    {      String name = xsdComplexTypeDefinition.getName();      if (name != null)      {        EClass result = (EClass)getBuiltInEClassifier(xsdComplexTypeDefinition.getTargetNamespace(), name);        if (result != null)        {          return result;        }      }    }    else if (xsdComplexTypeDefinition.getContainer() == null)    {      return (EClass)getBuiltInEClassifier(rootSchema.getSchemaForSchemaNamespace(), "anyType");    }    EClass eClass = EcoreFactory.eINSTANCE.createEClass();    setAnnotations(eClass, xsdComplexTypeDefinition);    // Do this early to prevent recursive loop.    xsdComponentToEModelElementMap.put(xsdComplexTypeDefinition, eClass);    String aliasName = getEcoreAttribute(xsdComplexTypeDefinition, "name");    if (aliasName == null)    {      aliasName = validName(xsdComplexTypeDefinition.getAliasName(), true);    }    eClass.setName(aliasName);    extendedMetaData.setName(eClass, xsdComplexTypeDefinition.getAliasName());    EPackage ePackage = getEPackage(xsdComplexTypeDefinition);    addToSortedList(ePackage.getEClassifiers(), eClass);    if (xsdComplexTypeDefinition.isAbstract())    {      eClass.setAbstract(true);    }    XSDTypeDefinition baseTypeDefinition = xsdComplexTypeDefinition.getBaseTypeDefinition();    if (!XSDConstants.isURType(baseTypeDefinition))    {      EClassifier baseType = getEClassifier(baseTypeDefinition);      if (baseType instanceof EClass && baseType != EcorePackage.eINSTANCE.getEObject())      {        eClass.getESuperTypes().add(baseType);      }    }    if (eClass.getESuperTypes().isEmpty() ||          xsdComplexTypeDefinition.getDerivationMethod() == XSDDerivationMethod.EXTENSION_LITERAL)    {      if (xsdComplexTypeDefinition.getContentTypeCategory() == XSDContentTypeCategory.SIMPLE_LITERAL)      {        extendedMetaData.setContentKind(eClass, ExtendedMetaData.SIMPLE_CONTENT);        if (eClass.getEAllStructuralFeatures().isEmpty())        {          EStructuralFeature eStructuralFeature =            createFeature              (eClass,               "value",               getEClassifier(xsdComplexTypeDefinition.getSimpleType()),               null,               0,               1);        }      }      else if (xsdComplexTypeDefinition.getContent() != null)      {        EStructuralFeature globalGroup = null;        boolean isMixed = xsdComplexTypeDefinition.getContentTypeCategory() == XSDContentTypeCategory.MIXED_LITERAL;        String featureMapName = getEcoreAttribute(xsdComplexTypeDefinition, "featureMap");        if (eClass.getESuperTypes().isEmpty() ?              "true".equals(getEcoreAttribute(xsdComplexTypeDefinition, "mixed")) :              extendedMetaData.getMixedFeature((EClass)eClass.getESuperTypes().get(0)) != null)        {          isMixed = true;        }        extendedMetaData.setContentKind(eClass, isMixed ? ExtendedMetaData.MIXED_CONTENT : ExtendedMetaData.ELEMENT_ONLY_CONTENT);        if (isMixed)        {          EStructuralFeature mixedFeature = extendedMetaData.getMixedFeature(eClass);          if (mixedFeature == null)          {            if (featureMapName == null)            {              featureMapName = "mixed";            }            mixedFeature =              createFeature                (eClass,                 featureMapName,                 EcorePackage.eINSTANCE.getEFeatureMapEntry(),                 null,                 0,                 -1);          }        }        else         {          globalGroup = extendedMetaData.getElement(eClass, null, ":group");          if (globalGroup == null && featureMapName != null && eClass.getESuperTypes().isEmpty())          {            globalGroup =              createFeature                (eClass,                 featureMapName,                 EcorePackage.eINSTANCE.getEFeatureMapEntry(),                 null,                 0,                 -1);            extendedMetaData.setName(globalGroup, ":group");            extendedMetaData.setFeatureKind(globalGroup, ExtendedMetaData.GROUP_FEATURE);          }        }        Map groups = new HashMap();        List particleInformation = collectParticles((XSDParticle)xsdComplexTypeDefinition.getContent());        for (Iterator i = particleInformation.iterator(); i.hasNext(); )        {          EffectiveOccurrence effectiveOccurrence = (EffectiveOccurrence)i.next();          XSDParticle xsdParticle = effectiveOccurrence.xsdParticle;          EStructuralFeature group = (EStructuralFeature)groups.get(effectiveOccurrence.xsdModelGroup);          XSDTerm xsdTerm = xsdParticle.getTerm();          EStructuralFeature eStructuralFeature;          String name = getEcoreAttribute(xsdParticle, "name");          if (xsdTerm instanceof XSDModelGroup)          {            XSDModelGroup xsdModelGroup = (XSDModelGroup)xsdTerm;            if (name == null)            {              name = getEcoreAttribute(xsdParticle, "featureMap");              if (name == null)              {                name = getEcoreAttribute(xsdModelGroup, "name");                if (name == null)                {                  name = getEcoreAttribute(xsdModelGroup, "featureMap");                  if (name == null)                  {                    if (xsdModelGroup.getContainer() instanceof XSDModelGroupDefinition)                    {                      XSDModelGroupDefinition xsdModelGroupDefinition = (XSDModelGroupDefinition)xsdModelGroup.getContainer();                      name =  getEcoreAttribute(xsdModelGroupDefinition, "name");                      if (name == null)                      {                        name = validName(xsdModelGroupDefinition.getName(), true);                      }                    }                    else                    {                      name = "group";                    }                  }                }              }            }            eStructuralFeature =              createFeature                (eClass,                 name,                 EcorePackage.eINSTANCE.getEFeatureMapEntry(),                 xsdParticle,                 0,                 -1);            groups.put(xsdTerm, eStructuralFeature);            extendedMetaData.setName(eStructuralFeature, name + ":" + eClass.getEAllStructuralFeatures().indexOf(eStructuralFeature));          }          else if (xsdTerm instanceof XSDWildcard)          {            if (name == null)            {              name = getEcoreAttribute(xsdTerm, "name");              if (name == null)              {                name = "any";              }            }            eStructuralFeature =              createFeature                (eClass,                 name,                 EcorePackage.eINSTANCE.getEFeatureMapEntry(),                 xsdParticle,                 effectiveOccurrence.minOccurs,                 effectiveOccurrence.maxOccurs);          }          else          {            XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)xsdTerm;            if (name == null)            {              name = getEcoreAttribute(xsdElementDeclaration, "name");              if (name == null)              {                name = validName(xsdElementDeclaration.getName(), true);              }            }            String groupName = getEcoreAttribute(xsdParticle, "featureMap");            if (groupName == null)            {              groupName = getEcoreAttribute(xsdElementDeclaration, "featureMap");            }            if (!"".equals(groupName) &&                 (groupName != null  ||                    xsdElementDeclaration.isAbstract() ||                     xsdElementDeclaration.getSubstitutionGroup().size() > 1))            {              if (groupName == null)              {                groupName = name + "Group";              }              eStructuralFeature =                 createFeature                  (eClass,                   groupName,                   EcorePackage.eINSTANCE.getEFeatureMapEntry(),                   xsdParticle,                   effectiveOccurrence.minOccurs,                   effectiveOccurrence.maxOccurs);              eStructuralFeature.setChangeable(true);              extendedMetaData.setFeatureKind(eStructuralFeature, ExtendedMetaData.GROUP_FEATURE);              extendedMetaData.setName(eStructuralFeature, xsdElementDeclaration.getName() + ":group");              if (group != null)              {                extendedMetaData.setGroup(eStructuralFeature, group);                eStructuralFeature.setDerived(true);                eStructuralFeature.setTransient(true);                eStructuralFeature.setVolatile(true);              }              else if (isMixed)              {                eStructuralFeature.setDerived(true);                eStructuralFeature.setTransient(true);                eStructuralFeature.setVolatile(true);              }              else if (globalGroup != null)              {                extendedMetaData.setGroup(eStructuralFeature, globalGroup);                eStructuralFeature.setDerived(true);                eStructuralFeature.setTransient(true);                eStructuralFeature.setVolatile(true);              }              group = eStructuralFeature;            }            XSDTypeDefinition elementTypeDefinition = xsdElementDeclaration.getTypeDefinition();            EClassifier eClassifier = getEClassifier(elementTypeDefinition);            XSDTypeDefinition referenceType = getEcoreTypeQNameAttribute(xsdElementDeclaration, "reference");            if (referenceType != null)            {              EClassifier referenceClassifier = getEClassifier(referenceType);              boolean needsHolder = false;              if (elementTypeDefinition instanceof XSDSimpleTypeDefinition)              {                XSDSimpleTypeDefinition xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition)elementTypeDefinition;                if (xsdSimpleTypeDefinition.getVariety() == XSDVariety.LIST_LITERAL)                {                  needsHolder = true;                  // Create a holder class like an anonymous complex type.                  //                  EClass holderClass = EcoreFactory.eINSTANCE.createEClass();                  setAnnotations(holderClass, xsdElementDeclaration);                  String holderName = xsdElementDeclaration.getName() + ":holder";                  holderClass.setName(validName(holderName, true));                  extendedMetaData.setName(holderClass, holderName);                  extendedMetaData.setContentKind(holderClass, ExtendedMetaData.SIMPLE_CONTENT);                              EPackage holderPackage = getEPackage(xsdElementDeclaration);                  addToSortedList(holderPackage.getEClassifiers(), holderClass);                  EReference holderReference =                    (EReference)createFeature                      (holderClass,                       "value",                       referenceClassifier,                       null,                       0,                       -1);                  holderReference.setResolveProxies(!isLocalReferenceType(xsdSimpleTypeDefinition));                  referenceClassifier = holderClass;                }              }              eStructuralFeature =                createFeature                  (eClass,                   name,                   referenceClassifier,                   xsdParticle,                   effectiveOccurrence.minOccurs,                   effectiveOccurrence.maxOccurs);              ((EReference)eStructuralFeature).setContainment(needsHolder);              if (needsHolder)              {                ((EReference)eStructuralFeature).setUnsettable(false);              }            }            else            {              eStructuralFeature =                createFeature                  (eClass,                   name,                   eClassifier,                   xsdParticle,                   effectiveOccurrence.minOccurs,                   effectiveOccurrence.maxOccurs);            }            // If the group is turned off, we better make the feature changeable.            //            if (!eStructuralFeature.isChangeable() && group == null)            {              eStructuralFeature.setChangeable(true);            }          }          if (group != null)          {            extendedMetaData.setGroup(eStructuralFeature, group);            eStructuralFeature.setDerived(true);            eStructuralFeature.setTransient(true);            eStructuralFeature.setVolatile(true);          }          else if (isMixed)          {            eStructuralFeature.setDerived(true);            eStructuralFeature.setTransient(true);            eStructuralFeature.setVolatile(true);          }          else if (globalGroup != null)          {            extendedMetaData.setGroup(eStructuralFeature, globalGroup);            eStructuralFeature.setDerived(true);            eStructuralFeature.setTransient(true);            eStructuralFeature.setVolatile(true);          }        }      }      else      {        extendedMetaData.setContentKind(eClass, ExtendedMetaData.EMPTY_CONTENT);      }      Collection baseAttributeUses = new HashSet();      if (baseTypeDefinition instanceof XSDComplexTypeDefinition)      {        for (Iterator i = ((XSDComplexTypeDefinition)baseTypeDefinition).getAttributeUses().iterator(); i.hasNext(); )        {          baseAttributeUses.add(((XSDAttributeUse)i.next()).getAttributeDeclaration().getURI());        }      }      for (Iterator i = xsdComplexTypeDefinition.getAttributeUses().iterator(); i.hasNext(); )      {        XSDAttributeUse xsdAttributeUse = (XSDAttributeUse)i.next();        XSDAttributeDeclaration xsdAttributeDeclaration = xsdAttributeUse.getAttributeDeclaration();        if (!baseAttributeUses.contains(xsdAttributeDeclaration.getURI()))        {          String name = getEcoreAttribute(xsdAttributeUse, "name");          if (name == null)          {            name = getEcoreAttribute(xsdAttributeDeclaration, "name");          }          if (name == null)          {            name = validName(xsdAttributeDeclaration.getName(), true);          }          XSDSimpleTypeDefinition attributeTypeDefinition = xsdAttributeDeclaration.getTypeDefinition();          EDataType eDataType = getEDataType(attributeTypeDefinition);          XSDTypeDefinition referenceType = getEcoreTypeQNameAttribute(xsdAttributeDeclaration, "reference");          if (referenceType != null)          {            int lowerBound = xsdAttributeUse.isRequired() ? 1 : 0;            int upperBound = 1;            if (attributeTypeDefinition.getVariety() == XSDVariety.LIST_LITERAL)            {              if (xsdAttributeUse.isRequired())              {                XSDMinLengthFacet xsdMinLengthFacet = attributeTypeDefinition.getEffectiveMinLengthFacet();                if (xsdMinLengthFacet != null)                {                  lowerBound = xsdMinLengthFacet.getValue();                }              }              XSDMaxLengthFacet xsdMaxLengthFacet = attributeTypeDefinition.getEffectiveMaxLengthFacet();              if (xsdMaxLengthFacet != null)              {                upperBound = xsdMaxLengthFacet.getValue();              }              else              {                upperBound = -1;              }            }            EClassifier referenceClassifier = getEClassifier(referenceType);            EStructuralFeature eStructuralFeature =              createFeature                (eClass,                 name,                 referenceClassifier,                 xsdAttributeUse,                 lowerBound,                 upperBound);          }          else          {            EStructuralFeature eStructuralFeature =              createFeature                (eClass,                 name,                 eDataType,                 xsdAttributeUse,                 xsdAttributeUse.isRequired() ? 1 : 0,                 1);          }        }      }      XSDWildcard xsdWildcard = xsdComplexTypeDefinition.getAttributeWildcardContent();      if (xsdWildcard != null)      {        String name = getEcoreAttribute(xsdWildcard, "name");        if (name == null)        {          name = "anyAttribute";        }        EStructuralFeature eStructuralFeature =          createFeature            (eClass,             name,             EcorePackage.eINSTANCE.getEFeatureMapEntry(),             xsdWildcard,             0,             -1);      }    }    else    {      int baseContentKind = extendedMetaData.getContentKind((EClass)eClass.getESuperTypes().get(0));      if (baseContentKind == ExtendedMetaData.MIXED_CONTENT &&             xsdComplexTypeDefinition.getContentTypeCategory() == XSDContentTypeCategory.SIMPLE_LITERAL)      {        extendedMetaData.setContentKind(eClass, ExtendedMetaData.SIMPLE_CONTENT);        EStructuralFeature eStructuralFeature =          createFeature            (eClass,             "rawValue",             getBuiltInEClassifier(xsdComplexTypeDefinition.getSchema().getSchemaForSchemaNamespace(), "string"),             null,             0,             1);        eStructuralFeature.setDerived(true);        eStructuralFeature.setTransient(true);        eStructuralFeature.setVolatile(true);        eStructuralFeature =          createFeature            (eClass,             "value",             getBuiltInEClassifier(xsdComplexTypeDefinition.getSchema().getSchemaForSchemaNamespace(), "anySimpleType"),             null,             0,             1);        eStructuralFeature.setDerived(true);        eStructuralFeature.setTransient(true);        eStructuralFeature.setVolatile(true);        if ("SimpleAnyType".equals(eClass.getName()) && XMLTypePackage.eNS_URI.equals(eClass.getEPackage().getNsURI()))        {          eStructuralFeature =            createFeature              (eClass,               "instanceType",               EcorePackage.eINSTANCE.getEDataType(),               null,               1,               1);          ((EReference)eStructuralFeature).setResolveProxies(false);        }      }      else      {        extendedMetaData.setContentKind(eClass, baseContentKind);      }    }    return eClass;  }