当前位置: 首页>>代码示例>>Java>>正文


Java ClassTransformer类代码示例

本文整理汇总了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);
        }
    }
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:21,代码来源:WrappingTransformer.java

示例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");
    }
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:18,代码来源:JPAWeavingHook.java

示例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;
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:24,代码来源:JPAWeavingHook.java

示例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);
}
 
开发者ID:osgi,项目名称:bundles,代码行数:19,代码来源:DatanucleusWrapper.java

示例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");
    }
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:9,代码来源:WrappingTransformer.java

示例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);
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:11,代码来源:JPAWeavingHook.java

示例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);
    }
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:11,代码来源:JPAWeavingHook.java

示例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));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:SpringPersistenceUnitInfo.java

示例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);
    }
}
 
开发者ID:wisdom-framework,项目名称:wisdom-jdbc,代码行数:35,代码来源:JPATransformer.java

示例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;
    }
}
 
开发者ID:wisdom-framework,项目名称:wisdom-jdbc,代码行数:16,代码来源:JPATransformer.java

示例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();
	}
}
 
开发者ID:osgi,项目名称:bundles,代码行数:34,代码来源:TransformersHook.java

示例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);
	}
}
 
开发者ID:osgi,项目名称:bundles,代码行数:10,代码来源:TransformersHook.java

示例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;
	}
}
 
开发者ID:osgi,项目名称:bundles,代码行数:17,代码来源:PersistenceUnitInfoImpl.java

示例14: addTransformer

import javax.persistence.spi.ClassTransformer; //导入依赖的package包/类
@Override
public void addTransformer(ClassTransformer transformer) {
    if (isNull(transformers)) {
        transformers = new ArrayList<>();
    }
    transformers.add(transformer);
}
 
开发者ID:gzlabs,项目名称:hightide,代码行数:8,代码来源:HightidePersistenceUnitInfo.java

示例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
}
 
开发者ID:dajudge,项目名称:testee.fi,代码行数:6,代码来源:PersistenceUnitInfoImpl.java


注:本文中的javax.persistence.spi.ClassTransformer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。