本文整理汇总了Java中javax.persistence.spi.ClassTransformer类的典型用法代码示例。如果您正苦于以下问题:Java ClassTransformer类的具体用法?Java ClassTransformer怎么用?Java ClassTransformer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClassTransformer类属于javax.persistence.spi包,在下文中一共展示了ClassTransformer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: WrappingTransformer
import javax.persistence.spi.ClassTransformer; //导入依赖的package包/类
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);
}
}
}
示例2: weave
import javax.persistence.spi.ClassTransformer; //导入依赖的package包/类
@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");
}
}
示例3: transformClass
import javax.persistence.spi.ClassTransformer; //导入依赖的package包/类
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;
}
示例4: createContainerEntityManagerFactory
import javax.persistence.spi.ClassTransformer; //导入依赖的package包/类
@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);
}
示例5: validate
import javax.persistence.spi.ClassTransformer; //导入依赖的package包/类
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");
}
}
示例6: addTransformer
import javax.persistence.spi.ClassTransformer; //导入依赖的package包/类
@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);
}
示例7: removeTransformer
import javax.persistence.spi.ClassTransformer; //导入依赖的package包/类
@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);
}
}
示例8: addTransformer
import javax.persistence.spi.ClassTransformer; //导入依赖的package包/类
/**
* 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));
}
示例9: weave
import javax.persistence.spi.ClassTransformer; //导入依赖的package包/类
@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);
}
}
示例10: register
import javax.persistence.spi.ClassTransformer; //导入依赖的package包/类
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;
}
}
示例11: weave
import javax.persistence.spi.ClassTransformer; //导入依赖的package包/类
@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();
}
}
示例12: register
import javax.persistence.spi.ClassTransformer; //导入依赖的package包/类
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);
}
}
示例13: addTransformer
import javax.persistence.spi.ClassTransformer; //导入依赖的package包/类
/**
* 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;
}
}
示例14: addTransformer
import javax.persistence.spi.ClassTransformer; //导入依赖的package包/类
@Override
public void addTransformer(ClassTransformer transformer) {
if (isNull(transformers)) {
transformers = new ArrayList<>();
}
transformers.add(transformer);
}
示例15: addTransformer
import javax.persistence.spi.ClassTransformer; //导入依赖的package包/类
@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
}