diff options
author | BJ Hargrave | 2011-10-31 18:51:48 +0000 |
---|---|---|
committer | BJ Hargrave | 2011-10-31 18:51:48 +0000 |
commit | 22ea986465e11d51890d7775b746c41794f4a141 (patch) | |
tree | a7893746ee22bcd451d2d4b339f76af49c4e679a | |
parent | 7e1d35c04d1f6559b7dc584e8d91adfc5ea0adac (diff) | |
download | rt.equinox.framework-22ea986465e11d51890d7775b746c41794f4a141.tar.gz rt.equinox.framework-22ea986465e11d51890d7775b746c41794f4a141.tar.xz rt.equinox.framework-22ea986465e11d51890d7775b746c41794f4a141.zip |
Bug 354191: Update OSGi framework API
12 files changed, 628 insertions, 238 deletions
diff --git a/bundles/org.eclipse.osgi/.settings/.api_filters b/bundles/org.eclipse.osgi/.settings/.api_filters index 18c2d4c9d..824e07270 100644 --- a/bundles/org.eclipse.osgi/.settings/.api_filters +++ b/bundles/org.eclipse.osgi/.settings/.api_filters @@ -1027,6 +1027,13 @@ </message_arguments> </filter> </resource> + <resource path="osgi/src/org/osgi/framework/resource/Wiring.java" type="org.osgi.framework.resource.Wiring"> + <filter id="1110441988"> + <message_arguments> + <message_argument value="org.osgi.framework.resource.Wiring"/> + </message_arguments> + </filter> + </resource> <resource path="osgi/src/org/osgi/framework/startlevel/BundleStartLevel.java" type="org.osgi.framework.startlevel.BundleStartLevel"> <filter comment="Ignore OSGi API" id="1110441988"> <message_arguments> @@ -1041,6 +1048,49 @@ </message_arguments> </filter> </resource> + <resource path="osgi/src/org/osgi/framework/wiring/BundleCapability.java" type="org.osgi.framework.wiring.BundleCapability"> + <filter id="1209008130"> + <message_arguments> + <message_argument value="1.1"/> + <message_argument value="3.8"/> + <message_argument value="getResource()"/> + </message_arguments> + </filter> + </resource> + <resource path="osgi/src/org/osgi/framework/wiring/BundleRequirement.java" type="org.osgi.framework.wiring.BundleRequirement"> + <filter id="1209008130"> + <message_arguments> + <message_argument value="1.1"/> + <message_argument value="3.8"/> + <message_argument value="getResource()"/> + </message_arguments> + </filter> + </resource> + <resource path="osgi/src/org/osgi/framework/wiring/BundleWire.java" type="org.osgi.framework.wiring.BundleWire"> + <filter id="1209008130"> + <message_arguments> + <message_argument value="1.1"/> + <message_argument value="3.8"/> + <message_argument value="getProvider()"/> + </message_arguments> + </filter> + <filter id="1209008130"> + <message_arguments> + <message_argument value="1.1"/> + <message_argument value="3.8"/> + <message_argument value="getRequirer()"/> + </message_arguments> + </filter> + </resource> + <resource path="osgi/src/org/osgi/framework/wiring/BundleWiring.java" type="org.osgi.framework.wiring.BundleWiring"> + <filter id="1209008130"> + <message_arguments> + <message_argument value="1.1"/> + <message_argument value="3.8"/> + <message_argument value="getResource()"/> + </message_arguments> + </filter> + </resource> <resource path="osgi/src/org/osgi/service/condpermadmin/ConditionalPermissionAdmin.java" type="org.osgi.service.condpermadmin.ConditionalPermissionAdmin"> <filter comment="Ignore OSGi API" id="403853384"> <message_arguments> diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/Bundle.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/Bundle.java index 9d9159b15..f1c96fd81 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/Bundle.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/Bundle.java @@ -1103,6 +1103,8 @@ public interface Bundle extends Comparable<Bundle> { * </pre> * * <p> + * URLs for directory entries must have their path end with "/". + * <p> * Note: Jar and zip files are not required to include directory entries. * URLs to directory entries will not be returned if the bundle contents do * not contain directory entries. diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/FrameworkUtil.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/FrameworkUtil.java index a902bc156..4e665ff58 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/FrameworkUtil.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/FrameworkUtil.java @@ -1,6 +1,6 @@ /* - * Copyright (c) OSGi Alliance (2005, 2010). All Rights Reserved. - * + * Copyright (c) OSGi Alliance (2005, 2011). All Rights Reserved. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,6 +19,8 @@ package org.osgi.framework; import java.lang.reflect.AccessibleObject; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.AbstractMap; @@ -35,11 +37,11 @@ import javax.security.auth.x500.X500Principal; /** * Framework Utility class. - * + * * <p> * This class contains utility methods which access Framework functions that may * be useful to bundles. - * + * * @since 1.3 * @ThreadSafe * @version $Id$ @@ -56,22 +58,22 @@ public class FrameworkUtil { * Creates a {@code Filter} object. This {@code Filter} object may * be used to match a {@code ServiceReference} object or a * {@code Dictionary} object. - * + * * <p> * If the filter cannot be parsed, an {@link InvalidSyntaxException} will be * thrown with a human readable message where the filter became unparsable. - * + * * <p> * This method returns a Filter implementation which may not perform as well * as the framework implementation-specific Filter implementation returned * by {@link BundleContext#createFilter(String)}. - * + * * @param filter The filter string. * @return A {@code Filter} object encapsulating the filter string. * @throws InvalidSyntaxException If {@code filter} contains an invalid * filter string that cannot be parsed. * @throws NullPointerException If {@code filter} is null. - * + * * @see Filter */ public static Filter createFilter(String filter) @@ -92,7 +94,7 @@ public class FrameworkUtil { * ignored, except in values. * <p> * The format of a wildcard match pattern is: - * + * * <pre> * matchPattern ::= dn-match ( ';' dn-match ) * * dn-match ::= ( '*' | rdn-match ) ( ',' rdn-match ) * | '-' @@ -107,13 +109,13 @@ public class FrameworkUtil { * <p> * For example, a match pattern with a wildcard that matches all DNs that * end with RDNs of o=ACME and c=US would look like this: - * + * * <pre> * *, o=ACME, c=US * </pre> - * + * * This match pattern would match the following DNs: - * + * * <pre> * cn = Bugs Bunny, o = ACME, c = US * ou = Carrots, cn=Daffy Duck, o=ACME, c=US @@ -121,37 +123,37 @@ public class FrameworkUtil { * dc=www, dc=acme, dc=com, o=ACME, c=US * o=ACME, c=US * </pre> - * + * * The following DNs would not match: - * + * * <pre> * street = 9C\, Avenue St. Drézéry, o=ACME, c=FR * dc=www, dc=acme, dc=com, c=US * </pre> - * + * * If a wildcard is used for a value of an RDN, the value must be exactly *. * The wildcard must match any value, and no substring matching must be * done. For example: - * + * * <pre> * cn=*,o=ACME,c=* * </pre> - * + * * This match pattern with wildcard must match the following DNs: - * + * * <pre> * cn=Bugs Bunny,o=ACME,c=US * cn = Daffy Duck , o = ACME , c = US * cn=Road Runner, o=ACME, c=NL * </pre> - * + * * But not: - * + * * <pre> * o=ACME, c=NL * dc=acme.com, cn=Bugs Bunny, o=ACME, c=US * </pre> - * + * * <p> * A match pattern may contain a chain of DN match patterns. The * semicolon(';' \u003B) must be used to separate DN match patterns in a @@ -161,7 +163,7 @@ public class FrameworkUtil { * The following example matches a certificate signed by Tweety Inc. in the * US. * </p> - * + * * <pre> * * ; ou=S & V, o=Tweety Inc., c=US * </pre> @@ -172,11 +174,11 @@ public class FrameworkUtil { * represents a single DN. For example, to match a DN where the Tweety Inc. * is in the DN chain, use the following expression: * </p> - * + * * <pre> * - ; *, o=Tweety Inc., c=US * </pre> - * + * * @param matchPattern The pattern against which to match the DN chain. * @param dnChain The DN chain to match against the specified pattern. Each * element of the chain must be of type {@code String} and use the @@ -197,7 +199,7 @@ public class FrameworkUtil { * Return a {@code Bundle} for the specified bundle class. The returned * {@code Bundle} is the bundle associated with the bundle class loader * which defined the specified class. - * + * * @param classFromBundle A class defined by a bundle class loader. * @return A {@code Bundle} for the specified bundle class or * {@code null} if the specified class was not defined by a @@ -225,7 +227,7 @@ public class FrameworkUtil { * constructor with the desired filter string. A Filter object can be called * numerous times to determine if the match argument matches the filter * string that was used to create the Filter object. - * + * * <p> * The syntax of a filter string is the string representation of LDAP search * filters as defined in RFC 1960: <i>A String Representation of LDAP Search @@ -234,11 +236,11 @@ public class FrameworkUtil { * Filters</i> (available at http://www.ietf.org/rfc/rfc2254.txt) supersedes * RFC 1960 but only adds extensible matching and is not applicable for this * API. - * + * * <p> * The string representation of an LDAP search filter is defined by the * following grammar. It uses a prefix format. - * + * * <pre> * <filter> ::= '(' <filtercomp> ')' * <filtercomp> ::= <and> | <or> | <not> | <item> @@ -260,7 +262,7 @@ public class FrameworkUtil { * <starval> ::= NULL | <value> '*' <starval> * <final> ::= NULL | <value> * </pre> - * + * * {@code <attr>} is a string representing an attribute, or key, * in the properties objects of the registered services. Attribute names are * not case sensitive; that is cn and CN both refer to the same attribute. @@ -272,29 +274,29 @@ public class FrameworkUtil { * character. Note that although both the {@code <substring>} and * {@code <present>} productions can produce the {@code 'attr=*'} * construct, this construct is used only to denote a presence filter. - * + * * <p> * Examples of LDAP filters are: - * + * * <pre> * "(cn=Babs Jensen)" * "(!(cn=Tim Howes))" * "(&(" + Constants.OBJECTCLASS + "=Person)(|(sn=Jensen)(cn=Babs J*)))" * "(o=univ*of*mich*)" * </pre> - * + * * <p> * The approximate match ({@code ~=}) is implementation specific but * should at least ignore case and white space differences. Optional are * codes like soundex or other smart "closeness" comparisons. - * + * * <p> * Comparison of values is not straightforward. Strings are compared * differently than numbers and it is possible for a key to have multiple * values. Note that that keys in the match argument must always be strings. * The comparison is defined by the object type of the key's value. The * following rules apply for comparison: - * + * * <blockquote> * <TABLE BORDER=0> * <TR> @@ -327,17 +329,17 @@ public class FrameworkUtil { * </TR> * </TABLE> * Note: arrays of primitives are also supported. </blockquote> - * + * * A filter matches a key that has multiple values if it matches at least * one of those values. For example, - * + * * <pre> * Dictionary d = new Hashtable(); * d.put("cn", new String[] {"a", "b", "c"}); * </pre> - * + * * d will match {@code (cn=a)} and also {@code (cn=b)} - * + * * <p> * A filter component that references a key having an unrecognizable data * type will evaluate to {@code false} . @@ -367,12 +369,12 @@ public class FrameworkUtil { /** * Constructs a {@link FilterImpl} object. This filter object may be * used to match a {@link ServiceReference} or a Dictionary. - * + * * <p> * If the filter cannot be parsed, an {@link InvalidSyntaxException} * will be thrown with a human readable message where the filter became * unparsable. - * + * * @param filterString the filter string. * @throws InvalidSyntaxException If the filter parameter contains an * invalid filter string that cannot be parsed. @@ -395,7 +397,7 @@ public class FrameworkUtil { * This {@code Filter} is executed using the keys and values of the * referenced service's properties. The keys are looked up in a case * insensitive manner. - * + * * @param reference The reference to the service whose properties are * used in the match. * @return {@code true} if the service's properties match this @@ -410,7 +412,7 @@ public class FrameworkUtil { * This {@code Filter} is executed using the specified * {@code Dictionary}'s keys and values. The keys are looked up in a * case insensitive manner. - * + * * @param dictionary The {@code Dictionary} whose key/value pairs are * used in the match. * @return {@code true} if the {@code Dictionary}'s values match this @@ -426,7 +428,7 @@ public class FrameworkUtil { * Filter using a {@code Dictionary}. This {@code Filter} is executed * using the specified {@code Dictionary}'s keys and values. The keys * are looked up in a normal manner respecting case. - * + * * @param dictionary The {@code Dictionary} whose key/value pairs are * used in the match. * @return {@code true} if the {@code Dictionary}'s values match this @@ -484,7 +486,7 @@ public class FrameworkUtil { * Filter using a {@code Map}. This {@code Filter} is executed using the * specified {@code Map}'s keys and values. The keys are looked up in a * normal manner respecting case. - * + * * @param map The {@code Map} whose key/value pairs are used in the * match. Maps with {@code null} key or values are not supported. * A {@code null} value is considered not present to the filter. @@ -503,7 +505,7 @@ public class FrameworkUtil { } return true; } - + case OR : { FilterImpl[] filters = (FilterImpl[]) value; for (FilterImpl f : filters) { @@ -513,12 +515,12 @@ public class FrameworkUtil { } return false; } - + case NOT : { FilterImpl filter = (FilterImpl) value; return !filter.matches(map); } - + case SUBSTRING : case EQUAL : case GREATER : @@ -527,13 +529,13 @@ public class FrameworkUtil { Object prop = (map == null) ? null : map.get(attr); return compare(op, prop, value); } - + case PRESENT : { Object prop = (map == null) ? null : map.get(attr); return prop != null; } } - + return false; } @@ -542,7 +544,7 @@ public class FrameworkUtil { * <p> * The filter string is normalized by removing whitespace which does not * affect the meaning of the filter. - * + * * @return This {@code Filter}'s filter string. */ public String toString() { @@ -558,7 +560,7 @@ public class FrameworkUtil { * <p> * The filter string is normalized by removing whitespace which does not * affect the meaning of the filter. - * + * * @return This {@code Filter}'s filter string. */ private StringBuffer normalize() { @@ -657,11 +659,11 @@ public class FrameworkUtil { /** * Compares this {@code Filter} to another {@code Filter}. - * + * * <p> * This implementation returns the result of calling * {@code this.toString().equals(obj.toString()}. - * + * * @param obj The object to compare against this {@code Filter}. * @return If the other object is a {@code Filter} object, then * returns the result of calling @@ -682,11 +684,11 @@ public class FrameworkUtil { /** * Returns the hashCode for this {@code Filter}. - * + * * <p> * This implementation returns the result of calling * {@code this.toString().hashCode()}. - * + * * @return The hashCode of this {@code Filter}. */ public int hashCode() { @@ -695,7 +697,7 @@ public class FrameworkUtil { /** * Encode the value string such that '(', '*', ')' and '\' are escaped. - * + * * @param value unencoded value string. * @return encoded value string. */ @@ -1174,38 +1176,73 @@ public class FrameworkUtil { return false; } - private static final Class< ? >[] constructorType = new Class[] {String.class}; + private static Object valueOf(Class< ? > target, String value2) { + do { + Method method; + try { + method = target.getMethod("valueOf", String.class); + } + catch (NoSuchMethodException e) { + break; + } + if (Modifier.isStatic(method.getModifiers()) + && target.isAssignableFrom(method.getReturnType())) { + setAccessible(method); + try { + return method.invoke(null, value2.trim()); + } + catch (IllegalAccessException e) { + return null; + } + catch (InvocationTargetException e) { + return null; + } + } + } while (false); + + do { + Constructor< ? > constructor; + try { + constructor = target.getConstructor(String.class); + } + catch (NoSuchMethodException e) { + break; + } + setAccessible(constructor); + try { + return constructor.newInstance(value2.trim()); + } + catch (IllegalAccessException e) { + return null; + } + catch (InvocationTargetException e) { + return null; + } + catch (InstantiationException e) { + return null; + } + } while (false); + + return null; + } + + private static void setAccessible(AccessibleObject accessible) { + if (!accessible.isAccessible()) { + AccessController.doPrivileged(new SetAccessibleAction( + accessible)); + } + } private boolean compare_Comparable(int operation, Comparable<Object> value1, Object value2) { if (operation == SUBSTRING) { return false; } - Constructor< ? > constructor; - try { - constructor = value1.getClass().getConstructor(constructorType); - } - catch (NoSuchMethodException e) { + value2 = valueOf(value1.getClass(), (String) value2); + if (value2 == null) { return false; } try { - if (!constructor.isAccessible()) - AccessController.doPrivileged(new SetAccessibleAction( - constructor)); - value2 = constructor - .newInstance(new Object[] {((String) value2).trim()}); - } - catch (IllegalAccessException e) { - return false; - } - catch (InvocationTargetException e) { - return false; - } - catch (InstantiationException e) { - return false; - } - - try { switch (operation) { case APPROX : case EQUAL : { @@ -1231,31 +1268,11 @@ public class FrameworkUtil { if (operation == SUBSTRING) { return false; } - Constructor< ? > constructor; - try { - constructor = value1.getClass().getConstructor(constructorType); - } - catch (NoSuchMethodException e) { + value2 = valueOf(value1.getClass(), (String) value2); + if (value2 == null) { return false; } try { - if (!constructor.isAccessible()) - AccessController.doPrivileged(new SetAccessibleAction( - constructor)); - value2 = constructor - .newInstance(new Object[] {((String) value2).trim()}); - } - catch (IllegalAccessException e) { - return false; - } - catch (InvocationTargetException e) { - return false; - } - catch (InstantiationException e) { - return false; - } - - try { switch (operation) { case APPROX : case EQUAL : @@ -1274,10 +1291,10 @@ public class FrameworkUtil { /** * Map a string for an APPROX (~=) comparison. - * + * * This implementation removes white spaces. This is the minimum * implementation allowed by the OSGi spec. - * + * * @param input Input string. * @return String ready for APPROX comparison. */ @@ -1649,7 +1666,7 @@ public class FrameworkUtil { /** * Create a case insensitive map from the specified dictionary. - * + * * @param dictionary * @throws IllegalArgumentException If {@code dictionary} contains case * variants of the same key name. @@ -1741,11 +1758,11 @@ public class FrameworkUtil { * what we refer to as the DN chain. Each DN is made up of relative * distinguished names (RDN) which in turn are made up of key value pairs. * For example: - * + * * <pre> * cn=ben+ou=research,o=ACME,c=us;ou=Super CA,c=CA * </pre> - * + * * is made up of two DNs: "{@code cn=ben+ou=research,o=ACME,c=us} * " and " {@code ou=Super CA,c=CA} * ". The first DN is made of of three RDNs: " @@ -1769,7 +1786,7 @@ public class FrameworkUtil { /** * Check the name/value pairs of the rdn against the pattern. - * + * * @param rdn List of name value pairs for a given RDN. * @param rdnPattern List of name value pattern pairs. * @return true if the list of name value pairs match the pattern. @@ -1842,7 +1859,7 @@ public class FrameworkUtil { * in the RDN List will be a String, if the element represents a * wildcard ("*"), or a List of Strings, each String representing a * name/value pair in the RDN. - * + * * @param dnChain * @return a list of DNs. * @throws IllegalArgumentException @@ -1946,7 +1963,7 @@ public class FrameworkUtil { /** * Takes a distinguished name in canonical form and fills in the * rdnArray with the extracted RDNs. - * + * * @param dn the distinguished name in canonical form. * @param rdn the list to fill in with RDNs extracted from the dn * @throws IllegalArgumentException if a formatting error is found. @@ -2153,7 +2170,7 @@ public class FrameworkUtil { /** * Matches a distinguished name chain against a pattern of a * distinguished name chain. - * + * * @param dnChain * @param pattern the pattern of distinguished name (DN) chains to match * against the dnChain. Wildcards ("*" or "-") can be used in diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/resource/Resource.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/resource/Resource.java index 56916cb25..3d95628ef 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/resource/Resource.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/resource/Resource.java @@ -1,6 +1,6 @@ /* * Copyright (c) OSGi Alliance (2011). All Rights Reserved. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -21,9 +21,9 @@ import java.util.List; /** * A resource is the representation of a uniquely identified and typed data. - * + * * A resources can be wired together via capabilities and requirements. - * + * * @ThreadSafe * @version $Id$ */ @@ -31,26 +31,26 @@ public interface Resource { /** * Returns the capabilities declared by this resource. * - * @param namespace - * The name space of the declared capabilities to return or - * {@code null} to return the declared capabilities from all name - * spaces. - * @return A list containing a snapshot of the declared {@link Capability}s, - * or an empty list if this resource declares no capabilities in the - * specified name space. + * @param namespace The name space of the declared capabilities to return or + * {@code null} to return the declared capabilities from all name + * spaces. + * @return An unmodifiable list containing the declared {@link Capability}s + * from the specified name space. The returned list will be empty if + * this resource declares no capabilities in the specified name + * space. */ List<Capability> getCapabilities(String namespace); /** * Returns the requirements declared by this bundle resource. - * - * @param namespace - * The name space of the declared requirements to return or - * {@code null} to return the declared requirements from all name - * spaces. - * @return A list containing a snapshot of the declared {@link Requirement} - * s, or an empty list if this resource declares no requirements in - * the specified name space. + * + * @param namespace The name space of the declared requirements to return or + * {@code null} to return the declared requirements from all name + * spaces. + * @return An unmodifiable list containing the declared {@link Requirement} + * s from the specified name space. The returned list will be empty + * if this resource declares no requirements in the specified name + * space. */ List<Requirement> getRequirements(String namespace); } diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/resource/Wire.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/resource/Wire.java index 87d274ba3..41ff1d01d 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/resource/Wire.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/resource/Wire.java @@ -1,6 +1,6 @@ /* * Copyright (c) OSGi Alliance (2011). All Rights Reserved. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -18,40 +18,43 @@ package org.osgi.framework.resource; /** * A wire connecting a {@link Capability} to a {@link Requirement}. - * + * * @ThreadSafe * @version $Id$ */ public interface Wire { /** * Returns the {@link Capability} for this wire. - * + * * @return The {@link Capability} for this wire. */ Capability getCapability(); /** - * Return the {@link Requirement} for this wire. - * + * Returns the {@link Requirement} for this wire. + * * @return The {@link Requirement} for this wire. */ Requirement getRequirement(); /** - * Return the providing {@link Resource resource} of the {@link #getCapability() capability}. + * Returns the resource providing the {@link #getCapability() capability}. * <p> - * The resource returned may differ from the resource referenced by the {@link #getCapability() - * capability}. - * @return the providing {@link Resource resource}. + * The returned resource may differ from the resource referenced by the + * {@link #getCapability() capability}. + * + * @return The resource providing the capability. */ Resource getProvider(); /** - * Return the requiring {@link Resource resource} of the {@link #getRequirement() requirement}. + * Returns the resource who {@link #getRequirement() requires} the + * {@link #getCapability() capability}. * <p> - * The resource returned my differ from the resource referenced by the {@link #getRequirement() - * requirement} - * @return the requiring {@link Resource resource}. + * The returned resource may differ from the resource referenced by the + * {@link #getRequirement() requirement}. + * + * @return The resource who requires the capability. */ Resource getRequirer(); } diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/resource/Wiring.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/resource/Wiring.java new file mode 100644 index 000000000..1dcd04f83 --- /dev/null +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/resource/Wiring.java @@ -0,0 +1,142 @@ +/* + * Copyright (c) OSGi Alliance (2011). All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.osgi.framework.resource; + +import java.util.List; + +/** + * A wiring for a resource. A wiring is associated with a resource and + * represents the dependencies with other wirings. + * + * @ThreadSafe + * @version $Id$ + */ +public interface Wiring { + /** + * Returns the capabilities provided by this wiring. + * + * <p> + * Only capabilities considered by the resolver are returned. For example, + * capabilities with + * {@link ResourceConstants#CAPABILITY_EFFECTIVE_DIRECTIVE effective} + * directive not equal to {@link ResourceConstants#EFFECTIVE_RESOLVE + * resolve} are not returned. + * + * <p> + * A capability may not be required by any wiring and thus there may be no + * {@link #getProvidedResourceWires(String) wires} for the capability. + * + * <p> + * A wiring for a non-fragment resource provides a subset of the declared + * capabilities from the resource and all attached fragment + * resources<sup>†</sup>. Not all declared capabilities may be + * provided since some may be discarded. For example, if a package is + * declared to be both exported and imported, only one is selected and the + * other is discarded. + * <p> + * A wiring for a fragment resource with a symbolic name must provide + * exactly one {@link ResourceConstants#IDENTITY_NAMESPACE identity} + * capability. + * <p> + * † The {@link ResourceConstants#IDENTITY_NAMESPACE identity} + * capability provided by attached fragment resource must not be included in + * the capabilities of the host wiring. + * + * @param namespace The name space of the capabilities to return or + * {@code null} to return the capabilities from all name spaces. + * @return A list containing a snapshot of the {@link Capability}s, or an + * empty list if this wiring provides no capabilities in the + * specified name space. For a given name space, the list contains + * the wires in the order the capabilities were specified in the + * manifests of the {@link #getResource() resource} and the attached + * fragment resources<sup>†</sup> of this wiring. There is no + * ordering defined between capabilities in different name spaces. + */ + List<Capability> getResourceCapabilities(String namespace); + + /** + * Returns the requirements of this wiring. + * + * <p> + * Only requirements considered by the resolver are returned. For example, + * requirements with + * {@link ResourceConstants#REQUIREMENT_EFFECTIVE_DIRECTIVE effective} + * directive not equal to {@link ResourceConstants#EFFECTIVE_RESOLVE + * resolve} are not returned. + * + * <p> + * A wiring for a non-fragment resource has a subset of the declared + * requirements from the resource and all attached fragment resources. Not + * all declared requirements may be present since some may be discarded. For + * example, if a package is declared to be optionally imported and is not + * actually imported, the requirement must be discarded. + * + * @param namespace The name space of the requirements to return or + * {@code null} to return the requirements from all name spaces. + * @return A list containing a snapshot of the {@link Requirement}s, or an + * empty list if this wiring uses no requirements in the specified + * name space. For a given name space, the list contains the wires + * in the order the requirements were specified in the manifests of + * the {@link #getResource() resource} and the attached fragment + * resources of this wiring. There is no ordering defined between + * requirements in different name spaces. + */ + List<Requirement> getResourceRequirements(String namespace); + + /** + * Returns the {@link Wire}s to the provided {@link Capability capabilities} + * of this wiring. + * + * @param namespace The name space of the capabilities for which to return + * wires or {@code null} to return the wires for the capabilities in + * all name spaces. + * @return A list containing a snapshot of the {@link Wire}s for the + * {@link Capability capabilities} of this wiring, or an empty list + * if this wiring has no capabilities in the specified name space. + * For a given name space, the list contains the wires in the order + * the capabilities were specified in the manifests of the + * {@link #getResource() resource} and the attached fragment + * resources of this wiring. There is no ordering defined between + * capabilities in different name spaces. + */ + List<Wire> getProvidedResourceWires(String namespace); + + /** + * Returns the {@link Wire}s to the {@link Requirement requirements} in use + * by this wiring. + * + * @param namespace The name space of the requirements for which to return + * wires or {@code null} to return the wires for the requirements in + * all name spaces. + * @return A list containing a snapshot of the {@link Wire}s for the + * {@link Requirement requirements} of this wiring, or an empty list + * if this wiring has no requirements in the specified name space. + * For a given name space, the list contains the wires in the order + * the requirements were specified in the manifests of the + * {@link #getResource() resource} and the attached fragment + * resources of this wiring. There is no ordering defined between + * requirements in different name spaces. + */ + List<Wire> getRequiredResourceWires(String namespace); + + /** + * Returns the resource associated with this wiring. + * + * @return The resource associated with this wiring. + */ + Resource getResource(); +} diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/wiring/BundleCapability.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/wiring/BundleCapability.java index 6516fa861..8b31e9d8c 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/wiring/BundleCapability.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/wiring/BundleCapability.java @@ -1,6 +1,6 @@ /* * Copyright (c) OSGi Alliance (2010, 2011). All Rights Reserved. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -23,7 +23,7 @@ import org.osgi.framework.resource.Capability; /** * A capability that has been declared from a {@link BundleRevision bundle * revision}. - * + * * @ThreadSafe * @noimplement * @version $Id$ @@ -32,10 +32,7 @@ public interface BundleCapability extends Capability { /** * Returns the bundle revision declaring this capability. - * - * <p> - * This method returns the same object as {@link #getResource()}. - * + * * @return The bundle revision declaring this capability. */ BundleRevision getRevision(); @@ -54,4 +51,14 @@ public interface BundleCapability extends Capability { * {@inheritDoc} */ Map<String, Object> getAttributes(); + + /** + * {@inheritDoc} + * + * <p> + * This method returns the same value as {@link #getRevision()}. + * + * @since 1.1 + */ + BundleRevision getResource(); } diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/wiring/BundleRequirement.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/wiring/BundleRequirement.java index f69b26cb7..5971652e6 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/wiring/BundleRequirement.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/wiring/BundleRequirement.java @@ -1,6 +1,6 @@ /* * Copyright (c) OSGi Alliance (2010, 2011). All Rights Reserved. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -18,12 +18,13 @@ package org.osgi.framework.wiring; import java.util.Map; +import org.osgi.framework.resource.Capability; import org.osgi.framework.resource.Requirement; /** * A requirement that has been declared from a {@link BundleRevision bundle * revision}. - * + * * @ThreadSafe * @noimplement * @version $Id$ @@ -31,17 +32,14 @@ import org.osgi.framework.resource.Requirement; public interface BundleRequirement extends Requirement { /** * Returns the bundle revision declaring this requirement. - * - * <p> - * This method returns the same object as {@link #getResource()}. - * + * * @return The bundle revision declaring this requirement. */ BundleRevision getRevision(); /** * Returns whether the specified capability matches this requirement. - * + * * @param capability The capability to match to this requirement. * @return {@code true} if the specified capability has the same * {@link #getNamespace() name space} as this requirement and the @@ -65,4 +63,21 @@ public interface BundleRequirement extends Requirement { * {@inheritDoc} */ Map<String, Object> getAttributes(); + + /** + * {@inheritDoc} + * + * <p> + * This method returns the same value as {@link #getRevision()}. + * + * @since 1.1 + */ + BundleRevision getResource(); + + /** + * {@inheritDoc} + * + * @since 1.1 + */ + boolean matches(Capability capability); } diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/wiring/BundleRevision.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/wiring/BundleRevision.java index ea4d3c17f..a9dd63b0e 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/wiring/BundleRevision.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/wiring/BundleRevision.java @@ -1,6 +1,6 @@ /* * Copyright (c) OSGi Alliance (2010, 2011). All Rights Reserved. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -22,6 +22,8 @@ import org.osgi.framework.Bundle; import org.osgi.framework.BundleReference; import org.osgi.framework.Constants; import org.osgi.framework.Version; +import org.osgi.framework.resource.Capability; +import org.osgi.framework.resource.Requirement; import org.osgi.framework.resource.Resource; import org.osgi.framework.resource.ResourceConstants; @@ -30,7 +32,7 @@ import org.osgi.framework.resource.ResourceConstants; * updated, a new bundle revision of the bundle is created. Since a bundle * update can change the entries in a bundle, different bundle wirings for the * same bundle can be associated with different bundle revisions. - * + * * <p> * For a bundle that has not been uninstalled, the most recent bundle revision * is defined to be the current bundle revision. A bundle in the UNINSTALLED @@ -38,7 +40,7 @@ import org.osgi.framework.resource.ResourceConstants; * bundle can be obtained by calling {@link Bundle#adapt(Class) bundle.adapt} * (BundleRevision.class). Since a bundle in the UNINSTALLED state does not have * a current revision, adapting such a bundle returns {@code null}. - * + * * <p> * The framework defines name spaces for {@link #PACKAGE_NAMESPACE package}, * {@link #BUNDLE_NAMESPACE bundle} and {@link #HOST_NAMESPACE host} @@ -46,7 +48,7 @@ import org.osgi.framework.resource.ResourceConstants; * wiring information by the framework. They must not be used in * {@link Constants#PROVIDE_CAPABILITY Provide-Capability} and * {@link Constants#REQUIRE_CAPABILITY Require-Capability} manifest headers. - * + * * @ThreadSafe * @noimplement * @version $Id$ @@ -54,7 +56,7 @@ import org.osgi.framework.resource.ResourceConstants; public interface BundleRevision extends BundleReference, Resource { /** * Returns the symbolic name for this bundle revision. - * + * * @return The symbolic name for this bundle revision. * @see Bundle#getSymbolicName() */ @@ -62,7 +64,7 @@ public interface BundleRevision extends BundleReference, Resource { /** * Returns the version for this bundle revision. - * + * * @return The version for this bundle revision, or * {@link Version#emptyVersion} if this bundle revision has no * version information. @@ -72,35 +74,37 @@ public interface BundleRevision extends BundleReference, Resource { /** * Returns the capabilities declared by this bundle revision. - * + * * @param namespace The name space of the declared capabilities to return or * {@code null} to return the declared capabilities from all name * spaces. - * @return A list containing a snapshot of the declared - * {@link BundleCapability}s, or an empty list if this bundle - * revision declares no capabilities in the specified name space. - * The list contains the declared capabilities in the order they are - * specified in the manifest. + * @return An unmodifiable list containing the declared + * {@link BundleCapability}s from the specified name space. The + * returned list will be empty if this bundle revision declares no + * capabilities in the specified name space. The list contains the + * declared capabilities in the order they are specified in the + * manifest. */ List<BundleCapability> getDeclaredCapabilities(String namespace); /** * Returns the requirements declared by this bundle revision. - * + * * @param namespace The name space of the declared requirements to return or * {@code null} to return the declared requirements from all name * spaces. - * @return A list containing a snapshot of the declared - * {@link BundleRequirement}s, or an empty list if this bundle - * revision declares no requirements in the specified name space. - * The list contains the declared requirements in the order they are - * specified in the manifest. + * @return An unmodifiable list containing the declared + * {@link BundleRequirement}s from the specified name space. The + * returned list will be empty if this bundle revision declares no + * requirements in the specified name space. The list contains the + * declared requirements in the order they are specified in the + * manifest. */ List<BundleRequirement> getDeclaredRequirements(String namespace); /** * Name space for package capabilities and requirements. - * + * * <p> * The name of the package is stored in the capability attribute of the same * name as this name space (osgi.wiring.package). The other @@ -118,14 +122,14 @@ public interface BundleRevision extends BundleReference, Resource { * bundle-version} capability attribute must contain the * {@link BundleRevision#getVersion() version} of the provider if one is * specified or {@link Version#emptyVersion} if not specified. - * + * * <p> * The package capabilities provided by the system bundle, that is the * bundle with id zero, must include the package specified by the * {@link Constants#FRAMEWORK_SYSTEMPACKAGES} and * {@link Constants#FRAMEWORK_SYSTEMPACKAGES_EXTRA} framework properties as * well as any other package exported by the framework implementation. - * + * * <p> * A bundle revision {@link BundleRevision#getDeclaredCapabilities(String) * declares} zero or more package capabilities (this is, exported packages) @@ -143,7 +147,7 @@ public interface BundleRevision extends BundleReference, Resource { /** * Name space for bundle capabilities and requirements. - * + * * <p> * The bundle symbolic name of the bundle is stored in the capability * attribute of the same name as this name space (osgi.wiring.bundle). @@ -156,14 +160,14 @@ public interface BundleRevision extends BundleReference, Resource { * attribute must contain the {@link Version} of the bundle from the * {@link Constants#BUNDLE_VERSION Bundle-Version} manifest header if one is * specified or {@link Version#emptyVersion} if not specified. - * + * * <p> * A non-fragment revision * {@link BundleRevision#getDeclaredCapabilities(String) declares} exactly * one<sup>†</sup> bundle capability (that is, the bundle can be * required by another bundle). A fragment revision must not declare a * bundle capability. - * + * * <p> * A bundle wiring for a non-fragment revision * {@link BundleWiring#getCapabilities(String) provides} exactly @@ -171,7 +175,7 @@ public interface BundleRevision extends BundleReference, Resource { * required by another bundle) and * {@link BundleWiring#getRequiredWires(String) requires} zero or more * bundle capabilities (that is, requires other bundles). - * + * * <p> * † A bundle with no bundle symbolic name (that is, a bundle with * {@link Constants#BUNDLE_MANIFESTVERSION Bundle-ManifestVersion} @@ -181,7 +185,7 @@ public interface BundleRevision extends BundleReference, Resource { /** * Name space for host capabilities and requirements. - * + * * <p> * The bundle symbolic name of the bundle is stored in the capability * attribute of the same name as this name space (osgi.wiring.host). @@ -194,7 +198,7 @@ public interface BundleRevision extends BundleReference, Resource { * attribute must contain the {@link Version} of the bundle from the * {@link Constants#BUNDLE_VERSION Bundle-Version} manifest header if one is * specified or {@link Version#emptyVersion} if not specified. - * + * * <p> * A non-fragment revision * {@link BundleRevision#getDeclaredCapabilities(String) declares} zero or @@ -203,7 +207,7 @@ public interface BundleRevision extends BundleReference, Resource { * attached}. A fragment revision must * {@link BundleRevision#getDeclaredRequirements(String) declare} exactly * one host requirement. - * + * * <p> * A bundle wiring for a non-fragment revision * {@link BundleWiring#getCapabilities(String) provides} zero or @@ -212,7 +216,7 @@ public interface BundleRevision extends BundleReference, Resource { * attached}. A bundle wiring for a fragment revision * {@link BundleWiring#getRequiredWires(String) requires} a host capability * for each host to which it is attached. - * + * * <p> * † A bundle with no bundle symbolic name (that is, a bundle with * {@link Constants#BUNDLE_MANIFESTVERSION Bundle-ManifestVersion} @@ -226,14 +230,14 @@ public interface BundleRevision extends BundleReference, Resource { * <ul> * <li>{@link #TYPE_FRAGMENT} * </ul> - * + * * A bundle revision may be more than one type at a time. A type code is * used to identify the bundle revision type for future extendability. - * + * * <p> * If this bundle revision is not one or more of the defined types then 0 is * returned. - * + * * @return The special types of this bundle revision. The type values are * ORed together. */ @@ -241,17 +245,39 @@ public interface BundleRevision extends BundleReference, Resource { /** * Bundle revision type indicating the bundle revision is a fragment. - * + * * @see #getTypes() */ int TYPE_FRAGMENT = 0x00000001; /** * Returns the bundle wiring which is using this bundle revision. - * + * * @return The bundle wiring which is using this bundle revision or * {@code null} if no bundle wiring is using this bundle revision. * @see BundleWiring#getRevision() */ BundleWiring getWiring(); + + /** + * {@inheritDoc} + * + * <p> + * This method returns the same value as + * {@link #getDeclaredCapabilities(String)}. + * + * @since 1.1 + */ + List<Capability> getCapabilities(String namespace); + + /** + * {@inheritDoc} + * + * <p> + * This method returns the same value as + * {@link #getDeclaredRequirements(String)}. + * + * @since 1.1 + */ + List<Requirement> getRequirements(String namespace); } diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/wiring/BundleWire.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/wiring/BundleWire.java index b9e5cf0a2..0d5aec119 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/wiring/BundleWire.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/wiring/BundleWire.java @@ -1,6 +1,6 @@ /* * Copyright (c) OSGi Alliance (2011). All Rights Reserved. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -21,7 +21,7 @@ import org.osgi.framework.resource.Wire; /** * A wire connecting a {@link BundleCapability} to a {@link BundleRequirement}. - * + * * @ThreadSafe * @noimplement * @version $Id$ @@ -29,14 +29,14 @@ import org.osgi.framework.resource.Wire; public interface BundleWire extends Wire { /** * Returns the {@link BundleCapability} for this wire. - * + * * @return The {@link BundleCapability} for this wire. */ BundleCapability getCapability(); /** * Return the {@link BundleRequirement} for this wire. - * + * * @return The {@link BundleRequirement} for this wire. */ BundleRequirement getRequirement(); @@ -44,12 +44,12 @@ public interface BundleWire extends Wire { /** * Returns the bundle wiring {@link BundleWiring#getProvidedWires(String) * providing} the {@link #getCapability() capability}. - * + * * <p> * The bundle revision referenced by the returned bundle wiring may differ - * from the bundle revision reference by the {@link #getCapability() + * from the bundle revision referenced by the {@link #getCapability() * capability}. - * + * * @return The bundle wiring providing the capability. If the bundle wiring * providing the capability is not {@link BundleWiring#isInUse() in * use}, {@code null} will be returned. @@ -60,16 +60,39 @@ public interface BundleWire extends Wire { * Returns the bundle wiring who * {@link BundleWiring#getRequiredWires(String) requires} the * {@link #getCapability() capability}. - * + * * <p> * The bundle revision referenced by the returned bundle wiring may differ - * from the bundle revision reference by the {@link #getRequirement() + * from the bundle revision referenced by the {@link #getRequirement() * requirement}. - * + * * @return The bundle wiring whose requirement is wired to the capability. * If the bundle wiring requiring the capability is not * {@link BundleWiring#isInUse() in use}, {@code null} will be * returned. */ BundleWiring getRequirerWiring(); + + /** + * {@inheritDoc} + * + * <p> + * This method returns the same value as {@link #getProviderWiring()}. + * {@link BundleWiring#getRevision() getRevision()}. + * + * @since 1.1 + */ + BundleRevision getProvider(); + + /** + * {@inheritDoc} + * + * <p> + * This method returns the same value as {@link #getRequirerWiring()}. + * {@link BundleWiring#getRevision() getRevision()}. + * + * @since 1.1 + */ + BundleRevision getRequirer(); + } diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/wiring/BundleWiring.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/wiring/BundleWiring.java index 0f6afa5f6..1479627fa 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/wiring/BundleWiring.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/wiring/BundleWiring.java @@ -1,6 +1,6 @@ /* * Copyright (c) OSGi Alliance (2010, 2011). All Rights Reserved. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -22,13 +22,17 @@ import java.util.List; import org.osgi.framework.Bundle; import org.osgi.framework.BundleReference; +import org.osgi.framework.resource.Capability; +import org.osgi.framework.resource.Requirement; import org.osgi.framework.resource.ResourceConstants; +import org.osgi.framework.resource.Wire; +import org.osgi.framework.resource.Wiring; /** * A wiring for a bundle. Each time a bundle is resolved, a new bundle wiring * for the bundle is created. A bundle wiring is associated with a bundle * revision and represents the dependencies with other bundle wirings. - * + * * <p> * The bundle wiring for a bundle is the {@link #isCurrent() current} bundle * wiring if it is the most recent bundle wiring for the current bundle @@ -39,25 +43,25 @@ import org.osgi.framework.resource.ResourceConstants; * loader. All bundles with non-current, in use bundle wirings are considered * removal pending. Once a bundle wiring is no longer in use, it is considered * stale and is discarded by the framework. - * + * * <p> * The current bundle wiring for a bundle can be obtained by calling * {@link Bundle#adapt(Class) bundle.adapt}(BundleWiring.class). A bundle in the * INSTALLED or UNINSTALLED state does not have a current wiring, adapting such * a bundle returns {@code null}. - * + * * @ThreadSafe * @noimplement * @version $Id$ */ -public interface BundleWiring extends BundleReference { +public interface BundleWiring extends BundleReference, Wiring { /** * Returns {@code true} if this bundle wiring is the current bundle wiring. * The bundle wiring for a bundle is the current bundle wiring if it is the * most recent bundle wiring for the current bundle revision. All bundles * with non-current, in use bundle wirings are considered * {@link FrameworkWiring#getRemovalPendingBundles() removal pending}. - * + * * @return {@code true} if this bundle wiring is the current bundle wiring; * {@code false} otherwise. */ @@ -68,7 +72,7 @@ public interface BundleWiring extends BundleReference { * in use if it is the {@link #isCurrent() current} wiring or if some other * in use bundle wiring is dependent upon it. Once a bundle wiring is no * longer in use, it is considered stale and is discarded by the framework. - * + * * @return {@code true} if this bundle wiring is in use; {@code false} * otherwise. */ @@ -76,25 +80,25 @@ public interface BundleWiring extends BundleReference { /** * Returns the capabilities provided by this bundle wiring. - * + * * <p> * Only capabilities considered by the resolver are returned. For example, * capabilities with * {@link ResourceConstants#CAPABILITY_EFFECTIVE_DIRECTIVE effective} * directive not equal to {@link ResourceConstants#EFFECTIVE_RESOLVE * resolve} are not returned. - * + * * <p> * A capability may not be required by any bundle wiring and thus there may * be no {@link #getProvidedWires(String) wires} for the capability. - * + * * <p> * A bundle wiring for a non-fragment revision provides a subset of the * declared capabilities from the bundle revision and all attached fragment * revisions<sup>†</sup>. Not all declared capabilities may be * provided since some may be discarded. For example, if a package is - * declared to be exported and import, only one is selected and the other is - * discarded. + * declared to be both exported and imported, only one is selected and the + * other is discarded. * <p> * A bundle wiring for a fragment revision with a symbolic name must provide * exactly one {@link ResourceConstants#IDENTITY_NAMESPACE identity} @@ -103,7 +107,7 @@ public interface BundleWiring extends BundleReference { * † The {@link ResourceConstants#IDENTITY_NAMESPACE identity} * capability provided by attached fragment revisions must not be included * in the capabilities of the host bundle wiring. - * + * * @param namespace The name space of the capabilities to return or * {@code null} to return the capabilities from all name spaces. * @return A list containing a snapshot of the {@link BundleCapability}s, or @@ -120,21 +124,21 @@ public interface BundleWiring extends BundleReference { /** * Returns the requirements of this bundle wiring. - * + * * <p> * Only requirements considered by the resolver are returned. For example, * requirements with * {@link ResourceConstants#REQUIREMENT_EFFECTIVE_DIRECTIVE effective} * directive not equal to {@link ResourceConstants#EFFECTIVE_RESOLVE * resolve} are not returned. - * + * * <p> * A bundle wiring for a non-fragment revision has a subset of the declared * requirements from the bundle revision and all attached fragment * revisions. Not all declared requirements may be present since some may be * discarded. For example, if a package is declared to be optionally * imported and is not actually imported, the requirement must be discarded. - * + * * @param namespace The name space of the requirements to return or * {@code null} to return the requirements from all name spaces. * @return A list containing a snapshot of the {@link BundleRequirement}s, @@ -152,7 +156,7 @@ public interface BundleWiring extends BundleReference { /** * Returns the {@link BundleWire}s to the provided {@link BundleCapability * capabilities} of this bundle wiring. - * + * * @param namespace The name space of the capabilities for which to return * wires or {@code null} to return the wires for the capabilities in * all name spaces. @@ -172,12 +176,12 @@ public interface BundleWiring extends BundleReference { /** * Returns the {@link BundleWire}s to the {@link BundleRequirement * requirements} in use by this bundle wiring. - * + * * <p> * This method may return different results if this bundle wiring adds wires * to more requirements. For example, dynamically importing a package will * establish a new wire to the dynamically imported package. - * + * * @param namespace The name space of the requirements for which to return * wires or {@code null} to return the wires for the requirements in * all name spaces. @@ -198,13 +202,13 @@ public interface BundleWiring extends BundleReference { * Returns the bundle revision for the bundle in this bundle wiring. Since a * bundle update can change the entries in a bundle, different bundle * wirings for the same bundle can have different bundle revisions. - * + * * <p> * The bundle object {@link BundleReference#getBundle() referenced} by the * returned {@code BundleRevision} may return different information than the * returned {@code BundleRevision} since the returned {@code BundleRevision} * may refer to an older revision of the bundle. - * + * * @return The bundle revision for this bundle wiring. * @see BundleRevision#getWiring() */ @@ -214,7 +218,7 @@ public interface BundleWiring extends BundleReference { * Returns the class loader for this bundle wiring. Since a bundle refresh * creates a new bundle wiring for a bundle, different bundle wirings for * the same bundle will have different class loaders. - * + * * @return The class loader for this bundle wiring. If this bundle wiring is * not {@link #isInUse() in use} or this bundle wiring is for a * fragment revision, {@code null} will be returned. @@ -230,7 +234,7 @@ public interface BundleWiring extends BundleReference { * loader is not used to search for entries. Only the contents of this * bundle wiring's bundle revision and its attached fragment revisions are * searched for the specified entries. - * + * * <p> * This method takes into account that the "contents" of this * bundle wiring can have attached fragments. This "bundle space" @@ -240,12 +244,14 @@ public interface BundleWiring extends BundleReference { * name. This method can either return only entries in the specified path or * recurse into subdirectories returning entries in the directory tree * beginning at the specified path. - * + * + * <p> + * URLs for directory entries must have their path end with "/". * <p> * Note: Jar and zip files are not required to include directory entries. * URLs to directory entries will not be returned if the bundle contents do * not contain directory entries. - * + * * @param path The path name in which to look. The path is always relative * to the root of this bundle wiring and may begin with * "/". A path value of "/" indicates the root of @@ -277,14 +283,14 @@ public interface BundleWiring extends BundleReference { /** * The find entries operation must recurse into subdirectories. - * + * * <p> * This bit may be set when calling * {@link #findEntries(String, String, int)} to specify the result must * include the matching entries from the specified path and its * subdirectories. If this bit is not set, then the result must only include * matching entries from the specified path. - * + * * @see #findEntries(String, String, int) */ int FINDENTRIES_RECURSE = 0x00000001; @@ -293,7 +299,7 @@ public interface BundleWiring extends BundleReference { * Returns the names of resources visible to this bundle wiring's * {@link #getClassLoader() class loader}. The returned names can be used to * access the resources via this bundle wiring's class loader. - * + * * <ul> * <li>Only the resource names for resources in bundle wirings will be * returned. The names of resources visible to a bundle wiring's parent @@ -302,7 +308,7 @@ public interface BundleWiring extends BundleReference { * <li>Only established wires will be examined for resources. This method * must not cause new wires for dynamic imports to be established. * </ul> - * + * * @param path The path name in which to look. The path is always relative * to the root of this bundle wiring's class loader and may begin * with "/". A path value of "/" indicates the @@ -332,14 +338,14 @@ public interface BundleWiring extends BundleReference { /** * The list resource names operation must recurse into subdirectories. - * + * * <p> * This bit may be set when calling * {@link #listResources(String, String, int)} to specify the result must * include the names of matching resources from the specified path and its * subdirectories. If this bit is not set, then the result must only include * names of matching resources from the specified path. - * + * * @see #listResources(String, String, int) */ int LISTRESOURCES_RECURSE = 0x00000001; @@ -351,7 +357,7 @@ public interface BundleWiring extends BundleReference { * revisions. The result must not include resource names for resources in * {@link BundleRevision#PACKAGE_NAMESPACE package} names which are * {@link #getRequiredWires(String) imported} by this wiring. - * + * * <p> * This bit may be set when calling * {@link #listResources(String, String, int)} to specify the result must @@ -361,8 +367,58 @@ public interface BundleWiring extends BundleReference { * reachable from this bundle wiring's class loader which may include the * names of matching resources contained in imported packages and required * bundles. - * + * * @see #listResources(String, String, int) */ int LISTRESOURCES_LOCAL = 0x00000002; + + /** + * {@inheritDoc} + * + * <p> + * This method returns the same value as {@link #getCapabilities(String)}. + * + * @since 1.1 + */ + List<Capability> getResourceCapabilities(String namespace); + + /** + * {@inheritDoc} + * + * <p> + * This method returns the same value as {@link #getRequirements(String)}. + * + * @since 1.1 + */ + List<Requirement> getResourceRequirements(String namespace); + + /** + * {@inheritDoc} + * + * <p> + * This method returns the same value as {@link #getProvidedWires(String)}. + * + * @since 1.1 + */ + List<Wire> getProvidedResourceWires(String namespace); + + /** + * {@inheritDoc} + * + * <p> + * This method returns the same value as {@link #getRequiredWires(String)}. + * + * @since 1.1 + */ + List<Wire> getRequiredResourceWires(String namespace); + + /** + * {@inheritDoc} + * + * <p> + * This method returns the same value as {@link #getRevision()}. + * + * @since 1.1 + */ + BundleRevision getResource(); } diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BundleDescriptionImpl.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BundleDescriptionImpl.java index e88293c9b..233688919 100644 --- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BundleDescriptionImpl.java +++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BundleDescriptionImpl.java @@ -12,9 +12,6 @@ *******************************************************************************/ package org.eclipse.osgi.internal.resolver; -import org.osgi.framework.resource.Capability; -import org.osgi.framework.resource.Requirement; - import java.io.IOException; import java.net.URL; import java.util.*; @@ -25,6 +22,7 @@ import org.eclipse.osgi.framework.util.KeyedElement; import org.eclipse.osgi.internal.loader.BundleLoaderProxy; import org.eclipse.osgi.service.resolver.*; import org.osgi.framework.*; +import org.osgi.framework.resource.*; import org.osgi.framework.wiring.*; public final class BundleDescriptionImpl extends BaseDescriptionImpl implements BundleDescription, KeyedElement { @@ -1035,6 +1033,39 @@ public final class BundleDescriptionImpl extends BaseDescriptionImpl implements } } + /** + * Coerce the generic type of a list from List<BundleWire> + * to List<Wire> + * @param l List to be coerced. + * @return l coerced to List<Wire> + */ + @SuppressWarnings("unchecked") + static List<Wire> asListWire(List<? extends Wire> l) { + return (List<Wire>) l; + } + + /** + * Coerce the generic type of a list from List<BundleCapability> + * to List<Capability> + * @param l List to be coerced. + * @return l coerced to List<Capability> + */ + @SuppressWarnings("unchecked") + static List<Capability> asListCapability(List<? extends Capability> l) { + return (List<Capability>) l; + } + + /** + * Coerce the generic type of a list from List<BundleRequirement> + * to List<Requirement> + * @param l List to be coerced. + * @return l coerced to List<Requirement> + */ + @SuppressWarnings("unchecked") + static List<Requirement> asListRequirement(List<? extends Requirement> l) { + return (List<Requirement>) l; + } + // Note that description wiring are identity equality based class DescriptionWiring implements BundleWiring { private volatile boolean valid = true; @@ -1082,6 +1113,10 @@ public final class BundleDescriptionImpl extends BaseDescriptionImpl implements return result; } + public List<Capability> getResourceCapabilities(String namespace) { + return asListCapability(getCapabilities(namespace)); + } + public List<BundleRequirement> getRequirements(String namespace) { List<BundleWire> requiredWires = getRequiredWires(namespace); if (requiredWires == null) @@ -1115,6 +1150,10 @@ public final class BundleDescriptionImpl extends BaseDescriptionImpl implements return requirements; } + public List<Requirement> getResourceRequirements(String namespace) { + return asListRequirement(getRequirements(namespace)); + } + public List<BundleWire> getProvidedWires(String namespace) { if (!isInUse()) return null; @@ -1142,6 +1181,10 @@ public final class BundleDescriptionImpl extends BaseDescriptionImpl implements return orderedResult; } + public List<Wire> getProvidedResourceWires(String namespace) { + return asListWire(getProvidedWires(namespace)); + } + public List<BundleWire> getRequiredWires(String namespace) { if (!isInUse()) return null; @@ -1167,10 +1210,18 @@ public final class BundleDescriptionImpl extends BaseDescriptionImpl implements return result; } + public List<Wire> getRequiredResourceWires(String namespace) { + return asListWire(getRequiredWires(namespace)); + } + public BundleRevision getRevision() { return BundleDescriptionImpl.this; } + public BundleRevision getResource() { + return getRevision(); + } + public ClassLoader getClassLoader() { SecurityManager sm = System.getSecurityManager(); if (sm != null) @@ -1232,13 +1283,11 @@ public final class BundleDescriptionImpl extends BaseDescriptionImpl implements } } - @SuppressWarnings({"cast", "unchecked", "rawtypes"}) public List<Capability> getCapabilities(String namespace) { - return (List<Capability>) (List) getDeclaredCapabilities(namespace); + return asListCapability(getDeclaredCapabilities(namespace)); } - @SuppressWarnings({"cast", "unchecked", "rawtypes"}) public List<Requirement> getRequirements(String namespace) { - return (List<Requirement>) (List) getDeclaredRequirements(namespace); + return asListRequirement(getDeclaredRequirements(namespace)); } } |