use of jodd.introspector.PropertyDescriptor 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.PropertyDescriptor 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.PropertyDescriptor in project jodd by oblac.
the class AnnotatedPropertyInterceptor method intercept.
public Object intercept(ActionRequest actionRequest) throws Exception {
Object action = actionRequest.getAction();
Class actionType = action.getClass();
PropertyDescriptor[] allProperties = lookupAnnotatedProperties(actionType);
for (PropertyDescriptor propertyDescriptor : allProperties) {
onAnnotatedProperty(actionRequest, propertyDescriptor);
}
return actionRequest.invoke();
}
use of jodd.introspector.PropertyDescriptor in project jodd by oblac.
the class AnnotatedPropertyInterceptor method lookupAnnotatedProperties.
/**
* Lookups for annotated properties. Caches all annotated properties on the first
* action class scan.
*/
protected PropertyDescriptor[] lookupAnnotatedProperties(Class type) {
PropertyDescriptor[] properties = annotatedProperties.get(type);
if (properties != null) {
return properties;
}
ClassDescriptor cd = ClassIntrospector.lookup(type);
PropertyDescriptor[] allProperties = cd.getAllPropertyDescriptors();
List<PropertyDescriptor> list = new ArrayList<>();
for (PropertyDescriptor propertyDescriptor : allProperties) {
Annotation ann = null;
if (propertyDescriptor.getFieldDescriptor() != null) {
ann = propertyDescriptor.getFieldDescriptor().getField().getAnnotation(annotations);
}
if (ann == null && propertyDescriptor.getWriteMethodDescriptor() != null) {
ann = propertyDescriptor.getWriteMethodDescriptor().getMethod().getAnnotation(annotations);
}
if (ann == null && propertyDescriptor.getReadMethodDescriptor() != null) {
ann = propertyDescriptor.getReadMethodDescriptor().getMethod().getAnnotation(annotations);
}
if (ann != null) {
list.add(propertyDescriptor);
}
}
if (list.isEmpty()) {
properties = EMPTY;
} else {
properties = list.toArray(new PropertyDescriptor[list.size()]);
}
annotatedProperties.put(type, properties);
return properties;
}
use of jodd.introspector.PropertyDescriptor 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