}
// build mapping from class name to index
classes = factory.getMappedClasses();
String[] names = factory.getElementNames();
StringIntHashMap namemap = new StringIntHashMap(names.length);
for (int i = 0; i < names.length; i++) {
String clasname = classes[i];
namemap.add(clasname, i);
}
// build mapping from abstract type name to index, and preserve classes
String[][] abstracts = factory.getAbstractMappings();
StringIntHashMap typemap = new StringIntHashMap(abstracts[0].length);
for (int i = 0; i < abstracts[0].length; i++) {
String name = abstracts[IBindingFactory.ABMAP_MAPPINGNAME_INDEX][i];
typemap.add(name, i);
preserveMethodClass(abstracts[IBindingFactory.ABMAP_ATTRMARMETH_INDEX][i]);
preserveMethodClass(abstracts[IBindingFactory.ABMAP_ATTRPRESMETH_INDEX][i]);
preserveMethodClass(abstracts[IBindingFactory.ABMAP_ATTRUMARMETH_INDEX][i]);
preserveMethodClass(abstracts[IBindingFactory.ABMAP_COMPLETEMETH_INDEX][i]);
preserveMethodClass(abstracts[IBindingFactory.ABMAP_CONTMARMETH_INDEX][i]);
preserveMethodClass(abstracts[IBindingFactory.ABMAP_CONTPRESMETH_INDEX][i]);
preserveMethodClass(abstracts[IBindingFactory.ABMAP_CONTUMARMETH_INDEX][i]);
preserveMethodClass(abstracts[IBindingFactory.ABMAP_CREATEMETH_INDEX][i]);
preserveMethodClass(abstracts[IBindingFactory.ABMAP_PREPAREMETH_INDEX][i]);
}
// process all the mapping definitions in binding
String[] namespaces = factory.getElementNamespaces();
String[] mars = factory.getMarshallerClasses();
String[] umars = factory.getUnmarshallerClasses();
while (ctx.isAt(URI_ELEMENTS, MAPPING_ELEMENT)) {
// first check for an abstract mapping
boolean abs = ctx.attributeBoolean(URI_ATTRIBUTES,
MAPPING_ABSTRACT, false);
String type = ctx.attributeText(URI_ATTRIBUTES, MAPPING_CLASS);
// get name definition if supplied
NameDefinition ndef = null;
if (isNamePresent(ctx)) {
int index = factory.getClassIndexMap().get(type);
String prename = names[index];
String prens = namespaces[index];
String defname = ctx.attributeText(URI_ATTRIBUTES, COMMON_NAME);
String defns = ctx.attributeText(URI_ATTRIBUTES, COMMON_NAMESPACE, prens);
if (!prename.equals(defname)) {
throw new JiBXException("Precompiled mapping for class " + type +
" uses element name '" + prename + "' which does not match element name '" +
defname + "' used in binding");
} else if (!Utility.safeEquals(prens, defns)) {
throw new JiBXException("Precompiled mapping for class " + type +
" uses element namespace '" + prens + "' which does not match element namespace '" +
defns + "' used in binding");
} else {
ndef = new NameDefinition(defname, defns, false);
}
}
// get type name and mapping name (type, or class if no type)
String mname = type;
String tname = null;
String text = ctx.attributeText(URI_ATTRIBUTES, MAPPING_TYPENAME,
null);
if (text != null) {
tname = QName.deserialize(text, ctx).toString();
mname = tname;
}
// build mapping definition to match
IMapping mapping;
if (abs) {
int index = typemap.get(mname);
if (index >= 0) {
mapping = new PrecompiledAbstractMapping(type, tname, mname,
index, factory, nsxlate, parent);
} else {
throw new IllegalStateException("Precompiled binding does not match supplied binding for " + factory.getBindingName() + ": type " + mname + " not found");