PropertyDefinition prop = m_property;
if (mdef == null) {
// generate generic mapping to unknown type
if (m_name != null) {
throw new JiBXException
("Name not allowed for generic mapping of type " + m_type);
}
wrap = new DirectGeneric(m_container, m_type, prop);
} else if (m_isSynthetic && mdef.isAbstract() && !mdef.isBase()) {
// collection reference to abstract non-base mapping as generic
wrap = new DirectGeneric(m_container, m_type, prop);
} else {
// check for reference from collection
if (prop.isImplicit()) {
prop.setOptional(false);
}
// add mapping namespaces to context (only if no element on mapping)
if (mdef.getName() == null) {
mdef.setLinkages();
ArrayList nss = mdef.getNamespaces();
if (nss != null) {
for (int i = 0; i < nss.size(); i++) {
defc.addImpliedNamespace((NamespaceDefinition)nss.get(i));
}
}
}
// generate wrapped component for all calls
String type = mdef.getBoundType();
if (prop.getTypeName() == null) {
prop = new PropertyDefinition(type, m_contextObject,
prop.isOptional());
}
if (m_name == null) {
wrap = mdef.buildRef(m_container, m_contextObject,
prop.getTypeName(), prop);
} else {
// force property required for internal structure
PropertyDefinition propcopy = new PropertyDefinition(prop);
propcopy.setOptional(false);
wrap = mdef.buildRef(m_container, m_contextObject,
prop.getTypeName(), propcopy);
m_wrappedReference = wrap;
if (mdef.getName() == null) {
// create the replacement components
IComponent icomp = wrap;
wrap = new ElementWrapper(defc, m_name, icomp, m_isNillable);
if (prop.isImplicit()) {
((ElementWrapper)wrap).setDirect(true);
}
if (prop.isOptional()) {
// make element optional
if (icomp instanceof ComponentProperty) {
((ComponentProperty)icomp).setSkipping(true);
}
((ElementWrapper)wrap).setOptionalNormal(true);
((ElementWrapper)wrap).setStructureObject(true);
((ElementWrapper)wrap).setDirect(true);
wrap = new OptionalStructureWrapper(wrap, prop,
true);
}
} else {
throw new JiBXException
("Name not allowed for reference to mapping of type " +
type + ", which already defines a name");
}
}