Search in sources :

Example 6 with In

use of jodd.madvoc.meta.In in project jodd by oblac.

the class ScopeDataResolverTest method testInAnnotations.

@Test
public void testInAnnotations() {
    ScopeDataResolver scopeDataResolver = new ScopeDataResolver();
    ScopeData[] scopeData = scopeDataResolver.resolveScopeData(Action.class);
    ScopeData.In[] in1 = scopeData[ScopeType.REQUEST.value()].in;
    ScopeData.In in = in1[0];
    assertEquals("input", in.name);
    assertEquals(String.class, in.type);
}
Also used : ScopeDataResolver(jodd.madvoc.component.ScopeDataResolver) In(jodd.madvoc.meta.In) ScopeData(jodd.madvoc.ScopeData) Test(org.junit.Test)

Example 7 with In

use of jodd.madvoc.meta.In 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);
}
Also used : ClassDescriptor(jodd.introspector.ClassDescriptor) PropertyDescriptor(jodd.introspector.PropertyDescriptor) InjectionPoint(jodd.madvoc.config.InjectionPoint) In(jodd.madvoc.meta.In) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) Out(jodd.madvoc.meta.Out) Field(java.lang.reflect.Field) ScopeData(jodd.madvoc.config.ScopeData)

Example 8 with In

use of jodd.madvoc.meta.In 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);
}
Also used : In(jodd.madvoc.meta.In) InjectionPoint(jodd.madvoc.config.InjectionPoint) ScopeData(jodd.madvoc.config.ScopeData) Annotation(java.lang.annotation.Annotation) InjectionPoint(jodd.madvoc.config.InjectionPoint) Out(jodd.madvoc.meta.Out)

Aggregations

In (jodd.madvoc.meta.In)8 ScopeData (jodd.madvoc.ScopeData)6 Out (jodd.madvoc.meta.Out)5 Annotation (java.lang.annotation.Annotation)2 ArrayList (java.util.ArrayList)2 ClassDescriptor (jodd.introspector.ClassDescriptor)2 PropertyDescriptor (jodd.introspector.PropertyDescriptor)2 ScopeType (jodd.madvoc.ScopeType)2 ScopeDataResolver (jodd.madvoc.component.ScopeDataResolver)2 InjectionPoint (jodd.madvoc.config.InjectionPoint)2 ScopeData (jodd.madvoc.config.ScopeData)2 InOut (jodd.madvoc.meta.InOut)2 Test (org.junit.Test)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 MadvocException (jodd.madvoc.MadvocException)1