本文整理匯總了Java中org.osgi.framework.Filter類的典型用法代碼示例。如果您正苦於以下問題:Java Filter類的具體用法?Java Filter怎麽用?Java Filter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Filter類屬於org.osgi.framework包,在下文中一共展示了Filter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createFilter
import org.osgi.framework.Filter; //導入依賴的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: createFilter
import org.osgi.framework.Filter; //導入依賴的package包/類
protected static Filter createFilter ( final String operand, final Filter... filters ) throws InvalidSyntaxException
{
final StringBuilder sb = new StringBuilder ();
sb.append ( "(" );
sb.append ( operand );
for ( final Filter filter : filters )
{
sb.append ( filter.toString () );
}
sb.append ( ")" );
return FrameworkUtil.createFilter ( sb.toString () );
}
示例3: createFilter
import org.osgi.framework.Filter; //導入依賴的package包/類
protected Filter createFilter ()
{
try
{
Class<?> filterClazz;
if ( this.clazz != null )
{
filterClazz = this.clazz;
}
else
{
filterClazz = ConnectionService.class;
}
return FilterUtil.createAndFilter ( filterClazz.getName (), createFilterParameters () );
}
catch ( final InvalidSyntaxException e )
{
logger.warn ( "Failed to create filter", e );
return null;
}
}
示例4: EventServiceImpl
import org.osgi.framework.Filter; //導入依賴的package包/類
public EventServiceImpl ( final BundleContext context ) throws InvalidSyntaxException
{
this.context = context;
this.storeListener = new StoreListener () {
@Override
public void notify ( final Event event )
{
EventServiceImpl.this.eventStored ( event );
}
};
final Filter filter = FilterUtil.createClassFilter ( Storage.class.getName () );
this.storageTracker = new SingleServiceTracker<Storage> ( this.context, filter, new SingleServiceListener<Storage> () {
@Override
public void serviceChange ( final ServiceReference<Storage> reference, final Storage service )
{
setStorage ( service );
}
} );
this.storageTracker.open ();
}
示例5: before
import org.osgi.framework.Filter; //導入依賴的package包/類
@Before
public void before() throws Exception {
assertAllBundlesResolved();
// Track ArtifactInstaller service ONLY from bundle org.osc.installer
Bundle installerBundle = findBundle("osc-installer");
Filter artifactInstallerTrackerFilter = FrameworkUtil.createFilter(String.format("(&(objectClass=%s)(service.bundleid=%d))", ArtifactInstaller.class.getName(), installerBundle.getBundleId()));
this.artifactInstallerTracker = new ServiceTracker<>(this.bundleContext, artifactInstallerTrackerFilter, null);
this.artifactInstallerTracker.open();
// Wait up to 5 seconds for ArtifactInstaller to appear
ArtifactInstaller artifactInstaller = this.artifactInstallerTracker.waitForService(5000);
if (artifactInstaller == null) {
fail("ArtifactInstaller service not available within 5 seconds");
}
this.fwkInstallerTracker = new ServiceTracker<>(this.bundleContext, FrameworkInstaller.class, null);
this.fwkInstallerTracker.open();
}
示例6: sendInitialBootstrappingEvents
import org.osgi.framework.Filter; //導入依賴的package包/類
private void sendInitialBootstrappingEvents(Set<MandatoryServiceDependency> deps) {
// send the fine grained event
List<OsgiServiceDependencyEvent> events = getUnsatisfiedDependenciesAsEvents(deps);
for (OsgiServiceDependencyEvent nestedEvent : events) {
BootstrappingDependencyEvent dependencyEvent =
new BootstrappingDependencyEvent(context, context.getBundle(), nestedEvent);
publishEvent(dependencyEvent);
}
// followed by the composite one
String filterAsString = createDependencyFilter(deps);
Filter filter = (filterAsString != null ? OsgiFilterUtils.createFilter(filterAsString) : null);
BootstrappingDependenciesEvent event =
new BootstrappingDependenciesEvent(context, context.getBundle(), events, filter, waitTime);
publishEvent(event);
}
示例7: BootstrappingDependenciesEvent
import org.osgi.framework.Filter; //導入依賴的package包/類
/**
* Constructs a new <code>BootstrappingDependencyEvent</code> instance.
*
* @param source
*/
public BootstrappingDependenciesEvent(ApplicationContext source, Bundle bundle,
Collection<OsgiServiceDependencyEvent> nestedEvents, Filter filter, long timeLeft) {
super(source, bundle);
Assert.notNull(nestedEvents);
this.dependencyEvents = nestedEvents;
this.dependenciesFilter = filter;
this.timeLeft = timeLeft;
List<String> depFilters = new ArrayList<String>(dependencyEvents.size());
for (OsgiServiceDependencyEvent dependency : nestedEvents) {
depFilters.add(dependency.getServiceDependency().getServiceFilter().toString());
}
dependencyFilters = Collections.unmodifiableCollection(depFilters);
}
示例8: DefaultOsgiServiceDependency
import org.osgi.framework.Filter; //導入依賴的package包/類
/**
* Constructs a new <code>DefaultOsgiServiceDependency</code> instance.
*
* @param beanName dependency bean name (can be null)
* @param filter dependency OSGi filter (can be null)
* @param mandatoryService flag indicating whether the dependency is
* mandatory or not
*/
public DefaultOsgiServiceDependency(String beanName, Filter filter, boolean mandatoryService) {
this.beanName = beanName;
this.filter = filter;
this.mandatoryService = mandatoryService;
// calculate internal fields
toString = "DependencyService[Name=" + (beanName != null ? beanName : "null") + "][Filter=" + filter
+ "][Mandatory=" + mandatoryService + "]";
int result = 17;
result = 37 * result + DefaultOsgiServiceDependency.class.hashCode();
result = 37 * result + (filter == null ? 0 : filter.hashCode());
result = 37 * result + (beanName == null ? 0 : beanName.hashCode());
result = 37 * result + (mandatoryService ? 0 : 1);
hashCode = result;
}
示例9: activate
import org.osgi.framework.Filter; //導入依賴的package包/類
/**
* OSGi component lifecycle listener for actication and modification of this
* service.
*
* @param componentContext
* OSGi component context.
* @param properties
* OSGi configuration properties.
* @throws Exception
* is thrown if the activation or modification of the service
* goes wrong.
*/
@Activate
@Modified
protected void activate(ComponentContext componentContext, Map<String, Object> properties) throws Exception {
// Check if a service tracker for the context path exists and close it.
if (_serviceTracker != null) {
_serviceTracker.close();
}
// Create a filter for ServletContext components and start tracking.
Filter filter = FrameworkUtil
.createFilter("(&(objectClass=" + ServletContext.class.getName() + ")(osgi.web.contextpath=*))");
_serviceTracker = new ServiceTracker<>(componentContext.getBundleContext(), filter, this);
_serviceTracker.open();
}
示例10: testNotifyListener
import org.osgi.framework.Filter; //導入依賴的package包/類
@Test
public void testNotifyListener() throws InvalidSyntaxException {
EndpointDescription endpoint1 = createEndpoint("myClass");
EndpointDescription endpoint2 = createEndpoint("notMyClass");
// Expect listener to be called for endpoint1 but not for endpoint2
EndpointListener epl = listenerExpects(endpoint1, "(objectClass=myClass)");
EndpointRepository exportRepository = new EndpointRepository();
EndpointListenerNotifier tm = new EndpointListenerNotifier(exportRepository);
EasyMock.replay(epl);
Set<Filter> filters = new HashSet<Filter>();
filters.add(FrameworkUtil.createFilter("(objectClass=myClass)"));
tm.add(epl, filters);
tm.endpointAdded(endpoint1, null);
tm.endpointAdded(endpoint2, null);
tm.endpointRemoved(endpoint1, null);
tm.endpointRemoved(endpoint2, null);
EasyMock.verify(epl);
}
示例11: testNotifyListeners
import org.osgi.framework.Filter; //導入依賴的package包/類
@Test
public void testNotifyListeners() throws InvalidSyntaxException {
EndpointDescription endpoint1 = createEndpoint("myClass");
EndpointListener epl = EasyMock.createStrictMock(EndpointListener.class);
epl.endpointAdded(EasyMock.eq(endpoint1), EasyMock.eq("(objectClass=myClass)"));
EasyMock.expectLastCall().once();
epl.endpointRemoved(EasyMock.eq(endpoint1), EasyMock.eq("(objectClass=myClass)"));
EasyMock.expectLastCall().once();
EndpointRepository exportRepository = new EndpointRepository();
EndpointListenerNotifier tm = new EndpointListenerNotifier(exportRepository);
EasyMock.replay(epl);
Set<Filter> filters = new HashSet<Filter>();
filters.add(FrameworkUtil.createFilter("(objectClass=myClass)"));
tm.add(epl, filters);
tm.endpointAdded(endpoint1, null);
tm.endpointRemoved(endpoint1, null);
tm.remove(epl);
EasyMock.verify(epl);
}
示例12: test
import org.osgi.framework.Filter; //導入依賴的package包/類
@Override
public boolean test(CachingServiceReference<T> ref) {
String target = (String)ref.getProperty(JAX_RS_WHITEBOARD_TARGET);
if (target == null) {
return true;
}
Filter filter;
try {
filter = FrameworkUtil.createFilter(target);
}
catch (InvalidSyntaxException ise) {
if (_log.isErrorEnabled()) {
_log.error("Invalid '{}' filter syntax in {}", JAX_RS_WHITEBOARD_TARGET, ref);
}
return false;
}
return filter.match(_serviceRuntimeReference);
}
示例13: findServices
import org.osgi.framework.Filter; //導入依賴的package包/類
public Collection<RegistryServiceReference> findServices(String clazz, String filter) {
ArrayList<RegistryServiceReference> refs = new ArrayList<RegistryServiceReference>();
try {
Filter f = filter == null ? null : ctx.createFilter(filter);
for ( RegistryServiceReference ref : references.values() ) {
if ( clazz == null || clazz.equals( ref.getInterface() ) ) {
if ( f == null || f.match( new Hashtable(ref.getProperties()) ) ) {
refs.add( ref );
}
}
}
} catch (InvalidSyntaxException e) {
throw new IllegalStateException(e);
}
return refs;
}
示例14: getServiceReferences
import org.osgi.framework.Filter; //導入依賴的package包/類
public ServiceReference[] getServiceReferences(String str, String str2) throws InvalidSyntaxException {
Collection collection;
checkValid();
Filter fromString = RFC1960Filter.fromString(str2);
if (str == null) {
collection = Framework.services;
} else {
List list = (List) Framework.classes_services.get(str);
if (list == null) {
return null;
}
}
List arrayList = new ArrayList();
ServiceReferenceImpl[] serviceReferenceImplArr = (ServiceReferenceImpl[]) collection.toArray(new ServiceReferenceImpl[collection.size()]);
for (int i = 0; i < serviceReferenceImplArr.length; i++) {
if (fromString.match(serviceReferenceImplArr[i])) {
arrayList.add(serviceReferenceImplArr[i]);
}
}
if (Framework.DEBUG_SERVICES && log.isInfoEnabled()) {
log.info("Framework: REQUESTED SERVICES " + str + " " + str2);
log.info("\tRETURNED " + arrayList);
}
return arrayList.size() == 0 ? null : (ServiceReference[]) arrayList.toArray(new ServiceReference[arrayList.size()]);
}
示例15: equals
import org.osgi.framework.Filter; //導入依賴的package包/類
public boolean equals(Object obj) {
if (!(obj instanceof RFC1960Filter)) {
return false;
}
RFC1960Filter rFC1960Filter = (RFC1960Filter) obj;
if (this.operands.size() != rFC1960Filter.operands.size()) {
return false;
}
Filter[] filterArr = (Filter[]) this.operands.toArray(new Filter[this.operands.size()]);
Filter[] filterArr2 = (Filter[]) rFC1960Filter.operands.toArray(new Filter[this.operands.size()]);
for (int i = EQUALS; i < filterArr.length; i += PRESENT) {
if (!filterArr[i].equals(filterArr2[i])) {
return false;
}
}
return true;
}