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


Java ServiceReference.getBundle方法代码示例

本文整理汇总了Java中org.osgi.framework.ServiceReference.getBundle方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceReference.getBundle方法的具体用法?Java ServiceReference.getBundle怎么用?Java ServiceReference.getBundle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.osgi.framework.ServiceReference的用法示例。


在下文中一共展示了ServiceReference.getBundle方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addingService

import org.osgi.framework.ServiceReference; //导入方法依赖的package包/类
@Override
public StoredPerProvider addingService(ServiceReference<PersistenceProvider> reference) {
    String providerName = (String)reference.getProperty(JAVAX_PERSISTENCE_PROVIDER);
    // FIXME should be set when creating the EMF was successful
    if (punit.getPersistenceProviderClassName() == null) {
        punit.setProviderClassName(providerName);
    }
    StoredPerProvider stored = new StoredPerProvider();
    LOGGER.info("Found provider for " + punit.getPersistenceUnitName() + " " + punit.getPersistenceProviderClassName());
    
    PersistenceProvider provider = context.getService(reference);

    createAndCloseDummyEMF(provider);

    stored.builder = new AriesEntityManagerFactoryBuilder(context, provider, reference.getBundle(), punit);
    Dictionary<String, ?> props = AriesEntityManagerFactoryBuilder.createBuilderProperties(punit, punit.getBundle());
    stored.reg = context.registerService(EntityManagerFactoryBuilder.class, stored.builder , props);
    return stored;
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:20,代码来源:PersistenceProviderTracker.java

示例2: WrappingTransformer

import org.osgi.framework.ServiceReference; //导入方法依赖的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

示例3: convert

import org.osgi.framework.ServiceReference; //导入方法依赖的package包/类
@Override
public Object convert(ServiceReference obj) {
    final Bundle bundle = obj.getBundle();
    if (bundle != null) {
        return bundle.getBundleContext().getService(obj);
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:NetigsoServices.java

示例4: type

import org.osgi.framework.ServiceReference; //导入方法依赖的package包/类
@Override
public Class<? extends Object> type(ServiceReference obj) {
    String[] arr = (String[])obj.getProperty(Constants.OBJECTCLASS);
    if (arr.length > 0) {
        final Bundle bundle = obj.getBundle();
        if (bundle != null) try {
            return (Class<?>)bundle.loadClass(arr[0]);
        } catch (ClassNotFoundException ex) {
            Netigso.LOG.log(Level.INFO, "Cannot load service class", arr[0]); // NOI18N
        }
    }
    return Object.class;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:NetigsoServices.java

示例5: createServiceProviderTCCLAdvice

import org.osgi.framework.ServiceReference; //导入方法依赖的package包/类
Advice createServiceProviderTCCLAdvice(ServiceReference reference) {
	Bundle bundle = reference.getBundle();
	// if reference is dead already, it's impossible to provide the service
	// class loader
	if (bundle == null)
		return null;

	return new ServiceTCCLInterceptor(ClassLoaderFactory.getBundleClassLoaderFor(bundle));
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:10,代码来源:StaticServiceProxyCreator.java

示例6: nullSafeToString

import org.osgi.framework.ServiceReference; //导入方法依赖的package包/类
/**
 * Returns a String representation of the given <code>ServiceReference</code>.
 * 
 * @param reference OSGi service reference (can be <code>null</code>)
 * @return String representation of the given service reference
 */
public static String nullSafeToString(ServiceReference reference) {
	if (reference == null)
		return NULL_STRING;

	StringBuilder buf = new StringBuilder();
	Bundle owningBundle = reference.getBundle();

	buf.append("ServiceReference [").append(OsgiStringUtils.nullSafeSymbolicName(owningBundle)).append("] ");
	String clazzes[] = (String[]) reference.getProperty(org.osgi.framework.Constants.OBJECTCLASS);

	buf.append(ObjectUtils.nullSafeToString(clazzes));
	buf.append("={");

	String[] keys = reference.getPropertyKeys();

	for (int i = 0; i < keys.length; i++) {
		if (!org.osgi.framework.Constants.OBJECTCLASS.equals(keys[i])) {
			buf.append(keys[i]).append('=').append(reference.getProperty(keys[i]));
			if (i < keys.length - 1) {
				buf.append(',');
			}
		}
	}

	buf.append('}');

	return buf.toString();
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:35,代码来源:OsgiStringUtils.java

示例7: findBundleWithHighestUsedServiceId

import org.osgi.framework.ServiceReference; //导入方法依赖的package包/类
@Nullable
private Bundle findBundleWithHighestUsedServiceId(final Collection<Bundle> containerBundles) {
    ServiceReference<?> highestServiceRef = null;
    for (Bundle bundle : containerBundles) {
        ServiceReference<?>[] references = bundle.getRegisteredServices();
        if (references == null) {
            continue;
        }

        for (ServiceReference<?> reference : references) {
            // We did check the service usage previously but it's possible the usage has changed since then.
            if (getServiceUsage(reference) == 0) {
                continue;
            }

            // Choose 'reference' if it has a lower service ranking or, if the rankings are equal
            // which is usually the case, if it has a higher service ID. For the latter the < 0
            // check looks backwards but that's how ServiceReference#compareTo is documented to work.
            if (highestServiceRef == null || reference.compareTo(highestServiceRef) < 0) {
                LOG.debug("Currently selecting bundle {} for destroy (with reference {})", bundle, reference);
                highestServiceRef = reference;
            }
        }
    }

    return highestServiceRef == null ? null : highestServiceRef.getBundle();
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:28,代码来源:BlueprintBundleTracker.java

示例8: getAllFactories

import org.osgi.framework.ServiceReference; //导入方法依赖的package包/类
@Override
public Map<String, Map.Entry<ModuleFactory, BundleContext>> getAllFactories() {
    Collection<ServiceReference<ModuleFactory>> serviceReferences;
    try {
        serviceReferences = bundleContext.getServiceReferences(ModuleFactory.class, null);
    } catch (final InvalidSyntaxException e) {
        throw new IllegalStateException(e);
    }
    Map<String, Map.Entry<ModuleFactory, BundleContext>> result = new HashMap<>(serviceReferences.size());
    for (ServiceReference<ModuleFactory> serviceReference : serviceReferences) {
        ModuleFactory factory = bundleContext.getService(serviceReference);
        // null if the service is not registered, the service object
        // returned by a ServiceFactory does not
        // implement the classes under which it was registered or the
        // ServiceFactory threw an exception.
        if (factory == null) {
            throw new NullPointerException(
                    "ServiceReference of class" + serviceReference.getClass() + "not found.");
        }

        String moduleName = factory.getImplementationName();
        if (moduleName == null || moduleName.isEmpty()) {
            throw new IllegalStateException("Invalid implementation name for " + factory);
        }
        if (serviceReference.getBundle() == null || serviceReference.getBundle().getBundleContext() == null) {
            throw new NullPointerException("Bundle context of " + factory + " ModuleFactory not found.");
        }
        LOG.debug("Reading factory {} {}", moduleName, factory);

        Map.Entry<ModuleFactory, BundleContext> conflicting = result.get(moduleName);
        if (conflicting != null) {
            String error = String.format(
                    "Module name is not unique. Found two conflicting factories with same name '%s': '%s' '%s'",
                    moduleName, conflicting.getKey(), factory);
            LOG.error(error);
            throw new IllegalArgumentException(error);
        }

        result.put(moduleName,
                new AbstractMap.SimpleImmutableEntry<>(factory, serviceReference.getBundle().getBundleContext()));
    }
    return result;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:44,代码来源:BundleContextBackedModuleFactoriesResolver.java


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