/**
* INTERNAL:
* Create and return the appropriate accessor based on the given node.
*/
protected MetadataAccessor buildAccessor(Node node) {
MetadataAccessibleObject accessibleObject;
// Process the required name attribute.
String attributeName = m_helper.getNodeValue(node, XMLConstants.ATT_NAME);
// WIP - left to do here is perform validation on the accessors just
// like the annotation processor does.
if (m_descriptor.usesPropertyAccess()) {
Method method = MetadataHelper.getMethodForPropertyName(attributeName, getJavaClass());
if (method == null) {
m_validator.throwUnableToDetermineClassForProperty(attributeName, getJavaClass());
}
accessibleObject = new MetadataMethod(method);
} else {
Field field = MetadataHelper.getFieldForName(attributeName, getJavaClass());
if (field == null) {
m_validator.throwUnableToDetermineClassForField(attributeName, getJavaClass());
}
accessibleObject = new MetadataField(field);
}
String nodeName = node.getLocalName();
if (nodeName.equals(XMLConstants.ONE_TO_ONE)) {
return new XMLOneToOneAccessor(accessibleObject, node, this);
} else if (nodeName.equals(XMLConstants.MANY_TO_ONE)) {
return new XMLManyToOneAccessor(accessibleObject, node, this);
} else if (nodeName.equals(XMLConstants.ONE_TO_MANY)) {
if (MetadataHelper.isSupportedCollectionClass(accessibleObject.getRawClass())) {
return new XMLOneToManyAccessor(accessibleObject, node, this);
} else {
m_validator.throwInvalidCollectionTypeForRelationship(getJavaClass(), accessibleObject.getRawClass(), getAttributeName());
return null;
}
} else if (nodeName.equals(XMLConstants.MANY_TO_MANY)) {
if (MetadataHelper.isSupportedCollectionClass(accessibleObject.getRawClass())) {
return new XMLManyToManyAccessor(accessibleObject, node, this);
} else {
m_validator.throwInvalidCollectionTypeForRelationship(getJavaClass(), accessibleObject.getRawClass(), getAttributeName());
return null;
}
} else if (nodeName.equals(XMLConstants.EMBEDDED)) {
return new XMLEmbeddedAccessor(accessibleObject, node, this);
} else if (nodeName.equals(XMLConstants.EMBEDDED_ID)) {