Search in sources :

Example 1 with ClassInfoRepository

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

the class ResultClassLookup method loadResultClasses.

private void loadResultClasses() {
    final String RESULT = Result.class.getName();
    _set.add(RESULT);
    ClassInfoRepository repo = Act.app().classLoader().classInfoRepository();
    ClassNode resultNode = repo.node(RESULT);
    if (null == resultNode) {
        // inside unit test
        add(Ok.class, NotFound.class, ErrorResult.class, NotAcceptable.class, Forbidden.class, NotImplemented.class, BadRequest.class, Conflict.class, MethodNotAllowed.class, Unauthorized.class, ServerError.class, NotModified.class, RenderBinary.class, Accepted.class, Created.class, NoResult.class, Redirect.class, RenderTemplate.class, RenderAny.class, ZXingResult.class, RenderJsonMap.class, RenderJSON.class, RenderContent.class, RenderXML.class, RenderCSV.class, RenderHtml.class, FilteredRenderJSON.class, FilteredRenderXML.class, RenderText.class);
    } else {
        resultNode.visitPublicSubTreeNodes(new $.Visitor<ClassNode>() {

            @Override
            public void visit(ClassNode classNode) throws Osgl.Break {
                _set.add(classNode.name());
            }
        });
    }
}
Also used : ClassNode(act.util.ClassNode) org.osgl.$(org.osgl.$) ClassInfoRepository(act.util.ClassInfoRepository)

Example 2 with ClassInfoRepository

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

the class ControllerClassMetaInfo method getAllWithList.

private void getAllWithList(final Set<String> withList, final ControllerClassMetaInfoManager infoBase) {
    withList.addAll(this.withList);
    if (null != superType) {
        final String superClass = superType.getClassName();
        App app = App.instance();
        ClassInfoRepository repo = app.classLoader().classInfoRepository();
        ControllerClassMetaInfo info = infoBase.controllerMetaInfo(superClass);
        String curSuperClass = superClass;
        while (null == info && !"java.lang.Object".equals(curSuperClass)) {
            ClassNode node = repo.node(curSuperClass);
            if (null != node) {
                node = node.parent();
            }
            if (null == node) {
                break;
            }
            curSuperClass = node.name();
            info = infoBase.controllerMetaInfo(curSuperClass);
        }
        if (null != info) {
            withList.add(superClass);
        }
    }
}
Also used : App(act.app.App) ClassNode(act.util.ClassNode) ClassInfoRepository(act.util.ClassInfoRepository)

Example 3 with ClassInfoRepository

use of act.util.ClassInfoRepository 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 4 with ClassInfoRepository

use of act.util.ClassInfoRepository 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 5 with ClassInfoRepository

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

the class ControllerByteCodeScannerTest method setup.

@Before
public void setup() throws Exception {
    super.setup();
    controllerScanner = new ControllerByteCodeScanner();
    jobScanner = new JobByteCodeScanner();
    scannerManager = mock(AppCodeScannerManager.class);
    classInfoRepository = mock(ClassInfoRepository.class);
    eventBus = mock(EventBus.class);
    when(mockApp.eventBus()).thenReturn(eventBus);
    jobManager = new JobManager(mockApp);
    classLoader = new TestingAppClassLoader(mockApp);
    $.setProperty(classLoader, classInfoRepository, "classInfoRepository");
    when(mockApp.classLoader()).thenReturn(classLoader);
    infoSrc = classLoader.controllerClassMetaInfoManager();
    when(mockApp.classLoader()).thenReturn(classLoader);
    when(mockApp.scannerManager()).thenReturn(scannerManager);
    when(mockApp.jobManager()).thenReturn(jobManager);
    when(mockAppConfig.possibleControllerClass(anyString())).thenReturn(true);
    when(mockRouter.isActionMethod(anyString(), anyString())).thenReturn(false);
    C.List<AppByteCodeScanner> scanners = $.cast(C.listOf(controllerScanner, jobScanner));
    // C.List<AppByteCodeScanner> scanners = C.list(controllerScanner);
    when(scannerManager.byteCodeScanners()).thenReturn(scanners);
    paramValueLoaderManager = mock(ParamValueLoaderManager.class);
    when(mockApp.service(ParamValueLoaderManager.class)).thenReturn(paramValueLoaderManager);
    controllerScanner.setApp(mockApp);
    jobScanner.setApp(mockApp);
    base = new File("./target/test-classes");
}
Also used : AppCodeScannerManager(act.app.AppCodeScannerManager) C(org.osgl.util.C) AppByteCodeScanner(act.app.AppByteCodeScanner) JobByteCodeScanner(act.job.bytecode.JobByteCodeScanner) ParamValueLoaderManager(act.inject.param.ParamValueLoaderManager) TestingAppClassLoader(act.app.TestingAppClassLoader) EventBus(act.event.EventBus) JobManager(act.job.JobManager) ClassInfoRepository(act.util.ClassInfoRepository) File(java.io.File) Before(org.junit.Before)

Aggregations

ClassInfoRepository (act.util.ClassInfoRepository)9 ClassNode (act.util.ClassNode)6 C (org.osgl.util.C)4 AppByteCodeScanner (act.app.AppByteCodeScanner)2 AppClassLoader (act.app.AppClassLoader)2 AppCodeScannerManager (act.app.AppCodeScannerManager)2 TestingAppClassLoader (act.app.TestingAppClassLoader)2 EventBus (act.event.EventBus)2 Before (org.junit.Before)2 App (act.app.App)1 ParamValueLoaderManager (act.inject.param.ParamValueLoaderManager)1 JobManager (act.job.JobManager)1 JobByteCodeScanner (act.job.bytecode.JobByteCodeScanner)1 File (java.io.File)1 org.osgl.$ (org.osgl.$)1 InvokeLog (testapp.util.InvokeLog)1