本文整理匯總了Java中org.osgi.framework.BundleContext.createFilter方法的典型用法代碼示例。如果您正苦於以下問題:Java BundleContext.createFilter方法的具體用法?Java BundleContext.createFilter怎麽用?Java BundleContext.createFilter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.osgi.framework.BundleContext
的用法示例。
在下文中一共展示了BundleContext.createFilter方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createFilter
import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
private static Filter createFilter(BundleContext context, PersistenceUnit punit) {
String filter;
if (punit.getPersistenceProviderClassName() != null) {
filter = String.format("(&(objectClass=%s)(%s=%s))",
PersistenceProvider.class.getName(),
JAVAX_PERSISTENCE_PROVIDER,
punit.getPersistenceProviderClassName());
} else {
filter = String.format("(objectClass=%s)", PersistenceProvider.class.getName());
}
try {
return context.createFilter(filter);
} catch (InvalidSyntaxException e) {
throw new IllegalArgumentException(e);
}
}
示例2: start
import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
@Override
public void start(BundleContext context) throws Exception {
String filterString = String.format("(|(objectClass=%s)(objectClass=%s))", RandomNumberGenerator.class.getName(), RandomStringGenerator.class.getName());
serviceTracker = new ServiceTracker<>(context, context.createFilter(filterString), new ServiceTrackerCustomizer<Object, Object>() {
@Override
public Object addingService(ServiceReference<Object> reference) {
setServiceReference(reference);
consumeServicesIfPresent(context, randomNumberGeneratorServiceReference, randomStringGeneratorServiceReference);
return context.getService(reference);
}
@Override
public void modifiedService(ServiceReference<Object> reference, Object service) {
}
@Override
public void removedService(ServiceReference<Object> reference, Object service) {
unsetServiceReference(reference);
}
});
serviceTracker.open();
ServiceReference<Object>[] serviceReferences = serviceTracker.getServiceReferences();
if (serviceReferences != null) {
Arrays.stream(serviceReferences).forEach(this::setServiceReference);
} else {
log.info("serviceReferences is null");
}
consumeServicesIfPresent(context, randomNumberGeneratorServiceReference, randomStringGeneratorServiceReference);
}
示例3: createFilter
import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
static Filter createFilter(BundleContext context, String driverClass, String puName) {
if (driverClass == null) {
throw new IllegalArgumentException("No javax.persistence.jdbc.driver supplied in persistence.xml");
}
String filter = String.format("(&(objectClass=%s)(%s=%s))",
DataSourceFactory.class.getName(),
DataSourceFactory.OSGI_JDBC_DRIVER_CLASS,
driverClass);
LOGGER.info("Tracking DataSourceFactory for punit " + puName + " with filter " + filter);
try {
return context.createFilter(filter);
} catch (InvalidSyntaxException e) {
throw new IllegalArgumentException(e);
}
}
示例4: createFilter
import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
static Filter createFilter(BundleContext context, String dsName, String puName) {
if (dsName == null) {
throw new IllegalArgumentException("No DataSource supplied in persistence.xml");
}
String subFilter = getSubFilter(dsName);
String filter = String.format("(&(objectClass=%s)%s)",
DataSource.class.getName(),
subFilter);
LOGGER.info("Tracking DataSource for punit " + puName + " with filter " + filter);
try {
return context.createFilter(filter);
} catch (InvalidSyntaxException e) {
throw new IllegalArgumentException(e);
}
}
示例5: create
import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
/**
* Creates an instance.
*
* @param serviceInterface
* the service interface
* @param context
* the BundleContext
* @param filter
* the OSGi service filter
* @return new WaitingServiceTracker instance
*/
public static <T> WaitingServiceTracker<T> create(@Nonnull final Class<T> serviceInterface,
@Nonnull final BundleContext context, @Nonnull final String filter) {
String newFilter = String.format("(&(%s=%s)%s)", Constants.OBJECTCLASS, serviceInterface.getName(), filter);
try {
ServiceTracker<T, ?> tracker = new ServiceTracker<>(context, context.createFilter(newFilter), null);
tracker.open();
return new WaitingServiceTracker<>(serviceInterface, tracker);
} catch (final InvalidSyntaxException e) {
throw new IllegalArgumentException(String.format("Invalid OSGi filter %s", newFilter), e);
}
}
示例6: DataSourceFactoryTracker
import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
public DataSourceFactoryTracker ( final BundleContext context, final String driver, final SingleServiceListener<DataSourceFactory> listener ) throws InvalidSyntaxException
{
super ( context, context.createFilter ( "(&(objectClass=" + DataSourceFactory.class.getName () + ")(" + DataSourceFactory.OSGI_JDBC_DRIVER_CLASS + "=" + driver + "))" ), listener );
this.driver = driver;
}