Package org.jboss.aop.classpool

Examples of org.jboss.aop.classpool.AOPClassPool


    * dynamicaly wrapped.
    */
   public void convertProcessedClasses(HotSwapper hotSwapper, CtClass clazz,
         Collection<CtField> fieldReads, Collection<CtField> fieldWrites, boolean constructor)
   {
      AOPClassPool classPool = (AOPClassPool) clazz.getClassPool();
      CodeConverter codeConverter = new CodeConverter();
      for (CtField field : fieldReads)
      {
         codeConverter.replaceFieldRead(field, clazz, FieldAccessTransformer.fieldRead(field.getName()));
      }
      for (CtField field : fieldWrites)
      {
         codeConverter.replaceFieldWrite(field, clazz, FieldAccessTransformer.fieldWrite(field.getName()));
      }
      if (constructor)
      {
         codeConverter.replaceNew(clazz, clazz, ConstructorExecutionTransformer.constructorFactory(clazz.getSimpleName()));
      }

      synchronized(processedClasses)
      {
      for (CtClass processedClass : processedClasses)
      {
         if (processedClass == clazz)
            continue;
         if (processedClass.getRefClasses() == null ||
                ! clazz.getRefClasses().contains(clazz.getName()))
          {
             continue;
          }
          try
          {
             processedClass.defrost();
             byte[] previousByteCode = processedClass.toBytecode();
             processedClass.defrost();
             processedClass.instrument(codeConverter);
             byte[] updatedByteCode = processedClass.toBytecode();
             if (!java.util.Arrays.equals(updatedByteCode, previousByteCode))
             {
               hotSwapper.registerChange(classPool.getClassLoader().loadClass(processedClass.getName()), updatedByteCode);
             }
             processedClass.defrost();
          }
          catch (Exception e)
          {
View Full Code Here


   public void wrap(CtClass clazz, Collection<org.jboss.aop.MethodInfo> methodInfos) throws Exception
   {
      for (org.jboss.aop.MethodInfo methodInfo : methodInfos)
      {
         Method method = methodInfo.getMethod();
         AOPClassPool classPool = (AOPClassPool) clazz.getClassPool();
         Class<?>[] parameterTypes = method.getParameterTypes();
         CtClass[] javassistParameterTypes = new CtClass[parameterTypes.length];
         for (int i = 0; i < parameterTypes.length; i++)
         {
            classPool.getLocally(parameterTypes[i].getName());
         }
         if (method.getName().indexOf("access$") >= 0)
         {
            continue;
         }
View Full Code Here

   public void unwrap(CtClass clazz, Collection<org.jboss.aop.MethodInfo> methodInfos) throws Exception
   {
      for (org.jboss.aop.MethodInfo methodInfo : methodInfos)
      {
         Method method = methodInfo.getMethod();
         AOPClassPool classPool = (AOPClassPool) clazz.getClassPool();
         Class<?>[] parameterTypes = method.getParameterTypes();
         CtClass[] javassistParameterTypes = new CtClass[parameterTypes.length];
         for (int i = 0; i < parameterTypes.length; i++)
         {
            javassistParameterTypes[i] = classPool.getLocally(parameterTypes[i].getName());
         }
         CtMethod javassistWMethod = clazz.getDeclaredMethod(method.getName(), javassistParameterTypes);
         if (wrapper.isNotPrepared(javassistWMethod, WrapperTransformer.SINGLE_TRANSFORMATION_INDEX))
         {
            continue;
View Full Code Here

       {
          if (manager.isNonAdvisableClassName(className))
          {
             return null;
          }
          AOPClassPool pool = (AOPClassPool) manager.registerClassLoader(loader);
          CtClass clazz = null;
          try
          {
             clazz = pool.getLocally(className);
          }
          catch (NotFoundException e)
          {
             // todo Bill Burke: this scares the shit out of me, but it must be done
             // I think it will screw up hotdeployment at some time.  Then again, maybe not ;)
             ByteArrayClassPath cp = new ByteArrayClassPath(className, classfileBuffer);
             pool.insertClassPath(cp);
             clazz = pool.getLocally(className);
          }
          if (clazz.isArray())
          {
             if (verbose && logger.isDebugEnabled()) logger.debug("cannot compile, isArray: " + className);
             pool.flushClass(className);
             return null;
          }
          if (clazz.isInterface())
          {
             if (verbose && logger.isDebugEnabled()) logger.debug("cannot compile, isInterface: " + className);
             pool.flushClass(className);
             return null;
          }
          if (clazz.isFrozen())
          {
             if (verbose && logger.isDebugEnabled()) logger.debug("warning, isFrozen: " + className);
             clazz.defrost();
          }

          ClassAdvisor advisor = AdvisorFactory.getClassAdvisor(clazz, manager);
          Instrumentor instrumentor = InstrumentorFactory.getInstrumentor(
                pool,
                manager,
                manager.dynamicStrategy.getJoinpointClassifier(),
                manager.dynamicStrategy.getDynamicTransformationObserver(clazz));

          if (!Instrumentor.isTransformable(clazz))
          {
             if (verbose && logger.isDebugEnabled()) logger.debug("[cannot compile] implements Untransformable: " + className);
             pool.flushClass(className);
             return null;
          }

          manager.attachMetaData(advisor, clazz, true);
          manager.applyInterfaceIntroductions(advisor, clazz);
          boolean transformed = instrumentor.transform(clazz, advisor);
          if (transformed)
          {
             pool.lockInCache(clazz);
             if (AspectManager.debugClasses)
             {
                SecurityActions.debugWriteFile(clazz);
             }

             byte[] rtn = clazz.toBytecode();
             if (AspectManager.getPrune()) clazz.prune();
             return rtn;
          }
          else
          {
             pool.soften(clazz);
          }
          return null;
       }
       catch (Exception ex)
       {
View Full Code Here

         if (manager.isNonAdvisableClassName(className))
         {
            return null;
         }

         AOPClassPool pool = (AOPClassPool) manager.registerClassLoader(loader);

         CtClass clazz = obtainCtClassInfo(pool, className, classfileBuffer);
        
         CtClass woven = instrumentClass(manager, pool, clazz, true);
         if (woven != null)
         {
            pool.lockInCache(woven);
            if (AspectManager.debugClasses)
            {
               SecurityActions.debugWriteFile(clazz);
            }
            byte[] rtn = woven.toBytecode();
            if (AspectManager.getPrune()) woven.prune();
            return rtn;
         }
         else
         {
            pool.soften(clazz);
         }
         return null;
      }
      catch (Exception ex)
      {
View Full Code Here

       {
          if (manager.isNonAdvisableClassName(className))
          {
             return null;
          }
          AOPClassPool pool = (AOPClassPool) manager.registerClassLoader(loader);
          CtClass clazz = null;
          try
          {
             clazz = pool.getLocally(className);
          }
          catch (NotFoundException e)
          {
             // todo Bill Burke: this scares the shit out of me, but it must be done
             // I think it will screw up hotdeployment at some time.  Then again, maybe not ;)
             ByteArrayClassPath cp = new ByteArrayClassPath(className, classfileBuffer);
             pool.insertClassPath(cp);
             clazz = pool.getLocally(className);
          }
          if (clazz.isArray())
          {
             if (verbose && logger.isDebugEnabled()) logger.debug("cannot compile, isArray: " + className);
             pool.flushClass(className);
             return null;
          }
          if (clazz.isInterface())
          {
             if (verbose && logger.isDebugEnabled()) logger.debug("cannot compile, isInterface: " + className);
             pool.flushClass(className);
             return null;
          }
          if (clazz.isFrozen())
          {
             if (verbose && logger.isDebugEnabled()) logger.debug("warning, isFrozen: " + className);
             clazz.defrost();
          }

          ClassAdvisor advisor = new ClassAdvisor(className, manager);
          Instrumentor instrumentor = InstrumentorFactory.getInstrumentor(
                pool,
                manager,
                manager.dynamicStrategy.getJoinpointClassifier(),
                manager.dynamicStrategy.getDynamicTransformationObserver(clazz));

          if (!Instrumentor.isTransformable(clazz))
          {
             if (verbose && logger.isDebugEnabled()) logger.debug("[cannot compile] implements Untransformable: " + className);
             pool.flushClass(className);
             return null;
          }

          manager.attachMetaData(advisor, clazz, true);
          manager.applyInterfaceIntroductions(advisor, clazz);
          boolean transformed = instrumentor.transform(clazz, advisor);
          if (transformed)
          {
             pool.lockInCache(clazz);
             if (AspectManager.debugClasses)
             {
                SecurityActions.debugWriteFile(clazz);
             }

             byte[] rtn = clazz.toBytecode();
             if (AspectManager.getPrune()) clazz.prune();
             return rtn;
          }
          else
          {
             pool.soften(clazz);
          }
          return null;
       }
       catch (Exception ex)
       {
View Full Code Here

   {
      boolean converted = false;
      String ref = null;
      try
      {
         AOPClassPool pool = AOPClassPool.createAOPClassPool(clazz.getClassPool(), AOPClassPoolRepository.getInstance());

         //Class.getRefClasses() only gets classes explicitly referenced in the class. We need to check the super classes and do some extra handling
         for (ReferenceClassIterator it = new ReferenceClassIterator(clazz.getRefClasses()) ; it.hasNext() ; )
         {
            ref = it.next();
            if (!manager.getInterceptionMarkers().convertReference(ref)
                || manager.isNonAdvisableClassName(ref)
                || ref.startsWith("java.")
                || ref.startsWith("javax.")
                || ref.startsWith("["))
            {
               continue;
            }
            // Only need a temporary advisor for resolving metadata
            CtClass ctRef = null;
            try
            {
               ctRef = pool.get(ref);
            }
            catch (NotFoundException e)
            {
               if (AspectManager.suppressReferenceErrors)
               {
View Full Code Here

         constructorExecutionTransformer.codeConverted();

         // registers the classes bytecodes to be hot swapped
         for (CtClass clazz : classes)
         {
            AOPClassPool classPool = (AOPClassPool) clazz.getClassPool();
            clazz.defrost();
            hotSwapper.registerChange(classPool.getClassLoader().loadClass(clazz.getName()),
                  clazz.toBytecode());
         }
         // performs the hot swap of registered classes
         hotSwapper.hotSwap();
      }
View Full Code Here

    * dynamicaly wrapped.
    */
   public void convertProcessedClasses(HotSwapper hotSwapper, CtClass clazz,
         Collection<CtField> fieldReads, Collection<CtField> fieldWrites, boolean constructor)
   {
      AOPClassPool classPool = (AOPClassPool) clazz.getClassPool();
      CodeConverter codeConverter = new CodeConverter();
      for (CtField field : fieldReads)
      {
         codeConverter.replaceFieldRead(field, clazz, FieldAccessTransformer.fieldRead(field.getName()));
      }
      for (CtField field : fieldWrites)
      {
         codeConverter.replaceFieldWrite(field, clazz, FieldAccessTransformer.fieldWrite(field.getName()));
      }
      if (constructor)
      {
         codeConverter.replaceNew(clazz, clazz, ConstructorExecutionTransformer.constructorFactory(clazz.getSimpleName()));
      }

      synchronized(processedClasses)
      {
      for (CtClass processedClass : processedClasses)
      {
         if (processedClass == clazz)
            continue;
         if (processedClass.getRefClasses() == null ||
                ! clazz.getRefClasses().contains(clazz.getName()))
          {
             continue;
          }
          try
          {
             processedClass.defrost();
             byte[] previousByteCode = processedClass.toBytecode();
             processedClass.defrost();
             processedClass.instrument(codeConverter);
             byte[] updatedByteCode = processedClass.toBytecode();
             if (!java.util.Arrays.equals(updatedByteCode, previousByteCode))
             {
               hotSwapper.registerChange(classPool.getClassLoader().loadClass(processedClass.getName()), updatedByteCode);
             }
             processedClass.defrost();
          }
          catch (Exception e)
          {
View Full Code Here

   public void wrap(CtClass clazz, Collection<org.jboss.aop.MethodInfo> methodInfos) throws Exception
   {
      for (org.jboss.aop.MethodInfo methodInfo : methodInfos)
      {
         Method method = methodInfo.getMethod();
         AOPClassPool classPool = (AOPClassPool) clazz.getClassPool();
         Class<?>[] parameterTypes = method.getParameterTypes();
         CtClass[] javassistParameterTypes = new CtClass[parameterTypes.length];
         for (int i = 0; i < parameterTypes.length; i++)
         {
            classPool.getLocally(parameterTypes[i].getName());
         }
         if (method.getName().indexOf("access$") >= 0)
         {
            continue;
         }
View Full Code Here

TOP

Related Classes of org.jboss.aop.classpool.AOPClassPool

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.