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 334582 | Differences between
and this patch

Collapse All | Expand All

(-).settings/.api_filters (-4 / +34 lines)
Lines 419-424 Link Here
419
</message_arguments>
419
</message_arguments>
420
</filter>
420
</filter>
421
</resource>
421
</resource>
422
<resource path="osgi/src/org/osgi/framework/AdaptPermission.java" type="org.osgi.framework.AdaptPermission">
423
<filter comment="Ignore OSGi API" id="1110441988">
424
<message_arguments>
425
<message_argument value="org.osgi.framework.AdaptPermission"/>
426
</message_arguments>
427
</filter>
428
</resource>
429
<resource path="osgi/src/org/osgi/framework/AdminPermission.java" type="org.osgi.framework.AdminPermission">
430
<filter comment="Ignore OSGi API" id="1141899266">
431
<message_arguments>
432
<message_argument value="1.6"/>
433
<message_argument value="3.7"/>
434
<message_argument value="WEAVE"/>
435
</message_arguments>
436
</filter>
437
</resource>
422
<resource path="osgi/src/org/osgi/framework/Bundle.java" type="org.osgi.framework.Bundle">
438
<resource path="osgi/src/org/osgi/framework/Bundle.java" type="org.osgi.framework.Bundle">
423
<filter id="403853384">
439
<filter id="403853384">
424
<message_arguments>
440
<message_arguments>
Lines 699-704 Link Here
699
<message_arguments>
715
<message_arguments>
700
<message_argument value="1.6"/>
716
<message_argument value="1.6"/>
701
<message_argument value="3.7"/>
717
<message_argument value="3.7"/>
718
<message_argument value="FILTER_DIRECTIVE"/>
719
</message_arguments>
720
</filter>
721
<filter comment="Ignore OSGi API" id="1209008130">
722
<message_arguments>
723
<message_argument value="1.6"/>
724
<message_argument value="3.7"/>
702
<message_argument value="FRAMEWORK_BSNVERSION"/>
725
<message_argument value="FRAMEWORK_BSNVERSION"/>
703
</message_arguments>
726
</message_arguments>
704
</filter>
727
</filter>
Lines 910-915 Link Here
910
</message_arguments>
933
</message_arguments>
911
</filter>
934
</filter>
912
</resource>
935
</resource>
936
<resource path="osgi/src/org/osgi/framework/hooks/service/ListenerHook.java" type="org.osgi.framework.hooks.service.ListenerHook$ListenerInfo">
937
<filter comment="Ignore OSGi API" id="403853384">
938
<message_arguments>
939
<message_argument value="org.osgi.framework.hooks.service.ListenerHook.ListenerInfo"/>
940
</message_arguments>
941
</filter>
942
</resource>
913
<resource path="osgi/src/org/osgi/framework/hooks/weaving/WeavingException.java" type="org.osgi.framework.hooks.weaving.WeavingException">
943
<resource path="osgi/src/org/osgi/framework/hooks/weaving/WeavingException.java" type="org.osgi.framework.hooks.weaving.WeavingException">
914
<filter comment="Ignore OSGi API" id="1110441988">
944
<filter comment="Ignore OSGi API" id="1110441988">
915
<message_arguments>
945
<message_arguments>
Lines 966-982 Link Here
966
</message_arguments>
996
</message_arguments>
967
</filter>
997
</filter>
968
</resource>
998
</resource>
969
<resource path="osgi/src/org/osgi/framework/wiring/BundleWiring.java" type="org.osgi.framework.wiring.BundleWiring">
999
<resource path="osgi/src/org/osgi/framework/wiring/BundleRevisions.java" type="org.osgi.framework.wiring.BundleRevisions">
970
<filter comment="Ignore OSGi API" id="1110441988">
1000
<filter comment="Ignore OSGi API" id="1110441988">
971
<message_arguments>
1001
<message_arguments>
972
<message_argument value="org.osgi.framework.wiring.BundleWiring"/>
1002
<message_argument value="org.osgi.framework.wiring.BundleRevisions"/>
973
</message_arguments>
1003
</message_arguments>
974
</filter>
1004
</filter>
975
</resource>
1005
</resource>
976
<resource path="osgi/src/org/osgi/framework/wiring/BundleWirings.java" type="org.osgi.framework.wiring.BundleWirings">
1006
<resource path="osgi/src/org/osgi/framework/wiring/BundleWiring.java" type="org.osgi.framework.wiring.BundleWiring">
977
<filter comment="Ignore OSGi API" id="1110441988">
1007
<filter comment="Ignore OSGi API" id="1110441988">
978
<message_arguments>
1008
<message_arguments>
979
<message_argument value="org.osgi.framework.wiring.BundleWirings"/>
1009
<message_argument value="org.osgi.framework.wiring.BundleWiring"/>
980
</message_arguments>
1010
</message_arguments>
981
</filter>
1011
</filter>
982
</resource>
1012
</resource>
(-)core/framework/org/eclipse/osgi/framework/internal/core/AbstractBundle.java (-2 / +22 lines)
Lines 30-37 Link Here
30
import org.eclipse.osgi.util.NLS;
30
import org.eclipse.osgi.util.NLS;
31
import org.osgi.framework.*;
31
import org.osgi.framework.*;
32
import org.osgi.framework.startlevel.BundleStartLevel;
32
import org.osgi.framework.startlevel.BundleStartLevel;
33
import org.osgi.framework.wiring.BundleRevision;
33
import org.osgi.framework.wiring.*;
34
import org.osgi.framework.wiring.BundleWiring;
35
34
36
/**
35
/**
37
 * This object is given out to bundles and wraps the internal Bundle object. It
36
 * This object is given out to bundles and wraps the internal Bundle object. It
Lines 1473-1479 Link Here
1473
			BundleDescription description = getBundleDescription();
1472
			BundleDescription description = getBundleDescription();
1474
			return (A) description.getBundleWiring();
1473
			return (A) description.getBundleWiring();
1475
		}
1474
		}
1475
		if (BundleRevisions.class.equals(adapterType)) {
1476
			return (A) new BundleRevisions() {
1477
				public Bundle getBundle() {
1478
					return AbstractBundle.this;
1479
				}
1480
1481
				public List<BundleRevision> getRevisions() {
1482
					List<BundleRevision> revisions = new ArrayList<BundleRevision>();
1483
					BundleDescription current = getBundleDescription();
1484
					if (current != null)
1485
						revisions.add(current);
1486
					BundleDescription[] removals = framework.adaptor.getState().getRemovalPending();
1487
					for (BundleDescription removed : removals) {
1488
						if (removed.getBundleId() == getBundleId() && removed != current) {
1489
							revisions.add(removed);
1490
						}
1491
					}
1492
					return revisions;
1493
				}
1476
1494
1495
			};
1496
		}
1477
		if (BundleRevision.class.equals(adapterType)) {
1497
		if (BundleRevision.class.equals(adapterType)) {
1478
			return (A) getBundleDescription();
1498
			return (A) getBundleDescription();
1479
		}
1499
		}
(-)core/framework/org/eclipse/osgi/framework/internal/core/BundleFragment.java (-45 / +1 lines)
Lines 13-28 Link Here
13
13
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.net.URL;
15
import java.net.URL;
16
import java.util.*;
16
import java.util.Enumeration;
17
import org.eclipse.osgi.framework.adaptor.BundleData;
17
import org.eclipse.osgi.framework.adaptor.BundleData;
18
import org.eclipse.osgi.framework.debug.Debug;
18
import org.eclipse.osgi.framework.debug.Debug;
19
import org.eclipse.osgi.internal.loader.BundleLoader;
19
import org.eclipse.osgi.internal.loader.BundleLoader;
20
import org.eclipse.osgi.service.resolver.BundleDescription;
21
import org.eclipse.osgi.service.resolver.HostSpecification;
22
import org.eclipse.osgi.util.NLS;
20
import org.eclipse.osgi.util.NLS;
23
import org.osgi.framework.*;
21
import org.osgi.framework.*;
24
import org.osgi.framework.wiring.BundleWiring;
25
import org.osgi.framework.wiring.BundleWirings;
26
22
27
public class BundleFragment extends AbstractBundle {
23
public class BundleFragment extends AbstractBundle {
28
24
Lines 335-378 Link Here
335
		// Fragments cannot have a BundleContext.
331
		// Fragments cannot have a BundleContext.
336
		return null;
332
		return null;
337
	}
333
	}
338
339
	@SuppressWarnings("unchecked")
340
	public <A> A adapt(Class<A> adapterType) {
341
		if (BundleWirings.class.equals(adapterType)) {
342
			return (A) new BundleWirings() {
343
				public Bundle getBundle() {
344
					return BundleFragment.this;
345
				}
346
347
				public List<BundleWiring> getWirings() {
348
					List<BundleWiring> wirings = new ArrayList<BundleWiring>();
349
					BundleDescription current = getBundleDescription();
350
					BundleDescription[] removed = framework.adaptor.getState().getRemovalPending();
351
352
					int i = -1;
353
					do {
354
						HostSpecification hostSpec = null;
355
						if (i == -1) {
356
							if (current != null)
357
								hostSpec = current.getHost();
358
						} else if (removed[i] != current && removed[i].getBundleId() == getBundleId()) {
359
							hostSpec = removed[i].getHost();
360
						}
361
						BundleDescription[] hostDescs = hostSpec == null ? null : hostSpec.getHosts();
362
						if (hostDescs != null) {
363
							for (BundleDescription host : hostDescs) {
364
								BundleWiring wiring = host.getBundleWiring();
365
								if (wiring != null)
366
									wirings.add(wiring);
367
							}
368
						}
369
						i++;
370
					} while (i < removed.length);
371
					return wirings;
372
				}
373
374
			};
375
		}
376
		return super.adapt(adapterType);
377
	}
378
}
334
}
(-)core/framework/org/eclipse/osgi/framework/internal/core/BundleHost.java (-32 / +1 lines)
Lines 13-19 Link Here
13
13
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.net.URL;
15
import java.net.URL;
16
import java.util.*;
16
import java.util.Enumeration;
17
import org.eclipse.osgi.framework.adaptor.*;
17
import org.eclipse.osgi.framework.adaptor.*;
18
import org.eclipse.osgi.framework.debug.Debug;
18
import org.eclipse.osgi.framework.debug.Debug;
19
import org.eclipse.osgi.framework.log.FrameworkLogEntry;
19
import org.eclipse.osgi.framework.log.FrameworkLogEntry;
Lines 22-29 Link Here
22
import org.eclipse.osgi.service.resolver.BundleDescription;
22
import org.eclipse.osgi.service.resolver.BundleDescription;
23
import org.eclipse.osgi.util.NLS;
23
import org.eclipse.osgi.util.NLS;
24
import org.osgi.framework.*;
24
import org.osgi.framework.*;
25
import org.osgi.framework.wiring.BundleWiring;
26
import org.osgi.framework.wiring.BundleWirings;
27
25
28
public class BundleHost extends AbstractBundle {
26
public class BundleHost extends AbstractBundle {
29
	public static final int LAZY_TRIGGER = 0x40000000;
27
	public static final int LAZY_TRIGGER = 0x40000000;
Lines 679-711 Link Here
679
		return (bcl instanceof ClassLoader) ? (ClassLoader) bcl : null;
677
		return (bcl instanceof ClassLoader) ? (ClassLoader) bcl : null;
680
	}
678
	}
681
679
682
	@SuppressWarnings("unchecked")
683
	public <A> A adapt(Class<A> adapterType) {
684
		if (BundleWirings.class.equals(adapterType)) {
685
			return (A) new BundleWirings() {
686
				public Bundle getBundle() {
687
					return BundleHost.this;
688
				}
689
690
				public List<BundleWiring> getWirings() {
691
					List<BundleWiring> wirings = new ArrayList<BundleWiring>();
692
					BundleWiring current = adapt(BundleWiring.class);
693
					if (current != null)
694
						wirings.add(current);
695
					BundleDescription[] removals = framework.adaptor.getState().getRemovalPending();
696
					for (BundleDescription removed : removals) {
697
						if (removed.getBundleId() == getBundleId()) {
698
							BundleWiring removedWiring = removed.getBundleWiring();
699
							if (removedWiring != null && removedWiring != current)
700
								wirings.add(removedWiring);
701
						}
702
					}
703
					return wirings;
704
				}
705
706
			};
707
		}
708
		return super.adapt(adapterType);
709
	}
710
711
}
680
}
(-)osgi/src/org/osgi/framework/AdaptPermission.java (+635 lines)
Added Link Here
1
/*
2
 * Copyright (c) OSGi Alliance (2010, 2011). All Rights Reserved.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package org.osgi.framework;
17
18
import java.io.IOException;
19
import java.io.NotSerializableException;
20
import java.io.ObjectInputStream;
21
import java.io.ObjectOutputStream;
22
import java.io.ObjectStreamField;
23
import java.security.AccessController;
24
import java.security.BasicPermission;
25
import java.security.Permission;
26
import java.security.PermissionCollection;
27
import java.security.PrivilegedAction;
28
import java.util.ArrayList;
29
import java.util.Collection;
30
import java.util.Collections;
31
import java.util.Enumeration;
32
import java.util.HashMap;
33
import java.util.List;
34
import java.util.Map;
35
36
/**
37
 * A bundle's authority to adapt an object to a type.
38
 * 
39
 * <p>
40
 * {@code AdaptPermission} has one action: {@code adapt}.
41
 * 
42
 * @ThreadSafe
43
 * @version $Id: bc4c5d392d2534a7744f6fc00f4665502f82033c $
44
 */
45
public class AdaptPermission extends BasicPermission {
46
47
	private static final long						serialVersionUID	= 1L;
48
49
	/**
50
	 * The action string {@code initiate}.
51
	 */
52
	public final static String						ADAPT				= "adapt";
53
54
	private final static int						ACTION_ADAPT		= 0x00000001;
55
	private final static int						ACTION_ALL			= ACTION_ADAPT;
56
	final static int								ACTION_NONE			= 0;
57
58
	/**
59
	 * The actions mask.
60
	 */
61
	transient int									action_mask;
62
63
	/**
64
	 * The actions in canonical form.
65
	 * 
66
	 * @serial
67
	 */
68
	private volatile String							actions				= null;
69
70
	/**
71
	 * The bundle used by this AdaptPermission.
72
	 */
73
	transient final Bundle							bundle;
74
75
	/**
76
	 * This holds a Filter matching object used to evaluate the filter in
77
	 * implies.
78
	 */
79
	transient Filter								filter;
80
81
	/**
82
	 * This map holds the properties of the permission, used to match a filter
83
	 * in implies. This is not initialized until necessary, and then cached in
84
	 * this object.
85
	 */
86
	private transient volatile Map<String, Object>	properties;
87
88
	/**
89
	 * Creates a new granted {@code AdaptPermission} object.
90
	 * 
91
	 * This constructor must only be used to create a permission that is going
92
	 * to be checked.
93
	 * <p>
94
	 * Examples:
95
	 * 
96
	 * <pre>
97
	 * (adaptClass=com.acme.*)
98
	 * (&amp;(signer=\*,o=ACME,c=US)(adaptClass=com.acme.*))
99
	 * (signer=\*,o=ACME,c=US)
100
	 * </pre>
101
	 * 
102
	 * <p>
103
	 * When a signer key is used within the filter expression the signer value
104
	 * must escape the special filter chars ('*', '(', ')').
105
	 * <p>
106
	 * The name is specified as a filter expression. The filter gives access to
107
	 * the following attributes:
108
	 * <ul>
109
	 * <li>signer - A Distinguished Name chain used to sign the exporting
110
	 * bundle. Wildcards in a DN are not matched according to the filter string
111
	 * rules, but according to the rules defined for a DN chain.</li>
112
	 * <li>location - The location of the exporting bundle.</li>
113
	 * <li>id - The bundle ID of the exporting bundle.</li>
114
	 * <li>name - The symbolic name of the exporting bundle.</li>
115
	 * <li>adaptClass - The name of the type to which an object can be adapted.</li>
116
	 * </ul>
117
	 * Filter attribute names are processed in a case sensitive manner.
118
	 * 
119
	 * @param filter A filter expression. Filter attribute names are processed
120
	 *        in a case sensitive manner. A special value of {@code "*"} can be
121
	 *        used to match all adaptations.
122
	 * @param actions {@code adapt}.
123
	 * @throws IllegalArgumentException If the filter has an invalid syntax.
124
	 */
125
	public AdaptPermission(String filter, String actions) {
126
		this(parseFilter(filter), parseActions(actions));
127
	}
128
129
	/**
130
	 * Creates a new requested {@code AdaptPermission} object to be used by the
131
	 * code that must perform {@code checkPermission}. {@code AdaptPermission}
132
	 * objects created with this constructor cannot be added to an
133
	 * {@code AdaptPermission} permission collection.
134
	 * 
135
	 * @param adaptClass The name of the type to which an object can be adapted.
136
	 * @param adaptableBundle The bundle associated with the object being
137
	 *        adapted.
138
	 * @param actions {@code adapt}.
139
	 */
140
	public AdaptPermission(String adaptClass, Bundle adaptableBundle,
141
			String actions) {
142
		super(adaptClass);
143
		setTransients(null, parseActions(actions));
144
		this.bundle = adaptableBundle;
145
		if (adaptClass == null) {
146
			throw new NullPointerException("adaptClass must not be null");
147
		}
148
		if (adaptableBundle == null) {
149
			throw new NullPointerException("adaptableBundle must not be null");
150
		}
151
	}
152
153
	/**
154
	 * Package private constructor used by AdaptPermissionCollection.
155
	 * 
156
	 * @param filter name filter
157
	 * @param mask action mask
158
	 */
159
	AdaptPermission(Filter filter, int mask) {
160
		super((filter == null) ? "*" : filter.toString());
161
		setTransients(filter, mask);
162
		this.bundle = null;
163
	}
164
165
	/**
166
	 * Called by constructors and when deserialized.
167
	 * 
168
	 * @param filter Permission's filter or {@code null} for wildcard.
169
	 * @param mask action mask
170
	 */
171
	private void setTransients(Filter filter, int mask) {
172
		this.filter = filter;
173
		if ((mask == ACTION_NONE) || ((mask & ACTION_ALL) != mask)) {
174
			throw new IllegalArgumentException("invalid action string");
175
		}
176
		this.action_mask = mask;
177
	}
178
179
	/**
180
	 * Parse action string into action mask.
181
	 * 
182
	 * @param actions Action string.
183
	 * @return action mask.
184
	 */
185
	private static int parseActions(String actions) {
186
		boolean seencomma = false;
187
188
		int mask = ACTION_NONE;
189
190
		if (actions == null) {
191
			return mask;
192
		}
193
194
		char[] a = actions.toCharArray();
195
196
		int i = a.length - 1;
197
		if (i < 0)
198
			return mask;
199
200
		while (i != -1) {
201
			char c;
202
203
			// skip whitespace
204
			while ((i != -1)
205
					&& ((c = a[i]) == ' ' || c == '\r' || c == '\n'
206
							|| c == '\f' || c == '\t'))
207
				i--;
208
209
			// check for the known strings
210
			int matchlen;
211
212
			if (i >= 4 && (a[i - 4] == 'a' || a[i - 4] == 'A')
213
					&& (a[i - 3] == 'd' || a[i - 3] == 'D')
214
					&& (a[i - 2] == 'a' || a[i - 2] == 'A')
215
					&& (a[i - 1] == 'p' || a[i - 1] == 'P')
216
					&& (a[i] == 't' || a[i] == 'T')) {
217
				matchlen = 5;
218
				mask |= ACTION_ADAPT;
219
220
			}
221
			else {
222
				// parse error
223
				throw new IllegalArgumentException("invalid actions: "
224
						+ actions);
225
			}
226
227
			// make sure we didn't just match the tail of a word
228
			// like "ackbarfadapt". Also, skip to the comma.
229
			seencomma = false;
230
			while (i >= matchlen && !seencomma) {
231
				switch (a[i - matchlen]) {
232
					case ',' :
233
						seencomma = true;
234
						/* FALLTHROUGH */
235
					case ' ' :
236
					case '\r' :
237
					case '\n' :
238
					case '\f' :
239
					case '\t' :
240
						break;
241
					default :
242
						throw new IllegalArgumentException(
243
								"invalid permission: " + actions);
244
				}
245
				i--;
246
			}
247
248
			// point i at the location of the comma minus one (or -1).
249
			i -= matchlen;
250
		}
251
252
		if (seencomma) {
253
			throw new IllegalArgumentException("invalid actions: " + actions);
254
		}
255
256
		return mask;
257
	}
258
259
	/**
260
	 * Parse filter string into a Filter object.
261
	 * 
262
	 * @param filterString The filter string to parse.
263
	 * @return a Filter for this bundle.
264
	 * @throws IllegalArgumentException If the filter syntax is invalid.
265
	 */
266
	private static Filter parseFilter(String filterString) {
267
		filterString = filterString.trim();
268
		if (filterString.equals("*")) {
269
			return null;
270
		}
271
		try {
272
			return FrameworkUtil.createFilter(filterString);
273
		}
274
		catch (InvalidSyntaxException e) {
275
			IllegalArgumentException iae = new IllegalArgumentException(
276
					"invalid filter");
277
			iae.initCause(e);
278
			throw iae;
279
		}
280
	}
281
282
	/**
283
	 * Determines if the specified permission is implied by this object.
284
	 * 
285
	 * <p>
286
	 * This method checks that the filter of the target is implied by the adapt
287
	 * class name of this object. The list of {@code AdaptPermission} actions
288
	 * must either match or allow for the list of the target object to imply the
289
	 * target {@code AdaptPermission} action.
290
	 * <p>
291
	 * 
292
	 * @param p The requested permission.
293
	 * @return {@code true} if the specified permission is implied by this
294
	 *         object; {@code false} otherwise.
295
	 */
296
	public boolean implies(Permission p) {
297
		if (!(p instanceof AdaptPermission)) {
298
			return false;
299
		}
300
		AdaptPermission requested = (AdaptPermission) p;
301
		if (bundle != null) {
302
			return false;
303
		}
304
		// if requested permission has a filter, then it is an invalid argument
305
		if (requested.filter != null) {
306
			return false;
307
		}
308
		return implies0(requested, ACTION_NONE);
309
	}
310
311
	/**
312
	 * Internal implies method. Used by the implies and the permission
313
	 * collection implies methods.
314
	 * 
315
	 * @param requested The requested AdaptPermission which has already be
316
	 *        validated as a proper argument. The requested AdaptPermission must
317
	 *        not have a filter expression.
318
	 * @param effective The effective actions with which to start.
319
	 * @return {@code true} if the specified permission is implied by this
320
	 *         object; {@code false} otherwise.
321
	 */
322
	boolean implies0(AdaptPermission requested, int effective) {
323
		/* check actions first - much faster */
324
		effective |= action_mask;
325
		final int desired = requested.action_mask;
326
		if ((effective & desired) != desired) {
327
			return false;
328
		}
329
		/* Get filter */
330
		Filter f = filter;
331
		if (f == null) {
332
			// it's "*"
333
			return true;
334
		}
335
		return f.matches(requested.getProperties());
336
	}
337
338
	/**
339
	 * Returns the canonical string representation of the
340
	 * {@code AdaptPermission} actions.
341
	 * 
342
	 * <p>
343
	 * Always returns present {@code AdaptPermission} actions in the following
344
	 * order: {@code adapt}.
345
	 * 
346
	 * @return Canonical string representation of the {@code AdaptPermission}
347
	 *         actions.
348
	 */
349
	public String getActions() {
350
		String result = actions;
351
		if (result == null) {
352
			actions = result = ADAPT;
353
		}
354
		return result;
355
	}
356
357
	/**
358
	 * Returns a new {@code PermissionCollection} object suitable for storing
359
	 * {@code AdaptPermission} objects.
360
	 * 
361
	 * @return A new {@code PermissionCollection} object.
362
	 */
363
	public PermissionCollection newPermissionCollection() {
364
		return new AdaptPermissionCollection();
365
	}
366
367
	/**
368
	 * Determines the equality of two {@code AdaptPermission} objects.
369
	 * 
370
	 * This method checks that specified permission has the same name and
371
	 * {@code AdaptPermission} actions as this {@code AdaptPermission} object.
372
	 * 
373
	 * @param obj The object to test for equality with this
374
	 *        {@code AdaptPermission} object.
375
	 * @return {@code true} if {@code obj} is a {@code AdaptPermission}, and has
376
	 *         the same name and actions as this {@code AdaptPermission} object;
377
	 *         {@code false} otherwise.
378
	 */
379
	public boolean equals(Object obj) {
380
		if (obj == this) {
381
			return true;
382
		}
383
384
		if (!(obj instanceof AdaptPermission)) {
385
			return false;
386
		}
387
388
		AdaptPermission cp = (AdaptPermission) obj;
389
390
		return (action_mask == cp.action_mask)
391
				&& getName().equals(cp.getName())
392
				&& ((bundle == cp.bundle) || ((bundle != null) && bundle
393
						.equals(cp.bundle)));
394
	}
395
396
	/**
397
	 * Returns the hash code value for this object.
398
	 * 
399
	 * @return A hash code value for this object.
400
	 */
401
	public int hashCode() {
402
		int h = 31 * 17 + getName().hashCode();
403
		h = 31 * h + getActions().hashCode();
404
		if (bundle != null) {
405
			h = 31 * h + bundle.hashCode();
406
		}
407
		return h;
408
	}
409
410
	/**
411
	 * WriteObject is called to save the state of this permission object to a
412
	 * stream. The actions are serialized, and the superclass takes care of the
413
	 * name.
414
	 */
415
	private synchronized void writeObject(java.io.ObjectOutputStream s)
416
			throws IOException {
417
		if (bundle != null) {
418
			throw new NotSerializableException("cannot serialize");
419
		}
420
		// Write out the actions. The superclass takes care of the name
421
		// call getActions to make sure actions field is initialized
422
		if (actions == null)
423
			getActions();
424
		s.defaultWriteObject();
425
	}
426
427
	/**
428
	 * readObject is called to restore the state of this permission from a
429
	 * stream.
430
	 */
431
	private synchronized void readObject(java.io.ObjectInputStream s)
432
			throws IOException, ClassNotFoundException {
433
		// Read in the action, then initialize the rest
434
		s.defaultReadObject();
435
		setTransients(parseFilter(getName()), parseActions(actions));
436
	}
437
438
	/**
439
	 * Called by {@code <@link AdaptPermission#implies(Permission)>}. This
440
	 * method is only called on a requested permission which cannot have a
441
	 * filter set.
442
	 * 
443
	 * @return a map of properties for this permission.
444
	 */
445
	private Map<String, Object> getProperties() {
446
		Map<String, Object> result = properties;
447
		if (result != null) {
448
			return result;
449
		}
450
		final Map<String, Object> map = new HashMap<String, Object>(5);
451
		map.put("adaptClass", getName());
452
		if (bundle != null) {
453
			AccessController.doPrivileged(new PrivilegedAction<Object>() {
454
				public Object run() {
455
					map.put("id", new Long(bundle.getBundleId()));
456
					map.put("location", bundle.getLocation());
457
					String name = bundle.getSymbolicName();
458
					if (name != null) {
459
						map.put("name", name);
460
					}
461
					SignerProperty signer = new SignerProperty(bundle);
462
					if (signer.isBundleSigned()) {
463
						map.put("signer", signer);
464
					}
465
					return null;
466
				}
467
			});
468
		}
469
		return properties = map;
470
	}
471
}
472
473
/**
474
 * Stores a set of {@code AdaptPermission} permissions.
475
 * 
476
 * @see java.security.Permission
477
 * @see java.security.Permissions
478
 * @see java.security.PermissionCollection
479
 */
480
481
final class AdaptPermissionCollection extends PermissionCollection {
482
	static final long						serialVersionUID	= -3350758995234427603L;
483
	/**
484
	 * Collection of permissions.
485
	 * 
486
	 * @serial
487
	 * @GuardedBy this
488
	 */
489
	private Map<String, AdaptPermission>	permissions;
490
491
	/**
492
	 * Boolean saying if "*" is in the collection.
493
	 * 
494
	 * @serial
495
	 * @GuardedBy this
496
	 */
497
	private boolean							all_allowed;
498
499
	/**
500
	 * Create an empty AdaptPermissions object.
501
	 */
502
	public AdaptPermissionCollection() {
503
		permissions = new HashMap<String, AdaptPermission>();
504
		all_allowed = false;
505
	}
506
507
	/**
508
	 * Adds a permission to this permission collection.
509
	 * 
510
	 * @param permission The {@code AdaptPermission} object to add.
511
	 * @throws IllegalArgumentException If the specified permission is not a
512
	 *         {@code AdaptPermission} instance or was constructed with a Bundle
513
	 *         object.
514
	 * @throws SecurityException If this {@code AdaptPermissionCollection}
515
	 *         object has been marked read-only.
516
	 */
517
	public void add(final Permission permission) {
518
		if (!(permission instanceof AdaptPermission)) {
519
			throw new IllegalArgumentException("invalid permission: "
520
					+ permission);
521
		}
522
		if (isReadOnly()) {
523
			throw new SecurityException("attempt to add a Permission to a "
524
					+ "readonly PermissionCollection");
525
		}
526
527
		final AdaptPermission ap = (AdaptPermission) permission;
528
		if (ap.bundle != null) {
529
			throw new IllegalArgumentException("cannot add to collection: "
530
					+ ap);
531
		}
532
533
		final String name = ap.getName();
534
		synchronized (this) {
535
			Map<String, AdaptPermission> pc = permissions;
536
			final AdaptPermission existing = pc.get(name);
537
			if (existing != null) {
538
				final int oldMask = existing.action_mask;
539
				final int newMask = ap.action_mask;
540
				if (oldMask != newMask) {
541
					pc.put(name, new AdaptPermission(existing.filter, oldMask
542
							| newMask));
543
544
				}
545
			}
546
			else {
547
				pc.put(name, ap);
548
			}
549
550
			if (!all_allowed) {
551
				if (name.equals("*")) {
552
					all_allowed = true;
553
				}
554
			}
555
		}
556
	}
557
558
	/**
559
	 * Determines if the specified permissions implies the permissions expressed
560
	 * in {@code permission}.
561
	 * 
562
	 * @param permission The Permission object to compare with this
563
	 *        {@code AdaptPermission} object.
564
	 * @return {@code true} if {@code permission} is a proper subset of a
565
	 *         permission in the set; {@code false} otherwise.
566
	 */
567
	public boolean implies(final Permission permission) {
568
		if (!(permission instanceof AdaptPermission)) {
569
			return false;
570
		}
571
		final AdaptPermission requested = (AdaptPermission) permission;
572
		/* if requested permission has a filter, then it is an invalid argument */
573
		if (requested.filter != null) {
574
			return false;
575
		}
576
577
		int effective = AdaptPermission.ACTION_NONE;
578
579
		Collection<AdaptPermission> perms;
580
		synchronized (this) {
581
			Map<String, AdaptPermission> pc = permissions;
582
			/* short circuit if the "*" Permission was added */
583
			if (all_allowed) {
584
				AdaptPermission ap = pc.get("*");
585
				if (ap != null) {
586
					effective |= ap.action_mask;
587
					final int desired = requested.action_mask;
588
					if ((effective & desired) == desired) {
589
						return true;
590
					}
591
				}
592
			}
593
			perms = pc.values();
594
		}
595
		/* iterate one by one over filteredPermissions */
596
		for (AdaptPermission perm : perms) {
597
			if (perm.implies0(requested, effective)) {
598
				return true;
599
			}
600
		}
601
		return false;
602
	}
603
604
	/**
605
	 * Returns an enumeration of all {@code AdaptPermission} objects in the
606
	 * container.
607
	 * 
608
	 * @return Enumeration of all {@code AdaptPermission} objects.
609
	 */
610
	public synchronized Enumeration<Permission> elements() {
611
		List<Permission> all = new ArrayList<Permission>(permissions.values());
612
		return Collections.enumeration(all);
613
	}
614
615
	/* serialization logic */
616
	private static final ObjectStreamField[]	serialPersistentFields	= {
617
			new ObjectStreamField("permissions", HashMap.class),
618
			new ObjectStreamField("all_allowed", Boolean.TYPE)			};
619
620
	private synchronized void writeObject(ObjectOutputStream out)
621
			throws IOException {
622
		ObjectOutputStream.PutField pfields = out.putFields();
623
		pfields.put("permissions", permissions);
624
		pfields.put("all_allowed", all_allowed);
625
		out.writeFields();
626
	}
627
628
	private synchronized void readObject(java.io.ObjectInputStream in)
629
			throws IOException, ClassNotFoundException {
630
		ObjectInputStream.GetField gfields = in.readFields();
631
		permissions = (HashMap<String, AdaptPermission>) gfields.get(
632
				"permissions", null);
633
		all_allowed = gfields.get("all_allowed", false);
634
	}
635
}
(-)osgi/src/org/osgi/framework/AdminPermission.java (-46 / +69 lines)
Lines 1-5 Link Here
1
/*
1
/*
2
 * Copyright (c) OSGi Alliance (2000, 2010). All Rights Reserved.
2
 * Copyright (c) OSGi Alliance (2000, 2011). All Rights Reserved.
3
 * 
3
 * 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
5
 * you may not use this file except in compliance with the License.
Lines 45-51 Link Here
45
 *  class                Bundle.loadClass
45
 *  class                Bundle.loadClass
46
 *  execute              Bundle.start
46
 *  execute              Bundle.start
47
 *                       Bundle.stop
47
 *                       Bundle.stop
48
 *                       StartLevel.setBundleStartLevel
48
 *                       BundleStartLevel.setStartLevel
49
 *  extensionLifecycle   BundleContext.installBundle for extension bundles
49
 *  extensionLifecycle   BundleContext.installBundle for extension bundles
50
 *                       Bundle.update for extension bundles
50
 *                       Bundle.update for extension bundles
51
 *                       Bundle.uninstall for extension bundles
51
 *                       Bundle.uninstall for extension bundles
Lines 56-78 Link Here
56
 *                       BundleContext.removeBundleListener for SynchronousBundleListener
56
 *                       BundleContext.removeBundleListener for SynchronousBundleListener
57
 *  metadata             Bundle.getHeaders
57
 *  metadata             Bundle.getHeaders
58
 *                       Bundle.getLocation
58
 *                       Bundle.getLocation
59
 *  resolve              PackageAdmin.refreshPackages
59
 *  resolve              FrameworkWiring.refreshBundles
60
 *                       PackageAdmin.resolveBundles
60
 *                       FrameworkWiring.resolveBundles
61
 *  resource             Bundle.getResource
61
 *  resource             Bundle.getResource
62
 *                       Bundle.getResources
62
 *                       Bundle.getResources
63
 *                       Bundle.getEntry
63
 *                       Bundle.getEntry
64
 *                       Bundle.getEntryPaths
64
 *                       Bundle.getEntryPaths
65
 *                       Bundle.findEntries
65
 *                       Bundle.findEntries
66
 *                       Bundle resource/entry URL creation
66
 *                       Bundle resource/entry URL creation
67
 *  startlevel           StartLevel.setStartLevel
67
 *  startlevel           FrameworkStartLevel.setStartLevel
68
 *                       StartLevel.setInitialBundleStartLevel 
68
 *                       FrameworkStartLevel.setInitialBundleStartLevel 
69
 *  context              Bundle.getBundleContext
69
 *  context              Bundle.getBundleContext
70
 *  weave                WovenClass.setBytes
71
 *                       WovenClass.getDynamicImports for modification
70
 * </pre>
72
 * </pre>
71
 * 
73
 * 
72
 * <p>
74
 * <p>
73
 * The special action &quot;*&quot; will represent all actions. The
75
 * The special action &quot;*&quot; will represent all actions. The
74
 * {@code resolve} action is implied by the {@code class},
76
 * {@code resolve} action is implied by the {@code class}, {@code execute} and
75
 * {@code execute} and {@code resource} actions.
77
 * {@code resource} actions.
76
 * <p>
78
 * <p>
77
 * The name of this permission is a filter expression. The filter gives access
79
 * The name of this permission is a filter expression. The filter gives access
78
 * to the following attributes:
80
 * to the following attributes:
Lines 87-93 Link Here
87
 * Filter attribute names are processed in a case sensitive manner.
89
 * Filter attribute names are processed in a case sensitive manner.
88
 * 
90
 * 
89
 * @ThreadSafe
91
 * @ThreadSafe
90
 * @version $Id: 8488ac114b71f92331d3a6739b878e4bd55fecdb $
92
 * @version $Id: 43baf9a6d7ce5e6108507834e841e340fd91c513 $
91
 */
93
 */
92
94
93
public final class AdminPermission extends BasicPermission {
95
public final class AdminPermission extends BasicPermission {
Lines 160-165 Link Here
160
	 */
162
	 */
161
	public final static String	CONTEXT						= "context";
163
	public final static String	CONTEXT						= "context";
162
164
165
	/**
166
	 * The action string {@code weave}.
167
	 * 
168
	 * @since 1.6
169
	 */
170
	public final static String						WEAVE						= "weave";
171
163
	private final static int	ACTION_CLASS				= 0x00000001;
172
	private final static int	ACTION_CLASS				= 0x00000001;
164
	private final static int	ACTION_EXECUTE				= 0x00000002;
173
	private final static int	ACTION_EXECUTE				= 0x00000002;
165
	private final static int	ACTION_LIFECYCLE			= 0x00000004;
174
	private final static int	ACTION_LIFECYCLE			= 0x00000004;
Lines 170-175 Link Here
170
	private final static int	ACTION_STARTLEVEL			= 0x00000100;
179
	private final static int	ACTION_STARTLEVEL			= 0x00000100;
171
	private final static int	ACTION_EXTENSIONLIFECYCLE	= 0x00000200;
180
	private final static int	ACTION_EXTENSIONLIFECYCLE	= 0x00000200;
172
	private final static int	ACTION_CONTEXT				= 0x00000400;
181
	private final static int	ACTION_CONTEXT				= 0x00000400;
182
	private final static int						ACTION_WEAVE				= 0x00000800;
173
	private final static int	ACTION_ALL					= ACTION_CLASS
183
	private final static int	ACTION_ALL					= ACTION_CLASS
174
																	| ACTION_EXECUTE
184
																	| ACTION_EXECUTE
175
																	| ACTION_LIFECYCLE
185
																	| ACTION_LIFECYCLE
Lines 179-185 Link Here
179
																	| ACTION_RESOURCE
189
																	| ACTION_RESOURCE
180
																	| ACTION_STARTLEVEL
190
																	| ACTION_STARTLEVEL
181
																	| ACTION_EXTENSIONLIFECYCLE
191
																	| ACTION_EXTENSIONLIFECYCLE
182
																	| ACTION_CONTEXT;
192
																						| ACTION_CONTEXT
193
																						| ACTION_WEAVE;
183
	final static int						ACTION_NONE					= 0;
194
	final static int						ACTION_NONE					= 0;
184
195
185
	/**
196
	/**
Lines 247-260 Link Here
247
	 * Null arguments are equivalent to "*".
258
	 * Null arguments are equivalent to "*".
248
	 * 
259
	 * 
249
	 * @param filter A filter expression that can use signer, location, id, and
260
	 * @param filter A filter expression that can use signer, location, id, and
250
	 *        name keys. A value of &quot;*&quot; or {@code null} matches
261
	 *        name keys. A value of &quot;*&quot; or {@code null} matches all
251
	 *        all bundle. Filter attribute names are processed in a case
262
	 *        bundle. Filter attribute names are processed in a case sensitive
252
	 *        sensitive manner.
263
	 *        manner.
253
	 * @param actions {@code class}, {@code execute},
264
	 * @param actions {@code class}, {@code execute}, {@code extensionLifecycle}
254
	 *        {@code extensionLifecycle}, {@code lifecycle},
265
	 *        , {@code lifecycle}, {@code listener}, {@code metadata},
255
	 *        {@code listener}, {@code metadata}, {@code resolve}
266
	 *        {@code resolve} , {@code resource}, {@code startlevel},
256
	 *        , {@code resource}, {@code startlevel} or
267
	 *        {@code context} or {@code weave}. A value of "*" or {@code null}
257
	 *        {@code context}. A value of "*" or {@code null}
258
	 *        indicates all actions.
268
	 *        indicates all actions.
259
	 * @throws IllegalArgumentException If the filter has an invalid syntax.
269
	 * @throws IllegalArgumentException If the filter has an invalid syntax.
260
	 */
270
	 */
Lines 265-281 Link Here
265
	}
275
	}
266
276
267
	/**
277
	/**
268
	 * Creates a new requested {@code AdminPermission} object to be used by
278
	 * Creates a new requested {@code AdminPermission} object to be used by the
269
	 * the code that must perform {@code checkPermission}.
279
	 * code that must perform {@code checkPermission}. {@code AdminPermission}
270
	 * {@code AdminPermission} objects created with this constructor cannot
280
	 * objects created with this constructor cannot be added to an
271
	 * be added to an {@code AdminPermission} permission collection.
281
	 * {@code AdminPermission} permission collection.
272
	 * 
282
	 * 
273
	 * @param bundle A bundle.
283
	 * @param bundle A bundle.
274
	 * @param actions {@code class}, {@code execute},
284
	 * @param actions {@code class}, {@code execute}, {@code extensionLifecycle}
275
	 *        {@code extensionLifecycle}, {@code lifecycle},
285
	 *        , {@code lifecycle}, {@code listener}, {@code metadata},
276
	 *        {@code listener}, {@code metadata}, {@code resolve}
286
	 *        {@code resolve} , {@code resource}, {@code startlevel},
277
	 *        , {@code resource}, {@code startlevel},
287
	 *        {@code context}, {@code weave}. A value of "*" or {@code null}
278
	 *        {@code context}. A value of "*" or {@code null}
279
	 *        indicates all actions.
288
	 *        indicates all actions.
280
	 * @since 1.3
289
	 * @since 1.3
281
	 */
290
	 */
Lines 503-521 Link Here
503
	
512
	
504
												}
513
												}
505
												else
514
												else
506
													if (i >= 0 &&
515
													if (i >= 4
507
	
516
															&& (a[i - 4] == 'w' || a[i - 4] == 'W')
508
													(a[i] == '*')) {
517
															&& (a[i - 3] == 'e' || a[i - 3] == 'E')
509
														matchlen = 1;
518
															&& (a[i - 2] == 'a' || a[i - 2] == 'A')
510
														mask |= ACTION_ALL;
519
															&& (a[i - 1] == 'v' || a[i - 1] == 'V')
511
	
520
															&& (a[i] == 'e' || a[i] == 'E')) {
512
													}
521
														matchlen = 5;
513
													else {
522
														mask |= ACTION_WEAVE;
514
														// parse error
523
515
														throw new IllegalArgumentException(
516
																"invalid permission: "
517
																		+ actions); 
518
													}
524
													}
525
													else
526
														if (i >= 0
527
																&& (a[i] == '*')) {
528
															matchlen = 1;
529
															mask |= ACTION_ALL;
530
531
														}
532
														else {
533
															// parse error
534
															throw new IllegalArgumentException(
535
																	"invalid permission: "
536
																			+ actions);
537
														}
519
	
538
	
520
			// make sure we didn't just match the tail of a word
539
			// make sure we didn't just match the tail of a word
521
			// like "ackbarfstartlevel". Also, skip to the comma.
540
			// like "ackbarfstartlevel". Also, skip to the comma.
Lines 668-681 Link Here
668
	 * {@code AdminPermission} actions.
687
	 * {@code AdminPermission} actions.
669
	 * 
688
	 * 
670
	 * <p>
689
	 * <p>
671
	 * Always returns present {@code AdminPermission} actions in the
690
	 * Always returns present {@code AdminPermission} actions in the following
672
	 * following order: {@code class}, {@code execute},
691
	 * order: {@code class}, {@code execute}, {@code extensionLifecycle},
673
	 * {@code extensionLifecycle}, {@code lifecycle},
692
	 * {@code lifecycle}, {@code listener}, {@code metadata}, {@code resolve},
674
	 * {@code listener}, {@code metadata}, {@code resolve},
693
	 * {@code resource}, {@code startlevel}, {@code context}, {@code weave}.
675
	 * {@code resource}, {@code startlevel}, {@code context}.
676
	 * 
694
	 * 
677
	 * @return Canonical string representation of the
695
	 * @return Canonical string representation of the {@code AdminPermission}
678
	 *         {@code AdminPermission} actions.
696
	 *         actions.
679
	 */
697
	 */
680
	public String getActions() {
698
	public String getActions() {
681
		String result = actions;
699
		String result = actions;
Lines 732-737 Link Here
732
				sb.append(CONTEXT);
750
				sb.append(CONTEXT);
733
				sb.append(',');
751
				sb.append(',');
734
			}
752
			}
753
754
			if ((mask & ACTION_WEAVE) == ACTION_WEAVE) {
755
				sb.append(WEAVE);
756
				sb.append(',');
757
			}
735
	
758
	
736
			// remove trailing comma
759
			// remove trailing comma
737
			if (sb.length() > 0) {
760
			if (sb.length() > 0) {
(-)osgi/src/org/osgi/framework/Bundle.java (-7 / +13 lines)
Lines 26-31 Link Here
26
import java.util.List;
26
import java.util.List;
27
import java.util.Map;
27
import java.util.Map;
28
28
29
import org.osgi.framework.wiring.FrameworkWiring;
30
29
/**
31
/**
30
 * An installed bundle in the Framework.
32
 * An installed bundle in the Framework.
31
 * 
33
 * 
Lines 74-80 Link Here
74
 * 
76
 * 
75
 * @ThreadSafe
77
 * @ThreadSafe
76
 * @noimplement
78
 * @noimplement
77
 * @version $Id: 2b49f64e7a633cefc70b438ec9e1f966ff4f8130 $
79
 * @version $Id: 46e30f6a4a403ace9bb2313435562d273900856b $
78
 */
80
 */
79
public interface Bundle extends Comparable<Bundle> {
81
public interface Bundle extends Comparable<Bundle> {
80
	/**
82
	/**
Lines 257-264 Link Here
257
	 * If this bundle's state is {@code UNINSTALLED} then an
259
	 * If this bundle's state is {@code UNINSTALLED} then an
258
	 * {@code IllegalStateException} is thrown.
260
	 * {@code IllegalStateException} is thrown.
259
	 * <p>
261
	 * <p>
260
	 * If the Framework implements the optional Start Level service and the
262
	 * If the current start level is less than this bundle's start level:
261
	 * current start level is less than this bundle's start level:
262
	 * <ul>
263
	 * <ul>
263
	 * <li>If the {@link #START_TRANSIENT} option is set, then a
264
	 * <li>If the {@link #START_TRANSIENT} option is set, then a
264
	 * {@code BundleException} is thrown indicating this bundle cannot be
265
	 * {@code BundleException} is thrown indicating this bundle cannot be
Lines 512-519 Link Here
512
	 * <p>
513
	 * <p>
513
	 * If this bundle has exported any packages that are imported by another
514
	 * If this bundle has exported any packages that are imported by another
514
	 * bundle, these packages must remain exported until the
515
	 * bundle, these packages must remain exported until the
515
	 * {@code PackageAdmin.refreshPackages} method has been has been called or
516
	 * {@link FrameworkWiring#refreshBundles(java.util.Collection, FrameworkListener...)
516
	 * the Framework is relaunched.
517
	 * FrameworkWiring.refreshBundles} method has been has been called or the
518
	 * Framework is relaunched.
517
	 * 
519
	 * 
518
	 * <p>
520
	 * <p>
519
	 * The following steps are required to update a bundle:
521
	 * The following steps are required to update a bundle:
Lines 624-631 Link Here
624
	 * <p>
626
	 * <p>
625
	 * If this bundle has exported any packages, the Framework must continue to
627
	 * If this bundle has exported any packages, the Framework must continue to
626
	 * make these packages available to their importing bundles until the
628
	 * make these packages available to their importing bundles until the
627
	 * {@code PackageAdmin.refreshPackages} method has been called or the
629
	 * {@link FrameworkWiring#refreshBundles(java.util.Collection, FrameworkListener...)
628
	 * Framework is relaunched.
630
	 * FrameworkWiring.refreshBundles} method has been called or the Framework
631
	 * is relaunched.
629
	 * 
632
	 * 
630
	 * <p>
633
	 * <p>
631
	 * The following steps are required to uninstall a bundle:
634
	 * The following steps are required to uninstall a bundle:
Lines 1204-1209 Link Here
1204
	 * @return The object, of the specified type, to which this bundle has been
1207
	 * @return The object, of the specified type, to which this bundle has been
1205
	 *         adapted or {@code null} if this bundle cannot be adapted to the
1208
	 *         adapted or {@code null} if this bundle cannot be adapted to the
1206
	 *         specified type.
1209
	 *         specified type.
1210
	 * @throws SecurityException If the caller does not have the appropriate
1211
	 *         {@code AdaptPermission[type,this,ADAPT]}, and the Java Runtime
1212
	 *         Environment supports permissions.
1207
	 * @since 1.6
1213
	 * @since 1.6
1208
	 */
1214
	 */
1209
	<A> A adapt(Class<A> type);
1215
	<A> A adapt(Class<A> type);
(-)osgi/src/org/osgi/framework/Constants.java (-6 / +6 lines)
Lines 1-5 Link Here
1
/*
1
/*
2
 * Copyright (c) OSGi Alliance (2000, 2010). All Rights Reserved.
2
 * Copyright (c) OSGi Alliance (2000, 2011). All Rights Reserved.
3
 *
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
5
 * you may not use this file except in compliance with the License.
Lines 28-34 Link Here
28
 * 
28
 * 
29
 * @since 1.1
29
 * @since 1.1
30
 * @noimplement
30
 * @noimplement
31
 * @version $Id: bf31cbaceba8df7648e343136ce87da520e7e675 $
31
 * @version $Id: dfc898e60b6825d9b1dada682a6aecc858daa7f4 $
32
 */
32
 */
33
33
34
public interface Constants {
34
public interface Constants {
Lines 1590-1610 Link Here
1590
	String	EFFECTIVE_ACTIVE						= "active";
1590
	String	EFFECTIVE_ACTIVE						= "active";
1591
1591
1592
	/**
1592
	/**
1593
	 * Manifest header attribute identifying the capability filter specified in
1593
	 * Manifest header directive identifying the capability filter specified in
1594
	 * the Require-Capability manifest header.
1594
	 * the Require-Capability manifest header.
1595
	 * 
1595
	 * 
1596
	 * <p>
1596
	 * <p>
1597
	 * The attribute value is encoded in the Require-Capability manifest header
1597
	 * The directive value is encoded in the Require-Capability manifest header
1598
	 * like:
1598
	 * like:
1599
	 * 
1599
	 * 
1600
	 * <pre>
1600
	 * <pre>
1601
	 *     Require-Capability: com.acme.capability; filter=&quot;(someattr=somevalue)&quot;
1601
	 *     Require-Capability: com.acme.capability; filter:=&quot;(someattr=somevalue)&quot;
1602
	 * </pre>
1602
	 * </pre>
1603
	 * 
1603
	 * 
1604
	 * @see #REQUIRE_CAPABILITY
1604
	 * @see #REQUIRE_CAPABILITY
1605
	 * @since 1.6
1605
	 * @since 1.6
1606
	 */
1606
	 */
1607
	String	FILTER_ATTRIBUTE						= "filter";
1607
	String	FILTER_DIRECTIVE						= "filter";
1608
1608
1609
	/**
1609
	/**
1610
	 * Framework launching property identifying capabilities which the system
1610
	 * Framework launching property identifying capabilities which the system
(-)osgi/src/org/osgi/framework/FrameworkEvent.java (-9 / +13 lines)
Lines 18-23 Link Here
18
18
19
import java.util.EventObject;
19
import java.util.EventObject;
20
20
21
import org.osgi.framework.startlevel.FrameworkStartLevel;
22
import org.osgi.framework.wiring.FrameworkWiring;
23
21
/**
24
/**
22
 * A general event from the Framework.
25
 * A general event from the Framework.
23
 * 
26
 * 
Lines 32-38 Link Here
32
 * 
35
 * 
33
 * @Immutable
36
 * @Immutable
34
 * @see FrameworkListener
37
 * @see FrameworkListener
35
 * @version $Id: 897075a0bc075c0bb89e77d113f05ca84406a073 $
38
 * @version $Id: e05c6ffd542fa432835961882bf6b15b0620ffb6 $
36
 */
39
 */
37
40
38
public class FrameworkEvent extends EventObject {
41
public class FrameworkEvent extends EventObject {
Lines 61-67 Link Here
61
	 * has reached the initial start level. The source of this event is the
64
	 * has reached the initial start level. The source of this event is the
62
	 * System Bundle.
65
	 * System Bundle.
63
	 * 
66
	 * 
64
	 * @see "The Start Level Service"
67
	 * @see "The Start Level Specification"
65
	 */
68
	 */
66
	public final static int	STARTED							= 0x00000001;
69
	public final static int	STARTED							= 0x00000001;
67
70
Lines 74-93 Link Here
74
	public final static int	ERROR							= 0x00000002;
77
	public final static int	ERROR							= 0x00000002;
75
78
76
	/**
79
	/**
77
	 * A PackageAdmin.refreshPackage operation has completed.
80
	 * A FrameworkWiring.refreshBundles operation has completed.
78
	 * 
81
	 * 
79
	 * <p>
82
	 * <p>
80
	 * This event is fired when the Framework has completed the refresh packages
83
	 * This event is fired when the Framework has completed the refresh bundles
81
	 * operation initiated by a call to the PackageAdmin.refreshPackages method.
84
	 * operation initiated by a call to the FrameworkWiring.refreshBundles
82
	 * The source of this event is the System Bundle.
85
	 * method. The source of this event is the System Bundle.
83
	 * 
86
	 * 
84
	 * @since 1.2
87
	 * @since 1.2
85
	 * @see "{@code PackageAdmin.refreshPackages}"
88
	 * @see FrameworkWiring#refreshBundles(java.util.Collection,
89
	 *      FrameworkListener...)
86
	 */
90
	 */
87
	public final static int	PACKAGES_REFRESHED				= 0x00000004;
91
	public final static int	PACKAGES_REFRESHED				= 0x00000004;
88
92
89
	/**
93
	/**
90
	 * A StartLevel.setStartLevel operation has completed.
94
	 * A FrameworkStartLevel.setStartLevel operation has completed.
91
	 * 
95
	 * 
92
	 * <p>
96
	 * <p>
93
	 * This event is fired when the Framework has completed changing the active
97
	 * This event is fired when the Framework has completed changing the active
Lines 95-101 Link Here
95
	 * The source of this event is the System Bundle.
99
	 * The source of this event is the System Bundle.
96
	 * 
100
	 * 
97
	 * @since 1.2
101
	 * @since 1.2
98
	 * @see "The Start Level Service"
102
	 * @see FrameworkStartLevel#setStartLevel(int, FrameworkListener...)
99
	 */
103
	 */
100
	public final static int	STARTLEVEL_CHANGED				= 0x00000008;
104
	public final static int	STARTLEVEL_CHANGED				= 0x00000008;
101
105
(-)osgi/src/org/osgi/framework/hooks/resolver/ResolverHook.java (-90 / +111 lines)
Lines 1-5 Link Here
1
/*
1
/*
2
 * Copyright (c) OSGi Alliance (2011). All Rights Reserved.
2
 * Copyright (c) OSGi Alliance (2010, 2011). All Rights Reserved.
3
 * 
3
 * 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
5
 * you may not use this file except in compliance with the License.
Lines 24-113 Link Here
24
import org.osgi.framework.wiring.FrameworkWiring;
24
import org.osgi.framework.wiring.FrameworkWiring;
25
25
26
/**
26
/**
27
 * OSGi Framework Resolver Hook instances are obtained from the OSGi {@link ResolverHookFactory
27
 * OSGi Framework Resolver Hook instances are obtained from the OSGi
28
 * Framework Resolver Hook Factory} service.  
28
 * {@link ResolverHookFactory Framework Resolver Hook Factory} service.
29
 * 
29
 * 
30
 * <p>
30
 * <p>
31
 * A Resolver Hook instance is called by the framework during a resolve
31
 * A Resolver Hook instance is called by the framework during a resolve process.
32
 * process.  A resolver hook may influence the outcome of a resolve process by removing entries
32
 * A resolver hook may influence the outcome of a resolve process by removing
33
 * from shrinkable collections that are passed to the hook during a resolve process.  A shrinkable 
33
 * entries from shrinkable collections that are passed to the hook during a
34
 * collection is a {@code Collection} that supports all remove operations.  Any other attempts to modify
34
 * resolve process. A shrinkable collection is a {@code Collection} that
35
 * a shrinkable collection will result in an {@code UnsupportedOperationException} being thrown.
35
 * supports all remove operations. Any other attempts to modify a shrinkable
36
 * collection will result in an {@code UnsupportedOperationException} being
37
 * thrown.
36
 * 
38
 * 
37
 * <p>
39
 * <p>
38
 * The following steps outline the way a framework uses the resolver hooks during a resolve
40
 * The following steps outline the way a framework uses the resolver hooks
39
 * process.
41
 * during a resolve process.
40
 * <ol>
42
 * <ol>
41
 *  <li> Collect a snapshot of registered resolver hook factories that will be called during the
43
 * <li>Collect a snapshot of registered resolver hook factories that will be
42
 *       current resolve process.  Any hook factories registered after the snapshot is taken must not be called
44
 * called during the current resolve process. Any hook factories registered
43
 *       during the current resolve process.  A resolver hook factory contained in the snapshot may become
45
 * after the snapshot is taken must not be called during the current resolve
44
 *       unregistered during the resolve process.  The framework should handle this and stop calling
46
 * process. A resolver hook factory contained in the snapshot may become
45
 *       the resolver hook instance provided by the unregistered hook factory for the remainder of the resolve process.</li>
47
 * unregistered during the resolve process. The framework should handle this and
46
 *  <li> For each registered hook factory call the {@link ResolverHookFactory#begin(Collection)} method to inform the 
48
 * stop calling the resolver hook instance provided by the unregistered hook
47
 *       hooks about a resolve process beginning and to obtain a Resolver Hook instance that will be used for the duration
49
 * factory and the current resolve process must fail. If possible, an exception
48
 *       of the resolve process.</li>
50
 * must be thrown to the caller of the API which triggered the resolve process.
49
 *  <li> Determine the collection of unresolved bundle revisions that may be considered for resolution during
51
 * In cases where the the caller is not available a framework event of type
50
 *       the current resolution process and place each of the bundle revisions in a shrinkable collection
52
 * error should be fired.</li>
51
 *       <b>{@code R}</b>.  For each resolver hook call the {@link #filterResolvable(Collection)} method with the 
53
 * <li>For each registered hook factory call the
52
 *       shrinkable collection <b>{@code R}</b>.</li>
54
 * {@link ResolverHookFactory#begin(Collection)} method to inform the hooks
53
 *  <li> The shrinkable collection <b>{@code R}</b> now contains all the unresolved bundle revisions that may end up
55
 * about a resolve process beginning and to obtain a Resolver Hook instance that
54
 *       as resolved at the end of the current resolve process.  Any other bundle revisions that 
56
 * will be used for the duration of the resolve process.</li>
55
 *       got removed from the shrinkable collection <b>{@code R}</b> must not end up as resolved at the end
57
 * <li>Determine the collection of unresolved bundle revisions that may be
56
 *       of the current resolve process.</li>
58
 * considered for resolution during the current resolution process and place
57
 *  <li> For each bundle revision {@code B} left in the shrinkable collection <b>{@code R}</b> that represents a 
59
 * each of the bundle revisions in a shrinkable collection {@code R}. For each
58
 *       singleton bundle do the following:
60
 * resolver hook call the {@link #filterResolvable(Collection)} method with the
59
 *       <p>
61
 * shrinkable collection {@code R}.</li>
60
 *         Determine the collection of available capabilities that have a name space of 
62
 * <li>The shrinkable collection {@code R} now contains all the unresolved
61
 *         {@link Capability#BUNDLE_CAPABILITY osgi.bundle}, are singletons, and have the same
63
 * bundle revisions that may end up as resolved at the end of the current
62
 *         symbolic name as the singleton bundle revision <b>{@code B}</b> and place each of the matching
64
 * resolve process. Any other bundle revisions that got removed from the
63
 *         capabilities into a shrinkable collection <b>{@code S}</b>.
65
 * shrinkable collection {@code R} must not end up as resolved at the end of the
64
66
 * current resolve process.</li>
65
 *         Remove the {@link Capability#BUNDLE_CAPABILITY osgi.bundle} capability provided by
67
 * <li>For each bundle revision {@code B} left in the shrinkable collection
66
 *         bundle revision <b>{@code B}</b> from shrinkable collection <b>{@code S}</b>.  A singleton bundle 
68
 * {@code R} that represents a singleton bundle do the following:<br/>
67
 *         cannot collide with itself.
69
 * Determine the collection of available capabilities that have a name space of
68
 *
70
 * {@link Capability#BUNDLE_CAPABILITY osgi.wiring.bundle}, are singletons, and
69
 *         For each resovler hook call the {@link #filterSingletonCollisions(Capability, Collection)}
71
 * have the same symbolic name as the singleton bundle revision {@code B} and
70
 *         with the {@link Capability#BUNDLE_CAPABILITY osgi.bundle} capability provided by bundle revision 
72
 * place each of the matching capabilities into a shrinkable collection
71
 *         <b>{@code B}</b> and the shrinkable collection <b>{@code S}</b>
73
 * {@code S}.
72
 *
73
 *         The shrinkable collection <b>{@code S}</b> now contains all singleton {@link Capability#BUNDLE_CAPABILITY 
74
 *         osgi.bundle} capabilities that can influence the ability of bundle revision <b>{@code B}</b> to resolve.
75
 *       </p>
76
 *  </li>
77
 *  <li> During a resolve process a framework is free to attempt to resolve any or all bundles contained in
78
 *       shrinkable collection <b>{@code R}</b>.  For each bundle revision <b>{@code B}</b> left in the shrinkable collection 
79
 *       <b>{@code R}</b> which the framework attempts to resolve the following steps must be followed:
80
 *       <p>
81
 *         For each requirement <b>{@code T}</b> specified by bundle revision <b>{@code B}</b> determine the 
82
 *         collection of capabilities that satisfy (or match) the requirement and place each matching capability into
83
 *         a shrinkable collection <b>{@code C}</b>.  A capability is considered to match a particular requirement
84
 *         if its attributes satisfy a specified requirement and the requirer bundle has permission to access the
85
 *         capability.
86
 * 
74
 * 
87
 *         For each resolver hook call the {@link #filterMatches(BundleRevision, Collection)} with the
75
 * Remove the {@link Capability#BUNDLE_CAPABILITY osgi.wiring.bundle} capability
88
 *         bundle revision <b>{@code B}</b> and the shrinkable collection <b>{@code C}</b>.
76
 * provided by bundle revision {@code B} from shrinkable collection {@code S}. A
89
 *
77
 * singleton bundle cannot collide with itself.
90
 *         The shrinkable collection <b>{@code C}</b> now contains all the capabilities that may be used to 
78
 * 
91
 *         satisfy the requirement <b>{@code T}</b>.  Any other capabilities that got removed from the 
79
 * For each resolver hook call the
92
 *         shrinkable collection <b>{@code C}</b> must not be used to satisfy requirement <b>{@code T}</b>.
80
 * {@link #filterSingletonCollisions(Capability, Collection)} with the
93
 *       </p>
81
 * {@link Capability#BUNDLE_CAPABILITY osgi.wiring.bundle} capability provided
94
 *  </li>
82
 * by bundle revision {@code B} and the shrinkable collection {@code S}
95
 *  <li> For each resolver hook call the {@link #end()} method to inform the hooks about a resolve 
83
 * 
96
 *       process ending.</li>
84
 * The shrinkable collection {@code S} now contains all singleton
85
 * {@link Capability#BUNDLE_CAPABILITY osgi.wiring.bundle} capabilities that can
86
 * influence the ability of bundle revision {@code B} to resolve.</li>
87
 * <li>During a resolve process a framework is free to attempt to resolve any or
88
 * all bundles contained in shrinkable collection {@code R}. For each bundle
89
 * revision {@code B} left in the shrinkable collection {@code R} which the
90
 * framework attempts to resolve the following steps must be followed:
91
 * <p/>
92
 * For each requirement {@code T} specified by bundle revision {@code B}
93
 * determine the collection of capabilities that satisfy (or match) the
94
 * requirement and place each matching capability into a shrinkable collection
95
 * {@code C}. A capability is considered to match a particular requirement if
96
 * its attributes satisfy a specified requirement and the requirer bundle has
97
 * permission to access the capability.
98
 * 
99
 * <p/>
100
 * For each resolver hook call the
101
 * {@link #filterMatches(BundleRevision, Collection)} with the bundle revision
102
 * {@code B} and the shrinkable collection {@code C}.
103
 * 
104
 * <p/>
105
 * The shrinkable collection {@code C} now contains all the capabilities that
106
 * may be used to satisfy the requirement {@code T}. Any other capabilities that
107
 * got removed from the shrinkable collection {@code C} must not be used to
108
 * satisfy requirement {@code T}.</li>
109
 * <li>For each resolver hook call the {@link #end()} method to inform the hooks
110
 * about a resolve process ending.</li>
97
 * </ol>
111
 * </ol>
98
 * In all cases, the order in which the resolver hooks are called is the reverse compareTo ordering of 
112
 * In all cases, the order in which the resolver hooks are called is the reverse
99
 * their Service References.  That is, the service with the highest ranking number must be called first.
113
 * compareTo ordering of their Service References. That is, the service with the
100
 * In cases where a shrinkable collection becomes empty the framework is required to call the
114
 * highest ranking number must be called first. In cases where a shrinkable
101
 * remaining registered hooks.
115
 * collection becomes empty the framework is required to call the remaining
116
 * registered hooks.
102
 * <p>
117
 * <p>
103
 * Resolver hooks are low level.  Implementations of the resolver hook must be careful not to create an unresolvable state which
118
 * Resolver hooks are low level. Implementations of the resolver hook must be
104
 * is very hard for a developer or a provisioner to diagnose.  Resolver hooks also must not be allowed to start another synchronous 
119
 * careful not to create an unresolvable state which is very hard for a
105
 * resolve process (e.g. by calling {@link Bundle#start()} or {@link FrameworkWiring#resolveBundles(Collection)}).  
120
 * developer or a provisioner to diagnose. Resolver hooks also must not be
106
 * The framework must detect this and throw an {@link IllegalStateException}.
121
 * allowed to start another synchronous resolve process (e.g. by calling
122
 * {@link Bundle#start()} or {@link FrameworkWiring#resolveBundles(Collection)}
123
 * ). The framework must detect this and throw an {@link IllegalStateException}.
107
 * 
124
 * 
108
 * @see ResolverHookFactory
125
 * @see ResolverHookFactory
109
 * @ThreadSafe
126
 * @NotThreadSafe
110
 * @version $Id: abc1f4bb4fd57b8bb41855b1282fe22cb13a9654 $
127
 * @version $Id: f2c91d233fd9a4547452e4c3f09d7bcbe8c565fb $
111
 */
128
 */
112
public interface ResolverHook {
129
public interface ResolverHook {
113
	/**
130
	/**
Lines 123-147 Link Here
123
	void filterResolvable(Collection<BundleRevision> candidates);
140
	void filterResolvable(Collection<BundleRevision> candidates);
124
141
125
	/**
142
	/**
126
	 * Filter singleton collisions hook method. This method is called during the resolve process
143
	 * Filter singleton collisions hook method. This method is called during the
127
	 * for the specified singleton.  The specified singleton represents a singleton capability
144
	 * resolve process for the specified singleton. The specified singleton
128
	 * and the specified collection represent a collection of singleton capabilities which are 
145
	 * represents a singleton capability and the specified collection represent
129
	 * considered collision candidates.  The singleton capability and the collection of collision 
146
	 * a collection of singleton capabilities which are considered collision
147
	 * candidates. The singleton capability and the collection of collision
130
	 * candidates must all use the same name space.
148
	 * candidates must all use the same name space.
131
	 * <p>
149
	 * <p>
132
	 * Currently only capabilities with the name space of {@link Capability#BUNDLE_CAPABILITY 
150
	 * Currently only capabilities with the name space of
133
	 * osgi.bundle} can be singletons.  In that case all the collision candidates
151
	 * {@link Capability#BUNDLE_CAPABILITY osgi.wiring.bundle} can be
134
	 * have the name space of {@link Capability#BUNDLE_CAPABILITY osgi.bundle}, are singletons, 
152
	 * singletons. In that case all the collision candidates have the name space
135
	 * and have the same symbolic name as the specified singleton capability.
153
	 * of {@link Capability#BUNDLE_CAPABILITY osgi.wiring.bundle}, are
154
	 * singletons, and have the same symbolic name as the specified singleton
155
	 * capability.
136
	 * <p>
156
	 * <p>
137
	 * In the future, capabilities in other name spaces may support the singleton concept.
157
	 * In the future, capabilities in other name spaces may support the
138
	 * Hook implementations should be prepared to receive calls to this method for 
158
	 * singleton concept. Hook implementations should be prepared to receive
139
	 * capabilities in name spaces other than {@link Capability#BUNDLE_CAPABILITY 
159
	 * calls to this method for capabilities in name spaces other than
140
	 * osgi.bundle}.  
160
	 * {@link Capability#BUNDLE_CAPABILITY osgi.wiring.bundle}.
141
	 * <p>
161
	 * <p>
142
	 * This method can filter the list of collision candidates by removing potential collisions.
162
	 * This method can filter the list of collision candidates by removing
143
	 * Removing a collision candidate will allow the specified singleton to resolve regardless of 
163
	 * potential collisions. Removing a collision candidate will allow the
144
	 * the resolution state of the removed collision candidate.
164
	 * specified singleton to resolve regardless of the resolution state of the
165
	 * removed collision candidate.
145
	 * 
166
	 * 
146
	 * @param singleton the singleton involved in a resolve process
167
	 * @param singleton the singleton involved in a resolve process
147
	 * @param collisionCandidates a collection of singleton collision candidates
168
	 * @param collisionCandidates a collection of singleton collision candidates
(-)osgi/src/org/osgi/framework/hooks/service/ListenerHook.java (-1 / +2 lines)
Lines 28-34 Link Here
28
 * addition and removal.
28
 * addition and removal.
29
 * 
29
 * 
30
 * @ThreadSafe
30
 * @ThreadSafe
31
 * @version $Id: c64053251939f402bb35b6a69fc3009888420872 $
31
 * @version $Id: c1687e95e568589cf3e6d927b7d372c9f88c5d16 $
32
 */
32
 */
33
33
34
public interface ListenerHook {
34
public interface ListenerHook {
Lines 67-72 Link Here
67
	 * which added the Service Listener and the filter with which it was added.
67
	 * which added the Service Listener and the filter with which it was added.
68
	 * 
68
	 * 
69
	 * @ThreadSafe
69
	 * @ThreadSafe
70
	 * @noimplement
70
	 */
71
	 */
71
	public interface ListenerInfo {
72
	public interface ListenerInfo {
72
		/**
73
		/**
(-)osgi/src/org/osgi/framework/hooks/weaving/WovenClass.java (-2 / +9 lines)
Lines 1-5 Link Here
1
/*
1
/*
2
 * Copyright (c) OSGi Alliance (2010). All Rights Reserved.
2
 * Copyright (c) OSGi Alliance (2010, 2011). All Rights Reserved.
3
 * 
3
 * 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
5
 * you may not use this file except in compliance with the License.
Lines 35-41 Link Here
35
 * 
35
 * 
36
 * @NotThreadSafe
36
 * @NotThreadSafe
37
 * @noimplement
37
 * @noimplement
38
 * @version $Id: f54547066bd0632e85242cac434a6bb8a759dff6 $
38
 * @version $Id: c9fdc8cc09e8455b52572c8eb3721a2e1778aa6b $
39
 */
39
 */
40
public interface WovenClass {
40
public interface WovenClass {
41
41
Lines 75-80 Link Here
75
	 * @throws NullPointerException If newBytes is {@code null}.
75
	 * @throws NullPointerException If newBytes is {@code null}.
76
	 * @throws IllegalStateException If weaving is {@link #isWeavingComplete()
76
	 * @throws IllegalStateException If weaving is {@link #isWeavingComplete()
77
	 *         complete}.
77
	 *         complete}.
78
	 * @throws SecurityException If the caller does not have
79
	 *         {@code AdminPermission[bundle,WEAVE]} and the Java runtime
80
	 *         environment supports permissions.
78
	 */
81
	 */
79
	public void setBytes(byte[] newBytes);
82
	public void setBytes(byte[] newBytes);
80
83
Lines 90-95 Link Here
90
	 * After weaving is {@link #isWeavingComplete() complete}, this object
93
	 * After weaving is {@link #isWeavingComplete() complete}, this object
91
	 * becomes effectively immutable and the returned list will be unmodifiable.
94
	 * becomes effectively immutable and the returned list will be unmodifiable.
92
	 * 
95
	 * 
96
	 * <p>
97
	 * If the Java runtime environment supports permissions, the caller must
98
	 * have {@code AdminPermission[bundle,WEAVE]} to modify the returned list.
99
	 * 
93
	 * @return A list containing zero or more dynamic import package
100
	 * @return A list containing zero or more dynamic import package
94
	 *         descriptions to add to the bundle wiring for this woven class.
101
	 *         descriptions to add to the bundle wiring for this woven class.
95
	 *         This list must throw {@code IllegalArgumentException} if a
102
	 *         This list must throw {@code IllegalArgumentException} if a
(-)osgi/src/org/osgi/framework/launch/Framework.java (-17 / +13 lines)
Lines 35-41 Link Here
35
 * 
35
 * 
36
 * @ThreadSafe
36
 * @ThreadSafe
37
 * @noimplement
37
 * @noimplement
38
 * @version $Id: e403b10bdb5ae9b9e42651ce04003923beacc3d9 $
38
 * @version $Id: 2be857d06f3605a04f701b59f11e127c0f8940dc $
39
 */
39
 */
40
public interface Framework extends Bundle {
40
public interface Framework extends Bundle {
41
41
Lines 51-58 Link Here
51
	 * <li>Have event handling enabled.</li>
51
	 * <li>Have event handling enabled.</li>
52
	 * <li>Have reified Bundle objects for all installed bundles.</li>
52
	 * <li>Have reified Bundle objects for all installed bundles.</li>
53
	 * <li>Have registered any framework services. For example,
53
	 * <li>Have registered any framework services. For example,
54
	 * {@code PackageAdmin}, {@code ConditionalPermissionAdmin},
54
	 * {@code ConditionalPermissionAdmin}.</li>
55
	 * {@code StartLevel}.</li>
56
	 * <li>Be {@link #adapt(Class) adaptable} to the OSGi defined types to which
55
	 * <li>Be {@link #adapt(Class) adaptable} to the OSGi defined types to which
57
	 * a system bundle can be adapted.</li>
56
	 * a system bundle can be adapted.</li>
58
	 * </ul>
57
	 * </ul>
Lines 134-145 Link Here
134
	 * <li>All installed bundles must be started in accordance with each
133
	 * <li>All installed bundles must be started in accordance with each
135
	 * bundle's persistent <i>autostart setting</i>. This means some bundles
134
	 * bundle's persistent <i>autostart setting</i>. This means some bundles
136
	 * will not be started, some will be started with <i>eager activation</i>
135
	 * will not be started, some will be started with <i>eager activation</i>
137
	 * and some will be started with their <i>declared activation</i> policy. If
136
	 * and some will be started with their <i>declared activation</i> policy.
138
	 * this Framework implements the optional <i>Start Level Service
137
	 * The start level of this Framework is moved to the start level specified
139
	 * Specification</i>, then the start level of this Framework is moved to the
138
	 * by the {@link Constants#FRAMEWORK_BEGINNING_STARTLEVEL beginning start
140
	 * start level specified by the
139
	 * level} framework property, as described in the <i>Start Level
141
	 * {@link Constants#FRAMEWORK_BEGINNING_STARTLEVEL beginning start level}
142
	 * framework property, as described in the <i>Start Level Service
143
	 * Specification</i>. If this framework property is not specified, then the
140
	 * Specification</i>. If this framework property is not specified, then the
144
	 * start level of this Framework is moved to start level one (1). Any
141
	 * start level of this Framework is moved to start level one (1). Any
145
	 * exceptions that occur during bundle starting must be wrapped in a
142
	 * exceptions that occur during bundle starting must be wrapped in a
Lines 153-159 Link Here
153
	 * @throws SecurityException If the caller does not have the appropriate
150
	 * @throws SecurityException If the caller does not have the appropriate
154
	 *         {@code AdminPermission[this,EXECUTE]}, and the Java Runtime
151
	 *         {@code AdminPermission[this,EXECUTE]}, and the Java Runtime
155
	 *         Environment supports permissions.
152
	 *         Environment supports permissions.
156
	 * @see "Start Level Service Specification"
153
	 * @see "Start Level Specification"
157
	 */
154
	 */
158
	void start() throws BundleException;
155
	void start() throws BundleException;
159
156
Lines 182-193 Link Here
182
	 * <ol>
179
	 * <ol>
183
	 * <li>This Framework's state is set to {@link #STOPPING}.</li>
180
	 * <li>This Framework's state is set to {@link #STOPPING}.</li>
184
	 * <li>All installed bundles must be stopped without changing each bundle's
181
	 * <li>All installed bundles must be stopped without changing each bundle's
185
	 * persistent <i>autostart setting</i>. If this Framework implements the
182
	 * persistent <i>autostart setting</i>. The start level of this Framework is
186
	 * optional <i>Start Level Service Specification</i>, then the start level
183
	 * moved to start level zero (0), as described in the <i>Start Level
187
	 * of this Framework is moved to start level zero (0), as described in the
184
	 * Specification</i>. Any exceptions that occur during bundle stopping must
188
	 * <i>Start Level Service Specification</i>. Any exceptions that occur
185
	 * be wrapped in a {@link BundleException} and then published as a framework
189
	 * during bundle stopping must be wrapped in a {@link BundleException} and
186
	 * event of type {@link FrameworkEvent#ERROR}</li>
190
	 * then published as a framework event of type {@link FrameworkEvent#ERROR}</li>
191
	 * <li>Unregister all services registered by this Framework.</li>
187
	 * <li>Unregister all services registered by this Framework.</li>
192
	 * <li>Event handling is disabled.</li>
188
	 * <li>Event handling is disabled.</li>
193
	 * <li>This Framework's state is set to {@link #RESOLVED}.</li>
189
	 * <li>This Framework's state is set to {@link #RESOLVED}.</li>
Lines 205-211 Link Here
205
	 * @throws SecurityException If the caller does not have the appropriate
201
	 * @throws SecurityException If the caller does not have the appropriate
206
	 *         {@code AdminPermission[this,EXECUTE]}, and the Java Runtime
202
	 *         {@code AdminPermission[this,EXECUTE]}, and the Java Runtime
207
	 *         Environment supports permissions.
203
	 *         Environment supports permissions.
208
	 * @see "Start Level Service Specification"
204
	 * @see "Start Level Specification"
209
	 */
205
	 */
210
	void stop() throws BundleException;
206
	void stop() throws BundleException;
211
207
(-)osgi/src/org/osgi/framework/wiring/BundleRevision.java (-6 / +30 lines)
Lines 1-5 Link Here
1
/*
1
/*
2
 * Copyright (c) OSGi Alliance (2010). All Rights Reserved.
2
 * Copyright (c) OSGi Alliance (2010, 2011). All Rights Reserved.
3
 * 
3
 * 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
5
 * you may not use this file except in compliance with the License.
Lines 17-22 Link Here
17
17
18
package org.osgi.framework.wiring;
18
package org.osgi.framework.wiring;
19
19
20
import java.util.Collection;
20
import java.util.List;
21
import java.util.List;
21
22
22
import org.osgi.framework.Bundle;
23
import org.osgi.framework.Bundle;
Lines 24-40 Link Here
24
import org.osgi.framework.Version;
25
import org.osgi.framework.Version;
25
26
26
/**
27
/**
27
 * Bundle Revision. Since a bundle update can change the entries in a bundle,
28
 * Bundle Revision. When a bundle is installed and each time a bundle is
28
 * different bundle wirings for the same bundle can be associated with different
29
 * updated, a new bundle revision of the bundle is created. Since a bundle
29
 * bundle revisions.
30
 * update can change the entries in a bundle, different bundle wirings for the
31
 * same bundle can be associated with different bundle revisions.
30
 * 
32
 * 
31
 * <p>
33
 * <p>
32
 * The current bundle revision for a bundle can be obtained by calling
34
 * The current bundle revision is the most recent bundle revision. The current
35
 * bundle revision for a bundle can be obtained by calling
33
 * {@link Bundle#adapt(Class) bundle.adapt}(BundleRevision.class).
36
 * {@link Bundle#adapt(Class) bundle.adapt}(BundleRevision.class).
34
 * 
37
 * 
35
 * @ThreadSafe
38
 * @ThreadSafe
36
 * @noimplement
39
 * @noimplement
37
 * @version $Id: 1a15861159e7071a1eb504afbc3f75f8af1aff01 $
40
 * @version $Id: 8784ab34979add57e814661e9024f1520e98d924 $
38
 */
41
 */
39
public interface BundleRevision extends BundleReference {
42
public interface BundleRevision extends BundleReference {
40
	/**
43
	/**
Lines 93-96 Link Here
93
	 * @see #getTypes()
96
	 * @see #getTypes()
94
	 */
97
	 */
95
	int	TYPE_FRAGMENT	= 0x00000001;
98
	int	TYPE_FRAGMENT	= 0x00000001;
99
100
	/**
101
	 * Returns the bundle wiring which is using this bundle revision.
102
	 * 
103
	 * @return The bundle wiring which is using this bundle revision or
104
	 *         {@code null} if this bundle revision is a {@link #TYPE_FRAGMENT
105
	 *         fragment} or no bundle wiring is using this bundle revision.
106
	 * @see BundleWiring#getBundleRevision()
107
	 */
108
	BundleWiring getBundleWiring();
109
110
	/**
111
	 * Returns the bundle wirings to which this fragment revision is attached.
112
	 * 
113
	 * @return The bundle wirings to which this fragment revision is attached.
114
	 *         The returned collection will be empty if this bundle revision is
115
	 *         not a {@link #TYPE_FRAGMENT fragment} or this fragment revision
116
	 *         is not attached to any bundle wirings.
117
	 * @see BundleWiring#getFragmentRevisions()
118
	 */
119
	Collection<BundleWiring> getHostWirings();
96
}
120
}
(-)osgi/src/org/osgi/framework/wiring/BundleRevisions.java (+61 lines)
Added Link Here
1
/*
2
 * Copyright (c) OSGi Alliance (2011). All Rights Reserved.
3
 * 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
package org.osgi.framework.wiring;
18
19
import java.util.List;
20
21
import org.osgi.framework.Bundle;
22
import org.osgi.framework.BundleReference;
23
24
/**
25
 * The {@link BundleRevision bundle revisions} of a bundle. When a bundle is
26
 * installed and each time a bundle is updated, a new bundle revision of the
27
 * bundle is created. The current bundle revision is the most recent bundle
28
 * revision. An in use bundle revision is associated with an
29
 * {@link BundleWiring#isInUse() in use} {@link BundleWiring}. Only the current
30
 * bundle revision and all in use bundle revisions are returned.
31
 * 
32
 * <p>
33
 * The bundle revisions for a bundle can be obtained by calling
34
 * {@link Bundle#adapt(Class) bundle.adapt}({@link BundleRevisions}.class).
35
 * {@link #getRevisions()} on the bundle.
36
 * 
37
 * @ThreadSafe
38
 * @noimplement
39
 * @version $Id: f0d2e2e4e67663d48a82905958d2d7db464ef882 $
40
 */
41
public interface BundleRevisions extends BundleReference {
42
	/**
43
	 * Return the bundle revisions for the {@link BundleReference#getBundle()
44
	 * referenced} bundle.
45
	 * 
46
	 * <p>
47
	 * The result is a list of the current bundle revision and the in use bundle
48
	 * revisions. The list is ordered in reverse chronological order such that
49
	 * the first item is the current bundle revision and last item is the oldest
50
	 * in use bundle revision.
51
	 * 
52
	 * <p>
53
	 * Generally the list will have at least one bundle revision for the bundle:
54
	 * the current bundle revision. However, for an uninstalled bundle with no
55
	 * in use bundle revisions, the list will be empty.
56
	 * 
57
	 * @return A list containing a snapshot of the {@link BundleRevision}s for
58
	 *         the referenced bundle.
59
	 */
60
	List<BundleRevision> getRevisions();
61
}
(-)osgi/src/org/osgi/framework/wiring/BundleWiring.java (-8 / +4 lines)
Lines 1-5 Link Here
1
/*
1
/*
2
 * Copyright (c) OSGi Alliance (2010). All Rights Reserved.
2
 * Copyright (c) OSGi Alliance (2010, 2011). All Rights Reserved.
3
 * 
3
 * 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
5
 * you may not use this file except in compliance with the License.
Lines 40-51 Link Here
40
 * by the framework.
40
 * by the framework.
41
 * 
41
 * 
42
 * <p>
42
 * <p>
43
 * A list of all in use bundle wirings for a bundle can be obtained by calling
44
 * {@link Bundle#adapt(Class) bundle.adapt}({@link BundleWirings}.class).
45
 * {@link BundleWirings#getWirings() getWirings()}. For non-fragment bundles,
46
 * the first item in the returned list is the current bundle wiring.
47
 * 
48
 * <p>
49
 * The current bundle wiring for a non-fragment bundle can be obtained by
43
 * The current bundle wiring for a non-fragment bundle can be obtained by
50
 * calling {@link Bundle#adapt(Class) bundle.adapt}(BundleWiring.class). A
44
 * calling {@link Bundle#adapt(Class) bundle.adapt}(BundleWiring.class). A
51
 * fragment bundle does not itself have bundle wirings. So calling
45
 * fragment bundle does not itself have bundle wirings. So calling
Lines 54-60 Link Here
54
 * 
48
 * 
55
 * @ThreadSafe
49
 * @ThreadSafe
56
 * @noimplement
50
 * @noimplement
57
 * @version $Id: 77da60ad2f9fdeea7bd9465b633b35f8a06c6cdf $
51
 * @version $Id: 2a2dc2113c066c3c591a0e54325272d29fcd6d7b $
58
 */
52
 */
59
public interface BundleWiring extends BundleReference {
53
public interface BundleWiring extends BundleReference {
60
	/**
54
	/**
Lines 126-131 Link Here
126
	 * may refer to an older revision of the bundle.
120
	 * may refer to an older revision of the bundle.
127
	 * 
121
	 * 
128
	 * @return The bundle revision for this bundle wiring.
122
	 * @return The bundle revision for this bundle wiring.
123
	 * @see BundleRevision#getBundleWiring()
129
	 */
124
	 */
130
	BundleRevision getBundleRevision();
125
	BundleRevision getBundleRevision();
131
126
Lines 145-150 Link Here
145
	 *         empty list if this bundle wiring does not have any attached
140
	 *         empty list if this bundle wiring does not have any attached
146
	 *         fragments. If this bundle wiring is not {@link #isInUse() in use}
141
	 *         fragments. If this bundle wiring is not {@link #isInUse() in use}
147
	 *         , {@code null} will be returned.
142
	 *         , {@code null} will be returned.
143
	 * @see BundleRevision#getHostWirings()
148
	 */
144
	 */
149
	List<BundleRevision> getFragmentRevisions();
145
	List<BundleRevision> getFragmentRevisions();
150
146
(-)osgi/src/org/osgi/framework/wiring/BundleWirings.java (-69 lines)
Removed Link Here
1
/*
2
 * Copyright (c) OSGi Alliance (2010). All Rights Reserved.
3
 * 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
package org.osgi.framework.wiring;
18
19
import java.util.List;
20
21
import org.osgi.framework.Bundle;
22
import org.osgi.framework.BundleReference;
23
24
/**
25
 * The {@link BundleWiring#isInUse() in use} bundle wirings for a bundle. Each
26
 * time a bundle is resolved, a new bundle wiring of the bundle is created. A
27
 * bundle wiring consists of a bundle and its attached fragments and represents
28
 * the dependencies with other bundle wirings.
29
 * 
30
 * <p>
31
 * The in use bundle wirings for a bundle can be obtained by calling
32
 * {@link Bundle#adapt(Class) bundle.adapt}({@link BundleWirings}.class).
33
 * {@link BundleWirings#getWirings() getWirings()}.
34
 * 
35
 * @ThreadSafe
36
 * @noimplement
37
 * @version $Id: ecf3e7820319a6710f4dff063577bd052f5dafe2 $
38
 */
39
public interface BundleWirings extends BundleReference {
40
	/**
41
	 * Return the {@link BundleWiring#isInUse() in use} wirings for the
42
	 * {@link BundleReference#getBundle() referenced} bundle.
43
	 * 
44
	 * <p>
45
	 * If the referenced bundle is a non-fragment bundle, then the result is a
46
	 * list of in use bundle wirings. The list is ordered in reverse
47
	 * chronological order such that the first bundle wiring is the
48
	 * {@link BundleWiring#isCurrent() current} bundle wiring and last wiring is
49
	 * the oldest in use bundle wiring.
50
	 * 
51
	 * <p>
52
	 * If the referenced bundle is a fragment bundle, then the result is a list
53
	 * of in use bundle wirings to which the referenced fragment bundle is
54
	 * attached. The ordering of the list is unspecified. If the fragment bundle
55
	 * is not attached to any bundle wiring, then the returned list will be
56
	 * empty.
57
	 * 
58
	 * <p>
59
	 * The list must only contain in use bundle wirings. Generally the list will
60
	 * have at least one bundle wiring for the bundle: the current bundle
61
	 * wiring. However, for an uninstalled bundle with no in use bundle wirings
62
	 * or a newly installed bundle which has not been resolved, the list will be
63
	 * empty.
64
	 * 
65
	 * @return A list containing a snapshot of the {@link BundleWiring}s for the
66
	 *         referenced bundle.
67
	 */
68
	List<BundleWiring> getWirings();
69
}
(-)osgi/src/org/osgi/framework/wiring/Capability.java (-5 / +5 lines)
Lines 1-5 Link Here
1
/*
1
/*
2
 * Copyright (c) OSGi Alliance (2010). All Rights Reserved.
2
 * Copyright (c) OSGi Alliance (2010, 2011). All Rights Reserved.
3
 * 
3
 * 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
5
 * you may not use this file except in compliance with the License.
Lines 35-41 Link Here
35
 * 
35
 * 
36
 * @ThreadSafe
36
 * @ThreadSafe
37
 * @noimplement
37
 * @noimplement
38
 * @version $Id: 6b7ced3912cc0570547c06bb4140b78d36d7ee42 $
38
 * @version $Id: 3ad14a4c94573f8ce5d4ac9d3cb2f96f44e67f72 $
39
 */
39
 */
40
public interface Capability {
40
public interface Capability {
41
	/**
41
	/**
Lines 73-79 Link Here
73
	 * package capabilities required by a bundle wiring may change as the bundle
73
	 * package capabilities required by a bundle wiring may change as the bundle
74
	 * wiring may dynamically import additional packages.
74
	 * wiring may dynamically import additional packages.
75
	 */
75
	 */
76
	String	PACKAGE_CAPABILITY	= "osgi.package";
76
	String	PACKAGE_CAPABILITY	= "osgi.wiring.package";
77
77
78
	/**
78
	/**
79
	 * Capability name space for bundle capabilities. The bundle symbolic name
79
	 * Capability name space for bundle capabilities. The bundle symbolic name
Lines 98-104 Link Here
98
	 * {@link Constants#BUNDLE_MANIFESTVERSION Bundle-ManifestVersion}
98
	 * {@link Constants#BUNDLE_MANIFESTVERSION Bundle-ManifestVersion}
99
	 * {@literal <} 2) must not provide a bundle capability.
99
	 * {@literal <} 2) must not provide a bundle capability.
100
	 */
100
	 */
101
	String	BUNDLE_CAPABILITY	= "osgi.bundle";
101
	String	BUNDLE_CAPABILITY	= "osgi.wiring.bundle";
102
102
103
	/**
103
	/**
104
	 * Capability name space for host capabilities. The bundle symbolic name of
104
	 * Capability name space for host capabilities. The bundle symbolic name of
Lines 123-129 Link Here
123
	 * {@link Constants#BUNDLE_MANIFESTVERSION Bundle-ManifestVersion}
123
	 * {@link Constants#BUNDLE_MANIFESTVERSION Bundle-ManifestVersion}
124
	 * {@literal <} 2) must not provide a host capability.
124
	 * {@literal <} 2) must not provide a host capability.
125
	 */
125
	 */
126
	String	HOST_CAPABILITY		= "osgi.host";
126
	String	HOST_CAPABILITY		= "osgi.wiring.host";
127
127
128
	/**
128
	/**
129
	 * Returns the name space of this capability.
129
	 * Returns the name space of this capability.
(-)resolver/src/org/eclipse/osgi/internal/resolver/BundleDescriptionImpl.java (+12 lines)
Lines 912-917 Link Here
912
		}
912
		}
913
	}
913
	}
914
914
915
	public Collection<BundleWiring> getHostWirings() {
916
		@SuppressWarnings("unchecked")
917
		Collection<BundleWiring> result = Collections.EMPTY_LIST;
918
		if (!isResolved() || (getTypes() & BundleRevision.TYPE_FRAGMENT) == 0)
919
			return result;
920
		BundleDescription[] hosts = host.getHosts();
921
		result = new ArrayList<BundleWiring>(hosts.length);
922
		for (BundleDescription hostDesc : hosts)
923
			result.add(hostDesc.getBundleWiring());
924
		return result;
925
	}
926
915
	// Note that description wiring are identity equality based
927
	// Note that description wiring are identity equality based
916
	class DescriptionWiring implements BundleWiring {
928
	class DescriptionWiring implements BundleWiring {
917
		private volatile boolean valid = true;
929
		private volatile boolean valid = true;
(-)resolver/src/org/eclipse/osgi/internal/resolver/StateBuilder.java (-1 / +1 lines)
Lines 466-472 Link Here
466
466
467
				GenericSpecificationImpl spec = new GenericSpecificationImpl();
467
				GenericSpecificationImpl spec = new GenericSpecificationImpl();
468
				spec.setType(namespace);
468
				spec.setType(namespace);
469
				String filterSpec = element.getAttribute(Constants.FILTER_ATTRIBUTE);
469
				String filterSpec = element.getDirective(Constants.FILTER_DIRECTIVE);
470
				if (filterSpec != null) {
470
				if (filterSpec != null) {
471
					try {
471
					try {
472
						FilterImpl filter = FilterImpl.newInstance(filterSpec);
472
						FilterImpl filter = FilterImpl.newInstance(filterSpec);

Return to bug 334582