Ejemplo n.º 1
0
  @Override
  public TrackingStruct addingService(ServiceReference<ResourceAnalyzer> reference) {
    TrackingStruct struct = new TrackingStruct();
    try {
      String filterStr = (String) reference.getProperty(ResourceAnalyzer.FILTER);
      Filter filter = (filterStr != null) ? FrameworkUtil.createFilter(filterStr) : null;

      ResourceAnalyzer analyzer = context.getService(reference);
      if (analyzer == null) return null;

      struct = new TrackingStruct();
      struct.analyzer = analyzer;
      struct.filter = filter;
      struct.valid = true;

      indexer.addAnalyzer(analyzer, filter);
    } catch (InvalidSyntaxException e) {
      struct.valid = false;
      log.log(
          reference,
          LogService.LOG_ERROR,
          "Ignoring ResourceAnalyzer due to invalid filter expression",
          e);
    }
    return struct;
  }
 Filter getAuthFilter() throws InvalidSyntaxException {
   StringBuilder sb = new StringBuilder("("); // $NON-NLS-1$
   sb.append(ServerConstants.CONFIG_AUTH_NAME);
   sb.append('=');
   sb.append(getAuthName());
   sb.append(')');
   return FrameworkUtil.createFilter(sb.toString());
 }
  /**
   * Parse filter string into a Filter object.
   *
   * @param filterString The filter string to parse.
   * @return a Filter for this bundle. If the specified filterString is not a filter expression,
   *     then {@code null} is returned.
   * @throws IllegalArgumentException If the filter syntax is invalid.
   */
  private static Filter parseFilter(String filterString) {
    filterString = filterString.trim();
    if (filterString.charAt(0) != '(') {
      return null;
    }

    try {
      return FrameworkUtil.createFilter(filterString);
    } catch (InvalidSyntaxException e) {
      IllegalArgumentException iae = new IllegalArgumentException("invalid filter");
      iae.initCause(e);
      throw iae;
    }
  }
Ejemplo n.º 4
0
  @Override
  public void modifiedService(ServiceReference<ResourceAnalyzer> reference, TrackingStruct struct) {
    if (struct.valid) {
      indexer.removeAnalyzer(struct.analyzer, struct.filter);
    }

    try {
      String filterStr = (String) reference.getProperty(ResourceAnalyzer.FILTER);
      Filter filter = (filterStr != null) ? FrameworkUtil.createFilter(filterStr) : null;

      struct = new TrackingStruct();
      struct.filter = filter;
      struct.valid = true;

      indexer.addAnalyzer(struct.analyzer, filter);
    } catch (InvalidSyntaxException e) {
      struct.valid = false;
      log.log(
          reference,
          LogService.LOG_ERROR,
          "Ignoring ResourceAnalyzer due to invalid filter expression",
          e);
    }
  }
Ejemplo n.º 5
0
 public Filter createFilter(String filter) throws InvalidSyntaxException {
   return FrameworkUtil.createFilter(filter);
 }