本文整理汇总了Java中org.osgi.framework.BundleReference类的典型用法代码示例。如果您正苦于以下问题:Java BundleReference类的具体用法?Java BundleReference怎么用?Java BundleReference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BundleReference类属于org.osgi.framework包,在下文中一共展示了BundleReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCallersBundleContext
import org.osgi.framework.BundleReference; //导入依赖的package包/类
/**
* Returns a BundleContext obtained from the given ClassLoader or from an ancestor ClassLoader.
* <p>
* First check whether this ClassLoader implements the BundleReference interface, if so try to get BundleContext.
* If not get from the parent ClassLoader. Repeat these steps until a not-null BundleContext is found or the parent
* ClassLoader becomes null.
*
* @param classLoaderOptional an {@code Optional} describing a ClassLoader
* @return BundleContext extracted from the give ClassLoader or from its ancestors ClassLoaders.
*/
private Optional<BundleContext> getCallersBundleContext(Optional<ClassLoader> classLoaderOptional) {
if (!classLoaderOptional.isPresent()) {
return Optional.empty();
}
Optional<BundleContext> bundleContextOptional = classLoaderOptional
.filter(classLoader -> classLoader instanceof BundleReference)
.map(classLoader -> (BundleReference) classLoader)
.map(bundleReference -> bundleReference.getBundle().getBundleContext());
if (bundleContextOptional.isPresent()) {
return bundleContextOptional;
} else {
return getCallersBundleContext(Optional.ofNullable(classLoaderOptional.get().getParent()));
}
}
示例2: getBeanManager
import org.osgi.framework.BundleReference; //导入依赖的package包/类
/**
* Retrieve the BeanManager from the CdiContainer service.
*/
static BeanManager getBeanManager() throws Exception {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader instanceof BundleReference) {
Bundle bundle = ((BundleReference) classLoader).getBundle();
ServiceReference<?>[] refs = bundle.getBundleContext().getServiceReferences(
"org.ops4j.pax.cdi.spi.CdiContainer", "(bundleId=" + bundle.getBundleId() + ")");
if (refs != null && refs.length == 1) {
Object cdiContainer = bundle.getBundleContext().getService(refs[0]);
try {
Method method = cdiContainer.getClass().getMethod("getBeanManager");
return (BeanManager) method.invoke(cdiContainer);
} finally {
bundle.getBundleContext().ungetService(refs[0]);
}
}
}
return null;
}
示例3: typeChanged
import org.osgi.framework.BundleReference; //导入依赖的package包/类
@Override
public void typeChanged(TypeEvent typeEvent) {
switch (typeEvent.eventType()) {
case ADDED:
Type type = typeEvent.type();
Class<?> rawType = getRawType(type);
ClassLoader classLoader = rawType.getClassLoader();
if (classLoader instanceof BundleReference) {
Bundle bundle = ((BundleReference) classLoader).getBundle();
cache.computeIfAbsent(bundle.getBundleId(), key -> new CopyOnWriteArraySet<>()).add(type);
} else {
LOG.warning(type + "'s class loader is not a BundleReference");
}
break;
case REMOVED:
default:
// nothing to do
}
}
示例4: isXOLoadedAsOSGiBundle
import org.osgi.framework.BundleReference; //导入依赖的package包/类
public static boolean isXOLoadedAsOSGiBundle() {
if (loadedAsBundle == null) {
ClassLoader classLoader = OSGiUtil.class.getClassLoader();
try {
classLoader.loadClass("org.osgi.framework.BundleReference");
} catch (ClassNotFoundException e) {
return false;
}
if (classLoader instanceof BundleReference) {
loadedAsBundle = true;
} else {
loadedAsBundle = false;
}
}
return loadedAsBundle;
}
示例5: Bpmn2JsonUnmarshaller
import org.osgi.framework.BundleReference; //导入依赖的package包/类
public Bpmn2JsonUnmarshaller() {
_helpers = new ArrayList<BpmnMarshallerHelper>();
DroolsPackageImpl.init();
BpsimPackageImpl.init();
// load the helpers to place them in field
if (getClass().getClassLoader() instanceof BundleReference) {
BundleContext context = ((BundleReference) getClass().getClassLoader()).
getBundle().getBundleContext();
try {
ServiceReference[] refs = context.getAllServiceReferences(
BpmnMarshallerHelper.class.getName(),
null);
for (ServiceReference ref : refs) {
BpmnMarshallerHelper helper = (BpmnMarshallerHelper) context.getService(ref);
_helpers.add(helper);
}
} catch (InvalidSyntaxException e) {
}
}
}
示例6: getContext
import org.osgi.framework.BundleReference; //导入依赖的package包/类
@Override
public LoggerContext getContext(final String fqcn, final ClassLoader loader, final boolean currentContext,
final URI configLocation) {
if (currentContext) {
final LoggerContext ctx = ContextAnchor.THREAD_CONTEXT.get();
if (ctx != null) {
return ctx;
}
return getDefault();
}
// it's quite possible that the provided ClassLoader may implement BundleReference which gives us a nice shortcut
if (loader instanceof BundleReference) {
return locateContext(((BundleReference) loader).getBundle(), configLocation);
}
final Class<?> callerClass = StackLocatorUtil.getCallerClass(fqcn);
if (callerClass != null) {
return locateContext(FrameworkUtil.getBundle(callerClass), configLocation);
}
final LoggerContext lc = ContextAnchor.THREAD_CONTEXT.get();
return lc == null ? getDefault() : lc;
}
示例7: probe
import org.osgi.framework.BundleReference; //导入依赖的package包/类
/**
* AgroalDataSource.from( ... ) wont't work due to limitations of ServiceLoader on OSGi environments.
* For this test, and OSGi deployments in general, the datasource implementation is instantiated directly.
*/
public void probe(BundleReference bundleReference) throws SQLException {
probeLogger.info( "In OSGi container running from a Bundle named " + bundleReference.getBundle().getSymbolicName() );
try ( AgroalDataSource dataSource = AgroalDataSource.from( new AgroalDataSourceConfigurationSupplier() ) ) {
try ( Connection connection = dataSource.getConnection() ) {
probeLogger.info( format( "Got connection {0}", connection ) );
}
}
}
示例8: getBundle
import org.osgi.framework.BundleReference; //导入依赖的package包/类
private Bundle getBundle(Class<?> testCaseClass) {
ClassLoader classLoader = testCaseClass.getClassLoader();
if (classLoader instanceof BundleReference) {
return ((BundleReference)classLoader).getBundle();
}
throw new RuntimeException("Test is not running inside BundleContext");
}
示例9: getBundleSymbolicName
import org.osgi.framework.BundleReference; //导入依赖的package包/类
/**
* Gets the bundle symbolic name.
*
* @param classe
* the class
* @return the bundle symbolic name
*/
protected String getBundleSymbolicName(final Class<?> classe) {
ClassLoader cl = classe.getClassLoader();
if (cl instanceof BundleReference) {
Bundle bundle = ((BundleReference) cl).getBundle();
if (bundle != null) {
return bundle.getSymbolicName();
}
}
return null;
}
示例10: getBundle
import org.osgi.framework.BundleReference; //导入依赖的package包/类
private Bundle getBundle() {
Bundle bundle = FrameworkUtil.getBundle(getClass());
if (bundle==null) {
// it wrong jar is included, it may take the wrong bundle classloader
LOG.warn("Cannot find bundle for "+this+", loader "+getClass().getClassLoader()+" of type "+getClass().getClassLoader().getClass()+"; is bundle reference? "+(getClass().getClassLoader() instanceof BundleReference));
LOG.info("Classloaders are: "+getClass().getClassLoader().getClass().getClassLoader()+" / "+BundleReference.class.getClassLoader());
// throw new IllegalStateException("Cannot find bundle for "+this+", loader "+getClass().getClassLoader()+" of type "+getClass().getClassLoader().getClass());
}
return bundle;
}
示例11: isFromBundle
import org.osgi.framework.BundleReference; //导入依赖的package包/类
private static boolean isFromBundle(Class<?> clazz) {
if(clazz == null)
return false;
if(!(clazz.getClassLoader() instanceof BundleReference))
return false;
BundleReference br = (BundleReference)clazz.getClassLoader();
return !OSGiUtil.isFrameworkBundle(br.getBundle());
}
示例12: createContainerEntityManagerFactory
import org.osgi.framework.BundleReference; //导入依赖的package包/类
@Override
public synchronized EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map props) {
Bundle bundle = ((BundleReference) info.getClassLoader()).getBundle();
synchronized (bundles) {
bundles.add(bundle);
}
return provider.createContainerEntityManagerFactory(info, props);
}
示例13: getImports
import org.osgi.framework.BundleReference; //导入依赖的package包/类
private List<String> getImports() throws IOException {
Bundle bundle;
if (persistenceProvider instanceof BundleReference) {
bundle = ((BundleReference) persistenceProvider).getBundle();
} else {
bundle = FrameworkUtil.getBundle(persistenceProvider.getClass());
}
if (bundle != null) {
// Get the export clauses of the JPA provider.
Clauses clauses = Clauses.parse(bundle.getHeaders().get(Constants.EXPORT_PACKAGE));
if (!clauses.isEmpty()) {
List<String> list = new ArrayList<>();
for (Map.Entry<String, Map<String, String>> e : clauses.entrySet()) {
// Create a new clause
StringBuilder sb = new StringBuilder();
sb.append(e.getKey());
for (Map.Entry<String, String> ee : e.getValue().entrySet()) {
if (ee.getKey().endsWith(":")) {
continue;
}
sb.append(";").append(ee.getKey()).append("=");
String v = ee.getValue();
if (WORD.matcher(v).matches()) {
sb.append(ee.getValue());
} else {
sb.append("\"").append(ee.getValue()).append("\"");
}
}
list.add(sb.toString());
}
// To retrieve the transaction manager.
list.add("org.wisdom.framework.jpa.accessor");
return list;
}
}
return Collections.emptyList();
}
示例14: getSymbolicName
import org.osgi.framework.BundleReference; //导入依赖的package包/类
protected String getSymbolicName( ClassLoader classLoader ) {
if ( classLoader instanceof BundleReference ) {
Bundle bundle = BundleReference.class.cast( classLoader ).getBundle();
return bundle.getSymbolicName();
} else {
return null;
}
}
示例15: ModuleAdaptor
import org.osgi.framework.BundleReference; //导入依赖的package包/类
ModuleAdaptor(OSGiRuntime runtime, ClassLoader classLoader, Resource resource, Dictionary<String, String> headers) {
super(runtime, classLoader, resource, headers);
if (classLoader instanceof BundleReference) {
bundle = ((BundleReference) classLoader).getBundle();
} else {
bundle = runtime.getSystemContext().getBundle();
}
}