// Primary key field must ALLWAYS be included ! (or then they must be checked if ....)
isValueObjectField = isValueObjectField ||
EjbUtils.hasFlag(metaFlags, EjbUtils.METADATA_METHOD_PRIMARY_KEY_FIELD);
if (isValueObjectField) {
EjbValueObjectFieldTag vTag = findMatchedTag(valueTag.getMatch(), method);
BeanProperty prop = javaClass.getBeanProperty(method.getPropertyName(), true);
if (log.isDebugEnabled()) {
log.debug(method.getName() + " is a value-object-field: matches or is a pk-field.");
}
// XXX: Todo, if we have a relation found by the RelationManager, then we must have
// it's treatment as such, or should be ignored
// Maybe just check if is a EjbUtils.METADATA_METHOD_RELATION_FIELD
Relation relation = getRelationManager().getRelationFor(method, javaClass);
if ((relation != null) ||
((vTag != null) && ((vTag.getAggregate() != null) || (vTag.getCompose() != null)))) {
// This is a value-object relation
// vTag must be non-null, because we need values from it
if ((vTag != null) && ((vTag.getAggregate() != null) ^ (vTag.getCompose() != null))) {
JavaClass relationEjb = null;
Type collectionType = null;
if (relation != null) {
if (!method.equals(relation.getLeftMethod())) {
log.debug(
"Current method doesn't match relations' left method. Reversing relation");
relation = relation.reverse();
if (log.isDebugEnabled()) {
log.debug("Reversed relation is relation=" + relation);
}
}
if (log.isDebugEnabled()) {
log.debug("Using relation information. relation=" + relation);
log.debug("1# Left bean=" +
((relation.getLeftBean() != null)
? relation.getLeftBean().getFullyQualifiedName() : null));
log.debug("1# Rigth bean=" +
((relation.getRightBean() != null)
? relation.getRightBean().getFullyQualifiedName() : null));
}
String relationEjbName = relation.getRightEJBName();
relationEjb = getBeanResolver().findEjbByName(relationEjbName);
collectionType = relation.getLeftMethod().getReturns();
} else {
log.debug("We don't have relation information for this method");
Type returnType = method.getReturns();
Type relationType = null;
if (returnType.isA(COLLECTION_TYPE) || returnType.isA(SET_TYPE)) {
String members = vTag.getMembers();
if (log.isDebugEnabled()) {
log.debug(returnType + ": Is a Set or Collection. Using members='" +
members + "'");
}
if (members == null) {
if (log.isWarnEnabled()) {
log.warn(EjbUtils.getMessageWithTagLocation(vTag,
"members is null. Skipping."));
}
continue;
}
relationType = new Type(members);
collectionType = returnType.isA(COLLECTION_TYPE) ? COLLECTION_TYPE : SET_TYPE;
} else {
if (log.isDebugEnabled()) {
log.debug(returnType + ": Using it to find it's match!");
}
relationType = returnType;
}
relationEjb = findBeanByInterface(getOriginalMetadata(), relationType);
}
if (relationEjb == null) {
log.warn("Couldn't find the related Ejb! Skipping.");
continue;
}
ValueObjectRelationMetadata vObjRelation = new ValueObjectRelationMetadata(relationEjb,
collectionType, (vTag.getAggregate() != null), vTag);
if (log.isDebugEnabled()) {
log.debug("Relation is " + vObjRelation);
}