if (!field.isAnnotationPresent(Reference.class)) {
continue;
}
Class<?> reference = field.getType();
ComponentReferenceModel referenceModel = new V1ComponentReferenceModel(switchyardNamespace.uri());
InterfaceModel interfaceModel = new V1InterfaceModel(InterfaceModel.JAVA);
if (field.getAnnotation(Reference.class) != null) {
Reference ref = field.getAnnotation(Reference.class);
if (ref.value() == null || "".equals(ref.value())) {
referenceModel.setName(reference.getSimpleName());
} else {
QName qname = QName.valueOf(ref.value());
referenceModel.setName(qname.getLocalPart());
}
} else {
referenceModel.setName(reference.getSimpleName());
}
referenceModel.setInterface(interfaceModel);
interfaceModel.setInterface(reference.getCanonicalName());
// Add policy requirements to reference if specified
Requires refRequires = field.getAnnotation(Requires.class);
if (refRequires != null) {
for (SecurityPolicy secPolicy : refRequires.security()) {
if (!secPolicy.supports(PolicyType.INTERACTION)) {
throw BeanMessages.MESSAGES.referenceOnlyCouldBeMarkedWithInteractionPolicyButIsNotTheOne(secPolicy.toString());
}
referenceModel.addPolicyRequirement(secPolicy.getQName());
}
for (TransactionPolicy txPolicy : refRequires.transaction()) {
if (!txPolicy.supports(PolicyType.INTERACTION)) {
throw BeanMessages.MESSAGES.referenceOnlyCouldBeMarkedWithInteractionPolicyButIsNotTheOne(txPolicy.toString());
}
referenceModel.addPolicyRequirement(txPolicy.getQName());
}
// Make sure we don't have conflicting policies
QName ptx = TransactionPolicy.PROPAGATES_TRANSACTION.getQName();
QName stx = TransactionPolicy.SUSPENDS_TRANSACTION.getQName();
if (referenceModel.hasPolicyRequirement(ptx) && referenceModel.hasPolicyRequirement(stx)) {
throw BeanMessages.MESSAGES.transactionPoliciesCannotCoexistService(ptx, stx, name);
}
}
references.add(referenceModel);
}