Java 类javax.persistence.spi.ClassTransformer 实例源码

项目:aries-jpa    文件:WrappingTransformer.java   
public WrappingTransformer(ClassTransformer delegate, ServiceReference<?> persistenceProvider) {
    validate(delegate, persistenceProvider);
    this.delegate = delegate;

    Object packages = persistenceProvider.getProperty("org.apache.aries.jpa.container.weaving.packages");
    if (packages instanceof String[]) {
        for (String s : (String[])packages) {
            packageImportsToAdd.add(s);
        }
    } else {
        Bundle provider = persistenceProvider.getBundle();
        String suffix = ";" + Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE + "=" + provider.getSymbolicName()
                        + ";" + Constants.BUNDLE_VERSION_ATTRIBUTE + "=" + provider.getVersion();

        BundleRevision br = provider.adapt(BundleWiring.class).getRevision();
        for (BundleCapability bc : br.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE)) {
            packageImportsToAdd.add(bc.getAttributes().get(BundleRevision.PACKAGE_NAMESPACE) + suffix);
        }
    }
}
项目:aries-jpa    文件:JPAWeavingHook.java   
@Override
public void weave(WovenClass wovenClass) {
    BundleWiring wiring = wovenClass.getBundleWiring();
    Bundle bundle = wiring.getBundle();
    ClassLoader cl = wiring.getClassLoader();
    Collection<ClassTransformer> transformersToTry = getTransformers(bundle);
    for (ClassTransformer transformer : transformersToTry) {
        if (transformClass(wovenClass, cl, transformer)) {
            LOGGER.info("Weaving " + wovenClass.getClassName() + " using " + transformer.getClass().getName());
            break;
        }
    }
    Class<?> dClass = wovenClass.getDefinedClass();
    if (transformersToTry.isEmpty() && dClass != null && dClass.getAnnotation(Entity.class) != null) {
        LOGGER.warn("Loading " + wovenClass.getClassName() + " before transformer is present");
    }
}
项目:aries-jpa    文件:JPAWeavingHook.java   
private static boolean transformClass(WovenClass wovenClass, ClassLoader cl, ClassTransformer transformer)
    throws ThreadDeath, OutOfMemoryError {
    try {
        byte[] result = transformer
            .transform(cl, 
                       wovenClass.getClassName(),
                       wovenClass.getDefinedClass(), 
                       wovenClass.getProtectionDomain(),
                       wovenClass.getBytes());
        if (result != null) {
            wovenClass.setBytes(result);
            wovenClass.getDynamicImports().add("org.eclipse.persistence.*");
            wovenClass.getDynamicImports().add("org.apache.openjpa.*");
            return true;
        }
    } catch (Exception t) {
        Bundle b = wovenClass.getBundleWiring().getBundle();
        String msg = String.format("Weaving failure on class %s in bundle %s/%s using transformer %s", wovenClass.getClassName(),
                                   b.getSymbolicName(), b.getVersion(), transformer);
        throw new WeavingException(msg, t);
    }
    return false;
}
项目:bundles    文件:DatanucleusWrapper.java   
@Override
@SuppressWarnings("unchecked")
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) {
    properties.put("datanucleus.jpa.addClassTransformer", "false");
    properties.put("datanucleus.plugin.pluginRegistryClassName", "org.datanucleus.plugin.OSGiPluginRegistry");

    info.addTransformer(new ClassTransformer() {

        @Override
        public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
                ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {

            // TODO Auto-generated method stub
            return null;
        }
    });
    return pp.createContainerEntityManagerFactory(info, properties);
}
项目:aries-jpa    文件:WrappingTransformer.java   
private static void validate(ClassTransformer delegate, ServiceReference<?> persistenceProvider) {
    if (delegate == null) {
        throw new NullPointerException("Transformer delegate may not be null");
    }
    if (persistenceProvider == null) {
        throw new NullPointerException("PersistenceProvider may not be null");
    }
}
项目:aries-jpa    文件:JPAWeavingHook.java   
@Override
public synchronized void addTransformer(Bundle pBundle, ClassTransformer transformer) {
    LOGGER.info("Adding transformer " + transformer.getClass().getName());
    LinkedHashSet<ClassTransformer> transformers = registeredTransformers.get(pBundle);
    if (transformers == null) {
        transformers = new LinkedHashSet<ClassTransformer>();
        registeredTransformers.put(pBundle, transformers);
    }
    transformers.add(transformer);
}
项目:aries-jpa    文件:JPAWeavingHook.java   
@Override
public synchronized void removeTransformer(Bundle pBundle, ClassTransformer transformer) {
    LinkedHashSet<ClassTransformer> set = registeredTransformers.get(pBundle);
    if (set == null || !set.remove(transformer)) {
        throw new IllegalStateException("Transformer " + transformer + " not registered");
    }
    if (set.isEmpty()) {
        registeredTransformers.remove(pBundle);
    }
}
项目:lams    文件:SpringPersistenceUnitInfo.java   
/**
 * This implementation delegates to the LoadTimeWeaver, if specified.
 */
@Override
public void addTransformer(ClassTransformer classTransformer) {
    if (this.loadTimeWeaver == null) {
        throw new IllegalStateException("Cannot apply class transformer without LoadTimeWeaver specified");
    }
    this.loadTimeWeaver.addTransformer(new ClassFileTransformerAdapter(classTransformer));
}
项目:spring4-understanding    文件:SpringPersistenceUnitInfo.java   
/**
 * This implementation delegates to the LoadTimeWeaver, if specified.
 */
@Override
public void addTransformer(ClassTransformer classTransformer) {
    if (this.loadTimeWeaver == null) {
        throw new IllegalStateException("Cannot apply class transformer without LoadTimeWeaver specified");
    }
    this.loadTimeWeaver.addTransformer(new ClassFileTransformerAdapter(classTransformer));
}
项目:wisdom-jdbc    文件:JPATransformer.java   
@Override
public void weave(WovenClass clazz) {
    try {
        if (transformers.isEmpty()) {
            return;
        }

        BundleWiring wiring = clazz.getBundleWiring();
        Bundle b = wiring.getBundle();

        ClassTransformer trfs[];
        synchronized (transformers) {
            Collection<ClassTransformer> list = transformers.get(b);
            if (list == null) {
                return;
            }
            trfs = list.toArray(new ClassTransformer[list.size()]);
        }
        LOGGER.info("Transforming {} with {}", clazz.getClassName(), Arrays.toString(trfs));
        for (ClassTransformer ctf : trfs) {
            if (ctf != null) {
                ctf.transform(wiring.getClassLoader(), clazz.getClassName(), clazz.getDefinedClass(),
                        clazz.getProtectionDomain(), clazz.getBytes());
            }
        }

        if (!imports.isEmpty()) {
            clazz.getDynamicImports().addAll(imports);
        }

    } catch (Exception e) {
        LOGGER.error("Error while weaving class {}", clazz.getClassName(), e);
    }
}
项目:wisdom-jdbc    文件:JPATransformer.java   
boolean register(Bundle b, ClassTransformer ctf) {
    LOGGER.info("register transformer {} on bundle {}", ctf, b);
    if (ctf == null) {
        ctf = DUMMY_TRANSFORMER;
    }
    synchronized (transformers) {
        List<ClassTransformer> list = transformers.get(b);
        if (list == null) {
            list = new ArrayList<>();
            transformers.put(b, list);
        }
        list.add(ctf);
        return true;
    }
}
项目:class-guard    文件:SpringPersistenceUnitInfo.java   
/**
 * This implementation delegates to the LoadTimeWeaver, if specified.
 */
@Override
public void addTransformer(ClassTransformer classTransformer) {
    if (this.loadTimeWeaver == null) {
        throw new IllegalStateException("Cannot apply class transformer without LoadTimeWeaver specified");
    }
    this.loadTimeWeaver.addTransformer(new ClassFileTransformerAdapter(classTransformer));
}
项目:bundles    文件:TransformersHook.java   
@Override
public void weave(WovenClass clazz) {
    try {
        if (transformers.isEmpty())
            return;

        BundleWiring wiring = clazz.getBundleWiring();
        Bundle b = wiring.getBundle();

        ClassTransformer trfs[];
        synchronized (transformers) {
            List<ClassTransformer> list = transformers.get(b);
            if (list == null)
                return;
            trfs = list.toArray(empty);
        }
        System.out.println("transforming " + Arrays.toString(trfs) + " " + clazz);
        for (ClassTransformer ctf : trfs) {
            if (ctf != null) {
                ctf.transform(wiring.getClassLoader(), clazz.getClassName(), clazz.getDefinedClass(),
                        clazz.getProtectionDomain(), clazz.getBytes());
            }

        }

        if (!imports.isEmpty())
            clazz.getDynamicImports().addAll(imports);

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
项目:bundles    文件:TransformersHook.java   
boolean register(Bundle b, ClassTransformer ctf) {
    System.out.println("register transformer " + ctf + " on bundle " + b);
    if (ctf == null) {
        ctf = DUMMY_TRANSFORMER;
    }
    synchronized (transformers) {
        return transformers.add(b, ctf);
    }
}
项目:bundles    文件:PersistenceUnitInfoImpl.java   
/**
 * Add a new transformer. SPEC: can this be called multiple times?
 * 
 * @see javax.persistence.spi.PersistenceUnitInfo#addTransformer(javax.persistence.spi.ClassTransformer)
 */
@Override
public void addTransformer(ClassTransformer transformer) {
    try {
        sourceBundle.bridge.transformersHook.register(sourceBundle.bundle, transformer);
        if (transformer != null)
            transformers.add(transformer);
    } catch (RuntimeException e) {
        e.printStackTrace();
        throw e;
    }
}
项目:hightide    文件:HightidePersistenceUnitInfo.java   
@Override
public void addTransformer(ClassTransformer transformer) {
    if (isNull(transformers)) {
        transformers = new ArrayList<>();
    }
    transformers.add(transformer);
}
项目:testee.fi    文件:PersistenceUnitInfoImpl.java   
@Override
public void addTransformer(final ClassTransformer transformer) {
    // This is called by eclipselink but doing nothing with it seems to be no problem right now
    // TODO investigate
}
项目:aries-jpa    文件:PersistenceUnit.java   
@Override
public void addTransformer(ClassTransformer transformer) {
    TransformerRegistry reg = TransformerRegistrySingleton.get();
    reg.addTransformer(bundle, transformer);
}
项目:aries-jpa    文件:WrappingTransformer.java   
public WrappingTransformer(ClassTransformer transformer) {
    delegate = transformer;
}
项目:aries-jpa    文件:JPAWeavingHook.java   
@SuppressWarnings("unchecked")
private synchronized Collection<ClassTransformer> getTransformers(Bundle bundle) {
    LinkedHashSet<ClassTransformer> transformers = registeredTransformers.get(bundle);
    return (Collection<ClassTransformer>)(transformers != null ? new ArrayList<ClassTransformer>(transformers) : Collections.emptyList());
}
项目:aries-jpa    文件:PersistenceUnitProxyWithTargetServer.java   
@Override
public void addTransformer(ClassTransformer arg0) {
    delegate.addTransformer(arg0);
}
项目:lams    文件:MutablePersistenceUnitInfo.java   
/**
 * This implementation throws an UnsupportedOperationException.
 */
@Override
public void addTransformer(ClassTransformer classTransformer) {
    throw new UnsupportedOperationException("addTransformer not supported");
}
项目:lams    文件:ClassFileTransformerAdapter.java   
public ClassFileTransformerAdapter(ClassTransformer classTransformer) {
    Assert.notNull(classTransformer, "ClassTransformer must not be null");
    this.classTransformer = classTransformer;
}
项目:vertx-jpa    文件:DefaultPersistenceUnitInfoImpl.java   
/**
 * This implementation throws an UnsupportedOperationException.
 */
@Override
public void addTransformer(ClassTransformer classTransformer) {
  throw new UnsupportedOperationException("addTransformer not supported");
}
项目:jspare-vertx-ms-blueprint    文件:DefaultPersistenceUnitInfoImpl.java   
/**
 * This implementation throws an UnsupportedOperationException.
 */
@Override
public void addTransformer(ClassTransformer classTransformer) {
    throw new UnsupportedOperationException("addTransformer not supported");
}
项目:spring4-understanding    文件:MutablePersistenceUnitInfo.java   
/**
 * This implementation throws an UnsupportedOperationException.
 */
@Override
public void addTransformer(ClassTransformer classTransformer) {
    throw new UnsupportedOperationException("addTransformer not supported");
}
项目:spring4-understanding    文件:ClassFileTransformerAdapter.java   
public ClassFileTransformerAdapter(ClassTransformer classTransformer) {
    Assert.notNull(classTransformer, "ClassTransformer must not be null");
    this.classTransformer = classTransformer;
}
项目:carbon    文件:DefaultPersistenceUnitInfo.java   
@Override
public void addTransformer(ClassTransformer transformer) {
}
项目:jspare-container    文件:DefaultPersistenceUnitInfoImpl.java   
/**
 * This implementation throws an UnsupportedOperationException.
 */
@Override
public void addTransformer(ClassTransformer classTransformer) {
  throw new UnsupportedOperationException("addTransformer not supported");
}
项目:cibet    文件:DefaultPersistenceUnitInfo.java   
public void addTransformer(ClassTransformer transformer) {
   classTransformers.add(transformer);
}
项目:cibet    文件:DelegatingPersistenceUnitInfo.java   
public void addTransformer(ClassTransformer transformer) {
    delegate.addTransformer(transformer);
}
项目:jpasecurity    文件:DelegatingPersistenceUnitInfo.java   
public void addTransformer(ClassTransformer transformer) {
    delegate.addTransformer(transformer);
}
项目:jspare-vertx-ms-blueprint    文件:DefaultPersistenceUnitInfoImpl.java   
/**
 * This implementation throws an UnsupportedOperationException.
 */
@Override
public void addTransformer(ClassTransformer classTransformer) {
    throw new UnsupportedOperationException("addTransformer not supported");
}
项目:dropwizard-entitymanager    文件:PersistenceUnitInfoImpl.java   
@Override
public void addTransformer(ClassTransformer transformer) {
    logger.warn("Dropwizard EntityManager does not support JPA class transformation.  " +
            "The " + transformer.getClass().getName() + " class transformer will be ignored.");
}
项目:dropwizard-entitymanager    文件:PersistenceUnitInfoImplTest.java   
@Test
public void testAddingClassTransformerGeneratesWarning() {
    ClassTransformer classTransformer = mock(ClassTransformer.class);
    persistenceUnitInfo.addTransformer(classTransformer);
    verify(logger).warn(contains("does not support"));
}
项目:osgi.ee    文件:PersistenceUnitInfoImpl.java   
@Override
public void addTransformer(ClassTransformer transformer) {
    System.out.println("WARNING: bytecode weaving using " + 
            transformer.getClass().getName() + " not performed for unit " + definition.name);
}
项目:class-guard    文件:MutablePersistenceUnitInfo.java   
/**
 * This implementation throws an UnsupportedOperationException.
 */
public void addTransformer(ClassTransformer classTransformer) {
    throw new UnsupportedOperationException("addTransformer not supported");
}
项目:class-guard    文件:ClassFileTransformerAdapter.java   
public ClassFileTransformerAdapter(ClassTransformer classTransformer) {
    Assert.notNull(classTransformer, "ClassTransformer must not be null");
    this.classTransformer = classTransformer;
}
项目:minnal    文件:MinnalPersistenceUnitInfo.java   
public void addTransformer(ClassTransformer transformer) {
    logger.info("Add transformer called on the persistent unit info. Ignoring");
    // TODO Support adding transformers.
    // Ignore this for now
}
项目:bundles    文件:TransformersHook.java   
boolean unregister(Bundle b, ClassTransformer ctf) {
    System.out.println("unregister transformer " + ctf + " on bundle " + b);
    synchronized (transformers) {
        return transformers.remove(b, ctf);
    }
}