use of jodd.madvoc.config.InjectionPoint in project jodd by oblac.
the class ScopeDataInspectorTest method testGenericAction.
@Test
void testGenericAction() {
ScopeDataInspector scopeDataInspector = new ScopeDataInspector();
PetiteContainer madpc = new PetiteContainer();
scopeDataInspector.scopeResolver = new ScopeResolver();
scopeDataInspector.scopeResolver.madpc = madpc;
madpc.addBean("madvocEncoding", new MadvocEncoding());
ScopeData scopeData = scopeDataInspector.inspectClassScopes(GenAction.class);
InjectionPoint[] in1 = scopeData.in();
InjectionPoint[] out1 = scopeData.out();
InjectionPoint in = in1[0];
InjectionPoint out = out1[0];
assertEquals("input", in.name());
assertEquals(String.class, in.type());
assertEquals("output", out.name());
assertEquals(Integer.class, out.type());
}
use of jodd.madvoc.config.InjectionPoint in project jodd by oblac.
the class ScopeDataInspector method inspectClassScopes.
/**
* Inspects {@link ScopeData} for given class. The results are not cached, so it should
* be used only dyring configuration-time.
* For cached version, use {@link #inspectClassScopesWithCache(Class)}.
*/
public ScopeData inspectClassScopes(final Class actionClass) {
final ClassDescriptor cd = ClassIntrospector.get().lookup(actionClass);
final PropertyDescriptor[] allProperties = cd.getAllPropertyDescriptors();
final List<InjectionPoint> listIn = new ArrayList<>(allProperties.length);
final List<InjectionPoint> listOut = new ArrayList<>(allProperties.length);
for (final PropertyDescriptor pd : allProperties) {
// collect annotations
Class<? extends MadvocScope> scope = null;
In in = null;
Out out = null;
if (pd.getFieldDescriptor() != null) {
final Field field = pd.getFieldDescriptor().getField();
in = field.getAnnotation(In.class);
out = field.getAnnotation(Out.class);
scope = resolveScopeClassFromAnnotations(field.getAnnotations());
}
if (pd.getWriteMethodDescriptor() != null) {
final Method method = pd.getWriteMethodDescriptor().getMethod();
if (in == null) {
in = method.getAnnotation(In.class);
}
if (out == null) {
out = method.getAnnotation(Out.class);
}
if (scope == null) {
scope = resolveScopeClassFromAnnotations(method.getAnnotations());
}
}
if (pd.getReadMethodDescriptor() != null) {
final Method method = pd.getReadMethodDescriptor().getMethod();
if (in == null) {
in = method.getAnnotation(In.class);
}
if (out == null) {
out = method.getAnnotation(Out.class);
}
if (scope == null) {
scope = resolveScopeClassFromAnnotations(method.getAnnotations());
}
}
// inspect all
final InjectionPoint ii = in == null ? null : buildInjectionPoint(in.value(), in.defaultValue(), pd.getName(), pd.getType(), scope);
if (ii != null) {
listIn.add(ii);
}
final InjectionPoint oi = out == null ? null : buildInjectionPoint(out.value(), null, pd.getName(), pd.getType(), scope);
if (oi != null) {
listOut.add(oi);
}
}
if ((listIn.isEmpty()) && (listOut.isEmpty())) {
return NO_SCOPE_DATA;
}
InjectionPoint[] in = null;
InjectionPoint[] out = null;
if (!listIn.isEmpty()) {
in = listIn.toArray(new InjectionPoint[0]);
}
if (!listOut.isEmpty()) {
out = listOut.toArray(new InjectionPoint[0]);
}
return new ScopeData(this, in, out);
}
use of jodd.madvoc.config.InjectionPoint in project jodd by oblac.
the class ScopeDataInspector method inspectMethodParameterScopes.
// ---------------------------------------------------------------- inspect method
/**
* Inspects {@link ScopeData} parameters for given method parameter information.
*/
public ScopeData inspectMethodParameterScopes(final String name, final Class type, final Annotation[] annotations) {
In in = null;
Out out = null;
for (final Annotation annotation : annotations) {
if (annotation instanceof In) {
in = (In) annotation;
} else if (annotation instanceof Out) {
out = (Out) annotation;
}
}
final Class<? extends MadvocScope> scope = resolveScopeClassFromAnnotations(annotations);
int count = 0;
InjectionPoint[] ins = null;
InjectionPoint[] outs = null;
if (in != null) {
final InjectionPoint scopeDataIn = buildInjectionPoint(in.value(), in.defaultValue(), name, type, scope);
if (scopeDataIn != null) {
count++;
ins = new InjectionPoint[] { scopeDataIn };
}
}
if (out != null) {
final InjectionPoint scopeDataOut = buildInjectionPoint(out.value(), null, name, type, scope);
if (scopeDataOut != null) {
count++;
outs = new InjectionPoint[] { scopeDataOut };
}
}
if (count == 0) {
return NO_SCOPE_DATA;
}
return new ScopeData(this, ins, outs);
}
use of jodd.madvoc.config.InjectionPoint in project jodd by oblac.
the class ScopeDataInspectorTest method testInAnnotations.
@Test
void testInAnnotations() {
ScopeDataInspector scopeDataInspector = new ScopeDataInspector();
PetiteContainer madpc = new PetiteContainer();
scopeDataInspector.scopeResolver = new ScopeResolver();
scopeDataInspector.scopeResolver.madpc = madpc;
madpc.addBean("madvocEncoding", new MadvocEncoding());
ScopeData scopeData = scopeDataInspector.inspectClassScopes(Action.class);
InjectionPoint[] in1 = scopeData.in();
InjectionPoint in = in1[0];
assertEquals("input", in.name());
assertEquals(String.class, in.type());
}
Aggregations