Package java.lang.instrument

Examples of java.lang.instrument.ClassFileTransformer


            public ClassLoader getNewTempClassLoader(ClassLoader classLoader) {
                return new TempClassLoader(classLoader);
            }
        };

        Agent.getInstrumentation().addTransformer(new ClassFileTransformer() {
            public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) {
                if (!className.equals("org/apache/openejb/core/cmp/jpa/Employee")) {
                    return null;
                }
                byte[] newBytes = addNewField(classfileBuffer);
View Full Code Here


        Log log = conf.getLog(OpenJPAConfiguration.LOG_ENHANCE);
        if (classes == null || classes.size() == 0 || !canRedefineClasses(log))
            return;

        Instrumentation inst = null;
        ClassFileTransformer t = null;
        try {
            inst = InstrumentationFactory.getInstrumentation(log);

            Class<?>[] array = classes.keySet().toArray(new Class[classes.size()]);
            if (JavaVersions.VERSION >= 6) {
                log.trace(_loc.get("retransform-types", classes.keySet()));

                t = new ClassFileTransformer() {
                    public byte[] transform(ClassLoader loader, String clsName,
                        Class<?> classBeingRedefined, ProtectionDomain pd,
                        byte[] classfileBuffer) {
                        return classes.get(classBeingRedefined);
                    }
View Full Code Here

   *             id the given class can not be found
   */
  public static IRuntime createFor(final Instrumentation inst,
      final String className, final String accessFieldName)
      throws ClassNotFoundException {
    final ClassFileTransformer transformer = new ClassFileTransformer() {
      public byte[] transform(final ClassLoader loader,
          final String name, final Class<?> classBeingRedefined,
          final ProtectionDomain protectionDomain, final byte[] source)
          throws IllegalClassFormatException {
        if (name.equals(className)) {
View Full Code Here

  @Nonnull
  private Collection<ClassFileTransformer> getAgents() throws MojoExecutionException {
    final Collection<ClassFileTransformer> agents = new ArrayList<ClassFileTransformer>();
    for (final String className : classTransformers) {
      final ClassFileTransformer instance = createAgentInstance(className);
      agents.add(instance);
    }
    return agents;
  }
View Full Code Here

       @Override
       public void addTransformer(final ClassTransformer transformer) {
           // Bridge between java.lang.instrument.ClassFileTransformer that DeploymentContext accepts
           // and javax.persistence.spi.ClassTransformer that JPA supplies.
           deploymentContext.addTransformer(new ClassFileTransformer() {
               public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
                                       ProtectionDomain protectionDomain, byte[] classfileBuffer)
                       throws IllegalClassFormatException {
                   return transformer.transform(loader, className, classBeingRedefined, protectionDomain, classfileBuffer);
               }
View Full Code Here

        // resolve against the system loader and injection into bootstrap classes fails. But that's still ok
        // because the byteman classes are still only foudn in one place.

        boolean isRedefine = inst.isRedefineClassesSupported();

        ClassFileTransformer transformer;
        ClassLoader loader = ClassLoader.getSystemClassLoader();
        Class transformerClazz;

        if (allowRedefine && isRedefine) {
            transformerClazz = loader.loadClass("org.jboss.byteman.agent.Retransformer");
View Full Code Here

  @Test
  public void testCtorWithClassLoaderThatDoesNotExposeAGetThrowawayClassLoaderMethodIsOkay() {
    JustAddTransformerClassLoader classLoader = new JustAddTransformerClassLoader();
    ReflectiveLoadTimeWeaver weaver = new ReflectiveLoadTimeWeaver(classLoader);
    weaver.addTransformer(new ClassFileTransformer() {
      @Override
      public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) {
        return "CAFEDEAD".getBytes();
      }
    });
View Full Code Here

       @Override
       public void addTransformer(final ClassTransformer transformer) {
           // Bridge between java.lang.instrument.ClassFileTransformer that DeploymentContext accepts
           // and javax.persistence.spi.ClassTransformer that JPA supplies.
           deploymentContext.addTransformer(new ClassFileTransformer() {
               public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
                                       ProtectionDomain protectionDomain, byte[] classfileBuffer)
                       throws IllegalClassFormatException {
                   return transformer.transform(loader, className, classBeingRedefined, protectionDomain, classfileBuffer);
               }
View Full Code Here

    transformers.addAll( createConvenienceTransformers() );

    //Add the configured class transformers
    if ( classTransformers != null ) {
      for (final String className : classTransformers) {
        final ClassFileTransformer instance = createAgentInstance(className);
        transformers.add( instance );
      }
    }
    return transformers;
  }
View Full Code Here

   *             id the given class can not be found
   */
  public static IRuntime createFor(final Instrumentation inst,
      final String className, final String accessFieldName)
      throws ClassNotFoundException {
    final ClassFileTransformer transformer = new ClassFileTransformer() {
      public byte[] transform(final ClassLoader loader,
          final String name, final Class<?> classBeingRedefined,
          final ProtectionDomain protectionDomain, final byte[] source)
          throws IllegalClassFormatException {
        if (name.equals(className)) {
View Full Code Here

TOP

Related Classes of java.lang.instrument.ClassFileTransformer

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.