use of jodd.introspector.ClassDescriptor in project jodd by oblac.
the class PetiteBeans method registerPetiteProvider.
// ---------------------------------------------------------------- providers
/**
* Registers instance method provider.
*
* @param providerName provider name
* @param beanName bean name
* @param methodName instance method name
* @param arguments method argument types
*/
public void registerPetiteProvider(String providerName, String beanName, String methodName, Class[] arguments) {
BeanDefinition beanDefinition = lookupBeanDefinition(beanName);
if (beanDefinition == null) {
throw new PetiteException("Bean not found: " + beanName);
}
Class beanType = beanDefinition.type;
ClassDescriptor cd = ClassIntrospector.lookup(beanType);
MethodDescriptor md = cd.getMethodDescriptor(methodName, arguments, true);
if (md == null) {
throw new PetiteException("Provider method not found: " + methodName);
}
ProviderDefinition providerDefinition = new ProviderDefinition(providerName, beanName, md.getMethod());
providers.put(providerName, providerDefinition);
}
use of jodd.introspector.ClassDescriptor in project jodd by oblac.
the class PetiteBeans method registerPetiteDestroyMethods.
/**
* Registers destroy method.
*
* @param beanName bean name
* @param destroyMethodNames destroy method names
*/
public void registerPetiteDestroyMethods(String beanName, String... destroyMethodNames) {
BeanDefinition beanDefinition = lookupExistingBeanDefinition(beanName);
ClassDescriptor cd = ClassIntrospector.lookup(beanDefinition.type);
if (destroyMethodNames == null) {
destroyMethodNames = StringPool.EMPTY_ARRAY;
}
int total = destroyMethodNames.length;
DestroyMethodPoint[] destroyMethodPoints = new DestroyMethodPoint[total];
int i;
for (i = 0; i < destroyMethodNames.length; i++) {
MethodDescriptor md = cd.getMethodDescriptor(destroyMethodNames[i], ReflectUtil.NO_PARAMETERS, true);
if (md == null) {
throw new PetiteException("Destroy method not found: " + beanDefinition.type.getName() + '#' + destroyMethodNames[i]);
}
destroyMethodPoints[i] = new DestroyMethodPoint(md.getMethod());
}
beanDefinition.addDestroyMethodPoints(destroyMethodPoints);
}
use of jodd.introspector.ClassDescriptor in project jodd by oblac.
the class PetiteBeans method registerPetiteSetInjectionPoint.
/**
* Registers set injection point.
*
* @param beanName bean name
* @param property set property name
*/
public void registerPetiteSetInjectionPoint(String beanName, String property) {
BeanDefinition beanDefinition = lookupExistingBeanDefinition(beanName);
ClassDescriptor cd = ClassIntrospector.lookup(beanDefinition.type);
PropertyDescriptor propertyDescriptor = cd.getPropertyDescriptor(property, true);
if (propertyDescriptor == null) {
throw new PetiteException("Property not found: " + beanDefinition.type.getName() + '#' + property);
}
SetInjectionPoint sip = injectionPointFactory.createSetInjectionPoint(propertyDescriptor);
beanDefinition.addSetInjectionPoint(sip);
}
use of jodd.introspector.ClassDescriptor in project jodd by oblac.
the class ScopeDataResolver method inspectClassScopeData.
/**
* Inspect action for all In/Out annotations.
* Returns <code>null</code> if there are no In and Out data.
*/
protected ScopeData inspectClassScopeData(Class actionClass, ScopeType scopeType) {
ClassDescriptor cd = ClassIntrospector.lookup(actionClass);
PropertyDescriptor[] allProperties = cd.getAllPropertyDescriptors();
List<ScopeData.In> listIn = new ArrayList<>(allProperties.length);
List<ScopeData.Out> listOut = new ArrayList<>(allProperties.length);
for (PropertyDescriptor pd : allProperties) {
// collect annotations
In in = null;
if (pd.getFieldDescriptor() != null) {
in = pd.getFieldDescriptor().getField().getAnnotation(In.class);
}
if (in == null && pd.getWriteMethodDescriptor() != null) {
in = pd.getWriteMethodDescriptor().getMethod().getAnnotation(In.class);
}
if (in == null && pd.getReadMethodDescriptor() != null) {
in = pd.getReadMethodDescriptor().getMethod().getAnnotation(In.class);
}
InOut inout = null;
if (pd.getFieldDescriptor() != null) {
inout = pd.getFieldDescriptor().getField().getAnnotation(InOut.class);
}
if (inout == null && pd.getWriteMethodDescriptor() != null) {
inout = pd.getWriteMethodDescriptor().getMethod().getAnnotation(InOut.class);
}
if (inout == null && pd.getReadMethodDescriptor() != null) {
inout = pd.getReadMethodDescriptor().getMethod().getAnnotation(InOut.class);
}
Out out = null;
if (pd.getFieldDescriptor() != null) {
out = pd.getFieldDescriptor().getField().getAnnotation(Out.class);
}
if (out == null && pd.getWriteMethodDescriptor() != null) {
out = pd.getWriteMethodDescriptor().getMethod().getAnnotation(Out.class);
}
if (out == null && pd.getReadMethodDescriptor() != null) {
out = pd.getReadMethodDescriptor().getMethod().getAnnotation(Out.class);
}
if (inout != null) {
if (in != null || out != null) {
throw new MadvocException("@InOut can not be used with @In or @Out: " + pd.getClassDescriptor().getClass() + '#' + pd.getName());
}
}
// inspect all
ScopeData.In ii = inspectIn(in, scopeType, pd.getName(), pd.getType());
if (ii != null) {
listIn.add(ii);
}
ii = inspectIn(inout, scopeType, pd.getName(), pd.getType());
if (ii != null) {
listIn.add(ii);
}
ScopeData.Out oi = inspectOut(out, scopeType, pd.getName(), pd.getType());
if (oi != null) {
listOut.add(oi);
}
oi = inspectOut(inout, scopeType, pd.getName(), pd.getType());
if (oi != null) {
listOut.add(oi);
}
}
if ((listIn.isEmpty()) && (listOut.isEmpty())) {
return null;
}
ScopeData scopeData = new ScopeData();
if (!listIn.isEmpty()) {
scopeData.in = listIn.toArray(new ScopeData.In[listIn.size()]);
}
if (!listOut.isEmpty()) {
scopeData.out = listOut.toArray(new ScopeData.Out[listOut.size()]);
}
return scopeData;
}
use of jodd.introspector.ClassDescriptor in project jodd by oblac.
the class AutomagicMadvocConfigurator method onActionClass.
// ---------------------------------------------------------------- handlers
/**
* Builds action configuration on founded action class.
* Action classes are annotated with {@link jodd.madvoc.meta.MadvocAction} annotation.
*/
@SuppressWarnings("NonConstantStringShouldBeStringBuffer")
protected void onActionClass(String className) throws ClassNotFoundException {
Class<?> actionClass = loadClass(className);
if (actionClass == null) {
return;
}
if (!checkClass(actionClass)) {
return;
}
if (actionClass.getAnnotation(MadvocAction.class) == null) {
return;
}
ClassDescriptor cd = ClassIntrospector.lookup(actionClass);
MethodDescriptor[] allMethodDescriptors = cd.getAllMethodDescriptors();
for (MethodDescriptor methodDescriptor : allMethodDescriptors) {
if (!methodDescriptor.isPublic()) {
continue;
}
// just public methods
Method method = methodDescriptor.getMethod();
boolean hasAnnotation = false;
for (ActionAnnotation<?> actionAnnotation : madvocConfig.getActionAnnotationInstances()) {
if (actionAnnotation.hasAnnotation(method)) {
hasAnnotation = true;
break;
}
}
if (!hasAnnotation) {
continue;
}
actionsManager.register(actionClass, method);
}
}
Aggregations