redefinitions[i] = new RedefinitionHolder(schemasAndChameleons[i].getRedefine());
StscState state = StscState.get();
for (int j = 0; j < schemasAndChameleons.length; j++)
{
Schema schema = schemasAndChameleons[j].getSchema();
String givenTargetNamespace = schemasAndChameleons[j].getChameleonNamespace();
// quick check for a few unsupported features
if (schema.sizeOfNotationArray() > 0)
{
state.warning("Schema <notation> is not yet supported for this release.", XmlErrorCodes.UNSUPPORTED_FEATURE, schema.getNotationArray(0));
}
// figure namespace (taking into account chameleons)
String targetNamespace = schema.getTargetNamespace();
boolean chameleon = false;
if (givenTargetNamespace != null && targetNamespace == null)
{
targetNamespace = givenTargetNamespace;
chameleon = true;
}
if (targetNamespace == null)
targetNamespace = "";
//SchemaContainer container = null;
if (targetNamespace.length() > 0 || !isEmptySchema(schema))
{
state.registerContribution(targetNamespace, schema.documentProperties().getSourceName());
state.addNewContainer(targetNamespace);
//container = state.getContainer(targetNamespace);
}
List redefChain = new ArrayList();
TopLevelComplexType[] complexTypes = schema.getComplexTypeArray();
for (int i = 0; i < complexTypes.length; i++)
{
TopLevelComplexType type = complexTypes[i];
TopLevelComplexType redef;
int p = j;
// 1. Traverse the list of redefining Schemas putting all redefinitions
// of this type in a List
do
{
redef = redefinitions[p].redefineComplexType(type.getName());
if (redef != null)
{
redefChain.add(type);
type = redef;
}
p = schemasAndChameleons[p].getRedefinedBy();
}
while (p >= 0);
SchemaTypeImpl t = translateGlobalComplexType(type, targetNamespace, chameleon, redefChain.size() > 0);
state.addGlobalType(t, null);
SchemaTypeImpl r;
// 2. Traverse the List built in step 1 in reverse and add all the
// types in it to the list of redefined types
for (int k = redefChain.size() - 1; k >= 0; k--)
{
redef = (TopLevelComplexType) redefChain.remove(k);
r = translateGlobalComplexType(redef, targetNamespace, chameleon, k > 0);
state.addGlobalType(r, t);
t = r;
}
}
TopLevelSimpleType[] simpleTypes = schema.getSimpleTypeArray();
for (int i = 0; i < simpleTypes.length; i++)
{
TopLevelSimpleType type = simpleTypes[i];
TopLevelSimpleType redef;
int p = j;
do
{
redef = redefinitions[p].redefineSimpleType(type.getName());
if (redef != null)
{
redefChain.add(type);
type = redef;
}
p = schemasAndChameleons[p].getRedefinedBy();
}
while (p >= 0);
SchemaTypeImpl t = translateGlobalSimpleType(type, targetNamespace, chameleon,redefChain.size() > 0);
state.addGlobalType(t, null);
SchemaTypeImpl r;
for (int k = redefChain.size()-1; k >= 0; k--)
{
redef = (TopLevelSimpleType) redefChain.remove(k);
r = translateGlobalSimpleType(redef, targetNamespace, chameleon, k > 0);
state.addGlobalType(r, t);
t = r;
}
}
TopLevelElement[] elements = schema.getElementArray();
for (int i = 0; i < elements.length; i++)
{
TopLevelElement element = elements[i];
state.addDocumentType(translateDocumentType(element, targetNamespace, chameleon), QNameHelper.forLNS(element.getName(), targetNamespace));
}
TopLevelAttribute[] attributes = schema.getAttributeArray();
for (int i = 0; i < attributes.length ; i++)
{
TopLevelAttribute attribute = attributes[i];
state.addAttributeType(translateAttributeType(attribute, targetNamespace, chameleon), QNameHelper.forLNS(attribute.getName(), targetNamespace));
}
NamedGroup[] modelgroups = schema.getGroupArray();
for (int i = 0; i < modelgroups.length; i++)
{
NamedGroup group = modelgroups[i];
NamedGroup redef;
int p = j;
do
{
redef = redefinitions[p].redefineModelGroup(group.getName());
if (redef != null)
{
redefChain.add(group);
group = redef;
}
p = schemasAndChameleons[p].getRedefinedBy();
}
while (p >= 0);
SchemaModelGroupImpl g = translateModelGroup(group, targetNamespace, chameleon, redefChain.size() > 0);
state.addModelGroup(g, null);
SchemaModelGroupImpl r;
for (int k = redefChain.size()-1; k >= 0; k--)
{
redef = (NamedGroup) redefChain.remove(k);
r = translateModelGroup(redef, targetNamespace, chameleon, k > 0);
state.addModelGroup(r, g);
g = r;
}
}
NamedAttributeGroup[] attrgroups = schema.getAttributeGroupArray();
for (int i = 0; i < attrgroups.length; i++)
{
NamedAttributeGroup group = attrgroups[i];
NamedAttributeGroup redef;
int p = j;
do
{
redef = redefinitions[p].redefineAttributeGroup(group.getName());
if (redef != null)
{
redefChain.add(group);
group = redef;
}
p = schemasAndChameleons[p].getRedefinedBy();
}
while (p >= 0);
SchemaAttributeGroupImpl g = translateAttributeGroup(group, targetNamespace, chameleon, redefChain.size() > 0);
state.addAttributeGroup(g, null);
SchemaAttributeGroupImpl r;
for (int k = redefChain.size()-1; k >= 0; k--)
{
redef = (NamedAttributeGroup) redefChain.remove(k);
r = translateAttributeGroup(redef, targetNamespace, chameleon, k > 0);
state.addAttributeGroup(r, g);
g = r;
}
}
AnnotationDocument.Annotation[] annotations = schema.getAnnotationArray();
for (int i = 0; i < annotations.length; i++)
state.addAnnotation(SchemaAnnotationImpl.getAnnotation(state.getContainer(targetNamespace), schema, annotations[i]), targetNamespace);
}
for (int i = 0; i < redefinitions.length; i++)