/**
* Process a reference
*/
private void processReference(final ClassDescription describedClass, final MethodAnnotation ad) {
final ReferenceDescription ref = new ReferenceDescription(ad);
describedClass.add(ref);
ref.setStrategy(ReferenceStrategy.EVENT);
final String methodName = ad.getAnnotatedMethod().getName();
final String defaultUnbindMethodName;
final String refNameByMethod;
if ( methodName.startsWith("add") ) {
refNameByMethod = methodName.substring(3);
defaultUnbindMethodName = "remove" + refNameByMethod;
} else if ( methodName.startsWith("set") ) {
refNameByMethod = methodName.substring(3);
defaultUnbindMethodName = "unset" + refNameByMethod;
} else if ( methodName.startsWith("bind") ) {
refNameByMethod = methodName.substring(4);
defaultUnbindMethodName = "unbind" + refNameByMethod;
} else {
refNameByMethod = methodName;
defaultUnbindMethodName = "un" + refNameByMethod;
}
final String defaultUpdateMethodName = "updated" + refNameByMethod;
// bind method
ref.setBind(ad.getAnnotatedMethod().getName());
// unbind method
final String unbind = ad.getStringValue("unbind",
this.hasMethod(describedClass, defaultUnbindMethodName) ? defaultUnbindMethodName : "-");
if ( !unbind.equals("-") ) {
ref.setUnbind(unbind);
}
// update method
final String updated = ad.getStringValue("updated",
this.hasMethod(describedClass, defaultUpdateMethodName) ? defaultUpdateMethodName : "-");
if ( !updated.equals("-") ) {
ref.setUpdated(updated);
}
// name
ref.setName(ad.getStringValue("name", refNameByMethod));
// service
final String serviceName = ad.getStringValue("service", null);
if ( serviceName != null ) {
ref.setInterfaceName(serviceName);
} else {
final Class<?>[] params = ad.getAnnotatedMethod().getParameterTypes();
if ( params != null && params.length > 0 ) {
ref.setInterfaceName(params[0].getName());
}
}
// cardinality
final String cardinality = ad.getEnumValue("cardinality", "MANDATORY");
if ( cardinality.equals("OPTIONAL") ) {
ref.setCardinality(ReferenceCardinality.OPTIONAL_UNARY);
} else if ( cardinality.equals("MULTIPLE") ) {
ref.setCardinality(ReferenceCardinality.OPTIONAL_MULTIPLE);
} else if ( cardinality.equals("AT_LEAST_ONE") ) {
ref.setCardinality(ReferenceCardinality.MANDATORY_MULTIPLE);
} else {
ref.setCardinality(ReferenceCardinality.MANDATORY_UNARY);
}
// policy
ref.setPolicy(ReferencePolicy.valueOf(ad.getEnumValue("policy", ReferencePolicy.STATIC.name())));
// policy option
ref.setPolicyOption(ReferencePolicyOption.valueOf(ad.getEnumValue("policyOption", ReferencePolicyOption.RELUCTANT.name())));
// target
ref.setTarget(ad.getStringValue("target", null));
}