org.osgi.framework.Filter Java Examples
The following examples show how to use
org.osgi.framework.Filter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RFC1960Filter.java From AtlasForAndroid with MIT License | 6 votes |
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; }
Example #2
Source File: ReferenceListener.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * */ void serviceEvent(ServiceReference<?> s, ServiceEvent se) { Filter f = getTargetFilter(); boolean match = f == null || f.match(s); if (match && ReferenceDescription.SCOPE_PROTOTYPE_REQUIRED.equals(ref.getScope())) { match = Constants.SCOPE_PROTOTYPE.equals(s.getProperty(Constants.SERVICE_SCOPE)); } int type = se.getType(); if (!match) { if (type != ServiceEvent.UNREGISTERING && serviceRefs.contains(s)) { type = ServiceEvent.MODIFIED_ENDMATCH; } else { return; } } serviceChanged(new RefServiceEvent(type, s, se)); }
Example #3
Source File: ReferenceListener.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Get filter string for finding this reference. */ private String getFilter() { final Filter target = getTargetFilter(); boolean addScope = ReferenceDescription.SCOPE_PROTOTYPE_REQUIRED.equals(ref.getScope()); if (addScope || target != null) { StringBuilder sb = new StringBuilder("(&("); sb.append(Constants.OBJECTCLASS).append('=').append(getInterface()).append(')'); if (addScope) { sb.append('(').append(Constants.SERVICE_SCOPE).append('=').append(Constants.SCOPE_PROTOTYPE).append(')'); } if (target != null) { sb.append(target); } sb.append(')'); return sb.toString(); } else { return "(" + Constants.OBJECTCLASS + "=" + getInterface() +")"; } }
Example #4
Source File: ConverterTracker.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
/** * The Constructor. * @param bundleContext * 插件所在的 bundle context * @param direction * 取<code>Converter.DIRECTION_POSITIVE</code>或 <code>Converter.DIRECTION_REVERSE</code> */ public ConverterTracker(BundleContext bundleContext, String direction) { this.direction = direction; supportTypes = new ArrayList<ConverterBean>(); this.context = bundleContext; String filterStr = new AndFilter(new EqFilter(Constants.OBJECTCLASS, Converter.class.getName()), new EqFilter( Converter.ATTR_DIRECTION, direction)).toString(); Filter filter = null; try { filter = context.createFilter(filterStr); } catch (InvalidSyntaxException e) { // ignore the exception e.printStackTrace(); } if (filter != null) { converterServiceTracker = new ServiceTracker(context, filter, new ConverterCustomizer()); } converterServiceTracker.open(); }
Example #5
Source File: FilterUtil.java From neoscada with Eclipse Public License 1.0 | 6 votes |
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 () ); }
Example #6
Source File: CMCommands.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
private Configuration[] getConfigurationsMatchingFilters(ConfigurationAdmin cm, Filter[] filters) throws Exception { final Configuration[] cs = cm.listConfigurations(null); if (cs == null || cs.length == 0) { return new Configuration[0]; } if (filters == null || filters.length == 0) { return cs; } final List<Configuration> matching = new ArrayList<Configuration>(); for (final Configuration cfg : cs) { for (final Filter filter : filters) { if (filter.match(cfg.getProperties())) { matching.add(cfg); break; } } } return matching.toArray(new Configuration[matching.size()]); }
Example #7
Source File: EndpointPermission.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Internal implies method. Used by the implies and the permission * collection implies methods. * * @param requested The requested EndpointPermission which has already be * validated as a proper argument. The requested EndpointPermission * must not have a filter expression. * @param effective The effective actions with which to start. * @return {@code true} if the specified permission is implied by this * object; {@code false} otherwise. */ boolean implies0(EndpointPermission requested, int effective) { /* check actions first - much faster */ effective |= action_mask; final int desired = requested.action_mask; if ((effective & desired) != desired) { return false; } /* if we have no filter */ Filter f = filter; if (f == null) { // it's "*" return true; } return f.matchCase(requested.getProperties()); }
Example #8
Source File: ConnectionTracker.java From neoscada with Eclipse Public License 1.0 | 6 votes |
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; } }
Example #9
Source File: ResolveContextImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void addToProvidersIfMatching(Resource res, List<Capability> providers, Requirement req) { String f = req.getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE); Filter filter = null; if(f != null) { try { filter = bc.createFilter(f); } catch (InvalidSyntaxException e) { // TODO log filter failure, skip System.err.println("Failed, " + f + ". " + e); return; } } for(Capability c : res.getCapabilities(req.getNamespace())) { if(filter != null && !filter.matches(c.getAttributes())) { continue; } providers.add(c); } }
Example #10
Source File: InjectOsgiServiceTest.java From jackson-modules-base with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Before public void setUp() throws Exception { bundleContext = mock(BundleContext.class); doThrow(new InvalidSyntaxException("", "")).when(bundleContext).createFilter(anyString()); Filter filter = mock(Filter.class); when(filter.toString()).thenReturn(OSGI_FILTER); doReturn(filter).when(bundleContext).createFilter(OSGI_FILTER); when(bundleContext.getServiceReferences(eq(Service.class.getName()), anyString())).thenReturn(new ServiceReference[]{mock(ServiceReference.class)}); when(bundleContext.getService(any(ServiceReference.class))).thenReturn(mock(Service.class)); mapper = JsonMapper.builder() .addModule(new OsgiJacksonModule(bundleContext)) .build(); }
Example #11
Source File: BundleLocationCondition.java From concierge with Eclipse Public License 1.0 | 6 votes |
/** * Constructs a condition that tries to match the passed Bundle's location * to the location pattern. * * @param bundle The Bundle being evaluated. * @param info The ConditionInfo from which to construct the condition. The * ConditionInfo must specify one or two arguments. The first * argument of the ConditionInfo specifies the location pattern * against which to match the bundle location. Matching is done * according to the filter string matching rules. Any '*' characters * in the first argument are used as wildcards when matching bundle * locations unless they are escaped with a '\' character. The * Condition is satisfied if the bundle location matches the pattern. * The second argument of the ConditionInfo is optional. If a second * argument is present and equal to "!", then the satisfaction of the * Condition is negated. That is, the Condition is satisfied if the * bundle location does NOT match the pattern. If the second argument * is present but does not equal "!", then the second argument is * ignored. * @return Condition object for the requested condition. */ static public Condition getCondition(final Bundle bundle, final ConditionInfo info) { if (!CONDITION_TYPE.equals(info.getType())) throw new IllegalArgumentException("ConditionInfo must be of type \"" + CONDITION_TYPE + "\""); String[] args = info.getArgs(); if (args.length != 1 && args.length != 2) throw new IllegalArgumentException("Illegal number of args: " + args.length); String bundleLocation = AccessController.doPrivileged(new PrivilegedAction<String>() { public String run() { return bundle.getLocation(); } }); Filter filter = null; try { filter = FrameworkUtil.createFilter("(location=" + escapeLocation(args[0]) + ")"); } catch (InvalidSyntaxException e) { // this should never happen, but just in case throw new RuntimeException("Invalid filter: " + e.getFilter(), e); } Dictionary<String, String> matchProps = new Hashtable<String, String>(2); matchProps.put("location", bundleLocation); boolean negate = (args.length == 2) ? "!".equals(args[1]) : false; return (negate ^ filter.match(matchProps)) ? Condition.TRUE : Condition.FALSE; }
Example #12
Source File: OSGiServiceCapabilityTracker.java From carbon-kernel with Apache License 2.0 | 6 votes |
/** * Returns and instance of {@link Filter}. * * @param capabilityNameList all the required capability services. * @return LDAP like filter */ private Filter getORFilter(List<String> capabilityNameList) { StringBuilder orFilterBuilder = new StringBuilder(); orFilterBuilder.append("(|"); for (String service : capabilityNameList) { orFilterBuilder.append("(").append(OBJECT_CLASS).append("=").append(service).append(")"); } orFilterBuilder.append(")"); BundleContext bundleContext = DataHolder.getInstance().getBundleContext(); try { return bundleContext.createFilter(orFilterBuilder.toString()); } catch (InvalidSyntaxException e) { throw new StartOrderResolverException("Error occurred while creating the service filter", e); } }
Example #13
Source File: RFC1960Filter.java From concierge with Eclipse Public License 1.0 | 6 votes |
/** * check if the filter equals another object. * * @param obj * the other object. * @return true if the object is an instance of RFC1960Filter and the * filters are equal. * @see java.lang.Object#equals(java.lang.Object) * @category Object */ public boolean equals(final Object obj) { if (obj instanceof RFC1960Filter) { final RFC1960Filter filter = (RFC1960Filter) obj; if (operands.size() != filter.operands.size()) { return false; } final Filter[] operandArray = operands .toArray(new Filter[operands.size()]); final Filter[] operandArray2 = filter.operands .toArray(new Filter[operands.size()]); for (int i = 0; i < operandArray.length; i++) { if (!operandArray[i].equals(operandArray2[i])) { return false; } } return true; } return false; }
Example #14
Source File: BundleLocationCondition.java From concierge with Eclipse Public License 1.0 | 6 votes |
/** * Constructs a condition that tries to match the passed Bundle's location * to the location pattern. * * @param bundle The Bundle being evaluated. * @param info The ConditionInfo from which to construct the condition. The * ConditionInfo must specify one or two arguments. The first * argument of the ConditionInfo specifies the location pattern * against which to match the bundle location. Matching is done * according to the filter string matching rules. Any '*' characters * in the first argument are used as wildcards when matching bundle * locations unless they are escaped with a '\' character. The * Condition is satisfied if the bundle location matches the pattern. * The second argument of the ConditionInfo is optional. If a second * argument is present and equal to "!", then the satisfaction of the * Condition is negated. That is, the Condition is satisfied if the * bundle location does NOT match the pattern. If the second argument * is present but does not equal "!", then the second argument is * ignored. * @return Condition object for the requested condition. */ static public Condition getCondition(final Bundle bundle, final ConditionInfo info) { if (!CONDITION_TYPE.equals(info.getType())) throw new IllegalArgumentException("ConditionInfo must be of type \"" + CONDITION_TYPE + "\""); String[] args = info.getArgs(); if (args.length != 1 && args.length != 2) throw new IllegalArgumentException("Illegal number of args: " + args.length); String bundleLocation = AccessController.doPrivileged(new PrivilegedAction<String>() { public String run() { return bundle.getLocation(); } }); Filter filter = null; try { filter = FrameworkUtil.createFilter("(location=" + escapeLocation(args[0]) + ")"); } catch (InvalidSyntaxException e) { // this should never happen, but just in case throw new RuntimeException("Invalid filter: " + e.getFilter(), e); } Dictionary<String, String> matchProps = new Hashtable<String, String>(2); matchProps.put("location", bundleLocation); boolean negate = (args.length == 2) ? "!".equals(args[1]) : false; return (negate ^ filter.match(matchProps)) ? Condition.TRUE : Condition.FALSE; }
Example #15
Source File: Subscription.java From concierge with Eclipse Public License 1.0 | 6 votes |
/** * creates a new EventHandlerSubscription instance. * * @param handler * an <code>EventHandler</code> that wants to subscribe. * @param topics * an array of strings representing the topics. * @param filter * a <code>Filter</code> for matching event properties. */ Subscription(final EventHandler eventHandler, final String[] topics, final Filter filter) { // security check if (EventAdminImpl.security != null) { ArrayList checkedTopics = new ArrayList(topics.length); for (int i = 0; i < topics.length; i++) { try { EventAdminImpl.security .checkPermission(new TopicPermission(topics[i], TopicPermission.SUBSCRIBE)); checkedTopics.add(topics[i]); } catch (SecurityException se) { System.err .println("Bundle does not have permission for subscribing to " + topics[i]); } } this.topics = (String[]) checkedTopics .toArray(new String[checkedTopics.size()]); } else { this.topics = topics; } this.handler = eventHandler; this.filter = filter; }
Example #16
Source File: FuchsiaUtilsTest.java From fuchsia with Apache License 2.0 | 6 votes |
@Test public void testGetFilterFromString() { Filter f = null; try { f = FuchsiaUtils.getFilter("(!(key=value))"); } catch (InvalidFilterException e) { fail("GetFilter thrown an exception on a valid String filter", e); } assertThat(f).isNotNull().isInstanceOf(Filter.class); Map<String, Object> map = new HashMap<String, Object>(); map.put("key", "value"); assertThat(f.matches(map)).isFalse(); map.clear(); map.put("key", "not-value"); assertThat(f.matches(map)).isTrue(); map.clear(); map.put("not-key", "value"); assertThat(f.matches(map)).isTrue(); }
Example #17
Source File: ImportPkg.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Create an import package entry. */ ImportPkg(ExportPkg p) { this.name = p.name; this.bpkgs = p.bpkgs; this.resolution = Constants.RESOLUTION_MANDATORY; this.bundleSymbolicName = null; if (p.version == Version.emptyVersion) { this.packageRange = null; } else { this.packageRange = new VersionRange(p.version.toString()); } this.bundleRange = null; this.attributes = p.attributes; // TODO, should we import unknown directives? final Map<String,String> dirs = new HashMap<String, String>(); final Filter filter = toFilter(); if (null!=filter) { dirs.put(Constants.FILTER_DIRECTIVE, filter.toString()); } this.directives = Collections.unmodifiableMap(dirs); this.parent = null; }
Example #18
Source File: DevicePermission.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static Filter parseFilter(String filter) { if ((1 == filter.length()) && ("*".equals(filter))) { return null; } try { return FrameworkUtil.createFilter(filter); } catch (InvalidSyntaxException ise) { IllegalArgumentException iae = new IllegalArgumentException("The filter is invalid: " + filter); iae.initCause(ise); throw iae; } }
Example #19
Source File: SubsystemPermission.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Internal implies method. Used by the implies and the permission * collection implies methods. * * @param requested The requested SubsystemPermision which has already been * validated as a proper argument. The requested SubsystemPermission * must not have a filter expression. * @param effective The effective actions with which to start. * @return {@code true} if the specified permission is implied by this * object; {@code false} otherwise. */ boolean implies0(SubsystemPermission requested, int effective) { /* check actions first - much faster */ effective |= action_mask; final int desired = requested.action_mask; if ((effective & desired) != desired) { return false; } /* Get our filter */ Filter f = filter; if (f == null) { // it's "*" return true; } /* is requested a wildcard filter? */ if (requested.subsystem == null) { return false; } Map<String, Object> requestedProperties = requested.getProperties(); if (requestedProperties == null) { /* * If the requested properties are null, then we have detected a * recursion getting the subsystem location. So we return true to * permit the subsystem location request in the SubsystemPermission * check up the stack to succeed. */ return true; } return f.matches(requestedProperties); }
Example #20
Source File: Reference.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Get target value for reference, if target is missing or the target * string is malformed return null. */ Filter getTarget(Map<?, Object> d, String src) { final Object prop = d.get(refDesc.name + ".target"); if (prop != null) { String res = null; if (prop instanceof String) { res = (String) prop; } else if (prop instanceof String []) { String [] propArray = (String []) prop; if (propArray.length == 1) { res = propArray[0]; } } if (res != null) { try { return FrameworkUtil.createFilter(res); } catch (final InvalidSyntaxException ise) { Activator.logError(comp.bc, "Failed to parse target property. Source is " + src, ise); } } else { Activator.logError(comp.bc, "Target property is no a single string. Source is " + src, null); } } return null; }
Example #21
Source File: RFC1960Filter.java From AtlasForAndroid with MIT License | 5 votes |
public boolean match(Dictionary dictionary) { Filter[] filterArr; int i; if (this.operator == PRESENT) { filterArr = (Filter[]) this.operands.toArray(new Filter[this.operands.size()]); for (i = EQUALS; i < filterArr.length; i += PRESENT) { if (!filterArr[i].match(dictionary)) { return false; } } return true; } else if (this.operator == OR_OPERATOR) { filterArr = (Filter[]) this.operands.toArray(new Filter[this.operands.size()]); for (i = EQUALS; i < filterArr.length; i += PRESENT) { if (filterArr[i].match(dictionary)) { return true; } } return false; } else if (this.operator != NOT_OPERATOR) { throw new IllegalStateException("PARSER ERROR"); } else if (((Filter) this.operands.get(EQUALS)).match(dictionary)) { return false; } else { return true; } }
Example #22
Source File: ProtobufferExportDeclarationWrapper.java From fuchsia with Apache License 2.0 | 5 votes |
private static Filter buildFilter() { Filter filter; String stringFilter = String.format("(&(%s=*)(%s=*)(%s=*)(%s=*)(%s=*))", ID, RPC_EXPORT_ADDRESS, RPC_EXPORT_CLASS, RPC_EXPORT_MESSAGE, RPC_EXPORT_SERVICE); try { filter = FuchsiaUtils.getFilter(stringFilter); } catch (InvalidFilterException e) { throw new IllegalStateException(e); } return filter; }
Example #23
Source File: ApplicationAdminPermission.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Filter getFilter() { if (appliedFilter == null) { try { appliedFilter = FrameworkUtil.createFilter(filter); } catch (InvalidSyntaxException e) { // we will return null } } return appliedFilter; }
Example #24
Source File: DelayedProbeInvokerFactory.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
/** * @return LDAP filter created by formatting the given arguments */ private static Filter filter(final String format, final Object... args) { try { return FrameworkUtil.createFilter(String.format(format, args)); } catch (final InvalidSyntaxException e) { throw new IllegalArgumentException(e); } }
Example #25
Source File: CMCommands.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Configuration[] getConfigurations(PrintWriter out, Session session, ConfigurationAdmin cm, String[] selection) throws Exception { final Filter[] filters = convertToFilters(out, session, selection); return getConfigurationsMatchingFilters(cm, filters); }
Example #26
Source File: CMCommands.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Filter[] convertToFilters(PrintWriter out, Session session, String[] selection) throws Exception { if (selection == null) { return null; } final Filter[] filters = new Filter[selection.length]; for (int i = 0; i < selection.length; ++i) { final String current = selection[i]; Filter filter = null; if (isInteger(current)) { try { filter = tryToCreateFilterFromIndex(session, current); } catch (final Exception e) { out.println("Warning: " +e.getMessage()); } } else if (startsWithParenthesis(current)) { filter = tryToCreateFilterFromLdapExpression(current); } else { filter = tryToCreateFilterFromPidContainingWildcards(current); } if (filter == null) { throw new Exception("Unable to handle selection argument " + current); } filters[i] = filter; } return filters; }
Example #27
Source File: CMCommands.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Filter tryToCreateFilterFromPidContainingWildcards(String pidContainingWildcards) throws Exception { return tryToCreateFilterFromLdapExpression("(" + Constants.SERVICE_PID + "=" + pidContainingWildcards + ")"); }
Example #28
Source File: RFC1960Filter.java From concierge with Eclipse Public License 1.0 | 5 votes |
/** * get a string representation of the filter. * * @return the string. * @category Object */ public String toString() { if (operator == NOT_OPERATOR) { return "(!" + operands.get(0) + ")"; } final StringBuffer buffer = new StringBuffer( operator == AND_OPERATOR ? "(&" : "(|"); final Filter[] operandArray = operands .toArray(new Filter[operands.size()]); for (int i = 0; i < operandArray.length; i++) { buffer.append(operandArray[i]); } buffer.append(")"); return buffer.toString(); }
Example #29
Source File: DefaultExportationLinkerTest.java From fuchsia with Apache License 2.0 | 5 votes |
@Test public void testIDecPropFilterFail() { DefaultExportationLinker il = new DefaultExportationLinker(bundleContext); il.start(); setProperties(il, "TestedLinker", "(scope=generic", "(instance.name=TestExporter)"); assertThat(il.getName()).isEqualTo("TestedLinker"); il.updated(); Filter exportDeclarationFilter = field("exportDeclarationFilter").ofType(Filter.class).in(il).get(); assertThat(exportDeclarationFilter).isNull(); assertThat(field("state").ofType(boolean.class).in(il).get()).isFalse(); }
Example #30
Source File: CoordinationPermission.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Called by constructors and when deserialized. * * @param filter Permission's filter or {@code null} for wildcard. * @param mask action mask */ private void setTransients(Filter filter, int mask) { this.filter = filter; if ((mask == ACTION_NONE) || ((mask & ACTION_ALL) != mask)) { throw new IllegalArgumentException("invalid action string"); } this.action_mask = mask; }