Package javassist

Examples of javassist.ClassPool


    private Component setupForIntegrationTest(InternalComponentResources resources, Logger logger,
            String componentClassName, MutableComponentModel model, BindingSource source,
            Runnable phaseTwoTraining) throws Exception
    {
        ClassPool pool = new ClassPool();
        ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
        pool.appendClassPath(new LoaderClassPath(contextLoader));

        Loader loader = new Loader(contextLoader, pool);

        loader.delegateLoadingOf("org.apache.tapestry.");

        CtClass ctClass = pool.get(componentClassName);
        InternalClassTransformation transformation = new InternalClassTransformationImpl(ctClass,
                _contextClassLoader, logger, null);

        replay();

        new ParameterWorker(source).transform(transformation, model);

        verify();

        transformation.finish();

        // System.out.println("Transformation: " + transformation);

        Class transformedClass = pool.toClass(ctClass, loader);

        Instantiator instantiator = transformation.createInstantiator(transformedClass);

        phaseTwoTraining.run();
View Full Code Here


    }

    private void createSynthComponentClass(String name) throws CannotCompileException,
            NotFoundException, IOException
    {
        ClassPool pool = new ClassPool();
        // Inside Maven Surefire, the system classpath is not sufficient to find all
        // the necessary files.
        pool.appendClassPath(new LoaderClassPath(_extraLoader));

        CtClass ctClass = pool.makeClass(SYNTH_COMPONENT_CLASSNAME);

        ctClass.setSuperclass(pool.get(BasicComponent.class.getName()));

        // Implement method getName()

        CtMethod method = CtNewMethod.make(
                "public String getName() { return \"" + name + "\"; }",
                ctClass);
        ctClass.addMethod(method);

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

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

     * modifying one or more CtClass instances.
     */
    @BeforeMethod
    public void setup_classpool()
    {
        _classPool = new ClassPool();

        _loader = new Loader(_contextClassLoader, _classPool);

        // This ensures that only the classes we explicitly access and modify
        // are loaded by the new loader; everthing else comes out of the common
View Full Code Here

        InternalComponentResources resources = mockInternalComponentResources();

        String componentClassName = StateHolder.class.getName();
        Class asoClass = ReadOnlyBean.class;

        ClassPool pool = new ClassPool();
        ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
        pool.appendClassPath(new LoaderClassPath(contextLoader));

        Loader loader = new Loader(contextLoader, pool);

        loader.delegateLoadingOf("org.apache.tapestry.");

        CtClass ctClass = pool.get(componentClassName);
        InternalClassTransformation transformation = new InternalClassTransformationImpl(ctClass,
                _contextClassLoader, logger, null);

        replay();

        new ApplicationStateWorker(manager).transform(transformation, model);

        verify();

        transformation.finish();

        Class transformedClass = pool.toClass(ctClass, loader);

        Instantiator instantiator = transformation.createInstantiator(transformedClass);

        Object component = instantiator.newInstance(resources);
View Full Code Here

    private Component setupForIntegrationTest(InternalComponentResources resources, Log log,
            String componentClassName, MutableComponentModel model, BindingSource source,
            Runnable phaseTwoTraining) throws Exception
    {
        ClassPool pool = new ClassPool();
        ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
        pool.appendClassPath(new LoaderClassPath(contextLoader));

        Loader loader = new Loader(contextLoader, pool);

        loader.delegateLoadingOf("org.apache.tapestry.");

        CtClass ctClass = pool.get(componentClassName);
        InternalClassTransformation transformation = new InternalClassTransformationImpl(ctClass,
                _contextClassLoader, log, null);

        replay();

        new ParameterWorker(source).transform(transformation, model);

        verify();

        transformation.finish();

        // System.out.println("Transformation: " + transformation);

        Class transformedClass = pool.toClass(ctClass, loader);

        Instantiator instantiator = transformation.createInstantiator(transformedClass);

        phaseTwoTraining.run();
View Full Code Here

      this.registry = registry;
   }
  
   public ScopedClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
   {     
      ClassPool parent = getCreateParentClassPools(cl, src, repository);

      ScopedClassPool pool = null;
     
      if (cl instanceof RealClassLoader)
      {
         Module module = registry.getModule(cl);
         if (module != null && module.getDeterminedParentDomainName() != null)
         {
            //It is scoped
            ClassLoaderSystem sys = ClassLoaderSystem.getInstance();
            ClassLoaderDomain domain = sys.getDomain(module.getDeterminedDomainName());
            boolean parentFirst = module.isJ2seClassLoadingCompliance();
            ClassPool parentDomainPool = getParentUnitClassPool(cl);
            pool = new ScopedJBoss5ClassPool(cl, parent, parentDomainPool, repository, getTempURL(module), parentFirst, domain);
         }
         else
         {
            pool =  new JBoss5ClassPool(cl, parent, repository, getTempURL(module));
View Full Code Here

      }
     

      try
      {
         ClassPool pool = getCorrectPoolForResource(classname, resourcename, url, trace);
         if (trace)
         {
            log.trace("getCached() Found pool for class " + classname + " " + pool);
         }
         if (pool != lastPool.get())
         {
            lastPool.set(pool);
            CtClass found = pool.get(classname);
            if (trace)
            {
               log.trace("getCached() Found clazz " + classname + " in " + pool + " : " + found);
            }
            return found;
View Full Code Here

   private ClassPool createTempPool()
   {
      //Rememeber that the stuff in jboss5/lib goes in a child classloader of the default classloader. We need
      //to make this the parent of the temp classloader
      ClassLoader aopLoader = AspectManager.class.getClassLoader();
      ClassPool pool = AspectManager.instance().registerClassLoader(aopLoader);
      return AOPClassPool.createAOPClassPool(pool, AOPClassPoolRepository.getInstance());
   }
View Full Code Here

   }

   private static CtClass createProxyCtClass(ClassLoader loader, ProxyMixin[] mixins, Class<?>[] interfaces)
   throws Exception
   {
      ClassPool pool = AspectManager.instance().findClassPool(loader);
      if (pool == null) throw new NullPointerException("Could not find ClassPool");


      String classname = null;
      synchronized (ProxyFactory.class)
      {
         classname = GENERATED_PROXIES_PACKAGE + ".AOPProxy$" + counter++;
      }

      CtClass base = pool.get("org.jboss.aop.proxy.Proxy");
      CtClass proxy = TransformerCommon.makeClass(pool, classname, base);
      proxy.addInterface(pool.get("org.jboss.aop.instrument.Untransformable"));
      CtClass map = pool.get("java.util.Map");
      CtField methodMap = new CtField(map, "methodMap", proxy);
      methodMap.setModifiers(Modifier.PRIVATE | Modifier.STATIC);
      Instrumentor.addSyntheticAttribute(methodMap);
      proxy.addField(methodMap);
      CtMethod getMethodMap = CtNewMethod.getter("getMethodMap", methodMap);
      getMethodMap.setModifiers(Modifier.PUBLIC);
      Instrumentor.addSyntheticAttribute(getMethodMap);
      proxy.addMethod(getMethodMap);

      HashSet<String> addedInterfaces = new HashSet<String>();
      HashSet<Long> addedMethods = new HashSet<Long>();
      if (mixins != null)
      {
         for (int i = 0; i < mixins.length; i++)
         {
            HashSet<Long> mixinMethods = new HashSet<Long>();
            Class<?>[] mixinf = mixins[i].getInterfaces();
            ClassPool mixPool = AspectManager.instance().findClassPool(mixins[i].getMixin().getClass());
            CtClass mixClass = mixPool.get(mixins[i].getMixin().getClass().getName());
            for (int j = 0; j < mixinf.length; j++)
            {
               if (addedInterfaces.contains(mixinf[j].getName())) throw new Exception("2 mixins are implementing the same interfaces");
               ClassPool mixIntfPool = AspectManager.instance().findClassPool(mixinf[j]);
               CtClass intfClass = mixIntfPool.get(mixinf[j].getName());
               CtMethod[] methods = intfClass.getMethods();
               for (int m = 0; m < methods.length; m++)
               {
                  if (methods[m].getDeclaringClass().getName().equals("java.lang.Object")) continue;
                  Long hash = new Long(JavassistMethodHashing.methodHash(methods[m]));
                  if (mixinMethods.contains(hash)) continue;
                  if (addedMethods.contains(hash)) throw new Exception("More than one mixin has same method");
                  mixinMethods.add(hash);
                  addedMethods.add(hash);
                  String returnStr = (methods[m].getReturnType().equals(CtClass.voidType)) ? "" : "return ";
                  String code = "{" +
                  "   " + mixClass.getName() + " mixin = (" + mixClass.getName() + ")mixins[" + i + "].getMixin();" +
                  "   " + returnStr + " mixin." + methods[m].getName() + "($$);" +
                  "}";
                  CtMethod newMethod = CtNewMethod.make(methods[m].getReturnType(), methods[m].getName(), methods[m].getParameterTypes(), methods[m].getExceptionTypes(), code, proxy);
                  newMethod.setModifiers(Modifier.PUBLIC);
                  proxy.addMethod(newMethod);
               }

               proxy.addInterface(intfClass);
               addedInterfaces.add(intfClass.getName());
            }
         }
      }

      for (int i = 0; i < interfaces.length; i++)
      {
         if (addedInterfaces.contains(interfaces[i].getName())) continue;
         ClassPool mixPool = AspectManager.instance().findClassPool(interfaces[i]);
         CtClass intfClass = mixPool.get(interfaces[i].getName());
         CtMethod[] methods = intfClass.getMethods();
         for (int m = 0; m < methods.length; m++)
         {
            if (methods[m].getDeclaringClass().getName().equals("java.lang.Object")) continue;
            Long hash = Long.valueOf(JavassistMethodHashing.methodHash(methods[m]));
View Full Code Here

   throws Exception
   {
      // Don't make a proxy of a proxy !
      if (ClassProxy.class.isAssignableFrom(clazz)) clazz = clazz.getSuperclass();

      ClassPool pool = AspectManager.instance().findClassPool(clazz);
      if (pool == null) throw new NullPointerException("Could not find ClassPool");

     
      Class<?> proxyClass = null;
      synchronized (maplock)
      {
         WeakHashMap<Class<?>, WeakReference<Class<?>>> proxiesForLoader = proxyCache.get(pool.getClassLoader());
         if (proxiesForLoader == null)
         {
            proxiesForLoader = new WeakHashMap<Class<?>, WeakReference<Class<?>>>();
            proxyCache.put(pool.getClassLoader(), proxiesForLoader);
         }
         if (proxiesForLoader != null)
         {
            WeakReference<Class<?>> ref = proxiesForLoader.get(clazz);
            if (ref != null)
View Full Code Here

TOP

Related Classes of javassist.ClassPool

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.