Search in sources :

Example 6 with ClassNode

use of act.util.ClassNode in project actframework by actframework.

the class FullStackAppBootstrapClassLoader method cache.

private synchronized ClassNode cache(Class<?> c) {
    String cname = canonicalName(c);
    if (null == cname) {
        return null;
    }
    String name = c.getName();
    ClassInfoRepository repo = (ClassInfoRepository) classInfoRepository();
    if (repo.has(cname)) {
        return repo.node(name, cname);
    }
    actClasses.add(c);
    ClassNode node = repo.node(name);
    node.modifiers(c.getModifiers());
    Class[] ca = c.getInterfaces();
    for (Class pc : ca) {
        if (pc == Object.class)
            continue;
        String pcname = canonicalName(pc);
        if (null != pcname) {
            cache(pc);
            node.addInterface(pcname);
        }
    }
    Class pc = c.getSuperclass();
    if (null != pc && Object.class != pc) {
        String pcname = canonicalName(pc);
        if (null != pcname) {
            cache(pc);
            node.parent(pcname);
        }
    }
    return node;
}
Also used : ClassNode(act.util.ClassNode) ClassInfoRepository(act.util.ClassInfoRepository)

Example 7 with ClassNode

use of act.util.ClassNode in project actframework by actframework.

the class ActionMethodMetaInfo method mergeFromWithList.

private void mergeFromWithList(final ControllerClassMetaInfoManager infoBase, final App app) {
    C.Set<String> withClasses = this.withList;
    if (withClasses.isEmpty()) {
        return;
    }
    ClassInfoRepository repo = app.classLoader().classInfoRepository();
    for (final String withClass : withClasses) {
        String curWithClass = withClass;
        ControllerClassMetaInfo withClassInfo = infoBase.controllerMetaInfo(curWithClass);
        while (null == withClassInfo && !"java.lang.Object".equals(curWithClass)) {
            ClassNode node = repo.node(curWithClass);
            if (null != node) {
                node = node.parent();
            }
            if (null == node) {
                break;
            }
            curWithClass = node.name();
            withClassInfo = infoBase.controllerMetaInfo(curWithClass);
        }
        if (null != withClassInfo) {
            withClassInfo.merge(infoBase, app);
            interceptors.mergeFrom(withClassInfo.interceptors);
        }
    }
}
Also used : ClassNode(act.util.ClassNode) C(org.osgl.util.C) ClassInfoRepository(act.util.ClassInfoRepository)

Example 8 with ClassNode

use of act.util.ClassNode in project actframework by actframework.

the class ControllerClassMetaInfo method mergeFromWithList.

private void mergeFromWithList(final ControllerClassMetaInfoManager infoBase, final App app) {
    C.Set<String> withClasses = C.newSet();
    getAllWithList(withClasses, infoBase);
    final ControllerClassMetaInfo me = this;
    ClassInfoRepository repo = app.classLoader().classInfoRepository();
    for (final String withClass : withClasses) {
        String curWithClass = withClass;
        ControllerClassMetaInfo withClassInfo = infoBase.controllerMetaInfo(curWithClass);
        while (null == withClassInfo && !"java.lang.Object".equals(curWithClass)) {
            ClassNode node = repo.node(curWithClass);
            if (null != node) {
                node = node.parent();
            }
            if (null == node) {
                break;
            }
            curWithClass = node.name();
            withClassInfo = infoBase.controllerMetaInfo(curWithClass);
        }
        if (null != withClassInfo) {
            withClassInfo.merge(infoBase, app);
            if (isMyAncestor(withClassInfo)) {
                interceptors.mergeFrom(withClassInfo.interceptors, me);
            } else {
                interceptors.mergeFrom(withClassInfo.interceptors);
            }
        }
    }
}
Also used : ClassNode(act.util.ClassNode) C(org.osgl.util.C) ClassInfoRepository(act.util.ClassInfoRepository)

Example 9 with ClassNode

use of act.util.ClassNode in project actframework by actframework.

the class JobMethodMetaInfo method extendedJobMethodMetaInfoList.

public List<JobMethodMetaInfo> extendedJobMethodMetaInfoList(App app) {
    E.illegalStateIf(!classInfo().isAbstract(), "this job method meta info is not abstract");
    final List<JobMethodMetaInfo> list = new ArrayList<>();
    final JobClassMetaInfo clsInfo = classInfo();
    String clsName = clsInfo.className();
    ClassNode node = app.classLoader().classInfoRepository().node(clsName);
    if (null == node) {
        return list;
    }
    final JobMethodMetaInfo me = this;
    node.visitTree(new Osgl.Visitor<ClassNode>() {

        @Override
        public void visit(ClassNode classNode) throws Osgl.Break {
            if (!classNode.isAbstract() && classNode.isPublic()) {
                JobClassMetaInfo subClsInfo = new JobClassMetaInfo().className(classNode.name());
                JobMethodMetaInfo subMethodInfo = new JobMethodMetaInfo(subClsInfo, JobMethodMetaInfo.this);
                if (me.isStatic()) {
                    subMethodInfo.invokeStaticMethod();
                } else {
                    subMethodInfo.invokeInstanceMethod();
                }
                subMethodInfo.name(me.name());
                subMethodInfo.returnType(me.returnType());
                list.add(subMethodInfo);
            }
        }
    });
    return list;
}
Also used : ClassNode(act.util.ClassNode) ArrayList(java.util.ArrayList) Osgl(org.osgl.Osgl)

Example 10 with ClassNode

use of act.util.ClassNode in project actframework by actframework.

the class MetricMetaInfoRepo method mergeFromParents.

private void mergeFromParents(ClassInfoRepository classInfoRepository) {
    // sort class names so that super class always be processed before extended class
    SortedSet<String> sortedClassNames = new TreeSet<>(classInfoRepository.parentClassFirst);
    sortedClassNames.addAll(contexts.keySet());
    for (String className : sortedClassNames) {
        String context = contexts.get(className);
        if (context.startsWith("/")) {
            context = calibrate(context);
        } else {
            ClassNode node = classInfoRepository.node(className);
            if (null != node) {
                ClassNode parentNode = node.parent();
                if (null != parentNode) {
                    String parentContext = contexts.get(parentNode.name());
                    context = concat(parentContext, context);
                }
            }
        }
        contexts.put(className, context);
    }
}
Also used : ClassNode(act.util.ClassNode)

Aggregations

ClassNode (act.util.ClassNode)12 ClassInfoRepository (act.util.ClassInfoRepository)6 AppClassLoader (act.app.AppClassLoader)2 ArrayList (java.util.ArrayList)2 org.osgl.$ (org.osgl.$)2 C (org.osgl.util.C)2 App (act.app.App)1 Osgl (org.osgl.Osgl)1