* @return detail
*/
private MappingDetail addDetail(MappingElement map) {
// check structure of mapping definition for schema type extension
MappingElement base = null;
StructureElement baseref = null;
ArrayList contents = map.getContentComponents();
if (contents.size() > 0) {
// type extension requires reference as first content component
Object content = contents.get(0);
if (content instanceof StructureElement) {
StructureElement struct = (StructureElement)content;
if (isTypeDerivation(struct)) {
base = (MappingElement)struct.getEffectiveMapping();
baseref = struct;
}
}
}
// next search recursively for text and/or child element components this is done at this point (with loop
// recursion, if needed) so that the flags can be set when creating the detail instance
boolean haschild = false;
boolean hastext = false;
ArrayList expands = new ArrayList();
expands.add(map);
for (int i = 0; i < expands.size(); i++) {
// check for container with element name or text content
ContainerElementBase contain = (ContainerElementBase)expands.get(i);
contents = contain.getContentComponents();
for (int j = 0; j < contents.size(); j++) {
IComponent comp = (IComponent)contents.get(j);
if (comp.hasName()) {
// component with name means child element
haschild = true;
} else if (comp instanceof ValueElement) {
// value with no name implies text content
hastext = true;
} else if (comp instanceof CollectionElement) {
// collection implies child element (repeating)
haschild = true;
} else {
// structure, check for mapping reference
StructureElement struct = (StructureElement)comp;
if (struct.children().size() > 0) {
// add container structure to expansion list
expands.add(comp);
} else {
MappingElementBase ref = (MappingElementBase)struct.getEffectiveMapping();
if (ref != null) {
// mapping element reference, check if named
if (ref.getName() != null) {
haschild = true;
} else {
expands.add(ref);
m_forceTypeMappings.add(ref);
}
}
}
}
}
}
// get the names for this mapping
ClassCustom custom = m_custom.addClassCustomization(map.getClassName());
QName tname = map.getTypeQName();
if (tname == null) {
NamespaceElement dfltns = map.getDefinitions().getElementDefaultNamespace();
if (dfltns != null) {
tname = new QName(dfltns.getUri(), custom.getTypeQName().getName());
} else {
tname = custom.getTypeQName();
}
}
QName oname = null;
String name = map.getName();
if (name == null) {
oname = custom.getElementQName();
} else {
oname = new QName(map.getNamespace().getUri(), name);
}
// add new mapping detail based on information found
MappingDetail detail = new MappingDetail(map, haschild, hastext, base, tname, oname);
m_mappingMap.put(map, detail);
// check for mapping to element name
if (map.getName() == null) {
// require base type generation as type
if (base != null) {
MappingDetail basedetail = forceMappingDetail(base);
basedetail.setType(true);
}
} else {
// force generating an element for this mapping
detail.setElement(true);
}
// error if mapping extension doesn't map to type extension
MappingElement extended = map.getExtendsMapping();
if (extended != null) {
// recursively check for extension type match
boolean isext = false;
MappingElement ancest = base;
while (ancest != null) {
if (ancest.getClassName().equals(extended.getClassName())) {
isext = true;
break;
} else {
ancest = forceMappingDetail(ancest).getExtensionBase();
}