use of jodd.introspector.MethodDescriptor in project jodd by oblac.
the class PetiteBeans method registerPetiteInitMethods.
/**
* Registers init method.
*
* @param beanName bean name
* @param invocationStrategy moment of invocation
* @param initMethodNames init method names
*/
public void registerPetiteInitMethods(String beanName, InitMethodInvocationStrategy invocationStrategy, String... initMethodNames) {
BeanDefinition beanDefinition = lookupExistingBeanDefinition(beanName);
ClassDescriptor cd = ClassIntrospector.lookup(beanDefinition.type);
if (initMethodNames == null) {
initMethodNames = StringPool.EMPTY_ARRAY;
}
int total = initMethodNames.length;
InitMethodPoint[] initMethodPoints = new InitMethodPoint[total];
int i;
for (i = 0; i < initMethodNames.length; i++) {
MethodDescriptor md = cd.getMethodDescriptor(initMethodNames[i], ReflectUtil.NO_PARAMETERS, true);
if (md == null) {
throw new PetiteException("Init method not found: " + beanDefinition.type.getName() + '#' + initMethodNames[i]);
}
initMethodPoints[i] = new InitMethodPoint(md.getMethod(), i, invocationStrategy);
}
beanDefinition.addInitMethodPoints(initMethodPoints);
}
use of jodd.introspector.MethodDescriptor in project jodd by oblac.
the class PetiteBeans method registerPetiteMethodInjectionPoint.
/**
* Registers method injection point.
*
* @param beanName bean name
* @param methodName method name
* @param arguments method arguments, may be <code>null</code>
* @param references injection references
*/
public void registerPetiteMethodInjectionPoint(String beanName, String methodName, Class[] arguments, String[] references) {
BeanDefinition beanDefinition = lookupExistingBeanDefinition(beanName);
String[][] ref = PetiteUtil.convertRefToReferences(references);
ClassDescriptor cd = ClassIntrospector.lookup(beanDefinition.type);
Method method = null;
if (arguments == null) {
MethodDescriptor[] methods = cd.getAllMethodDescriptors(methodName);
if (methods != null && methods.length > 0) {
if (methods.length > 1) {
throw new PetiteException(methods.length + " suitable methods found as injection points for: " + beanDefinition.type.getName() + '#' + methodName);
}
method = methods[0].getMethod();
}
} else {
MethodDescriptor md = cd.getMethodDescriptor(methodName, arguments, true);
if (md != null) {
method = md.getMethod();
}
}
if (method == null) {
throw new PetiteException("Method not found: " + beanDefinition.type.getName() + '#' + methodName);
}
MethodInjectionPoint mip = injectionPointFactory.createMethodInjectionPoint(method, ref);
beanDefinition.addMethodInjectionPoint(mip);
}
use of jodd.introspector.MethodDescriptor in project jodd by oblac.
the class PetiteBeans method registerPetiteProvider.
/**
* Registers static method provider.
*
* @param providerName provider name
* @param type class type
* @param staticMethodName static method name
* @param arguments method argument types
*/
public void registerPetiteProvider(String providerName, Class type, String staticMethodName, Class[] arguments) {
ClassDescriptor cd = ClassIntrospector.lookup(type);
MethodDescriptor md = cd.getMethodDescriptor(staticMethodName, arguments, true);
if (md == null) {
throw new PetiteException("Provider method not found: " + staticMethodName);
}
ProviderDefinition providerDefinition = new ProviderDefinition(providerName, md.getMethod());
providers.put(providerName, providerDefinition);
}
use of jodd.introspector.MethodDescriptor in project jodd by oblac.
the class DestroyMethodResolver method resolve.
public DestroyMethodPoint[] resolve(Object bean) {
Class<?> type = bean.getClass();
// lookup methods
List<DestroyMethodPoint> list = new ArrayList<>();
ClassDescriptor cd = new ClassDescriptor(type, false, false, false, null);
MethodDescriptor[] allMethods = cd.getAllMethodDescriptors();
for (MethodDescriptor methodDescriptor : allMethods) {
Method method = methodDescriptor.getMethod();
PetiteDestroyMethod petiteDestroyMethod = method.getAnnotation(PetiteDestroyMethod.class);
if (petiteDestroyMethod == null) {
continue;
}
if (method.getParameterTypes().length > 0) {
throw new PetiteException("Arguments are not allowed for Petite destroy method: " + type.getName() + '#' + method.getName());
}
list.add(new DestroyMethodPoint(method));
}
DestroyMethodPoint[] methods;
if (list.isEmpty()) {
methods = DestroyMethodPoint.EMPTY;
} else {
methods = list.toArray(new DestroyMethodPoint[list.size()]);
}
return methods;
}
use of jodd.introspector.MethodDescriptor in project jodd by oblac.
the class InitMethodResolver method resolve.
public InitMethodPoint[] resolve(Object bean) {
Class<?> type = bean.getClass();
// lookup methods
List<InitMethodPoint> list = new ArrayList<>();
ClassDescriptor cd = new ClassDescriptor(type, false, false, false, null);
MethodDescriptor[] allMethods = cd.getAllMethodDescriptors();
for (MethodDescriptor methodDescriptor : allMethods) {
Method method = methodDescriptor.getMethod();
PetiteInitMethod petiteInitMethod = method.getAnnotation(PetiteInitMethod.class);
if (petiteInitMethod == null) {
continue;
}
if (method.getParameterTypes().length > 0) {
throw new PetiteException("Arguments are not allowed for Petite init method: " + type.getName() + '#' + method.getName());
}
int order = petiteInitMethod.order();
list.add(new InitMethodPoint(method, order, petiteInitMethod.invoke()));
}
InitMethodPoint[] methods;
if (list.isEmpty()) {
methods = InitMethodPoint.EMPTY;
} else {
Collections.sort(list);
methods = list.toArray(new InitMethodPoint[list.size()]);
}
return methods;
}
Aggregations