String sAttributeName = XMLUtil.getStringAttr(element, "attribute");
if (sAttributeName != null)
{
Attribute attribute = metaclass.getAttribute(sAttributeName);
VirtualPrimitiveMapping primitiveMapping = new VirtualPrimitiveMapping();
primitiveMapping.setObjectKeyPart(keyTypeList.size() - 1);
primitiveMapping.setAttribute(attribute);
mapping.addAttributeMapping(primitiveMapping);
primitiveMapping.validate(metadata, m_helper.getWarnings());
}
}
});
mapping.setKey((Primitive[])keyTypeList.toArray(new Primitive[keyTypeList.size()]));
}
});
XMLUtil.withFirstChildElement(element, "AttributeMappings", false,
new XMLUtil.ElementHandler()
{
public void handleElement(Element element)
{
XMLUtil.forEachChildElement(element, "AttributeMapping", new XMLUtil.ElementHandler()
{
public void handleElement(Element element)
{
String sName = XMLUtil.getReqStringAttr(element, "name");
int nMaxLength = XMLUtil.getIntAttr(element, "maxLength", 0);
final Attribute attribute = metaclass.getAttribute(sName);
AttributeMapping attrMapping;
if (attribute.getType().isPrimitive())
{
VirtualPrimitiveMapping primitiveMapping = new VirtualPrimitiveMapping();
attrMapping = primitiveMapping;
if (element.hasAttribute("attributes"))
{
throw new MetadataException("err.meta.persistence.virtual.invalidPropertySpecified",
new Object[]{"attributes", sName, metaclass.getName()});
}
if (XMLUtil.getBooleanAttr(element, "objectSourceKey", false))
{
throw new MetadataException("err.meta.persistence.virtual.invalidPropertySpecified",
new Object[]{"objectSourceKey", sName, metaclass.getName()});
}
if (element.hasAttribute("destinationKey"))
{
throw new MetadataException("err.meta.persistence.virtual.invalidPropertySpecified",
new Object[]{"destinationKey", sName, metaclass.getName()});
}
if (nMaxLength != 0)
{
if (attribute.getType() != Primitive.BINARY && attribute.getType() != Primitive.STRING)
{
throw new MetadataException("err.meta.persistence.virtual.maxLengthSpecified",
new Object[]{attribute.getName(), metaclass.getName()});
}
primitiveMapping.setMaxLength(nMaxLength);
}
}
else
{
final VirtualClassMapping classMapping = new VirtualClassMapping();
attrMapping = classMapping;
classMapping.setComposition((Pair)m_helper.parse(
XMLUtil.getStringAttr(element, "attributes"),
true, null, null, metadata.getGlobalEnvironment()
));
final boolean bObjectSourceKey = XMLUtil.getBooleanAttr(element, "objectSourceKey", false);
final String sDestinationKeyName = XMLUtil.getStringAttr(element, "destinationKey");
if (nMaxLength != 0)
{
throw new MetadataException("err.meta.persistence.virtual.maxLengthSpecified",
new Object[]{attribute.getName(), metaclass.getName()});
}
loader.addPersistenceMappingFixup(new ContextFixup(m_helper)
{
public void fixup()
{
Metaclass type = (Metaclass)attribute.getType();
PersistenceMapping assocClassMapping = type.getPersistenceMapping();
if (assocClassMapping == null)
{
throw new MetadataException("err.meta.missingAssocPersistenceMapping",
new Object[]{attribute.getName(), metaclass.getName(), type.getName()});
}
classMapping.setSourceKey((bObjectSourceKey) ? mapping.getObjectKey() : new VirtualKey(attribute));
classMapping.setDestinationKey(assocClassMapping.addForeignKey(sDestinationKeyName, classMapping));
}