Search in sources :

Example 1 with After

use of org.exoplatform.container.spi.After in project kernel by exoplatform.

the class DefaultInterceptorChainFactory method resolveNext.

/**
 * Resolves the next dynamic {@link Interceptor} using the annotation {@link Before} and {@link After}
 * @param alreadyResolved the list of {@link Interceptor} already resolved
 * @param iter the Iterator containing the remaining dynamic {@link Interceptor} to resolve
 * @param resolveIfAbsent indicates if the interceptor must be resolved if the referred interceptor could not
 * be found
 */
protected void resolveNext(List<Interceptor> alreadyResolved, Iterator<Interceptor> iter, boolean resolveIfAbsent) {
    Interceptor it = iter.next();
    Before b = it.getClass().getAnnotation(Before.class);
    if (b != null) {
        // An annotation Before has been defined
        String id = b.value();
        if (id == null || (id = id.trim()).isEmpty()) {
            // No id set
            if (PropertyManager.isDevelopping()) {
                // NOSONAR
                System.out.println("WARN: No value set for the annotation Before of the interceptor " + it.getClass());
            }
            alreadyResolved.add(it);
            iter.remove();
            return;
        }
        // The id has been set
        for (int i = 0, length = alreadyResolved.size(); i < length; i++) {
            Interceptor interceptor = alreadyResolved.get(i);
            if (id.equals(interceptor.getId())) {
                // The id has been found
                if (i < length - 1) {
                    alreadyResolved.add(i + 1, it);
                } else {
                    alreadyResolved.add(it);
                }
                iter.remove();
                return;
            }
        }
        if (resolveIfAbsent) {
            if (PropertyManager.isDevelopping()) {
                System.out.println(// NOSONAR
                "WARN: Could not find the interceptor of " + id + " required by the interceptor " + it.getClass());
            }
            alreadyResolved.add(it);
            iter.remove();
        }
        return;
    }
    After a = it.getClass().getAnnotation(After.class);
    if (a != null) {
        // An annotation After has been defined
        String id = a.value();
        if (id == null || (id = id.trim()).isEmpty()) {
            // No id set
            if (PropertyManager.isDevelopping()) {
                // NOSONAR
                System.out.println("WARN: No value set for the annotation After of the interceptor " + it.getClass());
            }
            alreadyResolved.add(it);
            iter.remove();
            return;
        }
        // The id has been set
        for (int i = 0, length = alreadyResolved.size(); i < length; i++) {
            Interceptor interceptor = alreadyResolved.get(i);
            if (id.equals(interceptor.getId())) {
                // The id has been found
                alreadyResolved.add(i, it);
                iter.remove();
                return;
            }
        }
        if (resolveIfAbsent) {
            if (PropertyManager.isDevelopping()) {
                System.out.println(// NOSONAR
                "WARN: Could not find the interceptor of " + id + " required by the interceptor " + it.getClass());
            }
            alreadyResolved.add(it);
            iter.remove();
        }
        return;
    }
    // No annotation has been defined
    alreadyResolved.add(it);
    iter.remove();
}
Also used : Before(org.exoplatform.container.spi.Before) After(org.exoplatform.container.spi.After) Interceptor(org.exoplatform.container.spi.Interceptor)

Aggregations

After (org.exoplatform.container.spi.After)1 Before (org.exoplatform.container.spi.Before)1 Interceptor (org.exoplatform.container.spi.Interceptor)1