Package javassist

Examples of javassist.CtClass


    {
        ClassPool pool = new ClassPool(null);

        pool.appendSystemPath();

        CtClass ctClass = pool.makeClass(CLASS);

        ctClass.addInterface(pool.get(ReloadableService.class.getName()));

        CtMethod method = new CtMethod(pool.get("java.lang.String"), "getStatus", null, ctClass);

        method.setBody(String.format("return \"%s\";", status));

        ctClass.addMethod(method);

        ctClass.writeFile(classesDir.getAbsolutePath());
    }
View Full Code Here


    {
        ClassPool pool = new ClassPool(null);

        pool.appendSystemPath();

        CtClass ctClass = pool.makeClass(CLASS);

        ctClass.addInterface(pool.get(ReloadableService.class.getName()));

        CtMethod method = new CtMethod(pool.get("java.lang.String"), "getStatus", null, ctClass);

        method.setBody("return \"unreachable\";");

        ctClass.addMethod(method);

        CtConstructor constructor = new CtConstructor(new CtClass[0], ctClass);

        constructor.setBody("return $0;");

        constructor.setModifiers(Modifier.PROTECTED);

        ctClass.addConstructor(constructor);

        ctClass.writeFile(classesDir.getAbsolutePath());
    }
View Full Code Here

        source = new CtClassSourceImpl(pool, threadLoader);
    }

    private ClassFab newClassFab(String className, Class superClass)
    {
        CtClass ctClass = source.newClass(className, superClass);

        return new ClassFabImpl(source, ctClass, LoggerFactory.getLogger("ClassFab"));
    }
View Full Code Here

        super(setupClass, findTestClass());
    }

    public static void initEnv() throws Exception {
        ServiceFramwork.mode = ServiceFramwork.Mode.test;
        CtClass ctClass = ServiceFramwork.classPool.get("net.csdn.bootstrap.Bootstrap");
        //加载Guice容器
        Method method = ctClass.toClass().getDeclaredMethod("configureSystem");
        method.setAccessible(true);
        method.invoke(null);
    }
View Full Code Here

* Time: 下午5:35
*/
public class Application {
    public static void main(String[] args) {
        try {
            CtClass ctClass = ServiceFramwork.classPool.get("net.csdn.bootstrap.Bootstrap");
            Method method = ctClass.toClass().getMethod("main", new Class[]{args.getClass()});
            method.invoke(null, new Object[]{args});
        } catch (Exception e) {
            e.printStackTrace();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
View Full Code Here

        for (String item : WowCollections.split2(settings.get("application.util"), ",")) {
            ServiceFramwork.scanService.scanArchives(item, new ScanService.LoadClassEnhanceCallBack() {
                @Override
                public Class loaded(DataInputStream classFile) {
                    try {
                        CtClass ctClass = ServiceFramwork.classPool.makeClass(classFile);
                        if (!ctClass.hasAnnotation(Util.class)) {
                            return null;
                        }
                        logger.info("util load :    "+ctClass.getName());
                        final Class clzz = ctClass.toClass();
                        final Util util = (Util) clzz.getAnnotation(Util.class);
                        if (clzz.isInterface())
                            throw new AnnotationException(format("{} util should not be interface", clzz.getName()));
                        moduleList.add(new AbstractModule() {
                            @Override
View Full Code Here

            //自动加载所有Action类
            ServiceFramwork.scanService.scanArchives(item, new ScanService.LoadClassEnhanceCallBack() {
                @Override
                public Class loaded(DataInputStream classFile) {
                    try {
                        CtClass ctClass = enhancer.enhanceThisClass(classFile);
                        logger.info("controller load :    " + ctClass.getName());
                        controllers.add(ctClass);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    return null;
                }
            });
        }

        enhancer.enhanceThisClass2(controllers);
        for (String item : WowCollections.split2(settings.get("application.controller.default","net.csdn.api.controller.SystemInfoController"), ",")) {
            try {
                moduleList.add(bindAction(Class.forName(item)));
            } catch (Exception e) {
                logger.error("load default controller error:" + e);
            }
        }
        for (CtClass ctClass : controllers) {
            if (Modifier.isAbstract(ctClass.getModifiers())) continue;
            moduleList.add(bindAction(Class.forName(ctClass.getName())));
        }
        ServiceFramwork.injector = ServiceFramwork.injector.createChildInjector(moduleList);
    }
View Full Code Here

            ServiceFramwork.scanService.scanArchives(item, new ScanService.LoadClassEnhanceCallBack() {
                @Override
                public Class loaded(DataInputStream classFile) {
                    try {

                        CtClass ctClass = ServiceFramwork.classPool.makeClass(classFile);
                        TraceEnhancer.enhanceMethod(ctClass);
                        try {
                            ctClasses.add(ctClass.toClass());
                        } catch (Exception e) {
                            String name = ctClass.getName();
                            Class me = Class.forName(name);
                            if (!ctClasses.contains(me)) {
                                ctClasses.add(me);
                            }
                        }
View Full Code Here

    );

    @Override
    public CtClass enhanceThisClass(DataInputStream dataInputStream) throws Exception {
        CtClass ctClass = classPool.makeClassIfNew(dataInputStream);
        if (!ctClass.subtypeOf(classPool.get("net.csdn.modules.http.ApplicationController"))) {
            return ctClass;
        }

        if (Modifier.isAbstract(ctClass.getModifiers())) return ctClass;

        TraceEnhancer.enhanceMethod(ctClass);

        CtClass controller = classPool.get("net.csdn.modules.http.ApplicationController");

        //copy static fields to subclass.Importance because of inheritance strategy of java
        copyStaticFieldsToSubclass(controller, ctClass);

        //copy static methods to subclass
View Full Code Here

    public static void initEnv(Class classLoader) {
        try {
            ServiceFramwork.mode = ServiceFramwork.Mode.test;
            ServiceFramwork.scanService.setLoader(classLoader);
            CtClass ctClass = ServiceFramwork.classPool.get("net.csdn.bootstrap.Bootstrap");
            if (checkClassLoaded(ctClass.getName())) {
                return;
            }
            //加载Guice容器
            Method method = ctClass.toClass().getDeclaredMethod("configureSystem");
            method.setAccessible(true);
            method.invoke(null);
            injector = ServiceFramwork.injector;
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

TOP

Related Classes of javassist.CtClass

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.