EClass baseClass = null;
XSDTypeDefinition baseTypeDefinition = xsdComplexTypeDefinition.getBaseTypeDefinition();
if (!baseTypeDefinition.isCircular())
{
EClassifier baseType = getEClassifier(baseTypeDefinition);
if (baseType instanceof EClass && baseType != ecorePackage.getEObject())
{
eClass.getESuperTypes().add(baseClass = (EClass)baseType);
}
}
boolean isRestriction =
!eClass.getESuperTypes().isEmpty() &&
xsdComplexTypeDefinition.getDerivationMethod() == XSDDerivationMethod.RESTRICTION_LITERAL;
for (Iterator i = getEcoreTypeQNamesAttribute(xsdComplexTypeDefinition, "implements").iterator(); i.hasNext(); )
{
XSDTypeDefinition mixin = (XSDTypeDefinition)i.next();
if (!XSDConstants.isURType(mixin))
{
EClassifier mixinType = getEClassifier(mixin);
if (mixinType instanceof EClass && mixinType != ecorePackage.getEObject())
{
eClass.getESuperTypes().add(mixinType);
}
}
}
// 51210
// EAnnotation contentParticle = null;
if (xsdComplexTypeDefinition.getContentTypeCategory() == XSDContentTypeCategory.SIMPLE_LITERAL)
{
extendedMetaData.setContentKind(eClass, ExtendedMetaData.SIMPLE_CONTENT);
if (!"SimpleAnyType".equals(eClass.getName()) || !XMLTypePackage.eNS_URI.equals(eClass.getEPackage().getNsURI()))
{
if (eClass.getEAllStructuralFeatures().isEmpty())
{
XSDComplexTypeContent xsdComplexTypeContent = xsdComplexTypeDefinition.getContent();
String name = getEcoreAttribute(xsdComplexTypeContent, "name");
if (name == null)
{
name = "value";
}
createFeature
(eClass,
null,
name,
xsdComplexTypeContent,
false);
}
else
{
XSDSimpleTypeDefinition xsdSimpleTypeDefinition = xsdComplexTypeDefinition.getSimpleType();
getEClassifier(xsdSimpleTypeDefinition);
}
}
}
else
{
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 :
xsdComplexTypeDefinition.getContentTypeCategory() == XSDContentTypeCategory.EMPTY_LITERAL ?
ExtendedMetaData.EMPTY_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.getEFeatureMapEntry(),
null,
0,
-1);
extendedMetaData.setName(mixedFeature, ":mixed");
}
}
else
{
globalGroup = extendedMetaData.getElement(eClass, null, ":group");
if (globalGroup == null && featureMapName != null && eClass.getESuperTypes().isEmpty())
{
globalGroup =
createFeature
(eClass,
featureMapName,
ecorePackage.getEFeatureMapEntry(),
null,
0,
-1);
extendedMetaData.setName(globalGroup, ":group");
extendedMetaData.setFeatureKind(globalGroup, ExtendedMetaData.GROUP_FEATURE);
}
}
if (xsdComplexTypeDefinition.getContent() != null)
{
// 51210
// Map particleMap = new HashMap();
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 = null;
String name = getEcoreAttribute(xsdParticle, "name");
if (xsdTerm instanceof XSDModelGroup)
{
if (!isRestriction)
{
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.getEFeatureMapEntry(),
xsdParticle,
0,
-1);
groups.put(xsdTerm, eStructuralFeature);
extendedMetaData.setName(eStructuralFeature, name + ":" + eClass.getEAllStructuralFeatures().indexOf(eStructuralFeature));
}
}
else if (xsdTerm instanceof XSDWildcard)
{
if (!isRestriction)
{
if (name == null)
{
name = getEcoreAttribute(xsdTerm, "name");
if (name == null)
{
name = "any";
}
}
eStructuralFeature =
createFeature
(eClass,
name,
ecorePackage.getEFeatureMapEntry(),
xsdParticle,
effectiveOccurrence.minOccurs,
effectiveOccurrence.maxOccurs);
// 51210
// particleMap.put(xsdParticle, eStructuralFeature);
}
}
else
{
XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)xsdTerm;
boolean isRedundant = false;
if (isRestriction)
{
isRedundant =
extendedMetaData.getElement
(baseClass, xsdElementDeclaration.getTargetNamespace(), xsdElementDeclaration.getName()) != null;
if (!isRedundant)
{
group =
extendedMetaData.getElementWildcardAffiliation
(baseClass, xsdElementDeclaration.getTargetNamespace(), xsdElementDeclaration.getName());
}
}
if (!isRedundant)
{
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.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;
}
eStructuralFeature =
createFeature(eClass, xsdElementDeclaration, name, xsdParticle, effectiveOccurrence.minOccurs, effectiveOccurrence.maxOccurs);
// 51210
// particleMap.put(xsdParticle, eStructuralFeature);
// If the group is turned off, we better make the feature changeable.
//
if (!eStructuralFeature.isChangeable() && group == null && getEcoreAttribute(xsdParticle, xsdElementDeclaration, "changeable") == null)
{
eStructuralFeature.setChangeable(true);
}
}
}
if (eStructuralFeature != null)
{
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);
}
}
}
// 51210
// contentParticle = computeParticleConstraints(eClass, particleMap, (XSDParticle)xsdComplexTypeDefinition.getContent());
}
}
// 51210
// EAnnotation attributeParticle = null;
// if (isRestriction)
// {
// attributeParticle = ecoreFactory.createEAnnotation();
// attributeParticle.setSource("attributes");
// }
XSDWildcard baseXSDWildcard = null;
Collection baseAttributeUses = Collections.EMPTY_LIST;
Map baseAttributeURIs = new HashMap();
if (baseTypeDefinition instanceof XSDComplexTypeDefinition)
{
XSDComplexTypeDefinition complexBaseTypeDefinition = (XSDComplexTypeDefinition)baseTypeDefinition;
baseXSDWildcard = complexBaseTypeDefinition.getAttributeWildcard();
baseAttributeUses = complexBaseTypeDefinition.getAttributeUses();
for (Iterator i = baseAttributeUses.iterator(); i.hasNext(); )
{
XSDAttributeUse xsdAttributeUse = (XSDAttributeUse)i.next();
baseAttributeURIs.put(xsdAttributeUse.getAttributeDeclaration().getURI(), xsdAttributeUse);
}
}
for (Iterator i = getAttributeUses(xsdComplexTypeDefinition).iterator(); i.hasNext(); )
{
XSDAttributeUse xsdAttributeUse = (XSDAttributeUse)i.next();
XSDAttributeDeclaration xsdAttributeDeclaration = xsdAttributeUse.getAttributeDeclaration();
if (baseAttributeURIs.remove(xsdAttributeDeclaration.getURI()) == null)
{
String name = getEcoreAttribute(xsdAttributeUse, "name");
if (name == null)
{
name = getEcoreAttribute(xsdAttributeDeclaration, "name");
}
if (name == null)
{
name = validName(xsdAttributeDeclaration.getName(), true);
}
EStructuralFeature eStructuralFeature =
createFeature(eClass, xsdAttributeDeclaration, name, xsdAttributeUse, xsdAttributeUse.isRequired());
if (isRestriction)
{
EStructuralFeature attributeWildcardEStructuralFeature =
extendedMetaData.getAttributeWildcardAffiliation
(baseClass, xsdAttributeDeclaration.getTargetNamespace(), xsdAttributeDeclaration.getName());
if (attributeWildcardEStructuralFeature != null)
{
extendedMetaData.setGroup(eStructuralFeature, attributeWildcardEStructuralFeature);
eStructuralFeature.setDerived(true);
eStructuralFeature.setTransient(true);
eStructuralFeature.setVolatile(true);
}
}
}
/* 51210
else if (isRestriction && !baseAttributeUses.contains(xsdAttributeUse))
{
EStructuralFeature eStructuralFeature =
extendedMetaData.getAttribute(eClass, xsdAttributeDeclaration.getTargetNamespace(), xsdAttributeDeclaration.getName());
if (eStructuralFeature != null)
{
EAnnotation attributeEAnnotation = ecoreFactory.createEAnnotation();
if (xsdAttributeUse.isRequired())
{
attributeEAnnotation.getDetails().put("minOccurs", "1");
}
attributeEAnnotation.getReferences().add(eStructuralFeature);
if (xsdAttributeDeclaration.getTypeDefinition() != null)
{
EClassifier type = getEClassifier(xsdAttributeDeclaration.getTypeDefinition());
if (type != eStructuralFeature.getEType() && type != null)
{
attributeEAnnotation.getReferences().add(type);
}
}
attributeParticle.getContents().add(attributeEAnnotation);
}
}
*/
}
/* 51210
if (isRestriction && !baseAttributeURIs.isEmpty())
{
for (Iterator i = baseAttributeURIs.values().iterator(); i.hasNext(); )
{
XSDAttributeUse xsdAttributeUse = (XSDAttributeUse)i.next();
XSDAttributeDeclaration xsdAttributeDeclaration = xsdAttributeUse.getAttributeDeclaration();
EStructuralFeature eStructuralFeature =
extendedMetaData.getAttribute(eClass, xsdAttributeDeclaration.getTargetNamespace(), xsdAttributeDeclaration.getName());
if (eStructuralFeature != null)
{
EAnnotation attributeEAnnotation = ecoreFactory.createEAnnotation();
attributeEAnnotation.getReferences().add(eStructuralFeature);
attributeEAnnotation.getDetails().put("maxOccurs", "0");
attributeParticle.getContents().add(attributeEAnnotation);
}
}
}
*/
XSDWildcard xsdWildcard = xsdComplexTypeDefinition.getAttributeWildcard();
if (xsdWildcard != null && baseXSDWildcard != xsdWildcard || XSDConstants.isURType(xsdComplexTypeDefinition))
{
if (isRestriction && !XSDConstants.isURType(xsdComplexTypeDefinition))
{
// 51210
// attributeParticle.getDetails().put
// ("wildcard", BasicExtendedMetaData.getEncodedWildcards(xsdComplexTypeDefinition.getTargetNamespace(), getWildcards(xsdWildcard)));
}
else
{
String name = getEcoreAttribute(xsdWildcard, "name");
if (name == null)
{
name = "anyAttribute";
}
createFeature
(eClass,
name,
ecorePackage.getEFeatureMapEntry(),
xsdWildcard,
0,
-1);
}
}
if (isRestriction)
{
// 51210
// EAnnotation restrictionParticle = ecoreFactory.createEAnnotation();
// restrictionParticle.setSource("restriction");
// if (contentParticle != null)
// {
// restrictionParticle.getContents().add(contentParticle);
// }
// if (!attributeParticle.getContents().isEmpty() || !attributeParticle.getDetails().isEmpty())
// {
// restrictionParticle.getContents().add(attributeParticle);
// }
// contentParticle = restrictionParticle;
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.getEDataType(),
null,
1,
1);
((EReference)eStructuralFeature).setResolveProxies(false);
}
}
else
{
extendedMetaData.setContentKind(eClass, baseContentKind);
}
}
// 51210
// extendedMetaData.setContent(eClass, contentParticle);
XSDAnnotation xsdAnnotation = xsdComplexTypeDefinition.getAnnotation();
if (xsdAnnotation != null)
{
List applicationInformationList = xsdAnnotation.getApplicationInformation(EcorePackage.eNS_URI);
for (Iterator i = applicationInformationList.iterator(); i.hasNext(); )
{
Element applicationInformation = (Element)i.next();
if ("operations".equals(applicationInformation.getAttributeNS(EcorePackage.eNS_URI, "key")))
{
for (Iterator j = getElements(applicationInformation, "operation").iterator(); j.hasNext(); )
{
EOperation eOperation = ecoreFactory.createEOperation();
Element operation = (Element)j.next();
String operationName = operation.getAttributeNS(null, "name");
eOperation.setName(operationName);
XSDTypeDefinition returnType = getEcoreTypeQNameAttribute(xsdComplexTypeDefinition, operation, null, "type");
if (returnType != null)
{
EClassifier returnEType = getEClassifier(returnType);
eOperation.setEType(returnEType);
}
List exceptions = getEcoreTypeQNamesAttribute(xsdComplexTypeDefinition, operation, null, "exceptions");
for (Iterator k = exceptions.iterator(); k.hasNext(); )
{
XSDTypeDefinition exceptionTypeDefinition = (XSDTypeDefinition)k.next();
eOperation.getEExceptions().add(getEClassifier(exceptionTypeDefinition));
}
for (Iterator k = getElements(operation, "parameter").iterator(); k.hasNext(); )
{
EParameter eParameter = ecoreFactory.createEParameter();
Element parameter = (Element)k.next();
String paramaterName = parameter.getAttributeNS(null, "name");
XSDTypeDefinition parameterType = getEcoreTypeQNameAttribute(xsdComplexTypeDefinition, parameter, null, "type");
EClassifier parameterEType = getEClassifier(parameterType);
eParameter.setName(paramaterName);
eParameter.setEType(parameterEType);
populateETypedElement(eParameter, parameter);
eOperation.getEParameters().add(eParameter);