Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ClassPreProcessorAgentAdapter.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*******************************************************************************
  2. * Copyright (c) 2005 Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Alexandre Vasseur initial implementation
  11. *******************************************************************************/
  12. package org.aspectj.weaver.loadtime;
  13. import org.aspectj.weaver.loadtime.Aj;
  14. import org.aspectj.weaver.loadtime.ClassPreProcessor;
  15. import java.lang.instrument.ClassFileTransformer;
  16. import java.lang.instrument.IllegalClassFormatException;
  17. import java.security.ProtectionDomain;
  18. /**
  19. * Java 1.5 adapter for class pre processor
  20. *
  21. * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
  22. */
  23. public class ClassPreProcessorAgentAdapter implements ClassFileTransformer {
  24. /**
  25. * Concrete preprocessor.
  26. */
  27. private static ClassPreProcessor s_preProcessor;
  28. static {
  29. try {
  30. s_preProcessor = new Aj();
  31. s_preProcessor.initialize();
  32. } catch (Exception e) {
  33. throw new ExceptionInInitializerError("could not initialize JSR163 preprocessor due to: " + e.toString());
  34. }
  35. }
  36. /**
  37. * Weaving delegation
  38. *
  39. * @param loader the defining class loader
  40. * @param className the name of class beeing loaded
  41. * @param classBeingRedefined when hotswap is called
  42. * @param protectionDomain
  43. * @param bytes the bytecode before weaving
  44. * @return the weaved bytecode
  45. */
  46. public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
  47. ProtectionDomain protectionDomain, byte[] bytes) throws IllegalClassFormatException {
  48. if (classBeingRedefined == null) {
  49. return s_preProcessor.preProcess(className, bytes, loader);
  50. } else {
  51. //FIXME av for now we skip hotswap. We should think more about that
  52. new Exception("AspectJ5 does not weave hotswapped class (" + className + ")").printStackTrace();
  53. return bytes;
  54. }
  55. }
  56. }