}
//analyze the class for suitable methods.
final Map<String, MethodDef> lifecycleMethods = new HashMap<String, MethodDef>();
final Map<String, MethodDef> bindmethods = new HashMap<String, MethodDef>();
TypeRef typeRef = analyzer.getTypeRefFromFQN(impl);
Clazz clazz = analyzer.findClass(typeRef);
boolean privateAllowed = true;
boolean defaultAllowed = true;
String topPackage = typeRef.getPackageRef().getFQN();
while (clazz != null) {
final boolean pa = privateAllowed;
final boolean da = defaultAllowed;
final Map<String, MethodDef> classLifecyclemethods = new HashMap<String, MethodDef>();
final Map<String, MethodDef> classBindmethods = new HashMap<String, MethodDef>();
clazz.parseClassFileWithCollector(new ClassDataCollector() {
@Override
public void method(MethodDef md) {
Set<String> allowedParams = allowed;
String lifecycleName = null;
boolean isLifecycle = (cd.activate == null? "activate": cd.activate).equals(md.getName()) ||
md.getName().equals(cd.modified);
if (!isLifecycle && (cd.deactivate == null? "deactivate": cd.deactivate).equals(md.getName())) {
isLifecycle = true;
allowedParams = allowedDeactivate;
}
if (isLifecycle && !lifecycleMethods.containsKey(md.getName()) &&
(md.isPublic() ||
md.isProtected() ||
(md.isPrivate() && pa) ||
(!md.isPrivate()) && da) &&
isBetter(md, classLifecyclemethods.get(md.getName()), allowedParams)) {
classLifecyclemethods.put(md.getName(), md);
}
if (!bindmethods.containsKey(md.getName()) &&
(md.isPublic() ||
md.isProtected() ||
(md.isPrivate() && pa) ||
(!md.isPrivate()) && da) &&
isBetterBind(md, classBindmethods.get(md.getName()))) {
classBindmethods.put(md.getName(), md);
}
}
private boolean isBetter(MethodDef test, MethodDef existing, Set<String> allowedParams) {
int testRating = rateLifecycle(test, allowedParams);
if (existing == null)
return testRating < 6;// ignore invalid methods
if (testRating < rateLifecycle(existing, allowedParams))
return true;
return false;
}
private boolean isBetterBind(MethodDef test, MethodDef existing) {
int testRating = rateBind(test);
if (existing == null)
return testRating < 6;// ignore invalid methods
if (testRating < rateBind(existing))
return true;
return false;
}
});
lifecycleMethods.putAll(classLifecyclemethods);
bindmethods.putAll(classBindmethods);
typeRef = clazz.getSuper();
if (typeRef == null)
break;
clazz = analyzer.findClass(typeRef);
privateAllowed = false;
defaultAllowed = defaultAllowed && topPackage.equals(typeRef.getPackageRef().getFQN());
}
if (cd.activate != null && !lifecycleMethods.containsKey(cd.activate)) {
error("in component %s, activate method %s specified but not found", cd.implementation.getFQN(), cd.activate);