Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 202278 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/equinox/event/mapper/FrameworkEventAdapter.java (-5 / +5 lines)
Lines 22-32 Link Here
22
 */
22
 */
23
public class FrameworkEventAdapter extends EventAdapter {
23
public class FrameworkEventAdapter extends EventAdapter {
24
	// constants for Event topic substring
24
	// constants for Event topic substring
25
	public static final String HEADER = "org/osgi/framework/FrameworkEvent";
25
	public static final String HEADER = "org/osgi/framework/FrameworkEvent"; //$NON-NLS-1$
26
	public static final String STARTLEVEL_CHANGED = "STARTLEVEL_CHANGED";
26
	public static final String STARTLEVEL_CHANGED = "STARTLEVEL_CHANGED"; //$NON-NLS-1$
27
	public static final String STARTED = "STARTED";
27
	public static final String STARTED = "STARTED"; //$NON-NLS-1$
28
	public static final String PACKAGES_REFRESHED = "PACKAGES_REFRESHED";
28
	public static final String PACKAGES_REFRESHED = "PACKAGES_REFRESHED"; //$NON-NLS-1$
29
	public static final String ERROR = "ERROR";
29
	public static final String ERROR = "ERROR"; //$NON-NLS-1$
30
	protected FrameworkEvent event;
30
	protected FrameworkEvent event;
31
31
32
	public FrameworkEventAdapter(FrameworkEvent event, EventAdmin eventAdmin) {
32
	public FrameworkEventAdapter(FrameworkEvent event, EventAdmin eventAdmin) {
(-)src/org/eclipse/equinox/event/mapper/WireAdminEventAdapter.java (-107 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.equinox.event.mapper;
12
13
import java.util.Hashtable;
14
import org.osgi.framework.ServiceReference;
15
import org.osgi.service.event.Event;
16
import org.osgi.service.event.EventAdmin;
17
import org.osgi.service.wireadmin.Wire;
18
import org.osgi.service.wireadmin.WireAdminEvent;
19
20
/**
21
 * @version $Revision: 1.2 $
22
 */
23
public class WireAdminEventAdapter extends EventAdapter {
24
	// constants for Event topic substring
25
	public static final String TOPIC = "org/osgi/service/wireadmin/WireAdminEvent";
26
	public static final String WIRE_CREATED = "WIRE_CREATED";
27
	public static final String WIRE_CONNECTED_T = "WIRE_CONNECTED";
28
	public static final String WIRE_UPDATED = "WIRE_UPDATED";
29
	public static final String WIRE_TRACE = "WIRE_TRACE";
30
	public static final String WIRE_DISCONNECTED = "WIRE_DISCONNECTED";
31
	public static final String WIRE_DELETED = "WIRE_DELETED";
32
	public static final String PRODUCER_EXCEPTION = "PRODUCER_EXCEPTION";
33
	public static final String CONSUMER_EXCEPTION = "CONSUMER_EXCEPTION";
34
	// constants for Event properties
35
	public static final String WIRE = "wire";
36
	public static final String WIRE_FLAVORS = "wire.flavors";
37
	public static final String WIRE_SCOPE = "wire.scope";
38
	public static final String WIRE_CONNECTED_P = "wire.connected";
39
	public static final String WIRE_VALID = "wire.valid";
40
	private WireAdminEvent event;
41
42
	public WireAdminEventAdapter(WireAdminEvent event, EventAdmin admin) {
43
		super(admin);
44
		this.event = event;
45
	}
46
47
	/**
48
	 * @see org.eclipse.equinox.event.mapper.EventAdapter#convert()
49
	 */
50
	public Event convert() {
51
		String typename = null;
52
		switch (event.getType()) {
53
			case WireAdminEvent.WIRE_CONNECTED :
54
				typename = WIRE_CONNECTED_T;
55
				break;
56
			case WireAdminEvent.WIRE_CREATED :
57
				typename = WIRE_CREATED;
58
				break;
59
			case WireAdminEvent.WIRE_UPDATED :
60
				typename = WIRE_UPDATED;
61
				break;
62
			case WireAdminEvent.WIRE_DELETED :
63
				typename = WIRE_DELETED;
64
				break;
65
			case WireAdminEvent.WIRE_DISCONNECTED :
66
				typename = WIRE_DISCONNECTED;
67
				break;
68
			case WireAdminEvent.WIRE_TRACE :
69
				typename = WIRE_TRACE;
70
				break;
71
			case WireAdminEvent.PRODUCER_EXCEPTION :
72
				typename = PRODUCER_EXCEPTION;
73
				break;
74
			case WireAdminEvent.CONSUMER_EXCEPTION :
75
				typename = CONSUMER_EXCEPTION;
76
				break;
77
			default :
78
				return null;
79
		}
80
		String topic = TOPIC + Constants.TOPIC_SEPARATOR + typename;
81
		Hashtable properties = new Hashtable();
82
		Throwable t = event.getThrowable();
83
		if (t != null) {
84
			putExceptionProperties(properties, t);
85
		}
86
		ServiceReference ref = event.getServiceReference();
87
		if (ref == null) {
88
			throw new RuntimeException("WireAdminEvent's getServiceReference() returns null.");
89
		}
90
		putServiceReferenceProperties(properties, ref);
91
		Wire wire = event.getWire();
92
		if (wire != null) {
93
			properties.put(WIRE, wire);
94
			if (wire.getFlavors() != null) {
95
				properties.put(WIRE_FLAVORS, classes2strings(wire.getFlavors()));
96
			}
97
			if (wire.getScope() != null) {
98
				properties.put(WIRE_SCOPE, wire.getScope());
99
			}
100
			properties.put(WIRE_CONNECTED_P, new Boolean(wire.isConnected()));
101
			properties.put(WIRE_VALID, new Boolean(wire.isValid()));
102
		}
103
		properties.put(Constants.EVENT, event);
104
		Event converted = new Event(topic, properties);
105
		return converted;
106
	}
107
}
(-)src/org/eclipse/equinox/event/mapper/EventAdapter.java (-2 / +2 lines)
Lines 77-87 Link Here
77
		properties.put(Constants.SERVICE_ID, ref.getProperty(org.osgi.framework.Constants.SERVICE_ID));
77
		properties.put(Constants.SERVICE_ID, ref.getProperty(org.osgi.framework.Constants.SERVICE_ID));
78
		Object o = ref.getProperty(org.osgi.framework.Constants.SERVICE_PID);
78
		Object o = ref.getProperty(org.osgi.framework.Constants.SERVICE_PID);
79
		if ((o != null) && (o instanceof String)) {
79
		if ((o != null) && (o instanceof String)) {
80
			properties.put(Constants.SERVICE_PID, (String) o);
80
			properties.put(Constants.SERVICE_PID, o);
81
		}
81
		}
82
		Object o2 = ref.getProperty(org.osgi.framework.Constants.OBJECTCLASS);
82
		Object o2 = ref.getProperty(org.osgi.framework.Constants.OBJECTCLASS);
83
		if ((o2 != null) && (o2 instanceof String[])) {
83
		if ((o2 != null) && (o2 instanceof String[])) {
84
			properties.put(Constants.SERVICE_OBJECTCLASS, (String[]) o2);
84
			properties.put(Constants.SERVICE_OBJECTCLASS, o2);
85
		}
85
		}
86
	}
86
	}
87
87
(-)src/org/eclipse/equinox/event/mapper/ServiceEventAdapter.java (-4 / +4 lines)
Lines 22-31 Link Here
22
 */
22
 */
23
public class ServiceEventAdapter extends EventAdapter {
23
public class ServiceEventAdapter extends EventAdapter {
24
	// constants for Event topic substring
24
	// constants for Event topic substring
25
	public static final String HEADER = "org/osgi/framework/ServiceEvent";
25
	public static final String HEADER = "org/osgi/framework/ServiceEvent"; //$NON-NLS-1$
26
	public static final String UNREGISTERING = "UNREGISTERING";
26
	public static final String UNREGISTERING = "UNREGISTERING"; //$NON-NLS-1$
27
	public static final String MODIFIED = "MODIFIED";
27
	public static final String MODIFIED = "MODIFIED"; //$NON-NLS-1$
28
	public static final String REGISTERED = "REGISTERED";
28
	public static final String REGISTERED = "REGISTERED"; //$NON-NLS-1$
29
	private ServiceEvent event;
29
	private ServiceEvent event;
30
30
31
	public ServiceEventAdapter(ServiceEvent event, EventAdmin eventAdmin) {
31
	public ServiceEventAdapter(ServiceEvent event, EventAdmin eventAdmin) {
(-)src/org/eclipse/equinox/event/mapper/Constants.java (-15 / +15 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
2
 * Copyright (c) 2005, 2007 IBM Corporation.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 16-33 Link Here
16
public interface Constants {
16
public interface Constants {
17
	// constants for Event common properties; event specific properties are
17
	// constants for Event common properties; event specific properties are
18
	// defined in the corresponding event adapter.
18
	// defined in the corresponding event adapter.
19
	public static final String	BUNDLE				= "bundle";
19
	public static final String BUNDLE = "bundle"; //$NON-NLS-1$
20
	public static final String	BUNDLE_ID			= "bundle.id";
20
	public static final String BUNDLE_ID = "bundle.id"; //$NON-NLS-1$
21
	public static final String	BUNDLE_SYMBOLICNAME	= "bundle.symbolicName";
21
	public static final String BUNDLE_SYMBOLICNAME = "bundle.symbolicName"; //$NON-NLS-1$
22
	public static final String	EVENT				= "event";
22
	public static final String EVENT = "event"; //$NON-NLS-1$
23
	public static final String	EXCEPTION			= "exception";
23
	public static final String EXCEPTION = "exception"; //$NON-NLS-1$
24
	public static final String	EXCEPTION_CLASS		= "exception.class";
24
	public static final String EXCEPTION_CLASS = "exception.class"; //$NON-NLS-1$
25
	public static final String	EXCEPTION_MESSAGE	= "exception.message";
25
	public static final String EXCEPTION_MESSAGE = "exception.message"; //$NON-NLS-1$
26
	public static final String	MESSAGE				= "message";
26
	public static final String MESSAGE = "message"; //$NON-NLS-1$
27
	public static final String	SERVICE				= "service";
27
	public static final String SERVICE = "service"; //$NON-NLS-1$
28
	public static final String	SERVICE_ID			= "service.id";
28
	public static final String SERVICE_ID = "service.id"; //$NON-NLS-1$
29
	public static final String	SERVICE_OBJECTCLASS	= "service.objectClass";
29
	public static final String SERVICE_OBJECTCLASS = "service.objectClass"; //$NON-NLS-1$
30
	public static final String	SERVICE_PID			= "service.pid";
30
	public static final String SERVICE_PID = "service.pid"; //$NON-NLS-1$
31
	public static final String	TIMESTAMP			= "timestamp";
31
	public static final String TIMESTAMP = "timestamp"; //$NON-NLS-1$
32
	public static final char	TOPIC_SEPARATOR		= '/';
32
	public static final char TOPIC_SEPARATOR = '/';
33
}
33
}
(-)src/org/eclipse/equinox/event/mapper/LogReaderServiceTracker.java (-18 / +13 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
2
 * Copyright (c) 2005, 2007 IBM Corporation.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 20-53 Link Here
20
 * @version $Revision: 1.1 $
20
 * @version $Revision: 1.1 $
21
 */
21
 */
22
public class LogReaderServiceTracker extends ServiceTracker {
22
public class LogReaderServiceTracker extends ServiceTracker {
23
	private final LogReaderServiceListener	listener;
23
	private final LogReaderServiceListener listener;
24
	private ServiceReference				reference;
24
	private ServiceReference reference;
25
25
26
	public LogReaderServiceTracker(BundleContext context,
26
	public LogReaderServiceTracker(BundleContext context, LogReaderServiceListener listener) {
27
			LogReaderServiceListener listener) {
28
		super(context, LogReaderService.class.getName(), null);
27
		super(context, LogReaderService.class.getName(), null);
29
		this.listener = listener;
28
		this.listener = listener;
30
	}
29
	}
31
30
32
	public Object addingService(ServiceReference reference) {
31
	public Object addingService(ServiceReference ref) {
33
		Object object = super.addingService(reference);
32
		Object object = super.addingService(ref);
34
		if ((object != null) && (this.reference == null)
33
		if ((object != null) && (this.reference == null) && (object instanceof LogReaderService)) {
35
				&& (object instanceof LogReaderService)) {
34
			this.reference = ref;
36
			this.reference = reference;
35
			listener.logReaderServiceAdding(ref, (LogReaderService) object);
37
			listener.logReaderServiceAdding(reference,
38
					(LogReaderService) object);
39
		}
36
		}
40
		return object;
37
		return object;
41
	}
38
	}
42
39
43
	public void removedService(ServiceReference reference, Object service) {
40
	public void removedService(ServiceReference ref, Object service) {
44
		if ((service != null) && (this.reference.equals(reference))
41
		if ((service != null) && (this.reference.equals(ref)) && (service instanceof LogReaderService)) {
45
				&& (service instanceof LogReaderService)) {
42
			listener.logReaderServiceRemoved(ref, (LogReaderService) service);
46
			listener.logReaderServiceRemoved(reference,
47
					(LogReaderService) service);
48
			this.reference = null;
43
			this.reference = null;
49
		}
44
		}
50
		super.removedService(reference, service);
45
		super.removedService(ref, service);
51
		//this method calls ungetService()
46
		//this method calls ungetService()
52
	}
47
	}
53
}
48
}
(-)src/org/eclipse/equinox/event/mapper/UserAdminEventAdapter.java (-79 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.equinox.event.mapper;
13
14
import java.util.Hashtable;
15
import org.osgi.framework.ServiceReference;
16
import org.osgi.service.event.Event;
17
import org.osgi.service.event.EventAdmin;
18
import org.osgi.service.useradmin.Role;
19
import org.osgi.service.useradmin.UserAdminEvent;
20
21
/**
22
 * @version $Revision: 1.2 $
23
 */
24
public class UserAdminEventAdapter extends EventAdapter {
25
	// constants for Event topic substring
26
	public static final String TOPIC = "org/osgi/service/useradmin/UserAdminEvent";
27
	public static final String ROLE_CREATED = "ROLE_CREATED";
28
	public static final String ROLE_CHANGED = "ROLE_CHANGED";
29
	public static final String ROLE_REMOVED = "ROLE_REMOVED";
30
	// constants for Event properties
31
	public static final String ROLE = "role";
32
	public static final String ROLE_NAME = "role.name";
33
	public static final String ROLE_TYPE = "role.type";
34
	private UserAdminEvent event;
35
36
	public UserAdminEventAdapter(UserAdminEvent event, EventAdmin eventAdmin) {
37
		super(eventAdmin);
38
		this.event = event;
39
	}
40
41
	/**
42
	 * @see org.eclipse.equinox.event.mapper.EventAdapter#convert()
43
	 */
44
	public Event convert() {
45
		String typename = null;
46
		switch (event.getType()) {
47
			case UserAdminEvent.ROLE_CREATED :
48
				typename = ROLE_CREATED;
49
				break;
50
			case UserAdminEvent.ROLE_CHANGED :
51
				typename = ROLE_CHANGED;
52
				break;
53
			case UserAdminEvent.ROLE_REMOVED :
54
				typename = ROLE_REMOVED;
55
				break;
56
			default :
57
				return null;
58
		}
59
		String topic = TOPIC + Constants.TOPIC_SEPARATOR + typename;
60
		Hashtable properties = new Hashtable();
61
		ServiceReference ref = event.getServiceReference();
62
		if (ref == null) {
63
			throw new RuntimeException("UserAdminEvent's getServiceReference() returns null.");
64
		}
65
		putServiceReferenceProperties(properties, ref);
66
		Role role = event.getRole();
67
		if (role == null) {
68
			throw new RuntimeException("UserAdminEvent's getRole() returns null.");
69
		}
70
		if (role != null) {
71
			properties.put(ROLE, role);
72
			properties.put(ROLE_NAME, role.getName());
73
			properties.put(ROLE_TYPE, new Integer(role.getType()));
74
		}
75
		properties.put(Constants.EVENT, event);
76
		Event converted = new Event(topic, properties);
77
		return converted;
78
	}
79
}
(-)src/org/eclipse/equinox/event/mapper/EventRedeliverer.java (-210 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
2
 * Copyright (c) 2005, 2007 IBM Corporation.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-91 Link Here
11
11
12
package org.eclipse.equinox.event.mapper;
12
package org.eclipse.equinox.event.mapper;
13
13
14
import java.util.Dictionary;
15
import java.util.Hashtable;
16
import org.osgi.framework.*;
14
import org.osgi.framework.*;
17
import org.osgi.service.cm.ConfigurationEvent;
18
import org.osgi.service.cm.ConfigurationListener;
19
import org.osgi.service.event.EventAdmin;
15
import org.osgi.service.event.EventAdmin;
20
import org.osgi.service.log.LogEntry;
21
import org.osgi.service.log.LogListener;
22
import org.osgi.service.log.LogReaderService;
23
import org.osgi.service.upnp.UPnPDevice;
24
import org.osgi.service.upnp.UPnPEventListener;
25
import org.osgi.service.upnp.UPnPService;
26
import org.osgi.service.useradmin.UserAdminEvent;
27
import org.osgi.service.useradmin.UserAdminListener;
28
import org.osgi.service.wireadmin.WireAdminEvent;
29
import org.osgi.service.wireadmin.WireAdminListener;
30
import org.osgi.service.wireadmin.WireConstants;
31
import org.osgi.util.tracker.ServiceTracker;
16
import org.osgi.util.tracker.ServiceTracker;
32
17
33
/**
18
/**
34
 * Main class for redeliver special events like FrameworkEvents via EventAdmin.
19
 * Main class for redeliver special events like FrameworkEvents via EventAdmin.
35
 * 
20
 * 
36
 * 
37
 * @version $Revision: 1.1 $
21
 * @version $Revision: 1.1 $
38
 */
22
 */
39
public class EventRedeliverer implements FrameworkListener, BundleListener,
23
public class EventRedeliverer implements FrameworkListener, BundleListener, ServiceListener {
40
		ServiceListener, LogListener, LogReaderServiceListener,
24
	private ServiceTracker eventAdminTracker;
41
		ConfigurationListener, WireAdminListener, UPnPEventListener,
25
	private final static boolean DEBUG = false;
42
		UserAdminListener {
26
	private BundleContext bc;
43
	private ServiceTracker			eventAdminTracker;
44
	private LogReaderServiceTracker	logTracker;
45
	private LogReaderService		reader;
46
	private final static boolean	DEBUG	= false;
47
	private BundleContext			bc;
48
	private ServiceRegistration		configurationListenerReg;
49
	private ServiceRegistration		wireAdminListenerReg;
50
	private ServiceRegistration		upnpEventListenerReg;
51
	private ServiceRegistration		userAdminListenerReg;
52
27
53
	public EventRedeliverer(BundleContext bc) {
28
	public EventRedeliverer(BundleContext bc) {
54
		this.bc = bc;
29
		this.bc = bc;
55
	}
30
	}
56
31
57
	public void close() {
32
	public void close() {
58
		if (logTracker != null) {
59
			logTracker.close();
60
			logTracker = null;
61
		}
62
		if (eventAdminTracker != null) {
33
		if (eventAdminTracker != null) {
63
			eventAdminTracker.close();
34
			eventAdminTracker.close();
64
			eventAdminTracker = null;
35
			eventAdminTracker = null;
65
		}
36
		}
66
		if (reader != null) {
67
			reader.removeLogListener(this);
68
		}
69
		reader = null;
70
		bc.removeFrameworkListener(this);
37
		bc.removeFrameworkListener(this);
71
		bc.removeBundleListener(this);
38
		bc.removeBundleListener(this);
72
		bc.removeServiceListener(this);
39
		bc.removeServiceListener(this);
73
		if (configurationListenerReg != null) {
74
			configurationListenerReg.unregister();
75
			configurationListenerReg = null;
76
		}
77
		if (wireAdminListenerReg != null) {
78
			wireAdminListenerReg.unregister();
79
			wireAdminListenerReg = null;
80
		}
81
		if (upnpEventListenerReg != null) {
82
			upnpEventListenerReg.unregister();
83
			upnpEventListenerReg = null;
84
		}
85
		if (userAdminListenerReg != null) {
86
			userAdminListenerReg.unregister();
87
			userAdminListenerReg = null;
88
		}
89
	}
40
	}
90
41
91
	/**
42
	/**
Lines 94-147 Link Here
94
	 */
45
	 */
95
	public void open() {
46
	public void open() {
96
		// open ServiceTracker for EventAdmin
47
		// open ServiceTracker for EventAdmin
97
		eventAdminTracker = new ServiceTracker(bc, EventAdmin.class.getName(),
48
		eventAdminTracker = new ServiceTracker(bc, EventAdmin.class.getName(), null);
98
				null);
99
		eventAdminTracker.open();
49
		eventAdminTracker.open();
100
		// open ServiceTracker for LogReaderService
50
101
		logTracker = new LogReaderServiceTracker(bc, this);
102
		logTracker.open();
103
		// add legacy event listener for framework level event
51
		// add legacy event listener for framework level event
104
		bc.addFrameworkListener(this);
52
		bc.addFrameworkListener(this);
105
		bc.addBundleListener(this);
53
		bc.addBundleListener(this);
106
		bc.addServiceListener(this);
54
		bc.addServiceListener(this);
107
		// register configurationListener
108
		configurationListenerReg = bc.registerService(
109
				ConfigurationListener.class.getName(), this, null);
110
		// register WireAdminListener
111
		Hashtable ht = new Hashtable();
112
		// create an event mask to receive all the types of WireAdminEvent
113
		Integer mask = new Integer(WireAdminEvent.WIRE_CONNECTED
114
				| WireAdminEvent.WIRE_CREATED | WireAdminEvent.WIRE_DELETED
115
				| WireAdminEvent.WIRE_DISCONNECTED | WireAdminEvent.WIRE_TRACE
116
				| WireAdminEvent.WIRE_UPDATED
117
				| WireAdminEvent.CONSUMER_EXCEPTION
118
				| WireAdminEvent.PRODUCER_EXCEPTION);
119
		ht.put(WireConstants.WIREADMIN_EVENTS, mask);
120
		wireAdminListenerReg = bc.registerService(WireAdminListener.class
121
				.getName(), this, ht);
122
		// register UPnPEventListener
123
		// create a Filter object to receive all the UPnP events
124
		Hashtable ht2 = new Hashtable();
125
		Filter filter = null;
126
		try {
127
			filter = bc.createFilter("(|(|(" + UPnPDevice.TYPE + "=*)("
128
					+ UPnPDevice.ID + "=*))(|(" + UPnPService.TYPE + "=*)("
129
					+ UPnPService.ID + "=*)))");
130
		}
131
		catch (InvalidSyntaxException e) {
132
			System.out
133
					.println("Exception thrown while trying to create Filter. "
134
							+ e);
135
			e.printStackTrace(System.out);
136
		}
137
		if (filter != null) {
138
			ht2.put(UPnPEventListener.UPNP_FILTER, filter);
139
			upnpEventListenerReg = bc.registerService(UPnPEventListener.class
140
					.getName(), this, ht2);
141
		}
142
		// register usrAdminListener
143
		userAdminListenerReg = bc.registerService(UserAdminListener.class
144
				.getName(), this, null);
145
	}
55
	}
146
56
147
	private EventAdmin getEventAdmin() {
57
	private EventAdmin getEventAdmin() {
Lines 158-173 Link Here
158
		EventAdmin eventAdmin = getEventAdmin();
68
		EventAdmin eventAdmin = getEventAdmin();
159
		if (eventAdmin != null) {
69
		if (eventAdmin != null) {
160
			(new FrameworkEventAdapter(event, eventAdmin)).redeliver();
70
			(new FrameworkEventAdapter(event, eventAdmin)).redeliver();
161
		}
71
		} else {
162
		else {
163
			printNoEventAdminError();
72
			printNoEventAdminError();
164
		}
73
		}
165
	}
74
	}
166
75
167
	private void printNoEventAdminError() {
76
	private void printNoEventAdminError() {
168
		if (DEBUG) {
77
		if (DEBUG) {
169
			System.out.println(this.getClass().getName()
78
			System.out.println(this.getClass().getName() + ": Cannot find the EventAdmin."); //$NON-NLS-1$
170
					+ ": Cannot find the EventAdmin.");
171
		}
79
		}
172
	}
80
	}
173
81
Lines 179-186 Link Here
179
		EventAdmin eventAdmin = getEventAdmin();
87
		EventAdmin eventAdmin = getEventAdmin();
180
		if (eventAdmin != null) {
88
		if (eventAdmin != null) {
181
			(new BundleEventAdapter(event, eventAdmin)).redeliver();
89
			(new BundleEventAdapter(event, eventAdmin)).redeliver();
182
		}
90
		} else {
183
		else {
184
			printNoEventAdminError();
91
			printNoEventAdminError();
185
		}
92
		}
186
	}
93
	}
Lines 193-307 Link Here
193
		EventAdmin eventAdmin = getEventAdmin();
100
		EventAdmin eventAdmin = getEventAdmin();
194
		if (eventAdmin != null) {
101
		if (eventAdmin != null) {
195
			(new ServiceEventAdapter(event, eventAdmin)).redeliver();
102
			(new ServiceEventAdapter(event, eventAdmin)).redeliver();
196
		}
103
		} else {
197
		else {
198
			printNoEventAdminError();
199
		}
200
	}
201
202
	/**
203
	 * @param entry
204
	 * @see org.osgi.service.log.LogListener#logged(org.osgi.service.log.LogEntry)
205
	 */
206
	public void logged(LogEntry entry) {
207
		EventAdmin eventAdmin = getEventAdmin();
208
		if (eventAdmin != null) {
209
			(new LogEntryAdapter(entry, eventAdmin)).redeliver();
210
		}
211
		else {
212
			printNoEventAdminError();
104
			printNoEventAdminError();
213
		}
105
		}
214
	}
106
	}
215
107
216
	/**
217
	 * @param reference
218
	 * @param service
219
	 * @see org.eclipse.equinox.event.mapper.LogReaderServiceListener#logReaderServiceAdding(org.osgi.framework.ServiceReference,
220
	 *      org.osgi.service.log.LogReaderService)
221
	 */
222
	public void logReaderServiceAdding(ServiceReference reference,
223
			LogReaderService service) {
224
		if (reader != null) {
225
			return;
226
		}
227
		reader = service;
228
		reader.addLogListener(this);
229
	}
230
231
	/**
232
	 * @param reference
233
	 * @param service
234
	 * @see org.eclipse.equinox.event.mapper.LogReaderServiceListener#logReaderServiceRemoved(org.osgi.framework.ServiceReference,
235
	 *      org.osgi.service.log.LogReaderService)
236
	 */
237
	public void logReaderServiceRemoved(ServiceReference reference,
238
			LogReaderService service) {
239
		if ((reader != null) && reader.equals(service)) {
240
			reader.removeLogListener(this);
241
			reader = null;
242
		}
243
		// ungetService() will be called after returning to
244
		// LogReaderServiceTracker's removedService() method.
245
	}
246
247
	/**
248
	 * @param event
249
	 * @see org.osgi.service.cm.ConfigurationListener#configurationEvent(org.osgi.service.cm.ConfigurationEvent)
250
	 */
251
	public void configurationEvent(ConfigurationEvent event) {
252
		EventAdmin eventAdmin = getEventAdmin();
253
		if (eventAdmin != null) {
254
			(new ConfigurationEventAdapter(event, eventAdmin)).redeliver();
255
		}
256
		else {
257
			printNoEventAdminError();
258
		}
259
	}
260
261
	/**
262
	 * @param event
263
	 * @see org.osgi.service.wireadmin.WireAdminListener#wireAdminEvent(org.osgi.service.wireadmin.WireAdminEvent)
264
	 */
265
	public void wireAdminEvent(WireAdminEvent event) {
266
		EventAdmin eventAdmin = getEventAdmin();
267
		if (eventAdmin != null) {
268
			(new WireAdminEventAdapter(event, eventAdmin)).redeliver();
269
		}
270
		else {
271
			printNoEventAdminError();
272
		}
273
	}
274
275
	/**
276
	 * @param deviceId
277
	 * @param serviceId
278
	 * @param events
279
	 * @see org.osgi.service.upnp.UPnPEventListener#notifyUPnPEvent(java.lang.String,
280
	 *      java.lang.String, java.util.Dictionary)
281
	 */
282
	public void notifyUPnPEvent(String deviceId, String serviceId,
283
			Dictionary events) {
284
		EventAdmin eventAdmin = getEventAdmin();
285
		if (eventAdmin != null) {
286
			(new UPnPEventAdapter(deviceId, serviceId, events, eventAdmin))
287
					.redeliver();
288
		}
289
		else {
290
			printNoEventAdminError();
291
		}
292
	}
293
294
	/**
295
	 * @param event
296
	 * @see org.osgi.service.useradmin.UserAdminListener#roleChanged(org.osgi.service.useradmin.UserAdminEvent)
297
	 */
298
	public void roleChanged(UserAdminEvent event) {
299
		EventAdmin eventAdmin = getEventAdmin();
300
		if (eventAdmin != null) {
301
			(new UserAdminEventAdapter(event, eventAdmin)).redeliver();
302
		}
303
		else {
304
			printNoEventAdminError();
305
		}
306
	}
307
}
108
}
(-)src/org/eclipse/equinox/event/mapper/UPnPEventAdapter.java (-57 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.equinox.event.mapper;
13
14
import java.util.Dictionary;
15
import java.util.Hashtable;
16
import org.osgi.service.event.Event;
17
import org.osgi.service.event.EventAdmin;
18
19
/**
20
 * @version $Revision: 1.2 $
21
 */
22
public class UPnPEventAdapter extends EventAdapter {
23
	// constants for Event topic substring
24
	public static final String TOPIC = "org/osgi/service/upnp/UPnPEvent";
25
	// constants for Event properties
26
	public static final String UPNP_DEVICEID = "upnp.deviceId";
27
	public static final String UPNP_SERVICEID = "upnp.serviceId";
28
	public static final String UPNP_EVENTS = "upnp.events";
29
	private String deviceId;
30
	private String serviceId;
31
	private Dictionary events;
32
33
	public UPnPEventAdapter(String deviceId, String serviceId, Dictionary events, EventAdmin eventAdmin) {
34
		super(eventAdmin);
35
		this.deviceId = deviceId;
36
		this.serviceId = serviceId;
37
		this.events = events;
38
	}
39
40
	/**
41
	 * @see org.eclipse.equinox.event.mapper.EventAdapter#convert()
42
	 */
43
	public Event convert() {
44
		Hashtable properties = new Hashtable();
45
		if (deviceId != null) {
46
			properties.put(UPNP_DEVICEID, deviceId);
47
		}
48
		if (serviceId != null) {
49
			properties.put(UPNP_SERVICEID, serviceId);
50
		}
51
		if (events != null) {
52
			properties.put(UPNP_EVENTS, events);
53
		}
54
		Event converted = new Event(TOPIC, properties);
55
		return converted;
56
	}
57
}
(-)src/org/eclipse/equinox/event/mapper/ConfigurationEventAdapter.java (-68 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.equinox.event.mapper;
12
13
import java.util.Hashtable;
14
import org.osgi.framework.ServiceReference;
15
import org.osgi.service.cm.ConfigurationEvent;
16
import org.osgi.service.event.Event;
17
import org.osgi.service.event.EventAdmin;
18
19
/**
20
 * @version $Revision: 1.2 $
21
 */
22
public class ConfigurationEventAdapter extends EventAdapter {
23
	// constants for Event topic substring
24
	public static final String HEADER = "org/osgi/service/cm/ConfigurationEvent";
25
	public static final String CM_UPDATED = "CM_UPDATED";
26
	public static final String CM_DELETED = "CM_DELETED";
27
	// constants for Event properties
28
	public static final String CM_FACTORY_PID = "cm.factoryPid";
29
	public static final String CM_PID = "cm.pid";
30
	private ConfigurationEvent event;
31
32
	public ConfigurationEventAdapter(ConfigurationEvent event, EventAdmin eventAdmin) {
33
		super(eventAdmin);
34
		this.event = event;
35
	}
36
37
	/**
38
	 * @see org.eclipse.equinox.event.mapper.EventAdapter#convert()
39
	 */
40
	public Event convert() {
41
		String typename = null;
42
		switch (event.getType()) {
43
			case ConfigurationEvent.CM_UPDATED :
44
				typename = CM_UPDATED;
45
				break;
46
			case ConfigurationEvent.CM_DELETED :
47
				typename = CM_DELETED;
48
				break;
49
			default :
50
				return null;
51
		}
52
		String topic = HEADER + Constants.TOPIC_SEPARATOR + typename;
53
		Hashtable properties = new Hashtable();
54
		ServiceReference ref = event.getReference();
55
		if (ref == null) {
56
			throw new RuntimeException("ServiceEvent.getServiceReference() is null");
57
		}
58
		properties.put(CM_PID, event.getPid());
59
		if (event.getFactoryPid() != null) {
60
			properties.put(CM_FACTORY_PID, event.getFactoryPid());
61
		}
62
		putServiceReferenceProperties(properties, ref);
63
		// assert objectClass includes
64
		// "org.osgi.service.cm.ConfigurationAdmin"
65
		Event converted = new Event(topic, properties);
66
		return converted;
67
	}
68
}
(-)src/org/eclipse/equinox/event/mapper/LogEntryAdapter.java (-78 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.equinox.event.mapper;
13
14
import java.util.Hashtable;
15
import org.osgi.framework.Bundle;
16
import org.osgi.framework.ServiceReference;
17
import org.osgi.service.event.Event;
18
import org.osgi.service.event.EventAdmin;
19
import org.osgi.service.log.LogEntry;
20
import org.osgi.service.log.LogService;
21
22
/**
23
 * @version $Revision: 1.2 $
24
 */
25
public class LogEntryAdapter extends EventAdapter {
26
	// constants for Event topic substring
27
	public static final String TOPIC = "org/osgi/service/log/LogEntry";
28
	// constants for Event properties
29
	public static final String TIMESTAMP = "timestamp";
30
	public static final String MESSAGE = "message";
31
	public static final String LOG_LEVEL = "log.level";
32
	public static final String LOG_ENTRY = "log.entry";
33
	private LogEntry entry;
34
35
	public LogEntryAdapter(LogEntry entry, EventAdmin eventAdmin) {
36
		super(eventAdmin);
37
		this.entry = entry;
38
	}
39
40
	/**
41
	 * @see org.eclipse.equinox.event.mapper.EventAdapter#convert()
42
	 */
43
	public Event convert() {
44
		String topic = TOPIC;
45
		int level = entry.getLevel();
46
		switch (level) {
47
			case LogService.LOG_ERROR :
48
			case LogService.LOG_WARNING :
49
			case LogService.LOG_INFO :
50
			case LogService.LOG_DEBUG :
51
				break;
52
			default :
53
				// other log levels are represented by their decimal value
54
				topic += Constants.TOPIC_SEPARATOR + level;
55
		}
56
		Hashtable properties = new Hashtable();
57
		Bundle bundle = entry.getBundle();
58
		if (bundle == null) {
59
			throw new RuntimeException("LogEntry.getBundle() returns null");
60
		}
61
		putBundleProperties(properties, bundle);
62
		Throwable t = entry.getException();
63
		if (t != null) {
64
			putExceptionProperties(properties, t);
65
		}
66
		ServiceReference ref = entry.getServiceReference();
67
		if (ref != null) {
68
			putServiceReferenceProperties(properties, ref);
69
		}
70
		properties.put(LOG_ENTRY, entry);
71
		properties.put(LOG_LEVEL, new Integer(entry.getLevel()));
72
		if (entry.getMessage() != null)
73
			properties.put(MESSAGE, entry.getMessage());
74
		properties.put(TIMESTAMP, new Long(entry.getTime()));
75
		Event converted = new Event(topic, properties);
76
		return converted;
77
	}
78
}
(-)src/org/eclipse/equinox/event/mapper/BundleEventAdapter.java (-12 / +11 lines)
Lines 21-34 Link Here
21
 */
21
 */
22
public class BundleEventAdapter extends EventAdapter {
22
public class BundleEventAdapter extends EventAdapter {
23
	// constants for Event topic substring
23
	// constants for Event topic substring
24
	public static final String HEADER = "org/osgi/framework/BundleEvent";
24
	public static final String HEADER = "org/osgi/framework/BundleEvent"; //$NON-NLS-1$
25
	public static final String INSTALLED = "INSTALLED";
25
	public static final String INSTALLED = "INSTALLED"; //$NON-NLS-1$
26
	public static final String STOPPED = "STOPPED";
26
	public static final String STOPPED = "STOPPED"; //$NON-NLS-1$
27
	public static final String STARTED = "STARTED";
27
	public static final String STARTED = "STARTED"; //$NON-NLS-1$
28
	public static final String UPDATED = "UPDATED";
28
	public static final String UPDATED = "UPDATED"; //$NON-NLS-1$
29
	public static final String UNINSTALLED = "UNINSTALLED";
29
	public static final String UNINSTALLED = "UNINSTALLED"; //$NON-NLS-1$
30
	public static final String RESOLVED = "RESOLVED";
30
	public static final String RESOLVED = "RESOLVED"; //$NON-NLS-1$
31
	public static final String UNRESOLVED = "UNRESOLVED";
31
	public static final String UNRESOLVED = "UNRESOLVED"; //$NON-NLS-1$
32
	private BundleEvent event;
32
	private BundleEvent event;
33
33
34
	public BundleEventAdapter(BundleEvent event, EventAdmin eventAdmin) {
34
	public BundleEventAdapter(BundleEvent event, EventAdmin eventAdmin) {
Lines 66-81 Link Here
66
				break;
66
				break;
67
			default :
67
			default :
68
				// unknown events must be send as their decimal value
68
				// unknown events must be send as their decimal value
69
				typename = "" + event.getType();
69
				typename = Integer.toString(event.getType());
70
		}
70
		}
71
		String topic = HEADER + Constants.TOPIC_SEPARATOR + typename;
71
		String topic = HEADER + Constants.TOPIC_SEPARATOR + typename;
72
		Hashtable properties = new Hashtable();
72
		Hashtable properties = new Hashtable();
73
		Bundle bundle = event.getBundle();
73
		Bundle bundle = event.getBundle();
74
		if (bundle == null) {
74
		if (bundle == null) {
75
			throw new RuntimeException("BundleEvent.getBundle() returns null");
75
			throw new RuntimeException("BundleEvent.getBundle() returns null"); //$NON-NLS-1$
76
		} else {
77
			putBundleProperties(properties, bundle);
78
		}
76
		}
77
		putBundleProperties(properties, bundle);
79
		properties.put(Constants.EVENT, event);
78
		properties.put(Constants.EVENT, event);
80
		Event converted = new Event(topic, properties);
79
		Event converted = new Event(topic, properties);
81
		return converted;
80
		return converted;
(-)META-INF/MANIFEST.MF (-5 / +1 lines)
Lines 1-18 Link Here
1
Bundle-ManifestVersion: 2
1
Bundle-ManifestVersion: 2
2
Bundle-Name: %bundleName
2
Bundle-Name: %bundleName
3
Bundle-Version: 1.0.200.qualifier
3
Bundle-Version: 1.1.0.qualifier
4
Bundle-SymbolicName: org.eclipse.equinox.event
4
Bundle-SymbolicName: org.eclipse.equinox.event
5
Bundle-Activator: org.eclipse.equinox.event.Activator
5
Bundle-Activator: org.eclipse.equinox.event.Activator
6
Bundle-Copyright: %bundleCopyright
6
Bundle-Copyright: %bundleCopyright
7
Import-Package: org.eclipse.osgi.framework.eventmgr;version="1.1.0",
7
Import-Package: org.eclipse.osgi.framework.eventmgr;version="1.1.0",
8
 org.eclipse.osgi.util,
8
 org.eclipse.osgi.util,
9
 org.osgi.framework,
9
 org.osgi.framework,
10
 org.osgi.service.cm,
11
 org.osgi.service.event,
10
 org.osgi.service.event,
12
 org.osgi.service.log,
11
 org.osgi.service.log,
13
 org.osgi.service.upnp,
14
 org.osgi.service.useradmin,
15
 org.osgi.service.wireadmin,
16
 org.osgi.util.tracker
12
 org.osgi.util.tracker
17
Export-Package: org.eclipse.equinox.event; x-internal:=true,
13
Export-Package: org.eclipse.equinox.event; x-internal:=true,
18
 org.eclipse.equinox.event.mapper; x-internal:=true
14
 org.eclipse.equinox.event.mapper; x-internal:=true

Return to bug 202278