Search in sources :

Example 1 with AppClassLoader

use of act.app.AppClassLoader in project actframework by actframework.

the class ControllerClassMetaInfo method parent.

public ControllerClassMetaInfo parent(boolean checkClassInfoRepo) {
    if (null != parent) {
        return parent;
    }
    if (!checkClassInfoRepo) {
        return null;
    }
    AppClassLoader classLoader = Act.app().classLoader();
    ClassInfoRepository repo = classLoader.classInfoRepository();
    ClassNode parentNode = repo.node(superType.getClassName());
    while (null != parentNode) {
        parentNode = parentNode.parent();
        if (null != parentNode) {
            ControllerClassMetaInfo parentInfo = classLoader.controllerClassMetaInfo(parentNode.name());
            if (null != parentInfo) {
                return parentInfo;
            }
        } else {
            return null;
        }
    }
    return null;
}
Also used : ClassNode(act.util.ClassNode) AppClassLoader(act.app.AppClassLoader) ClassInfoRepository(act.util.ClassInfoRepository)

Example 2 with AppClassLoader

use of act.app.AppClassLoader in project actframework by actframework.

the class GenieInjector method foundAutoBinding.

@AnnotatedClassFinder(value = AutoBind.class, callOn = SysEventId.DEPENDENCY_INJECTOR_PROVISIONED, noAbstract = false)
public static void foundAutoBinding(final Class<?> autoBinding) {
    // check if there are manual binding (via modules) for the class already
    if (hasBinding(autoBinding)) {
        return;
    }
    final AppClassLoader cl = Act.app().classLoader();
    ClassInfoRepository repo = cl.classInfoRepository();
    ClassNode root = repo.node(autoBinding.getName());
    E.invalidConfigurationIf(null == root, "Cannot find AutoBind root: %s", autoBinding.getName());
    final Set<Class<?>> candidates = new LinkedHashSet<>();
    root.visitPublicNotAbstractSubTreeNodes(new $.Visitor<ClassNode>() {

        @Override
        public void visit(ClassNode classNode) throws Osgl.Break {
            try {
                Class<?> clazz = $.classForName(classNode.name(), cl);
                if (Env.matches(clazz)) {
                    candidates.add(clazz);
                }
            } catch (ConfigurationException e) {
                throw e;
            } catch (RuntimeException e) {
                throw new ConfigurationException(e, "Unable to auto bind on %s", autoBinding.getName());
            }
        }
    });
    if (!candidates.isEmpty()) {
        GenieInjector injector = Act.app().injector();
        // key is: set of annotations plus name
        Map<$.T2<Set<Annotation>, String>, Class<?>> multiCandidatesMap = new HashMap<>();
        for (Class<?> c : candidates) {
            BeanSpec spec = BeanSpec.of(c, injector);
            Set<Annotation> qualifiers = spec.qualifiers();
            String name = spec.name();
            $.T2<Set<Annotation>, String> key = $.T2(qualifiers, name);
            if (multiCandidatesMap.containsKey(key)) {
                throw new ConfigurationException("Unable to auto bind on %s: multiple same qualified candidates found", autoBinding);
            } else {
                multiCandidatesMap.put(key, c);
            }
        }
        for (Map.Entry<$.T2<Set<Annotation>, String>, Class<?>> entry : multiCandidatesMap.entrySet()) {
            Genie.Binder binder = new Genie.Binder(autoBinding).to(entry.getValue());
            $.T2<Set<Annotation>, String> key = entry.getKey();
            Set<Annotation> qualifiers = key._1;
            String name = key._2;
            if (!qualifiers.isEmpty()) {
                binder = binder.withAnnotation(qualifiers.toArray(new Annotation[qualifiers.size()]));
            }
            if (null != name) {
                binder.named(name);
            }
            binder.register(injector.genie());
        }
    } else {
        Act.LOGGER.warn("Unable to auto bind on %s: implementation not found", autoBinding);
    }
}
Also used : AppClassLoader(act.app.AppClassLoader) ConfigurationException(org.osgl.exception.ConfigurationException) org.osgl.$(org.osgl.$) Annotation(java.lang.annotation.Annotation)

Example 3 with AppClassLoader

use of act.app.AppClassLoader in project actframework by actframework.

the class ControllerClassMetaInfoManager method buildControllerHierarchies.

public void buildControllerHierarchies() {
    AppClassLoader cl = Act.app().classLoader();
    ControllerClassMetaInfoManager manager = cl.controllerClassMetaInfoManager();
    ClassInfoRepository repo = cl.classInfoRepository();
    for (ControllerClassMetaInfo info : manager.controllers.values()) {
        buildSuperClassMetaInfo(info, manager, repo);
    }
}
Also used : AppClassLoader(act.app.AppClassLoader) ClassInfoRepository(act.util.ClassInfoRepository)

Example 4 with AppClassLoader

use of act.app.AppClassLoader in project actframework by actframework.

the class DependencyInjectorBase method registerDiListener.

@Override
public synchronized void registerDiListener(DependencyInjectionListener listener) {
    Class[] targets = listener.listenTo();
    for (Class c : targets) {
        List<DependencyInjectionListener> list = listeners.get(c);
        if (null == list) {
            final List<DependencyInjectionListener> list0 = new ArrayList<>();
            list = list0;
            final AppClassLoader cl = app().classLoader();
            ClassNode node = cl.classInfoRepository().node(c.getName());
            node.visitPublicNotAbstractTreeNodes(new $.Visitor<ClassNode>() {

                @Override
                public void visit(ClassNode classNode) throws Osgl.Break {
                    listeners.put($.classForName(classNode.name(), cl), list0);
                }
            });
            listeners.put(c, list);
        }
        list.add(listener);
    }
}
Also used : ClassNode(act.util.ClassNode) org.osgl.$(org.osgl.$) AppClassLoader(act.app.AppClassLoader) ArrayList(java.util.ArrayList)

Aggregations

AppClassLoader (act.app.AppClassLoader)4 ClassInfoRepository (act.util.ClassInfoRepository)2 ClassNode (act.util.ClassNode)2 org.osgl.$ (org.osgl.$)2 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1 ConfigurationException (org.osgl.exception.ConfigurationException)1