Package javassist

Examples of javassist.CtClass$DelayedFileOutputStream


    }

    private Class<?> createArtificialApplicationResourcesClass() {
        try {
            ClassPool classPool = ClassPool.getDefault();
            CtClass applicationResourcesCtClass = classPool.makeClass(APP_FUSE_RESOURCE_FILE_NAME);
            return applicationResourcesCtClass.toClass();
        } catch (CannotCompileException e) {
            throw new RuntimeException("Unable to instantiate Wicket application", e);
        }
    }
View Full Code Here


      throws Exception {
    enhanceThisClass_(applicationClass);
  }
 
  private void enhanceThisClass_(ApplicationClass applicationClass) throws Exception {
        final CtClass ctClass = makeClass(applicationClass);
       
        // enhances only EnhancedModel classes
        if (!ctClass.subtypeOf(classPool.get(EnhancedModel.class.getName()))) {
            return;
        }
       
        String entityName = ctClass.getName();
       
        Logger.debug("Play-Siena: enhancing EnhancedModel " + entityName);
       
        // all
        try {
          ctClass.getDeclaredMethod("all");
        }catch(NotFoundException ex){
            CtMethod all = CtMethod.make("public static play.modules.siena.QueryWrapper all() { return new play.modules.siena.QueryWrapper(siena.Model.all("+entityName+".class)); }", ctClass);
            ctClass.addMethod(all);         
        }
 
        // batch
        try {
          ctClass.getDeclaredMethod("batch");
        }catch(NotFoundException ex){
          CtMethod batch = CtMethod.make("public static play.modules.siena.BatchWrapper batch() { return new play.modules.siena.BatchWrapper(siena.Model.batch("+entityName+".class)); }", ctClass);
          ctClass.addMethod(batch);
        }
       
        // getbyKey
        try {
          ctClass.getDeclaredMethod("getByKey");
        }catch(NotFoundException ex){
          CtMethod batch = CtMethod.make("public static play.modules.siena.EnhancedModel getByKey(Object key) { return (play.modules.siena.EnhancedModel)siena.Model.getByKey("+entityName+".class, key); }", ctClass);
          ctClass.addMethod(batch);
        }

        // create
        try {
          ctClass.getDeclaredMethod("create");
        }catch(NotFoundException ex){
            CtMethod create = CtMethod.make("public static play.modules.siena.EnhancedModel create(String name, play.mvc.Scope.Params params) { return play.modules.siena.EnhancedModel.create("+entityName+".class, name, params.all()); }",ctClass);
            ctClass.addMethod(create);
        }


        // count
        try {
          ctClass.getDeclaredMethod("count");
        }catch(NotFoundException ex){
          CtMethod count = CtMethod.make("public static long count() { return (long)siena.Model.all("+entityName+".class).count(); }", ctClass);
          ctClass.addMethod(count);
        }

        // findAll
        try {
          ctClass.getDeclaredMethod("findAll");
        }catch(NotFoundException ex){
          CtMethod findAll = CtMethod.make("public static java.util.List findAll() { return (java.util.List)siena.Model.all("+entityName+".class).fetch(); }", ctClass);
          ctClass.addMethod(findAll);
        }

        // deleteAll
        try {
          ctClass.getDeclaredMethod("deleteAll");
       }catch(NotFoundException ex){
          CtMethod deleteAll = CtMethod.make("public static long deleteAll() { return (long)siena.Model.all("+entityName+".class).delete(); }", ctClass);
          ctClass.addMethod(deleteAll);
        }
 
        // findById
       try {
         ctClass.getDeclaredMethod("findById");
       }catch(NotFoundException ex){
         CtMethod findById = CtMethod.make("public static play.modules.siena.EnhancedModel findById(Object id) { return (play.modules.siena.EnhancedModel)siena.Model.getByKey("+entityName+".class, id); }", ctClass);
         ctClass.addMethod(findById);
       }
       
        // Done.
        applicationClass.enhancedByteCode = ctClass.toBytecode();
        ctClass.detach();
  }
View Full Code Here

    public byte[] transform(ClassLoader loader, String className, byte[] classfileBuffer) {

        ClassPool pool = createClassPool(loader);

        CtClass clazz = getCtClass(className, pool);

        byte[] newByteCode = transformClassCode(className, classfileBuffer, pool, clazz);

        return newByteCode;
    }
View Full Code Here

     * modifier.
     */
    @Override
    protected CtClass get0(String classname, boolean useCache) throws NotFoundException {

        CtClass clazz = null;

        if (useCache) {
            clazz = getCached(classname);
            if (clazz != null) {
                return clazz;
            }
        }

        clazz = createCtClass(classname, useCache);

        if (clazz != null) {

            if (useCache) {
                cacheCtClass(clazz.getName(), clazz, false);
            }

            return clazz;
        }

View Full Code Here

             * be loaded. Atm I have found no solution other than this ugly hack
             * to make it work. We really need to investigate the real cause of
             * this behavior.
             */
            if (!name.startsWith(CGLIB_ENHANCER) && !name.startsWith(CGLIB_METHOD_WRAPPER)) {
                final CtClass ctClass = classPool.get(name);
                if (ctClass.isFrozen()) {
                    ctClass.defrost();
                }
                bytes = ctClass.toBytecode();
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return bytes == null ? null : defineClass(name, bytes, 0, bytes.length);
View Full Code Here

    /**
     * Load a mocked version of the class.
     */
    private Class<?> loadMockClass(String name) {
        CtClass type = null;
        byte[] clazz = null;

        ClassPool.doPruning = false;
        try {
            type = classPool.get(name);
            for (MockTransformer transformer : mockTransformerChain) {
                type = transformer.transform(type);
            }
            clazz = type.toBytecode();
        } catch (Exception e) {
            throw new IllegalStateException("Failed to transform class with name " + name + ". Reason: " + e.getMessage(), e);
        }

        return defineClass(name, clazz, 0, clazz.length);
View Full Code Here

        }
    }

    public void loadType(String type) throws NotFoundException
    {
        CtClass objectType = _classPool.get(type);
        _objectTypeMap.put(type, objectType);
    }
View Full Code Here

    public CtClass getObjectType(String type)
    {

            synchronized (this) {
                CtClass result = getClassMapping().getType(type);

                if (result == null)
                {
                    try
                    {
View Full Code Here

    public ClassFabricator getClassFabricator()
    {
        if (_classFabricator == null)
        {
            CtClass jaParentClass = getObjectType(_parentClass.getName());
            ClassPool classPool = _classFactory.getClassPool();
            _classFabricator = new ClassFabricator(_className, jaParentClass, classPool);
        }
        return _classFabricator;
    }
View Full Code Here

    }

    @Override
    public void onLoad(ClassPool pool, String classname) throws NotFoundException, CannotCompileException {
        if (GWT.equals(classname)) {
            CtClass cc = pool.get(classname);
            for (CtMethod method : cc.getMethods()) {
                if (METHOD.equals(method.getName())) {
                    method.setBody(BODY);
                    return;
                }
            }
View Full Code Here

TOP

Related Classes of javassist.CtClass$DelayedFileOutputStream

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.