Java Code Examples for org.osgi.framework.Constants#OBJECTCLASS

The following examples show how to use org.osgi.framework.Constants#OBJECTCLASS . 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: ServiceTracker.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Create a {@code ServiceTracker} on the specified class name.
 * 
 * <p>
 * Services registered under the specified class name will be tracked by
 * this {@code ServiceTracker}.
 * 
 * @param context The {@code BundleContext} against which the tracking is
 *        done.
 * @param clazz The class name of the services to be tracked.
 * @param customizer The customizer object to call when services are added,
 *        modified, or removed in this {@code ServiceTracker}. If customizer
 *        is {@code null}, then this {@code ServiceTracker} will be used as
 *        the {@code ServiceTrackerCustomizer} and this
 *        {@code ServiceTracker} will call the
 *        {@code ServiceTrackerCustomizer} methods on itself.
 */
public ServiceTracker(final BundleContext context, final String clazz, final ServiceTrackerCustomizer<S, T> customizer) {
	this.context = context;
	this.trackReference = null;
	this.trackClass = clazz;
	this.customizer = (customizer == null) ? this : customizer;
	// we call clazz.toString to verify clazz is non-null!
	this.listenerFilter = "(" + Constants.OBJECTCLASS + "=" + clazz.toString() + ")";
	try {
		this.filter = context.createFilter(listenerFilter);
	} catch (InvalidSyntaxException e) {
		/*
		 * we could only get this exception if the clazz argument was
		 * malformed
		 */
		IllegalArgumentException iae = new IllegalArgumentException("unexpected InvalidSyntaxException: " + e.getMessage());
		iae.initCause(e);
		throw iae;
	}
}
 
Example 2
Source File: ReferenceListener.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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 3
Source File: PropertiesDictionary.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
 public Object get(Object key) {
   if (key == Constants.OBJECTCLASS) {
     return (ocIndex >= 0) ? values[ocIndex] : null;
   } else if (key == Constants.SERVICE_ID) {
     return (sidIndex >= 0) ? values[sidIndex] : null;
   } else if (key == Constants.SERVICE_BUNDLEID) {
     return (sidIndex >= 0) ? values[sbidIndex] : null;
   } else if (key == Constants.SERVICE_SCOPE) {
     return (sidIndex >= 0) ? values[ssIndex] : null;
   }
   for (int i = size - 1; i >= 0; i--) {
     if (((String)key).equalsIgnoreCase(keys[i])) {
return values[i];
     }
   }
   return null;
 }
 
Example 4
Source File: ServiceTracker.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create a {@code ServiceTracker} on the specified class name.
 * 
 * <p>
 * Services registered under the specified class name will be tracked by
 * this {@code ServiceTracker}.
 * 
 * @param context The {@code BundleContext} against which the tracking is
 *        done.
 * @param clazz The class name of the services to be tracked.
 * @param customizer The customizer object to call when services are added,
 *        modified, or removed in this {@code ServiceTracker}. If customizer
 *        is {@code null}, then this {@code ServiceTracker} will be used as
 *        the {@code ServiceTrackerCustomizer} and this
 *        {@code ServiceTracker} will call the
 *        {@code ServiceTrackerCustomizer} methods on itself.
 */
public ServiceTracker(final BundleContext context, final String clazz, final ServiceTrackerCustomizer<S, T> customizer) {
	this.context = context;
	this.trackReference = null;
	this.trackClass = clazz;
	this.customizer = (customizer == null) ? this : customizer;
	// we call clazz.toString to verify clazz is non-null!
	this.listenerFilter = "(" + Constants.OBJECTCLASS + "=" + clazz.toString() + ")";
	try {
		this.filter = context.createFilter(listenerFilter);
	} catch (InvalidSyntaxException e) {
		/*
		 * we could only get this exception if the clazz argument was
		 * malformed
		 */
		IllegalArgumentException iae = new IllegalArgumentException("unexpected InvalidSyntaxException: " + e.getMessage());
		iae.initCause(e);
		throw iae;
	}
}
 
Example 5
Source File: ComponentServiceListener.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private String getObjectClassFilter(Set<String> cns)
{
  if (cns.size() == 1) {
    return "(" + Constants.OBJECTCLASS + "=" + cns.iterator().next() +")";
  } else {
    StringBuilder sb = new StringBuilder("(|");
    // TODO? Should we limit this and listen to all events?
    for (String cn : cns) {
      sb.append('(').append(Constants.OBJECTCLASS).append('=').append(cn).append(')');
    }
    sb.append(')');
    return sb.toString();
  }
}
 
Example 6
Source File: PropertiesDictionary.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
PropertiesDictionary(@SuppressWarnings("rawtypes") Dictionary in,
                     String[] classes, Long sid, Long bid, String scope)
{
  final int max_size = (in != null ? in.size() : 0) + size;
  keys = new String[max_size];
  values = new Object[max_size];
  keys[ocIndex] = Constants.OBJECTCLASS;
  values[ocIndex] = classes;
  keys[sidIndex] = Constants.SERVICE_ID;
  values[sidIndex] = sid != null ? sid : new Long(nextServiceID++);
  keys[sbidIndex] = Constants.SERVICE_BUNDLEID;
  values[sbidIndex] = bid;
  keys[ssIndex] = Constants.SERVICE_SCOPE;
  values[ssIndex] = scope;
  if (in != null) {
    try {
      for (@SuppressWarnings("rawtypes")
      final Enumeration e = in.keys(); e.hasMoreElements();) {
        final String key = (String) e.nextElement();
        if (!key.equalsIgnoreCase(Constants.OBJECTCLASS) &&
            !key.equalsIgnoreCase(Constants.SERVICE_ID) &&
            !key.equalsIgnoreCase(Constants.SERVICE_BUNDLEID) &&
            !key.equalsIgnoreCase(Constants.SERVICE_SCOPE)) {
          for (int i = size - 1; i >= 0; i--) {
            if (key.equalsIgnoreCase(keys[i])) {
              throw new IllegalArgumentException(
                                                 "Several entries for property: "
                                                     + key);
            }
          }
          keys[size] = key;
          values[size++] = in.get(key);
        }
      }
    } catch (final ClassCastException ignore) {
      throw new IllegalArgumentException(
                                         "Properties contains key that is not of type java.lang.String");
    }
  }
}
 
Example 7
Source File: EventProcessor.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public EventProcessor ( final BundleContext context ) throws InvalidSyntaxException
{
    this ( "(" + Constants.OBJECTCLASS + "=" + EventService.class.getName () + ")", context );
}
 
Example 8
Source File: ContentHandlerWrapper.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
ContentHandlerWrapper(FrameworkContext       framework,
	String                 mimetype) {

  this.framework = framework;
  this.mimetype  = mimetype;

  filter =
    "(&" +
    "(" + Constants.OBJECTCLASS + "=" +
    ContentHandler.class.getName() + ")" +
    "(" + URLConstants.URL_CONTENT_MIMETYPE + "=" + mimetype +
    ")" +
    ")";

  final ServiceListener serviceListener =
    new ServiceListener() {
      public void serviceChanged(ServiceEvent evt) {
        @SuppressWarnings("unchecked")
        final
        ServiceReference<ContentHandler> ref =
            (ServiceReference<ContentHandler>) evt.getServiceReference();

        switch (evt.getType()) {
        case ServiceEvent.MODIFIED:
          // fall through
        case ServiceEvent.REGISTERED:
          if (best == null) {
            updateBest();
            return ;
          }

          if (compare(best, ref) > 0) {
            best = ref;
          }
          break;
        case ServiceEvent.MODIFIED_ENDMATCH:
          // fall through
        case ServiceEvent.UNREGISTERING:
          if (best.equals(ref)) {
            best = null;
          }
        }
      }
    };

  try {
    framework.systemBundle.bundleContext.addServiceListener(serviceListener, filter);

  } catch (final Exception e) {
    throw new IllegalArgumentException("Could not register service listener for content handler: " + e);
  }

  if (framework.debug.url) {
    framework.debug.println("created wrapper for " + mimetype + ", filter=" + filter);
  }
}