while (comp != topcomp) {
if (comp.isGlobal()) {
if (!(item instanceof ReferenceItem)) {
refcomps.add(comp);
}
QName qname = ((INamed)comp).getQName();
if (qname == null) {
throw new IllegalStateException("Internal error - no name on global definition");
} else {
uritoprefix.put(qname.getUri(), qname.getPrefix());
}
break;
} else {
comp = comp.getParent();
}
}
// now check the actual item type
if (item instanceof GroupItem) {
// check non-inlined group which uses separate class
GroupItem childgroup = (GroupItem)item;
if (!childgroup.isIgnored()) {
if (childgroup.isInline()) {
scanItemTree(childgroup, comptoclas, refcomps, uritoprefix);
} else {
// add component to class mapping to stop schema fragment generation when reached
TypeData genclas = childgroup.getGenerateClass();
if (genclas == null) {
throw new IllegalStateException("Internal error - no generate class");
} else {
comptoclas.put(childgroup.getSchemaComponent(), genclas);
}
// check for type definition or reference used (with associated namespace reference)
QName tname = null;
comp = item.getSchemaComponent();
switch (comp.type()) {
case SchemaBase.ATTRIBUTE_TYPE:
tname = ((AttributeElement)comp).getType();
break;
case SchemaBase.ELEMENT_TYPE:
tname = ((ElementElement)comp).getType();
break;
}
if (tname != null) {
uritoprefix.put(tname.getUri(), tname.getPrefix());
}
QName rname = null;
if (comp instanceof IReference) {
rname = ((IReference)comp).getRef();
}
if (rname != null) {
uritoprefix.put(rname.getUri(), rname.getPrefix());
}
}
}
} else if (item instanceof ReferenceItem) {
// make sure namespace collected for reference
DefinitionItem def = ((ReferenceItem)item).getDefinition();
AnnotatedBase defcomp = def.getSchemaComponent();
if (defcomp instanceof INamed) {
QName qname = ((INamed)defcomp).getQName();
if (qname == null && defcomp instanceof IReference) {
qname = ((IReference)defcomp).getRef();
}
if (qname != null) {
uritoprefix.put(qname.getUri(), qname.getPrefix());
}
}
TypeData genclas = def.getGenerateClass();
if (genclas != null) {
comptoclas.put(defcomp, genclas);
}
}
}
}
// also check for substitution group used with element
if (topcomp.type() == SchemaBase.ELEMENT_TYPE) {
QName sname = ((ElementElement)topcomp).getSubstitutionGroup();
if (sname != null) {
uritoprefix.put(sname.getUri(), sname.getPrefix());
}
}
}