Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2003, 2009 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 
 package org.eclipse.osgi.internal.serviceregistry;
 
Service Listener delegate.
 
Filter for listener.
 
 	private final FilterImpl filter;
Real listener.
 
 	private final ServiceListener listener;
The bundle context
 
 	private final BundleContextImpl context;
is this an AllServiceListener
 
 	private final boolean allservices;
an objectClass required by the filter
 
 	private final String objectClass;
indicates whether the listener has been removed
 
 	private volatile boolean removed;

Constructor.

Parameters:
context The bundle context of the bundle which added the specified service listener.
filterstring The filter string specified when this service listener was added.
listener The service listener object.
Throws:
org.osgi.framework.InvalidSyntaxException if the filter is invalid.
 
 	FilteredServiceListener(final BundleContextImpl contextfinal ServiceListener listenerfinal String filterstringthrows InvalidSyntaxException {
 		if (filterstring == null) {
 			this. = null;
 			this. = null;
 		} else {
 			FilterImpl filterImpl = FilterImpl.newInstance(filterstring);
 			String clazz = filterImpl.getRequiredObjectClass();
 			if (clazz == null) {
 				this. = null;
 				this. = filterImpl;
 			} else {
 				this. = clazz.intern(); /*intern the name for future identity comparison */
 				this. = filterstring.equals(getObjectClassFilterString(this.)) ? null : filterImpl;
 			}
 		}
 		this. = false;
 		this. = listener;
 		this. = context;
 		this. = (listener instanceof AllServiceListener);
 	}

Receives notification that a service has had a lifecycle change.

Parameters:
event The ServiceEvent object.
 
 	public void serviceChanged(ServiceEvent event) {
 
 		// first check if we can short circuit the filter match if the required objectClass does not match the event
 		objectClassCheck: if ( != null) {
 			String[] classes = reference.getClasses();
 			int size = classes.length;
 			for (int i = 0; i < sizei++) {
 				if (classes[i] == // objectClass strings have previously been interned for identity comparison 
 					break objectClassCheck;
 			}
 			return// no class in this event matches a required part of the filter; we do not need to deliver this event
 		}
 		// TODO could short circuit service.id filters as well since the id is constant for a registration.
 
 		if (!ServiceRegistry.hasListenServicePermission(event))
 			return;
 
 		if (. && .) {
 			String listenerName = this.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(this)); //$NON-NLS-1$
 			Debug.println("filterServiceEvent(" + listenerName + ", \"" + getFilter() + "\", " + reference.getRegistration().getProperties() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
 		}
 
 		event = filterMatch(event);
 		if (event == null) {
 			return;
 		}
 		if ( || ServiceRegistry.isAssignableTo(reference)) {
 			if (. && .) {
				String listenerName = .getClass().getName() + "@" + Integer.toHexString(System.identityHashCode()); //$NON-NLS-1$
				Debug.println("dispatchFilteredServiceEvent(" + listenerName + ")"); //$NON-NLS-1$ //$NON-NLS-2$
			}
		}
	}

Returns a service event that should be delivered to the listener based on the filter evaluation. This may result in a service event of type MODIFIED_ENDMATCH.

Parameters:
delivered The service event delivered by the framework.
Returns:
The event to be delivered or null if no event is to be delivered to the listener.
	private ServiceEvent filterMatch(ServiceEvent delivered) {
		boolean modified = delivered.getType() == .;
		ServiceEvent event = modified ? ((ModifiedServiceEventdelivered).getModifiedEvent() : delivered;
		if ( == null) {
			return event;
		}
		ServiceReference reference = event.getServiceReference();
		if (.match(reference)) {
			return event;
		}
		if (modified) {
			ModifiedServiceEvent modifiedServiceEvent = (ModifiedServiceEventdelivered;
			if (modifiedServiceEvent.matchPreviousProperties()) {
				return modifiedServiceEvent.getModifiedEndMatchEvent();
			}
		}
		// does not match and did not match previous properties; do not send event
		return null;
	}

The string representation of this Filtered listener.

Returns:
The string representation of this listener.
	public String toString() {
		String filterString = getFilter();
		if (filterString == null) {
			filterString = ""//$NON-NLS-1$
		}
		return .getClass().getName() + "@" + Integer.toHexString(System.identityHashCode()) + filterString//$NON-NLS-1$
	}

Return the bundle context for the ListenerHook.

Returns:
The context of the bundle which added the service listener.
See also:
org.osgi.framework.hooks.service.ListenerHook.ListenerInfo.getBundleContext()
		return ;
	}

Return the filter string for the ListenerHook.

Returns:
The filter string with which the listener was added. This may be null if the listener was added without a filter.
See also:
org.osgi.framework.hooks.service.ListenerHook.ListenerInfo.getFilter()
	public String getFilter() {
		if ( != null) {
			return .toString();
		}
	}

Return the state of the listener for this addition and removal life cycle. Initially this method will return false indicating the listener has been added but has not been removed. After the listener has been removed, this method must always return true.

Returns:
false if the listener has not been been removed, true otherwise.
	public boolean isRemoved() {
		return ;
	}

Mark the service listener registration as removed.
	void markRemoved() {
		 = true;
	}

Returns an objectClass filter string for the specified class name.

Returns:
A filter string for the specified class name or null if the specified class name is null.
	private static String getObjectClassFilterString(String className) {
		if (className == null) {
			return null;
		}
		return "(" + . + "=" + className + ")"//$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
	}
New to GrepCode? Check out our FAQ X