You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ClassPreProcessorAgentAdapter.java 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 java.lang.instrument.ClassFileTransformer;
  14. import java.lang.instrument.IllegalClassFormatException;
  15. import java.security.ProtectionDomain;
  16. /**
  17. * Java 1.5 adapter for class pre processor
  18. *
  19. * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
  20. */
  21. public class ClassPreProcessorAgentAdapter implements ClassFileTransformer {
  22. /**
  23. * Concrete preprocessor.
  24. */
  25. private static ClassPreProcessor s_preProcessor;
  26. static {
  27. try {
  28. s_preProcessor = new Aj();
  29. s_preProcessor.initialize();
  30. } catch (Exception e) {
  31. throw new ExceptionInInitializerError("could not initialize JSR163 preprocessor due to: " + e.toString());
  32. }
  33. }
  34. /**
  35. * Invokes the weaver to modify some set of input bytes.
  36. *
  37. * @param loader the defining class loader
  38. * @param className the name of class being loaded
  39. * @param classBeingRedefined is set when hotswap is being attempted
  40. * @param protectionDomain the protection domain for the class being loaded
  41. * @param bytes the incoming bytes (before weaving)
  42. * @return the woven bytes
  43. */
  44. public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain,
  45. byte[] bytes) throws IllegalClassFormatException {
  46. if (classBeingRedefined != null) {
  47. System.err.println("INFO: (Enh120375): AspectJ attempting reweave of '" + className + "'");
  48. }
  49. return s_preProcessor.preProcess(className, bytes, loader, protectionDomain);
  50. }
  51. }