當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。