blob: 87b16e5491bad0c401b307eb8f847d9791e891f2 [file] [log] [blame]
Richard S. Hall930fecc2005-08-16 18:33:34 +00001/*
2 * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/ServiceReference.java,v 1.11 2005/05/13 20:32:55 hargrave Exp $
3 *
4 * Copyright (c) OSGi Alliance (2000, 2005). All Rights Reserved.
5 *
6 * This program and the accompanying materials are made available under the
7 * terms of the Eclipse Public License v1.0 which accompanies this
8 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html.
9 */
10
11package org.osgi.framework;
12
13import java.util.Dictionary;
14
15/**
16 * A reference to a service.
17 *
18 * <p>
19 * The Framework returns <code>ServiceReference</code> objects from the
20 * <code>BundleContext.getServiceReference</code> and
21 * <code>BundleContext.getServiceReferences</code> methods.
22 * <p>
23 * A <code>ServiceReference</code> object may be shared between bundles and can be
24 * used to examine the properties of the service and to get the service object.
25 * <p>
26 * Every service registered in the Framework has a unique
27 * <code>ServiceRegistration</code> object and may have multiple, distinct
28 * <code>ServiceReference</code> objects referring to it.
29 * <code>ServiceReference</code> objects associated with a
30 * <code>ServiceRegistration</code> object have the same <code>hashCode</code>
31 * and are considered equal (more specifically, their <code>equals()</code>
32 * method will return <code>true</code> when compared).
33 * <p>
34 * If the same service object is registered multiple times,
35 * <code>ServiceReference</code> objects associated with different
36 * <code>ServiceRegistration</code> objects are not equal.
37 *
38 * @version $Revision: 1.11 $
39 * @see BundleContext#getServiceReference
40 * @see BundleContext#getServiceReferences
41 * @see BundleContext#getService
42 */
43
44public abstract interface ServiceReference {
45 /**
46 * Returns the property value to which the specified property key is mapped
47 * in the properties <code>Dictionary</code> object of the service
48 * referenced by this <code>ServiceReference</code> object.
49 *
50 * <p>
51 * Property keys are case-insensitive.
52 *
53 * <p>
54 * This method must continue to return property values after the service has
55 * been unregistered. This is so references to unregistered services (for
56 * example, <code>ServiceReference</code> objects stored in the log) can
57 * still be interrogated.
58 *
59 * @param key The property key.
60 * @return The property value to which the key is mapped; <code>null</code>
61 * if there is no property named after the key.
62 */
63 public abstract Object getProperty(String key);
64
65 /**
66 * Returns an array of the keys in the properties <code>Dictionary</code>
67 * object of the service referenced by this <code>ServiceReference</code>
68 * object.
69 *
70 * <p>
71 * This method will continue to return the keys after the service has been
72 * unregistered. This is so references to unregistered services (for
73 * example, <code>ServiceReference</code> objects stored in the log) can
74 * still be interrogated.
75 *
76 * <p>
77 * This method is <i>case-preserving </i>; this means that every key in the
78 * returned array must have the same case as the corresponding key in the
79 * properties <code>Dictionary</code> that was passed to the
80 * {@link BundleContext#registerService(String[],Object,Dictionary)}or
81 * {@link ServiceRegistration#setProperties}methods.
82 *
83 * @return An array of property keys.
84 */
85 public abstract String[] getPropertyKeys();
86
87 /**
88 * Returns the bundle that registered the service referenced by this
89 * <code>ServiceReference</code> object.
90 *
91 * <p>
92 * This method must return <code>null</code> when the service has
93 * been unregistered. This can be used to determine if the service has been
94 * unregistered.
95 *
96 * @return The bundle that registered the service referenced by this
97 * <code>ServiceReference</code> object; <code>null</code> if
98 * that service has already been unregistered.
99 * @see BundleContext#registerService(String[],Object,Dictionary)
100 */
101 public abstract Bundle getBundle();
102
103 /**
104 * Returns the bundles that are using the service referenced by this
105 * <code>ServiceReference</code> object. Specifically, this method returns
106 * the bundles whose usage count for that service is greater than zero.
107 *
108 * @return An array of bundles whose usage count for the service referenced
109 * by this <code>ServiceReference</code> object is greater than
110 * zero; <code>null</code> if no bundles are currently using that
111 * service.
112 *
113 * @since 1.1
114 */
115 public abstract Bundle[] getUsingBundles();
116
117 /**
118 * Tests if the bundle that registered the service referenced by this
119 * <code>ServiceReference</code> and the specified bundle use the same source
120 * for the package of the specified class name.
121 * <p>
122 * This method performs the following checks:
123 * <ol>
124 * <li>Get the package name from the specified class name.</li>
125 * <li>For the bundle that registered the service referenced by this
126 * <code>ServiceReference</code> (registrant bundle); find the source for the
127 * package. If no source is found then return <code>true</code> if the
128 * registrant bundle is equal to the specified bundle; otherwise return
129 * <code>false</code>.</li>
130 * <li>If the package source of the registrant bundle is equal to the
131 * package source of the specified bundle then return <code>true</code>;
132 * otherwise return <code>false</code>.</li>
133 * </ol>
134 *
135 * @param bundle The <code>Bundle</code> object to check.
136 * @param className The class name to check.
137 * @return <code>true</code> if the bundle which registered the service
138 * referenced by this <code>ServiceReference</code> and the specified
139 * bundle use the same source for the package of the specified class
140 * name. Otherwise <code>false</code> is returned.
141 *
142 * @since 1.3
143 */
144 public abstract boolean isAssignableTo(Bundle bundle, String className);
145
146}