}
Enumeration enumeration = e2Group.enumerate();
while (enumeration.hasMoreElements()) {
Particle particle = (Particle)enumeration.nextElement();
if (particle.getStructureType() == Structure.ELEMENT) {
ElementDecl element = (ElementDecl)particle;
ElementDecl main = e1Group.getElementDecl(element.getName());
if (main == null) {
e1Group.addElementDecl(element);
element.setMinOccurs(0);
}
else {
merge(main, element);
}
}
}
//-- add all attributes from type2
enumeration = cType2.getAttributeDecls();
while (enumeration.hasMoreElements()) {
//-- check for attribute with same name
AttributeDecl attNew = (AttributeDecl)enumeration.nextElement();
String attName = attNew.getName();
AttributeDecl attPrev = cType1.getAttributeDecl(attName);
if (attPrev == null) {
attNew.setUse(AttributeDecl.USE_OPTIONAL);
cType1.addAttributeDecl(attNew);
}
else {
String type1 = attPrev.getSimpleType().getName();
String type2 = attNew.getSimpleType().getName();
if (!type1.equals(type2)) {
String typeName = _nsPrefix + ':' +
DatatypeHandler.whichType(type1, type2);
attPrev.setSimpleTypeReference(typeName); }
}
}
//-- loop through all element/attribute declarations
//-- of e1 and if they do not exist in e2, simply
//-- mark them as optional
enumeration = e1Group.enumerate();
while (enumeration.hasMoreElements()) {
Particle particle = (Particle)enumeration.nextElement();
if (particle.getStructureType() == Structure.ELEMENT) {
ElementDecl element = (ElementDecl)particle;
if (e2Group.getElementDecl(element.getName()) == null) {
element.setMinOccurs(0);
}
}