use of jodd.introspector.MethodDescriptor in project jodd by oblac.
the class SetResolver method resolve.
/**
* Resolves all collections for given type.
*/
public SetInjectionPoint[] resolve(Class type, boolean autowire) {
ClassDescriptor cd = ClassIntrospector.lookup(type);
List<SetInjectionPoint> list = new ArrayList<>();
PropertyDescriptor[] allProperties = cd.getAllPropertyDescriptors();
for (PropertyDescriptor propertyDescriptor : allProperties) {
if (propertyDescriptor.isGetterOnly()) {
continue;
}
Class propertyType = propertyDescriptor.getType();
if (!ReflectUtil.isTypeOf(propertyType, Collection.class)) {
continue;
}
MethodDescriptor writeMethodDescriptor = propertyDescriptor.getWriteMethodDescriptor();
FieldDescriptor fieldDescriptor = propertyDescriptor.getFieldDescriptor();
PetiteInject ref = null;
if (writeMethodDescriptor != null) {
ref = writeMethodDescriptor.getMethod().getAnnotation(PetiteInject.class);
}
if (ref == null && fieldDescriptor != null) {
ref = fieldDescriptor.getField().getAnnotation(PetiteInject.class);
}
if ((!autowire) && (ref == null)) {
continue;
}
list.add(injectionPointFactory.createSetInjectionPoint(propertyDescriptor));
}
SetInjectionPoint[] fields;
if (list.isEmpty()) {
fields = SetInjectionPoint.EMPTY;
} else {
fields = list.toArray(new SetInjectionPoint[list.size()]);
}
return fields;
}
use of jodd.introspector.MethodDescriptor 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.MethodDescriptor 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.MethodDescriptor 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);
}
}
use of jodd.introspector.MethodDescriptor in project jodd by oblac.
the class JsonAnnotationManager method scanClassForAnnotations.
/**
* Scans class for annotations and returns {@link jodd.json.meta.JsonAnnotationManager.TypeData}.
*/
private TypeData scanClassForAnnotations(Class type) {
ClassDescriptor cd = ClassIntrospector.lookup(type);
PropertyDescriptor[] pds = cd.getAllPropertyDescriptors();
ArrayList<String> includedList = new ArrayList<>();
ArrayList<String> excludedList = new ArrayList<>();
ArrayList<String> jsonNames = new ArrayList<>();
ArrayList<String> realNames = new ArrayList<>();
JSONAnnotation jsonAnnotation = new JSONAnnotation(JoddJson.jsonAnnotation);
for (PropertyDescriptor pd : pds) {
JSONAnnotationData data = null;
{
MethodDescriptor md = pd.getReadMethodDescriptor();
if (md != null) {
Method method = md.getMethod();
data = jsonAnnotation.readAnnotationData(method);
}
}
if (data == null) {
MethodDescriptor md = pd.getWriteMethodDescriptor();
if (md != null) {
Method method = md.getMethod();
data = jsonAnnotation.readAnnotationData(method);
}
}
if (data == null) {
FieldDescriptor fd = pd.getFieldDescriptor();
if (fd != null) {
Field field = fd.getField();
data = jsonAnnotation.readAnnotationData(field);
}
}
if (data != null) {
// annotation found
String propertyName = pd.getName();
String newPropertyName = data.getName();
if (newPropertyName != null) {
realNames.add(propertyName);
jsonNames.add(newPropertyName);
propertyName = newPropertyName;
}
if (data.isIncluded()) {
includedList.add(propertyName);
} else {
excludedList.add(propertyName);
}
}
}
String[] reals = null;
if (!realNames.isEmpty()) {
reals = realNames.toArray(new String[realNames.size()]);
}
String[] jsons = null;
if (!jsonNames.isEmpty()) {
jsons = jsonNames.toArray(new String[jsonNames.size()]);
}
// type
JSONAnnotationData data = (JSONAnnotationData) jsonAnnotation.readAnnotationData(type);
return new TypeData(includedList, excludedList, data != null && data.isStrict(), jsons, reals);
}
Aggregations