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


Java BundleReference类代码示例

本文整理汇总了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()));
    }
}
 
开发者ID:wso2,项目名称:carbon-jndi,代码行数:28,代码来源:DefaultContextFactory.java

示例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;
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:22,代码来源:OSGICDISupport.java

示例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
    }
}
 
开发者ID:javabits,项目名称:yar,代码行数:20,代码来源:BundleTypeCleaner.java

示例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;
}
 
开发者ID:buschmais,项目名称:extended-objects,代码行数:18,代码来源:OSGiUtil.java

示例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) {
        }
    }
}
 
开发者ID:kiegroup,项目名称:kie-wb-common,代码行数:21,代码来源:Bpmn2JsonUnmarshaller.java

示例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;
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:22,代码来源:BundleContextSelector.java

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

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

示例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;
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:18,代码来源:GrammarHelper.java

示例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;
}
 
开发者ID:cloudsoft,项目名称:brooklyn-tosca,代码行数:11,代码来源:OsgiAwarePathMatchingResourcePatternResolver.java

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

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

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

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

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


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