You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2005/08/16 20:34:41 UTC
svn commit: r233031 [19/21] - in /incubator/oscar/trunk: ./ etc/ lib/ src/
src/org/ src/org/apache/ src/org/apache/osgi/ src/org/apache/osgi/bundle/
src/org/apache/osgi/bundle/bundlerepository/
src/org/apache/osgi/bundle/bundlerepository/kxmlsax/ src/o...
Added: incubator/oscar/trunk/src/org/osgi/framework/ServiceEvent.java
URL: http://svn.apache.org/viewcvs/incubator/oscar/trunk/src/org/osgi/framework/ServiceEvent.java?rev=233031&view=auto
==============================================================================
--- incubator/oscar/trunk/src/org/osgi/framework/ServiceEvent.java (added)
+++ incubator/oscar/trunk/src/org/osgi/framework/ServiceEvent.java Tue Aug 16 11:33:34 2005
@@ -0,0 +1,129 @@
+/*
+ * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/ServiceEvent.java,v 1.9 2005/05/13 20:32:56 hargrave Exp $
+ *
+ * Copyright (c) OSGi Alliance (2000, 2005). All Rights Reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this
+ * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html.
+ */
+
+package org.osgi.framework;
+
+import java.util.Dictionary;
+import java.util.EventObject;
+
+/**
+ * A service lifecycle change event.
+ * <p>
+ * <code>ServiceEvent</code> objects are delivered to a <code>ServiceListener</code>
+ * objects when a change occurs in this service's lifecycle. A type code is used
+ * to identify the event type for future extendability.
+ *
+ * <p>
+ * OSGi Alliance reserves the right to extend the set of types.
+ *
+ * @version $Revision: 1.9 $
+ * @see ServiceListener
+ */
+
+public class ServiceEvent extends EventObject {
+ static final long serialVersionUID = 8792901483909409299L;
+ /**
+ * Reference to the service that had a change occur in its lifecycle.
+ */
+ private ServiceReference reference;
+
+ /**
+ * Type of service lifecycle change.
+ */
+ private int type;
+
+ /**
+ * This service has been registered.
+ * <p>
+ * This event is synchronously delivered <strong>after </strong> the service
+ * has been registered with the Framework.
+ *
+ * <p>
+ * The value of <code>REGISTERED</code> is 0x00000001.
+ *
+ * @see BundleContext#registerService(String[],Object,Dictionary)
+ */
+ public final static int REGISTERED = 0x00000001;
+
+ /**
+ * The properties of a registered service have been modified.
+ * <p>
+ * This event is synchronously delivered <strong>after </strong> the service
+ * properties have been modified.
+ *
+ * <p>
+ * The value of <code>MODIFIED</code> is 0x00000002.
+ *
+ * @see ServiceRegistration#setProperties
+ */
+ public final static int MODIFIED = 0x00000002;
+
+ /**
+ * This service is in the process of being unregistered.
+ * <p>
+ * This event is synchronously delivered <strong>before </strong> the
+ * service has completed unregistering.
+ *
+ * <p>
+ * If a bundle is using a service that is <code>UNREGISTERING</code>, the
+ * bundle should release its use of the service when it receives this event.
+ * If the bundle does not release its use of the service when it receives
+ * this event, the Framework will automatically release the bundle's use of
+ * the service while completing the service unregistration operation.
+ *
+ * <p>
+ * The value of UNREGISTERING is 0x00000004.
+ *
+ * @see ServiceRegistration#unregister
+ * @see BundleContext#ungetService
+ */
+ public final static int UNREGISTERING = 0x00000004;
+
+ /**
+ * Creates a new service event object.
+ *
+ * @param type The event type.
+ * @param reference A <code>ServiceReference</code> object to the service that
+ * had a lifecycle change.
+ */
+ public ServiceEvent(int type, ServiceReference reference) {
+ super(reference);
+ this.reference = reference;
+ this.type = type;
+ }
+
+ /**
+ * Returns a reference to the service that had a change occur in its
+ * lifecycle.
+ * <p>
+ * This reference is the source of the event.
+ *
+ * @return Reference to the service that had a lifecycle change.
+ */
+ public ServiceReference getServiceReference() {
+ return (reference);
+ }
+
+ /**
+ * Returns the type of event. The event type values are:
+ * <ul>
+ * <li>{@link #REGISTERED}
+ * <li>{@link #MODIFIED}
+ * <li>{@link #UNREGISTERING}
+ * </ul>
+ *
+ * @return Type of service lifecycle change.
+ */
+
+ public int getType() {
+ return (type);
+ }
+}
+
Added: incubator/oscar/trunk/src/org/osgi/framework/ServiceFactory.java
URL: http://svn.apache.org/viewcvs/incubator/oscar/trunk/src/org/osgi/framework/ServiceFactory.java?rev=233031&view=auto
==============================================================================
--- incubator/oscar/trunk/src/org/osgi/framework/ServiceFactory.java (added)
+++ incubator/oscar/trunk/src/org/osgi/framework/ServiceFactory.java Tue Aug 16 11:33:34 2005
@@ -0,0 +1,89 @@
+/*
+ * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/ServiceFactory.java,v 1.6 2005/05/13 20:32:55 hargrave Exp $
+ *
+ * Copyright (c) OSGi Alliance (2000, 2005). All Rights Reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this
+ * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html.
+ */
+
+package org.osgi.framework;
+
+/**
+ * Allows services to provide customized service objects in the OSGi
+ * environment.
+ *
+ * <p>
+ * When registering a service, a <code>ServiceFactory</code> object can be used
+ * instead of a service object, so that the bundle developer can gain control of
+ * the specific service object granted to a bundle that is using the service.
+ *
+ * <p>
+ * When this happens, the <code>BundleContext.getService(ServiceReference)</code>
+ * method calls the <code>ServiceFactory.getService</code> method to create a
+ * service object specifically for the requesting bundle. The service object
+ * returned by the <code>ServiceFactory</code> object is cached by the Framework
+ * until the bundle releases its use of the service.
+ *
+ * <p>
+ * When the bundle's use count for the service equals zero (including the bundle
+ * stopping or the service being unregistered), the
+ * <code>ServiceFactory.ungetService</code> method is called.
+ *
+ * <p>
+ * <code>ServiceFactory</code> objects are only used by the Framework and are not
+ * made available to other bundles in the OSGi environment.
+ *
+ * @version $Revision: 1.6 $
+ * @see BundleContext#getService
+ */
+
+public abstract interface ServiceFactory {
+ /**
+ * Creates a new service object.
+ *
+ * <p>
+ * The Framework invokes this method the first time the specified
+ * <code>bundle</code> requests a service object using the
+ * <code>BundleContext.getService(ServiceReference)</code> method. The service
+ * factory can then return a specific service object for each bundle.
+ *
+ * <p>
+ * The Framework caches the value returned (unless it is <code>null</code>),
+ * and will return the same service object on any future call to
+ * <code>BundleContext.getService</code> from the same bundle.
+ *
+ * <p>
+ * The Framework will check if the returned service object is an instance of
+ * all the classes named when the service was registered. If not, then
+ * <code>null</code> is returned to the bundle.
+ *
+ * @param bundle The bundle using the service.
+ * @param registration The <code>ServiceRegistration</code> object for the
+ * service.
+ * @return A service object that <strong>must </strong> be an instance of
+ * all the classes named when the service was registered.
+ * @see BundleContext#getService
+ */
+ public abstract Object getService(Bundle bundle,
+ ServiceRegistration registration);
+
+ /**
+ * Releases a service object.
+ *
+ * <p>
+ * The Framework invokes this method when a service has been released by a
+ * bundle. The service object may then be destroyed.
+ *
+ * @param bundle The bundle releasing the service.
+ * @param registration The <code>ServiceRegistration</code> object for the
+ * service.
+ * @param service The service object returned by a previous call to the
+ * <code>ServiceFactory.getService</code> method.
+ * @see BundleContext#ungetService
+ */
+ public abstract void ungetService(Bundle bundle,
+ ServiceRegistration registration, Object service);
+}
+
Added: incubator/oscar/trunk/src/org/osgi/framework/ServiceListener.java
URL: http://svn.apache.org/viewcvs/incubator/oscar/trunk/src/org/osgi/framework/ServiceListener.java?rev=233031&view=auto
==============================================================================
--- incubator/oscar/trunk/src/org/osgi/framework/ServiceListener.java (added)
+++ incubator/oscar/trunk/src/org/osgi/framework/ServiceListener.java Tue Aug 16 11:33:34 2005
@@ -0,0 +1,51 @@
+/*
+ * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/ServiceListener.java,v 1.8 2005/05/13 20:32:55 hargrave Exp $
+ *
+ * Copyright (c) OSGi Alliance (2000, 2005). All Rights Reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this
+ * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html.
+ */
+
+package org.osgi.framework;
+
+import java.util.EventListener;
+
+/**
+ * A <code>ServiceEvent</code> listener.
+ *
+ * <p><code>ServiceListener</code> is a listener interface that may be implemented by a bundle
+ * developer.
+ * <p>A <code>ServiceListener</code> object is registered with the Framework using the
+ * <code>BundleContext.addServiceListener</code> method.
+ * <code>ServiceListener</code> objects are called with a <code>ServiceEvent</code> object when
+ * a service is registered, modified, or is in the process of unregistering.
+ *
+ * <p><code>ServiceEvent</code> object delivery to <code>ServiceListener</code> objects is filtered by the
+ * filter specified when the listener was registered. If the Java Runtime Environment
+ * supports permissions, then additional filtering is done.
+ * <code>ServiceEvent</code> objects are only delivered to the listener if the bundle which defines
+ * the listener object's class has the appropriate <code>ServicePermission</code> to get the service
+ * using at least one of the named classes the service was registered under.
+ *
+ * <p><code>ServiceEvent</code> object delivery to <code>ServiceListener</code> objects is
+ * further filtered according to package sources as defined in
+ * {@link ServiceReference#isAssignableTo(Bundle, String)}.
+ *
+ * @version $Revision: 1.8 $
+ * @see ServiceEvent
+ * @see ServicePermission
+ */
+
+public abstract interface ServiceListener extends EventListener
+{
+ /**
+ * Receives notification that a service has had a lifecycle change.
+ *
+ * @param event The <code>ServiceEvent</code> object.
+ */
+ public abstract void serviceChanged(ServiceEvent event);
+}
+
+
Added: incubator/oscar/trunk/src/org/osgi/framework/ServicePermission.java
URL: http://svn.apache.org/viewcvs/incubator/oscar/trunk/src/org/osgi/framework/ServicePermission.java?rev=233031&view=auto
==============================================================================
--- incubator/oscar/trunk/src/org/osgi/framework/ServicePermission.java (added)
+++ incubator/oscar/trunk/src/org/osgi/framework/ServicePermission.java Tue Aug 16 11:33:34 2005
@@ -0,0 +1,502 @@
+/*
+ * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/ServicePermission.java,v 1.10 2005/05/13 20:32:55 hargrave Exp $
+ *
+ * Copyright (c) OSGi Alliance (2000, 2005). All Rights Reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this
+ * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html.
+ */
+
+package org.osgi.framework;
+
+import java.io.IOException;
+import java.security.*;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+/**
+ * Indicates a bundle's authority to register or get a service.
+ * <ul>
+ * <li>The <code>ServicePermission.REGISTER</code> action allows a bundle to
+ * register a service on the specified names.
+ * <li>The <code>ServicePermission.GET</code> action allows a bundle to detect a
+ * service and get it.
+ * </ul>
+ * Permission to get a service is required in order to detect events regarding
+ * the service. Untrusted bundles should not be able to detect the presence of
+ * certain services unless they have the appropriate <code>ServicePermission</code>
+ * to get the specific service.
+ *
+ * @version $Revision: 1.10 $
+ */
+
+final public class ServicePermission extends BasicPermission {
+ static final long serialVersionUID = -7662148639076511574L;
+ /**
+ * The action string <code>get</code> (Value is "get").
+ */
+ public final static String GET = "get";
+ /**
+ * The action string <code>register</code> (Value is "register").
+ */
+ public final static String REGISTER = "register";
+
+ private final static int ACTION_GET = 0x00000001;
+ private final static int ACTION_REGISTER = 0x00000002;
+ private final static int ACTION_ALL = ACTION_GET
+ | ACTION_REGISTER;
+ private final static int ACTION_NONE = 0;
+ private final static int ACTION_ERROR = 0x80000000;
+
+ /**
+ * The actions mask.
+ */
+ private transient int action_mask = ACTION_NONE;
+
+ /**
+ * The actions in canonical form.
+ *
+ * @serial
+ */
+ private String actions = null;
+
+ /**
+ * Create a new ServicePermission.
+ *
+ * <p>
+ * The name of the service is specified as a fully qualified class name.
+ *
+ * <pre>
+ *
+ * ClassName ::= <class name> | <class name ending in ".*">
+ *
+ * </pre>
+ *
+ * Examples:
+ *
+ * <pre>
+ * org.osgi.service.http.HttpService
+ * org.osgi.service.http.*
+ * org.osgi.service.snmp.*
+ * </pre>
+ *
+ * <p>
+ * There are two possible actions: <code>get</code> and <code>register</code>.
+ * The <code>get</code> permission allows the owner of this permission to
+ * obtain a service with this name. The <code>register</code> permission
+ * allows the bundle to register a service under that name.
+ *
+ * @param name class name
+ * @param actions <code>get</code>,<code>register</code> (canonical order)
+ */
+
+ public ServicePermission(String name, String actions) {
+ this(name, getMask(actions));
+ }
+
+ /**
+ * Package private constructor used by ServicePermissionCollection.
+ *
+ * @param name class name
+ * @param mask action mask
+ */
+ ServicePermission(String name, int mask) {
+ super(name);
+
+ init(mask);
+ }
+
+ /**
+ * Called by constructors and when deserialized.
+ *
+ * @param mask action mask
+ */
+ private void init(int mask) {
+ if ((mask == ACTION_NONE) || ((mask & ACTION_ALL) != mask)) {
+ throw new IllegalArgumentException("invalid action string");
+ }
+
+ action_mask = mask;
+ }
+
+ /**
+ * Parse action string into action mask.
+ *
+ * @param actions Action string.
+ * @return action mask.
+ */
+ private static int getMask(String actions) {
+ boolean seencomma = false;
+
+ int mask = ACTION_NONE;
+
+ if (actions == null) {
+ return mask;
+ }
+
+ char[] a = actions.toCharArray();
+
+ int i = a.length - 1;
+ if (i < 0)
+ return mask;
+
+ while (i != -1) {
+ char c;
+
+ // skip whitespace
+ while ((i != -1)
+ && ((c = a[i]) == ' ' || c == '\r' || c == '\n'
+ || c == '\f' || c == '\t'))
+ i--;
+
+ // check for the known strings
+ int matchlen;
+
+ if (i >= 2 && (a[i - 2] == 'g' || a[i - 2] == 'G')
+ && (a[i - 1] == 'e' || a[i - 1] == 'E')
+ && (a[i] == 't' || a[i] == 'T')) {
+ matchlen = 3;
+ mask |= ACTION_GET;
+
+ }
+ else
+ if (i >= 7 && (a[i - 7] == 'r' || a[i - 7] == 'R')
+ && (a[i - 6] == 'e' || a[i - 6] == 'E')
+ && (a[i - 5] == 'g' || a[i - 5] == 'G')
+ && (a[i - 4] == 'i' || a[i - 4] == 'I')
+ && (a[i - 3] == 's' || a[i - 3] == 'S')
+ && (a[i - 2] == 't' || a[i - 2] == 'T')
+ && (a[i - 1] == 'e' || a[i - 1] == 'E')
+ && (a[i] == 'r' || a[i] == 'R')) {
+ matchlen = 8;
+ mask |= ACTION_REGISTER;
+
+ }
+ else {
+ // parse error
+ throw new IllegalArgumentException("invalid permission: "
+ + actions);
+ }
+
+ // make sure we didn't just match the tail of a word
+ // like "ackbarfregister". Also, skip to the comma.
+ seencomma = false;
+ while (i >= matchlen && !seencomma) {
+ switch (a[i - matchlen]) {
+ case ',' :
+ seencomma = true;
+ /* FALLTHROUGH */
+ case ' ' :
+ case '\r' :
+ case '\n' :
+ case '\f' :
+ case '\t' :
+ break;
+ default :
+ throw new IllegalArgumentException(
+ "invalid permission: " + actions);
+ }
+ i--;
+ }
+
+ // point i at the location of the comma minus one (or -1).
+ i -= matchlen;
+ }
+
+ if (seencomma) {
+ throw new IllegalArgumentException("invalid permission: " + actions);
+ }
+
+ return mask;
+ }
+
+ /**
+ * Determines if a <code>ServicePermission</code> object "implies" the
+ * specified permission.
+ *
+ * @param p The target permission to check.
+ * @return <code>true</code> if the specified permission is implied by this
+ * object; <code>false</code> otherwise.
+ */
+
+ public boolean implies(Permission p) {
+ if (p instanceof ServicePermission) {
+ ServicePermission target = (ServicePermission) p;
+
+ return (((action_mask & target.action_mask) == target.action_mask) && super
+ .implies(p));
+ }
+
+ return (false);
+ }
+
+ /**
+ * Returns the canonical string representation of the actions. Always
+ * returns present actions in the following order: <code>get</code>,
+ * <code>register</code>.
+ *
+ * @return The canonical string representation of the actions.
+ */
+ public String getActions() {
+ if (actions == null) {
+ StringBuffer sb = new StringBuffer();
+ boolean comma = false;
+
+ if ((action_mask & ACTION_GET) == ACTION_GET) {
+ sb.append(GET);
+ comma = true;
+ }
+
+ if ((action_mask & ACTION_REGISTER) == ACTION_REGISTER) {
+ if (comma)
+ sb.append(',');
+ sb.append(REGISTER);
+ }
+
+ actions = sb.toString();
+ }
+
+ return (actions);
+ }
+
+ /**
+ * Returns a new <code>PermissionCollection</code> object for storing
+ * <code>ServicePermission<code> objects.
+ *
+ * @return A new <code>PermissionCollection</code> object suitable for storing
+ * <code>ServicePermission</code> objects.
+ */
+ public PermissionCollection newPermissionCollection() {
+ return (new ServicePermissionCollection());
+ }
+
+ /**
+ * Determines the equalty of two ServicePermission objects.
+ *
+ * Checks that specified object has the same class name and action as this
+ * <code>ServicePermission</code>.
+ *
+ * @param obj The object to test for equality.
+ * @return true if obj is a <code>ServicePermission</code>, and has the same
+ * class name and actions as this <code>ServicePermission</code>
+ * object; <code>false</code> otherwise.
+ */
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return (true);
+ }
+
+ if (!(obj instanceof ServicePermission)) {
+ return (false);
+ }
+
+ ServicePermission p = (ServicePermission) obj;
+
+ return ((action_mask == p.action_mask) && getName().equals(p.getName()));
+ }
+
+ /**
+ * Returns the hash code value for this object.
+ *
+ * @return Hash code value for this object.
+ */
+
+ public int hashCode() {
+ return (getName().hashCode() ^ getActions().hashCode());
+ }
+
+ /**
+ * Returns the current action mask. Used by the ServicePermissionCollection
+ * object.
+ *
+ * @return The actions mask.
+ */
+ int getMask() {
+ return (action_mask);
+ }
+
+ /**
+ * WriteObject is called to save the state of this permission to a stream.
+ * The actions are serialized, and the superclass takes care of the name.
+ */
+
+ private synchronized void writeObject(java.io.ObjectOutputStream s)
+ throws IOException {
+ // Write out the actions. The superclass takes care of the name
+ // call getActions to make sure actions field is initialized
+ if (actions == null)
+ getActions();
+ s.defaultWriteObject();
+ }
+
+ /**
+ * readObject is called to restore the state of this permission from a
+ * stream.
+ */
+ private synchronized void readObject(java.io.ObjectInputStream s)
+ throws IOException, ClassNotFoundException {
+ // Read in the action, then initialize the rest
+ s.defaultReadObject();
+ init(getMask(actions));
+ }
+}
+
+/**
+ * Stores a set of ServicePermission permissions.
+ *
+ * @see java.security.Permission
+ * @see java.security.Permissions
+ * @see java.security.PermissionCollection
+ */
+
+final class ServicePermissionCollection extends PermissionCollection {
+ static final long serialVersionUID = 662615640374640621L;
+ /**
+ * Table of permissions.
+ *
+ * @serial
+ */
+ private Hashtable permissions;
+
+ /**
+ * Boolean saying if "*" is in the collection.
+ *
+ * @serial
+ */
+ private boolean all_allowed;
+
+ /**
+ * Creates an empty ServicePermissions object.
+ *
+ */
+
+ public ServicePermissionCollection() {
+ permissions = new Hashtable();
+ all_allowed = false;
+ }
+
+ /**
+ * Adds a permission to the <code>ServicePermission</code> objects using the
+ * key for the hash as the name.
+ *
+ * @param permission The Permission object to add.
+ *
+ * @exception IllegalArgumentException If the permission is not a
+ * ServicePermission object.
+ *
+ * @exception SecurityException If this <code>ServicePermissionCollection</code>
+ * object has been marked read-only.
+ */
+
+ public void add(Permission permission) {
+ if (!(permission instanceof ServicePermission))
+ throw new IllegalArgumentException("invalid permission: "
+ + permission);
+ if (isReadOnly())
+ throw new SecurityException("attempt to add a Permission to a "
+ + "readonly PermissionCollection");
+
+ ServicePermission sp = (ServicePermission) permission;
+ String name = sp.getName();
+
+ ServicePermission existing = (ServicePermission) permissions.get(name);
+
+ if (existing != null) {
+ int oldMask = existing.getMask();
+ int newMask = sp.getMask();
+ if (oldMask != newMask) {
+ permissions.put(name, new ServicePermission(name, oldMask
+ | newMask));
+ }
+ }
+ else {
+ permissions.put(name, permission);
+ }
+
+ if (!all_allowed) {
+ if (name.equals("*"))
+ all_allowed = true;
+ }
+ }
+
+ /**
+ * Determines if a set of permissions implies the permissions expressed in
+ * <code>permission</code>.
+ *
+ * @param permission The Permission object to compare.
+ *
+ * @return <code>true</code> if <code>permission</code> is a proper subset of a
+ * permission in the set; <code>false</code> otherwise.
+ */
+
+ public boolean implies(Permission permission) {
+ if (!(permission instanceof ServicePermission))
+ return (false);
+
+ ServicePermission sp = (ServicePermission) permission;
+ ServicePermission x;
+
+ int desired = sp.getMask();
+ int effective = 0;
+
+ // short circuit if the "*" Permission was added
+ if (all_allowed) {
+ x = (ServicePermission) permissions.get("*");
+ if (x != null) {
+ effective |= x.getMask();
+ if ((effective & desired) == desired)
+ return (true);
+ }
+ }
+
+ // strategy:
+ // Check for full match first. Then work our way up the
+ // name looking for matches on a.b.*
+
+ String name = sp.getName();
+
+ x = (ServicePermission) permissions.get(name);
+
+ if (x != null) {
+ // we have a direct hit!
+ effective |= x.getMask();
+ if ((effective & desired) == desired)
+ return (true);
+ }
+
+ // work our way up the tree...
+ int last, offset;
+
+ offset = name.length() - 1;
+
+ while ((last = name.lastIndexOf(".", offset)) != -1) {
+
+ name = name.substring(0, last + 1) + "*";
+ x = (ServicePermission) permissions.get(name);
+
+ if (x != null) {
+ effective |= x.getMask();
+ if ((effective & desired) == desired)
+ return (true);
+ }
+ offset = last - 1;
+ }
+
+ // we don't have to check for "*" as it was already checked
+ // at the top (all_allowed), so we just return false
+ return (false);
+ }
+
+ /**
+ * Returns an enumeration of all the <code>ServicePermission</code> objects in
+ * the container.
+ *
+ * @return Enumeration of all the ServicePermission objects.
+ */
+
+ public Enumeration elements() {
+ return (permissions.elements());
+ }
+}
+
Added: incubator/oscar/trunk/src/org/osgi/framework/ServiceReference.java
URL: http://svn.apache.org/viewcvs/incubator/oscar/trunk/src/org/osgi/framework/ServiceReference.java?rev=233031&view=auto
==============================================================================
--- incubator/oscar/trunk/src/org/osgi/framework/ServiceReference.java (added)
+++ incubator/oscar/trunk/src/org/osgi/framework/ServiceReference.java Tue Aug 16 11:33:34 2005
@@ -0,0 +1,146 @@
+/*
+ * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/ServiceReference.java,v 1.11 2005/05/13 20:32:55 hargrave Exp $
+ *
+ * Copyright (c) OSGi Alliance (2000, 2005). All Rights Reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this
+ * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html.
+ */
+
+package org.osgi.framework;
+
+import java.util.Dictionary;
+
+/**
+ * A reference to a service.
+ *
+ * <p>
+ * The Framework returns <code>ServiceReference</code> objects from the
+ * <code>BundleContext.getServiceReference</code> and
+ * <code>BundleContext.getServiceReferences</code> methods.
+ * <p>
+ * A <code>ServiceReference</code> object may be shared between bundles and can be
+ * used to examine the properties of the service and to get the service object.
+ * <p>
+ * Every service registered in the Framework has a unique
+ * <code>ServiceRegistration</code> object and may have multiple, distinct
+ * <code>ServiceReference</code> objects referring to it.
+ * <code>ServiceReference</code> objects associated with a
+ * <code>ServiceRegistration</code> object have the same <code>hashCode</code>
+ * and are considered equal (more specifically, their <code>equals()</code>
+ * method will return <code>true</code> when compared).
+ * <p>
+ * If the same service object is registered multiple times,
+ * <code>ServiceReference</code> objects associated with different
+ * <code>ServiceRegistration</code> objects are not equal.
+ *
+ * @version $Revision: 1.11 $
+ * @see BundleContext#getServiceReference
+ * @see BundleContext#getServiceReferences
+ * @see BundleContext#getService
+ */
+
+public abstract interface ServiceReference {
+ /**
+ * Returns the property value to which the specified property key is mapped
+ * in the properties <code>Dictionary</code> object of the service
+ * referenced by this <code>ServiceReference</code> object.
+ *
+ * <p>
+ * Property keys are case-insensitive.
+ *
+ * <p>
+ * This method must continue to return property values after the service has
+ * been unregistered. This is so references to unregistered services (for
+ * example, <code>ServiceReference</code> objects stored in the log) can
+ * still be interrogated.
+ *
+ * @param key The property key.
+ * @return The property value to which the key is mapped; <code>null</code>
+ * if there is no property named after the key.
+ */
+ public abstract Object getProperty(String key);
+
+ /**
+ * Returns an array of the keys in the properties <code>Dictionary</code>
+ * object of the service referenced by this <code>ServiceReference</code>
+ * object.
+ *
+ * <p>
+ * This method will continue to return the keys after the service has been
+ * unregistered. This is so references to unregistered services (for
+ * example, <code>ServiceReference</code> objects stored in the log) can
+ * still be interrogated.
+ *
+ * <p>
+ * This method is <i>case-preserving </i>; this means that every key in the
+ * returned array must have the same case as the corresponding key in the
+ * properties <code>Dictionary</code> that was passed to the
+ * {@link BundleContext#registerService(String[],Object,Dictionary)}or
+ * {@link ServiceRegistration#setProperties}methods.
+ *
+ * @return An array of property keys.
+ */
+ public abstract String[] getPropertyKeys();
+
+ /**
+ * Returns the bundle that registered the service referenced by this
+ * <code>ServiceReference</code> object.
+ *
+ * <p>
+ * This method must return <code>null</code> when the service has
+ * been unregistered. This can be used to determine if the service has been
+ * unregistered.
+ *
+ * @return The bundle that registered the service referenced by this
+ * <code>ServiceReference</code> object; <code>null</code> if
+ * that service has already been unregistered.
+ * @see BundleContext#registerService(String[],Object,Dictionary)
+ */
+ public abstract Bundle getBundle();
+
+ /**
+ * Returns the bundles that are using the service referenced by this
+ * <code>ServiceReference</code> object. Specifically, this method returns
+ * the bundles whose usage count for that service is greater than zero.
+ *
+ * @return An array of bundles whose usage count for the service referenced
+ * by this <code>ServiceReference</code> object is greater than
+ * zero; <code>null</code> if no bundles are currently using that
+ * service.
+ *
+ * @since 1.1
+ */
+ public abstract Bundle[] getUsingBundles();
+
+ /**
+ * Tests if the bundle that registered the service referenced by this
+ * <code>ServiceReference</code> and the specified bundle use the same source
+ * for the package of the specified class name.
+ * <p>
+ * This method performs the following checks:
+ * <ol>
+ * <li>Get the package name from the specified class name.</li>
+ * <li>For the bundle that registered the service referenced by this
+ * <code>ServiceReference</code> (registrant bundle); find the source for the
+ * package. If no source is found then return <code>true</code> if the
+ * registrant bundle is equal to the specified bundle; otherwise return
+ * <code>false</code>.</li>
+ * <li>If the package source of the registrant bundle is equal to the
+ * package source of the specified bundle then return <code>true</code>;
+ * otherwise return <code>false</code>.</li>
+ * </ol>
+ *
+ * @param bundle The <code>Bundle</code> object to check.
+ * @param className The class name to check.
+ * @return <code>true</code> if the bundle which registered the service
+ * referenced by this <code>ServiceReference</code> and the specified
+ * bundle use the same source for the package of the specified class
+ * name. Otherwise <code>false</code> is returned.
+ *
+ * @since 1.3
+ */
+ public abstract boolean isAssignableTo(Bundle bundle, String className);
+
+}
Added: incubator/oscar/trunk/src/org/osgi/framework/ServiceRegistration.java
URL: http://svn.apache.org/viewcvs/incubator/oscar/trunk/src/org/osgi/framework/ServiceRegistration.java?rev=233031&view=auto
==============================================================================
--- incubator/oscar/trunk/src/org/osgi/framework/ServiceRegistration.java (added)
+++ incubator/oscar/trunk/src/org/osgi/framework/ServiceRegistration.java Tue Aug 16 11:33:34 2005
@@ -0,0 +1,105 @@
+/*
+ * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/ServiceRegistration.java,v 1.8 2005/05/13 20:32:55 hargrave Exp $
+ *
+ * Copyright (c) OSGi Alliance (2000, 2005). All Rights Reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this
+ * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html.
+ */
+
+package org.osgi.framework;
+
+import java.util.Dictionary;
+
+/**
+ * A registered service.
+ *
+ * <p>
+ * The Framework returns a <code>ServiceRegistration</code> object when a
+ * <code>BundleContext.registerService</code> method invocation is successful.
+ * The <code>ServiceRegistration</code> object is for the private use of the
+ * registering bundle and should not be shared with other bundles.
+ * <p>
+ * The <code>ServiceRegistration</code> object may be used to update the
+ * properties of the service or to unregister the service.
+ *
+ * @version $Revision: 1.8 $
+ * @see BundleContext#registerService(String[],Object,Dictionary)
+ */
+
+public abstract interface ServiceRegistration {
+ /**
+ * Returns a <code>ServiceReference</code> object for a service being
+ * registered.
+ * <p>
+ * The <code>ServiceReference</code> object may be shared with other bundles.
+ *
+ * @exception java.lang.IllegalStateException If this
+ * <code>ServiceRegistration</code> object has already been
+ * unregistered.
+ * @return <code>ServiceReference</code> object.
+ */
+ public abstract ServiceReference getReference();
+
+ /**
+ * Updates the properties associated with a service.
+ *
+ * <p>
+ * The {@link Constants#OBJECTCLASS} and {@link Constants#SERVICE_ID} keys
+ * cannot be modified by this method. These values are set by the Framework
+ * when the service is registered in the OSGi environment.
+ *
+ * <p>
+ * The following steps are required to modify service properties:
+ * <ol>
+ * <li>The service's properties are replaced with the provided properties.
+ * <li>A service event of type {@link ServiceEvent#MODIFIED} is
+ * synchronously sent.
+ * </ol>
+ *
+ * @param properties The properties for this service. See {@link Constants}
+ * for a list of standard service property keys. Changes should not
+ * be made to this object after calling this method. To update the
+ * service's properties this method should be called again.
+ *
+ * @exception IllegalStateException If this <code>ServiceRegistration</code>
+ * object has already been unregistered.
+ *
+ * @exception IllegalArgumentException If <code>properties</code> contains
+ * case variants of the same key name.
+ */
+ public abstract void setProperties(Dictionary properties);
+
+ /**
+ * Unregisters a service. Remove a <code>ServiceRegistration</code> object
+ * from the Framework service registry. All <code>ServiceReference</code>
+ * objects associated with this <code>ServiceRegistration</code> object can no
+ * longer be used to interact with the service.
+ *
+ * <p>
+ * The following steps are required to unregister a service:
+ * <ol>
+ * <li>The service is removed from the Framework service registry so that
+ * it can no longer be used. <code>ServiceReference</code> objects for the
+ * service may no longer be used to get a service object for the service.
+ * <li>A service event of type {@link ServiceEvent#UNREGISTERING} is
+ * synchronously sent so that bundles using this service can release their
+ * use of it.
+ * <li>For each bundle whose use count for this service is greater than
+ * zero: <br>
+ * The bundle's use count for this service is set to zero. <br>
+ * If the service was registered with a {@link ServiceFactory} object, the
+ * <code>ServiceFactory.ungetService</code> method is called to release the
+ * service object for the bundle.
+ * </ol>
+ *
+ * @exception java.lang.IllegalStateException If this
+ * <code>ServiceRegistration</code> object has already been
+ * unregistered.
+ * @see BundleContext#ungetService
+ * @see ServiceFactory#ungetService
+ */
+ public abstract void unregister();
+}
+
Added: incubator/oscar/trunk/src/org/osgi/framework/SynchronousBundleListener.java
URL: http://svn.apache.org/viewcvs/incubator/oscar/trunk/src/org/osgi/framework/SynchronousBundleListener.java?rev=233031&view=auto
==============================================================================
--- incubator/oscar/trunk/src/org/osgi/framework/SynchronousBundleListener.java (added)
+++ incubator/oscar/trunk/src/org/osgi/framework/SynchronousBundleListener.java Tue Aug 16 11:33:34 2005
@@ -0,0 +1,43 @@
+/*
+ * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/SynchronousBundleListener.java,v 1.8 2005/05/13 20:32:54 hargrave Exp $
+ *
+ * Copyright (c) OSGi Alliance (2001, 2005). All Rights Reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this
+ * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html.
+ */
+
+package org.osgi.framework;
+
+/**
+ * A synchronous <code>BundleEvent</code> listener.
+ *
+ * <p>
+ * <code>SynchronousBundleListener</code> is a listener interface that may be
+ * implemented by a bundle developer.
+ * <p>
+ * A <code>SynchronousBundleListener</code> object is registered with the
+ * Framework using the {@link BundleContext#addBundleListener} method.
+ * <code>SynchronousBundleListener</code> objects are called with a
+ * <code>BundleEvent</code> object when a bundle has been installed,
+ * resolved, started, stopped, updated, unresolved, or uninstalled.
+ * <p>
+ * Unlike normal <code>BundleListener</code> objects,
+ * <code>SynchronousBundleListener</code>s are synchronously called during bundle
+ * lifecycle processing. The bundle lifecycle processing will not proceed
+ * until all <code>SynchronousBundleListener</code>s have completed.
+ * <code>SynchronousBundleListener</code> objects will be called prior to
+ * <code>BundleListener</code> objects.
+ * <p>
+ * <code>AdminPermission</code> is required to add or remove a
+ * <code>SynchronousBundleListener</code> object.
+ *
+ * @version $Revision: 1.8 $
+ * @since 1.1
+ * @see BundleEvent
+ */
+
+public abstract interface SynchronousBundleListener extends BundleListener {
+}
+
Added: incubator/oscar/trunk/src/org/osgi/framework/Version.java
URL: http://svn.apache.org/viewcvs/incubator/oscar/trunk/src/org/osgi/framework/Version.java?rev=233031&view=auto
==============================================================================
--- incubator/oscar/trunk/src/org/osgi/framework/Version.java (added)
+++ incubator/oscar/trunk/src/org/osgi/framework/Version.java Tue Aug 16 11:33:34 2005
@@ -0,0 +1,344 @@
+/*
+ * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/Version.java,v 1.13 2005/05/13 20:32:55 hargrave Exp $
+ *
+ * Copyright (c) OSGi Alliance (2004, 2005). All Rights Reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this
+ * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html.
+ */
+
+package org.osgi.framework;
+
+import java.util.NoSuchElementException;
+import java.util.StringTokenizer;
+
+/**
+ * Version identifier for bundles and packages.
+ *
+ * <p>
+ * Version identifiers have four components.
+ * <ol>
+ * <li>Major version. A non-negative integer.</li>
+ * <li>Minor version. A non-negative integer.</li>
+ * <li>Micro version. A non-negative integer.</li>
+ * <li>Qualifier. A text string. See <code>Version(String)</code> for the
+ * format of the qualifier string.</li>
+ * </ol>
+ *
+ * <p>
+ * <code>Version</code> objects are immutable.
+ *
+ * @version $Revision: 1.13 $
+ * @since 1.3
+ */
+
+public class Version implements Comparable {
+ private final int major;
+ private final int minor;
+ private final int micro;
+ private final String qualifier;
+ private static final String SEPARATOR = "."; //$NON-NLS-1$
+
+ /**
+ * The empty version "0.0.0". Equivalent to calling
+ * <code>new Version(0,0,0)</code>.
+ */
+ public static final Version emptyVersion = new Version(0, 0, 0);
+
+ /**
+ * Creates a version identifier from the specified numerical components.
+ *
+ * <p>
+ * The qualifier is set to the empty string.
+ *
+ * @param major Major component of the version identifier.
+ * @param minor Minor component of the version identifier.
+ * @param micro Micro component of the version identifier.
+ * @throws IllegalArgumentException If the numerical components are
+ * negative.
+ */
+ public Version(int major, int minor, int micro) {
+ this(major, minor, micro, null);
+ }
+
+ /**
+ * Creates a version identifier from the specifed components.
+ *
+ * @param major Major component of the version identifier.
+ * @param minor Minor component of the version identifier.
+ * @param micro Micro component of the version identifier.
+ * @param qualifier Qualifier component of the version identifier. If
+ * <code>null</code> is specified, then the qualifier will be set
+ * to the empty string.
+ * @throws IllegalArgumentException If the numerical components are negative
+ * or the qualifier string is invalid.
+ */
+ public Version(int major, int minor, int micro, String qualifier) {
+ if (qualifier == null) {
+ qualifier = ""; //$NON-NLS-1$
+ }
+
+ this.major = major;
+ this.minor = minor;
+ this.micro = micro;
+ this.qualifier = qualifier;
+ validate();
+ }
+
+ /**
+ * Created a version identifier from the specified string.
+ *
+ * <p>
+ * Here is the grammar for version strings.
+ *
+ * <pre>
+ * version ::= major('.'minor('.'micro('.'qualifier)?)?)?
+ * major ::= digit+
+ * minor ::= digit+
+ * micro ::= digit+
+ * qualifier ::= (alpha|digit|'_'|'-')+
+ * digit ::= [0..9]
+ * alpha ::= [a..zA..Z]
+ * </pre>
+ * There must be no whitespace in version.
+ *
+ * @param version String representation of the version identifier.
+ * @throws IllegalArgumentException If <code>version</code> is improperly
+ * formatted.
+ */
+ public Version(String version) {
+ int major = 0;
+ int minor = 0;
+ int micro = 0;
+ String qualifier = ""; //$NON-NLS-1$
+
+ try {
+ StringTokenizer st = new StringTokenizer(version, SEPARATOR, true);
+ major = Integer.parseInt(st.nextToken());
+
+ if (st.hasMoreTokens()) {
+ st.nextToken(); // consume delimiter
+ minor = Integer.parseInt(st.nextToken());
+
+ if (st.hasMoreTokens()) {
+ st.nextToken(); // consume delimiter
+ micro = Integer.parseInt(st.nextToken());
+
+ if (st.hasMoreTokens()) {
+ st.nextToken(); // consume delimiter
+ qualifier = st.nextToken();
+
+ if (st.hasMoreTokens()) {
+ throw new IllegalArgumentException("invalid format"); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+ }
+ catch (NoSuchElementException e) {
+ throw new IllegalArgumentException("invalid format"); //$NON-NLS-1$
+ }
+
+ this.major = major;
+ this.minor = minor;
+ this.micro = micro;
+ this.qualifier = qualifier;
+ validate();
+ }
+
+ /**
+ * Called by the Version constructors to validate the version components.
+ *
+ * @throws IllegalArgumentException If the numerical components are negative
+ * or the qualifier string is invalid.
+ */
+ private void validate() {
+ if (major < 0) {
+ throw new IllegalArgumentException("negative major"); //$NON-NLS-1$
+ }
+ if (minor < 0) {
+ throw new IllegalArgumentException("negative minor"); //$NON-NLS-1$
+ }
+ if (micro < 0) {
+ throw new IllegalArgumentException("negative micro"); //$NON-NLS-1$
+ }
+ int length = qualifier.length();
+ for (int i = 0; i < length; i++) {
+ if ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-".indexOf(qualifier.charAt(i)) == -1) { //$NON-NLS-1$
+ throw new IllegalArgumentException("invalid qualifier"); //$NON-NLS-1$
+ }
+ }
+ }
+
+ /**
+ * Parses a version identifier from the specified string.
+ *
+ * <p>
+ * See <code>Version(String)</code> for the format of the version string.
+ *
+ * @param version String representation of the version identifier. Leading
+ * and trailing whitespace will be ignored.
+ * @return A <code>Version</code> object representing the version
+ * identifier. If <code>version</code> is <code>null</code> or
+ * the empty string then <code>emptyVersion</code> will be
+ * returned.
+ * @throws IllegalArgumentException If <code>version</code> is improperly
+ * formatted.
+ */
+ public static Version parseVersion(String version) {
+ if (version == null) {
+ return emptyVersion;
+ }
+
+ version = version.trim();
+ if (version.length() == 0) {
+ return emptyVersion;
+ }
+
+ return new Version(version);
+ }
+
+ /**
+ * Returns the major component of this version identifier.
+ *
+ * @return The major component.
+ */
+ public int getMajor() {
+ return major;
+ }
+
+ /**
+ * Returns the minor component of this version identifier.
+ *
+ * @return The minor component.
+ */
+ public int getMinor() {
+ return minor;
+ }
+
+ /**
+ * Returns the micro component of this version identifier.
+ *
+ * @return The micro component.
+ */
+ public int getMicro() {
+ return micro;
+ }
+
+ /**
+ * Returns the qualifier component of this version identifier.
+ *
+ * @return The qualifier component.
+ */
+ public String getQualifier() {
+ return qualifier;
+ }
+
+ /**
+ * Returns the string representation of this version identifier.
+ *
+ * <p>
+ * The format of the version string will be <code>major.minor.micro</code>
+ * if qualifier is the empty string or
+ * <code>major.minor.micro.qualifier</code> otherwise.
+ *
+ * @return The string representation of this version identifier.
+ */
+ public String toString() {
+ String base = major + SEPARATOR + minor + SEPARATOR + micro;
+ if (qualifier.length() == 0) { //$NON-NLS-1$
+ return base;
+ }
+ else {
+ return base + SEPARATOR + qualifier;
+ }
+ }
+
+ /**
+ * Returns a hash code value for the object.
+ *
+ * @return An integer which is a hash code value for this object.
+ */
+ public int hashCode() {
+ return (major << 24) + (minor << 16) + (micro << 8)
+ + qualifier.hashCode();
+ }
+
+ /**
+ * Compares this <code>Version</code> object to another object.
+ *
+ * <p>
+ * A version is considered to be <b>equal to </b> another version if the
+ * major, minor and micro components are equal and the qualifier component
+ * is equal (using <code>String.equals</code>).
+ *
+ * @param object The <code>Version</code> object to be compared.
+ * @return <code>true</code> if <code>object</code> is a
+ * <code>Version</code> and is equal to this object;
+ * <code>false</code> otherwise.
+ */
+ public boolean equals(Object object) {
+ if (object == this) { // quicktest
+ return true;
+ }
+
+ if (!(object instanceof Version)) {
+ return false;
+ }
+
+ Version other = (Version) object;
+ return (major == other.major) && (minor == other.minor)
+ && (micro == other.micro) && qualifier.equals(other.qualifier);
+ }
+
+ /**
+ * Compares this <code>Version</code> object to another object.
+ *
+ * <p>
+ * A version is considered to be <b>less than </b> another version if its
+ * major component is less than the other version's major component, or the
+ * major components are equal and its minor component is less than the other
+ * version's minor component, or the major and minor components are equal
+ * and its micro component is less than the other version's micro component,
+ * or the major, minor and micro components are equal and it's qualifier
+ * component is less than the other version's qualifier component (using
+ * <code>String.compareTo</code>).
+ *
+ * <p>
+ * A version is considered to be <b>equal to</b> another version if the
+ * major, minor and micro components are equal and the qualifier component
+ * is equal (using <code>String.compareTo</code>).
+ *
+ * @param object The <code>Version</code> object to be compared.
+ * @return A negative integer, zero, or a positive integer if this object is
+ * less than, equal to, or greater than the specified
+ * <code>Version</code> object.
+ * @throws ClassCastException If the specified object is not a
+ * <code>Version</code>.
+ */
+ public int compareTo(Object object) {
+ if (object == this) { // quicktest
+ return 0;
+ }
+
+ Version other = (Version) object;
+
+ int result = major - other.major;
+ if (result != 0) {
+ return result;
+ }
+
+ result = minor - other.minor;
+ if (result != 0) {
+ return result;
+ }
+
+ result = micro - other.micro;
+ if (result != 0) {
+ return result;
+ }
+
+ return qualifier.compareTo(other.qualifier);
+ }
+}
\ No newline at end of file
Added: incubator/oscar/trunk/src/org/osgi/service/condpermadmin/BundleLocationCondition.java
URL: http://svn.apache.org/viewcvs/incubator/oscar/trunk/src/org/osgi/service/condpermadmin/BundleLocationCondition.java?rev=233031&view=auto
==============================================================================
--- incubator/oscar/trunk/src/org/osgi/service/condpermadmin/BundleLocationCondition.java (added)
+++ incubator/oscar/trunk/src/org/osgi/service/condpermadmin/BundleLocationCondition.java Tue Aug 16 11:33:34 2005
@@ -0,0 +1,49 @@
+/*
+ * $Header: /cvshome/build/org.osgi.service.condpermadmin/src/org/osgi/service/condpermadmin/BundleLocationCondition.java,v 1.9 2005/05/25 16:22:46 twatson Exp $
+ *
+ * Copyright (c) OSGi Alliance (2005). All Rights Reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this
+ * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html.
+ */
+package org.osgi.service.condpermadmin;
+
+import java.io.FilePermission;
+import org.osgi.framework.Bundle;
+
+/**
+ *
+ * Checks to see if a Bundle matches the given location pattern. Pattern matching
+ * is done using FilePermission style patterns.
+ *
+ * @version $Revision: 1.9 $
+ */
+public class BundleLocationCondition {
+ private static final String CONDITION_TYPE = "org.osgi.service.condpermadmin.BundleLocationCondition";
+ /**
+ * Constructs a condition that tries to match the passed Bundle's location
+ * to the location pattern.
+ *
+ * @param bundle the Bundle being evaluated.
+ * @param info the ConditionInfo to construct the condition for. The args of the
+ * ConditionInfo specify the location to match the Bundle
+ * location to. Matching is done according to the patterns documented
+ * in FilePermission.
+ */
+ static public Condition getCondition(Bundle bundle, ConditionInfo info) {
+ if (!CONDITION_TYPE.equals(info.getType()))
+ throw new IllegalArgumentException("ConditionInfo must be of type \"" + CONDITION_TYPE + "\"");
+ String[] args = info.getArgs();
+ if (args.length != 1)
+ throw new IllegalArgumentException("Illegal number of args: " + args.length);
+ String location = args[0];
+ FilePermission locationPat = new FilePermission(location, "read");
+ FilePermission sourcePat = new FilePermission(bundle.getLocation().toString(), "read");
+ return locationPat.implies(sourcePat) ? Condition.TRUE : Condition.FALSE;
+ }
+
+ private BundleLocationCondition() {
+ // private constructor to prevent objects of this type
+ }
+}
Added: incubator/oscar/trunk/src/org/osgi/service/condpermadmin/BundleSignerCondition.java
URL: http://svn.apache.org/viewcvs/incubator/oscar/trunk/src/org/osgi/service/condpermadmin/BundleSignerCondition.java?rev=233031&view=auto
==============================================================================
--- incubator/oscar/trunk/src/org/osgi/service/condpermadmin/BundleSignerCondition.java (added)
+++ incubator/oscar/trunk/src/org/osgi/service/condpermadmin/BundleSignerCondition.java Tue Aug 16 11:33:34 2005
@@ -0,0 +1,66 @@
+/*
+ * $Header: /cvshome/build/org.osgi.service.condpermadmin/src/org/osgi/service/condpermadmin/BundleSignerCondition.java,v 1.4 2005/05/25 16:22:46 twatson Exp $
+ *
+ * Copyright (c) OSGi Alliance (2005). All Rights Reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this
+ * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html.
+ */
+
+package org.osgi.service.condpermadmin;
+
+import org.osgi.framework.Bundle;
+
+/**
+ * This condition checks the signer of a bundle. Since the bundle's signer can only change
+ * when the bundle is updated, this condition is immutable.
+ * <p>
+ * The condition expressed using a single String that specifies a Distinguished Name (DN)
+ * chain to match bundle signers against. DN's are encoded using IETF RFC 2253. Usually
+ * signers use certificates that are issued by certificate authorities, which also have a
+ * corresponding DN and certificate. The certificate authorities can form a chain of trust
+ * where the last DN and certificate is known by the framework. The signer of a bundle is
+ * expressed as signers DN followed by the DN of its issuer followed by the DN of the next
+ * issuer until the DN of the root certificate authority. Each DN is separated by a semicolon.
+ * <p>
+ * A bundle can satisfy this condition if one of its signers has a DN chain that matches the
+ * DN chain used to construct this condition.
+ * Wildcards (`*') can be used to allow greater flexibility in specifying the DN chains.
+ * Wildcards can be used in place of DNs, RDNs, or the value in an RDN. If a wildcard is
+ * used for a value of an RDN, the value must be exactly "*" and will match any value for
+ * the corresponding type in that RDN. If a wildcard is used for a RDN, it must be the
+ * first RDN and will match any number of RDNs (including zero RDNs).
+ *
+ * @version $Revision: 1.4 $
+ */
+public class BundleSignerCondition {
+ private static final String CONDITION_TYPE = "org.osgi.service.condpermadmin.BundleSignerCondition";
+ /**
+ * Constructs a condition that tries to match the passed Bundle's location
+ * to the location pattern.
+ *
+ * @param bundle the Bundle being evaluated.
+ * @param info the ConditionInfo to construct the condition for. The args of the
+ * ConditionInfo specify the chain of distinguished names pattern to match
+ * against the signer of the Bundle
+ */
+ static public Condition getCondition(Bundle bundle, ConditionInfo info) {
+/*
+ if (!CONDITION_TYPE.equals(info.getType()))
+ throw new IllegalArgumentException("ConditionInfo must be of type \"" + CONDITION_TYPE + "\"");
+ String[] args = info.getArgs();
+ if (args.length != 1)
+ throw new IllegalArgumentException("Illegal number of args: " + args.length);
+ // implementation specific code used here
+ AbstractBundle ab = (AbstractBundle) bundle;
+ return ab.getBundleData().matchDNChain(args[0]) ? Condition.TRUE : Condition.FALSE;
+*/
+ // TODO: Fix BundleSignerCondition.getCondition()
+ return null;
+ }
+
+ private BundleSignerCondition() {
+ // private constructor to prevent objects of this type
+ }
+}
Added: incubator/oscar/trunk/src/org/osgi/service/condpermadmin/Condition.java
URL: http://svn.apache.org/viewcvs/incubator/oscar/trunk/src/org/osgi/service/condpermadmin/Condition.java?rev=233031&view=auto
==============================================================================
--- incubator/oscar/trunk/src/org/osgi/service/condpermadmin/Condition.java (added)
+++ incubator/oscar/trunk/src/org/osgi/service/condpermadmin/Condition.java Tue Aug 16 11:33:34 2005
@@ -0,0 +1,97 @@
+/*
+ * $Header: /cvshome/build/org.osgi.service.condpermadmin/src/org/osgi/service/condpermadmin/Condition.java,v 1.9 2005/05/25 16:22:46 twatson Exp $
+ *
+ * Copyright (c) OSGi Alliance (2004, 2005). All Rights Reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this
+ * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html.
+ */
+
+package org.osgi.service.condpermadmin;
+
+import java.util.Dictionary;
+
+/**
+ * This interface is used to implement Conditions that are bound to Permissions
+ * using ConditionalPermissionCollection. The Permissions of the
+ * ConditionalPermissionCollection can only be used if the associated Condition
+ * is satisfied.
+ */
+public interface Condition {
+ /**
+ * A condition object that will always evaluate to true and that is never postponed.
+ */
+ public final static Condition TRUE = new BooleanCondition(true);
+
+ /**
+ * A condition object that will always evaluate to false and that is never postponed.
+ */
+ public final static Condition FALSE = new BooleanCondition(false);
+
+ /**
+ * This method returns true if the evaluation of the Condition must be postponed
+ * until the end of the permission check. If it returns false, it must be able
+ * to directly answer the isSatisfied method. In other
+ * words, isSatisfied() will return very quickly since no external sources,
+ * such as for example users, need to be consulted.
+ *
+ * @return false if evaluation is immediate, otherwise true to indicate the evaluation must be postponed.
+ */
+ boolean isPostponed();
+
+ /**
+ * This method returns true if the Condition is satisfied.
+ */
+ boolean isSatisfied();
+
+ /**
+ * This method returns true if the satisfiability may change.
+ */
+ boolean isMutable();
+
+ /**
+ * This method returns true if the set of Conditions are satisfied. Although
+ * this method is not static, it should be implemented as if it were static.
+ * All of the passed Conditions will have the same type and will correspond
+ * to the class type of the object on which this method is invoked.
+ *
+ * @param conds the array of Conditions that must be satisfied
+ * @param context a Dictionary object that implementors can use to track
+ * state. If this method is invoked multiple times in the same permission
+ * evaluation, the same Dictionary will be passed multiple times. The
+ * SecurityManager treats this Dictionary as an opaque object simply
+ * creates an empty dictionary and passes it to subsequent invocations
+ * if multiple invocatios are needed.
+ * @return true if all the Conditions are satisfied.
+ */
+ boolean isSatisfied(Condition conds[], Dictionary context);
+
+ /**
+ * Package internal class used to define the {@link Condition#FALSE} and
+ * {@link Condition#TRUE} constants.
+ */
+ final static class BooleanCondition implements Condition {
+ boolean satisfied;
+ BooleanCondition(boolean satisfied) {
+ this.satisfied = satisfied;
+ }
+ public boolean isPostponed() {
+ return false;
+ }
+ public boolean isSatisfied() {
+ return satisfied;
+ }
+ public boolean isMutable() {
+ return false;
+ }
+ public boolean isSatisfied(Condition[] conds, Dictionary context) {
+ for(int i = 0; i < conds.length; i++) {
+ if (!conds[i].isSatisfied())
+ return false;
+ }
+ return true;
+ }
+
+ }
+}
Added: incubator/oscar/trunk/src/org/osgi/service/condpermadmin/ConditionInfo.java
URL: http://svn.apache.org/viewcvs/incubator/oscar/trunk/src/org/osgi/service/condpermadmin/ConditionInfo.java?rev=233031&view=auto
==============================================================================
--- incubator/oscar/trunk/src/org/osgi/service/condpermadmin/ConditionInfo.java (added)
+++ incubator/oscar/trunk/src/org/osgi/service/condpermadmin/ConditionInfo.java Tue Aug 16 11:33:34 2005
@@ -0,0 +1,314 @@
+/*
+ * $Header: /cvshome/build/org.osgi.service.condpermadmin/src/org/osgi/service/condpermadmin/ConditionInfo.java,v 1.6 2005/05/13 20:33:31 hargrave Exp $
+ *
+ * Copyright (c) OSGi Alliance (2004, 2005). All Rights Reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this
+ * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html.
+ */
+
+package org.osgi.service.condpermadmin;
+
+import java.util.Vector;
+
+/**
+ * Condition representation used by the Conditional Permission Admin service.
+ *
+ * <p>
+ * This class encapsulates two pieces of information: a Condition <i>type</i>
+ * (class name), which must implement <tt>Condition</tt>, and the arguments
+ * passed to its constructor.
+ *
+ * <p>
+ * In order for a Condition represented by a <tt>ConditionInfo</tt> to be
+ * instantiated and considered during a permission check, its Condition class
+ * must be available from the system classpath.
+ *
+ */
+
+public class ConditionInfo {
+
+ private String type;
+
+ private String args[];
+
+ /**
+ * Constructs a <tt>ConditionInfo</tt> from the given type and args.
+ *
+ * @param type
+ * The fully qualified class name of the condition represented by
+ * this <tt>ConditionInfo</tt>. The class must implement
+ * <tt>Condition</tt> and must define a constructor that takes
+ * a <tt>Bundle</tt> and the correct number of argument
+ * strings.
+ *
+ * @param args
+ * The arguments that will be passed to the constructor of the
+ * <tt>Conditon</tt> class identified by <tt>type</tt>.
+ *
+ * @exception java.lang.NullPointerException
+ * if <tt>type</tt> is <tt>null</tt>.
+ */
+ public ConditionInfo(String type, String args[]) {
+ this.type = type;
+ this.args = args;
+ if (type == null) {
+ throw new NullPointerException("type is null");
+ }
+ }
+
+ /**
+ * Constructs a <tt>ConditionInfo</tt> object from the given encoded
+ * <tt>ConditionInfo</tt> string.
+ *
+ * @param encodedCondition
+ * The encoded <tt>ConditionInfo</tt>.
+ * @see #getEncoded
+ * @exception java.lang.IllegalArgumentException
+ * if <tt>encodedCondition</tt> is not properly formatted.
+ */
+ public ConditionInfo(String encodedCondition) {
+ if (encodedCondition == null) {
+ throw new NullPointerException("missing encoded permission");
+ }
+ if (encodedCondition.length() == 0) {
+ throw new IllegalArgumentException("empty encoded permission");
+ }
+
+ try {
+ char[] encoded = encodedCondition.toCharArray();
+
+ /* the first character must be '[' */
+ if (encoded[0] != '[') {
+ throw new IllegalArgumentException(
+ "first character not open bracket");
+ }
+
+ /* type is not quoted or encoded */
+ int end = 1;
+ int begin = end;
+
+ while ((encoded[end] != ' ') && (encoded[end] != ')')) {
+ end++;
+ }
+
+ if (end == begin) {
+ throw new IllegalArgumentException("expecting type");
+ }
+
+ this.type = new String(encoded, begin, end - begin);
+
+ Vector args = new Vector();
+ /* type may be followed by name which is quoted and encoded */
+ while (encoded[end] == ' ') {
+ end++;
+
+ if (encoded[end] != '"') {
+ throw new IllegalArgumentException("expecting quoted name");
+ }
+
+ end++;
+ begin = end;
+
+ while (encoded[end] != '"') {
+ if (encoded[end] == '\\') {
+ end++;
+ }
+
+ end++;
+ }
+
+ args.add(decodeString(encoded, begin, end));
+ end++;
+ }
+ this.args = (String[]) args.toArray(new String[0]);
+ /* the final character must be ')' */
+ if ((encoded[end] != ']') || (end + 1 != encoded.length)) {
+ throw new IllegalArgumentException("last character not "
+ + "close bracket");
+ }
+ } catch (ArrayIndexOutOfBoundsException e) {
+ throw new IllegalArgumentException("parsing terminated abruptly");
+ }
+ }
+
+ /**
+ * Returns the string encoding of this <tt>ConditionInfo</tt> in a form
+ * suitable for restoring this <tt>ConditionInfo</tt>.
+ *
+ * <p>
+ * The encoding format is:
+ *
+ * <pre>
+ *
+ * [type "arg0" "arg1" ...]
+ *
+ * </pre>
+ *
+ * where <i>argX</i> are strings that are encoded for proper parsing.
+ * Specifically, the <tt>"</tt>, <tt>\</tt>, carriage return, and
+ * linefeed characters are escaped using <tt>\"</tt>, <tt>\\</tt>,
+ * <tt>\r</tt>, and <tt>\n</tt>, respectively.
+ *
+ * <p>
+ * The encoded string must contain no leading or trailing whitespace
+ * characters. A single space character must be used between type and "<i>arg0</i>"
+ * and between all arguments.
+ *
+ * @return The string encoding of this <tt>ConditionInfo</tt>.
+ */
+ public final String getEncoded() {
+ StringBuffer output = new StringBuffer();
+ output.append('[');
+ output.append(type);
+
+ for (int i = 0; i < args.length; i++) {
+ output.append(" \"");
+ encodeString(args[i], output);
+ output.append('\"');
+ }
+
+ output.append(']');
+
+ return (output.toString());
+ }
+
+ /**
+ * Returns the string representation of this <tt>ConditionInfo</tt>. The
+ * string is created by calling the <tt>getEncoded</tt> method on this
+ * <tt>ConditionInfo</tt>.
+ *
+ * @return The string representation of this <tt>ConditionInfo</tt>.
+ */
+ public String toString() {
+ return (getEncoded());
+ }
+
+ /**
+ * Returns the fully qualified class name of the condition represented by
+ * this <tt>ConditionInfo</tt>.
+ *
+ * @return The fully qualified class name of the condition represented by
+ * this <tt>ConditionInfo</tt>.
+ */
+ public final String getType() {
+ return (type);
+ }
+
+ /**
+ * Returns arguments of this <tt>ConditionInfo</tt>.
+ *
+ * @return The arguments of this <tt>ConditionInfo</tt>. have a name.
+ */
+ public final String[] getArgs() {
+ return (args);
+ }
+
+ /**
+ * Determines the equality of two <tt>ConditionInfo</tt> objects.
+ *
+ * This method checks that specified object has the same type and args as
+ * this <tt>ConditionInfo</tt> object.
+ *
+ * @param obj
+ * The object to test for equality with this
+ * <tt>ConditionInfo</tt> object.
+ * @return <tt>true</tt> if <tt>obj</tt> is a <tt>ConditionInfo</tt>,
+ * and has the same type and args as this <tt>ConditionInfo</tt>
+ * object; <tt>false</tt> otherwise.
+ */
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return (true);
+ }
+
+ if (!(obj instanceof ConditionInfo)) {
+ return (false);
+ }
+
+ ConditionInfo other = (ConditionInfo) obj;
+
+ if (!type.equals(other.type) || args.length != other.args.length)
+ return false;
+
+ for (int i = 0; i < args.length; i++) {
+ if (!args[i].equals(other.args[i]))
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Returns the hash code value for this object.
+ *
+ * @return A hash code value for this object.
+ */
+
+ public int hashCode() {
+ int hash = type.hashCode();
+
+ for (int i = 0; i < args.length; i++) {
+ hash ^= args[i].hashCode();
+ }
+ return (hash);
+ }
+
+ /**
+ * This escapes the quotes, backslashes, \n, and \r in the string using a
+ * backslash and appends the newly escaped string to a StringBuffer.
+ */
+ private static void encodeString(String str, StringBuffer output) {
+ int len = str.length();
+
+ for (int i = 0; i < len; i++) {
+ char c = str.charAt(i);
+
+ switch (c) {
+ case '"':
+ case '\\':
+ output.append('\\');
+ output.append(c);
+ break;
+ case '\r':
+ output.append("\\r");
+ break;
+ case '\n':
+ output.append("\\n");
+ break;
+ default:
+ output.append(c);
+ break;
+ }
+ }
+ }
+
+ /**
+ * Takes an encoded character array and decodes it into a new String.
+ */
+ private static String decodeString(char[] str, int begin, int end) {
+ StringBuffer output = new StringBuffer(end - begin);
+
+ for (int i = begin; i < end; i++) {
+ char c = str[i];
+
+ if (c == '\\') {
+ i++;
+
+ if (i < end) {
+ c = str[i];
+
+ if (c == 'n') {
+ c = '\n';
+ } else if (c == 'r') {
+ c = '\r';
+ }
+ }
+ }
+
+ output.append(c);
+ }
+
+ return (output.toString());
+ }
+}
Added: incubator/oscar/trunk/src/org/osgi/service/condpermadmin/ConditionalPermissionAdmin.java
URL: http://svn.apache.org/viewcvs/incubator/oscar/trunk/src/org/osgi/service/condpermadmin/ConditionalPermissionAdmin.java?rev=233031&view=auto
==============================================================================
--- incubator/oscar/trunk/src/org/osgi/service/condpermadmin/ConditionalPermissionAdmin.java (added)
+++ incubator/oscar/trunk/src/org/osgi/service/condpermadmin/ConditionalPermissionAdmin.java Tue Aug 16 11:33:34 2005
@@ -0,0 +1,89 @@
+/*
+ * $Header: /cvshome/build/org.osgi.service.condpermadmin/src/org/osgi/service/condpermadmin/ConditionalPermissionAdmin.java,v 1.6 2005/07/14 10:47:13 pkriens Exp $
+ *
+ * Copyright (c) OSGi Alliance (2005). All Rights Reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this
+ * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html.
+ */
+
+package org.osgi.service.condpermadmin;
+
+import java.security.AccessControlContext;
+import java.util.Enumeration;
+import org.osgi.service.permissionadmin.PermissionInfo;
+
+/**
+ * This is a framework service that allows ConditionalPermissionInfos to be
+ * added to, retrieved from, and removed from the framework.
+ *
+ * @version $Revision: 1.6 $
+ */
+public interface ConditionalPermissionAdmin {
+ /**
+ * Add a new Conditional Permission Info to the repository.
+ *
+ * The Conditional Permission Info will be given a unique, never reused name.
+ *
+ * @param conds the Conditions that need to be satisfied to enable the
+ * corresponding Permissions.
+ * @param perms the Permissions that are enable when the corresponding
+ * Conditions are satisfied.
+ * @return the ConditionalPermissionInfo that for the newly added Conditions
+ * and Permissions.
+ */
+ ConditionalPermissionInfo addConditionalPermissionInfo(
+ ConditionInfo conds[], PermissionInfo perms[]);
+
+ /**
+ * Set or create a Conditional Permission Info with conditions and
+ * permissions.
+ *
+ * If the given <code>name</code> is null or not used in the repository
+ * yet, a new Conditional Permission Info must be created, otherwise the
+ * existing Conditional Permission Info must be reused.
+ *
+ * @param name the name of this Conditional Permission Info, or
+ * <code>null</code>.
+ * @param conds the Conditions that need to be satisfied to enable the
+ * corresponding Permissions.
+ * @param perms the Permissions that are enable when the corresponding
+ * Conditions are satisfied.
+ * @return the ConditionalPermissionInfo that for the newly added Conditions
+ * and Permissions.
+ */
+ ConditionalPermissionInfo setConditionalPermissionInfo(String name,
+ ConditionInfo conds[], PermissionInfo perms[]);
+
+ /**
+ * Returns the ConditionalPermissionInfos that are currently managed by
+ * ConditionalPermissionAdmin. The Enumeration is made up of
+ * ConditionalPermissionInfos. Calling ConditionalPermissionInfo.delete()
+ * will remove the ConditionalPermissionInfo from
+ * ConditionalPermissionAdmin.
+ *
+ * @return the ConditionalPermissionInfos that are currently managed by
+ * ConditionalPermissionAdmin. The Enumeration is made up of
+ * ConditionalPermissionInfos.
+ */
+ Enumeration getConditionalPermissionInfos();
+
+ /**
+ * Return the the Conditional Permission Info with the given name.
+ *
+ * @param name the name of the Conditional Permission Info that must be
+ * returned
+ */
+ ConditionalPermissionInfo getConditionalPermissionInfo(String name);
+
+ /**
+ * Returns the AccessControlContext that corresponds to the given signers.
+ *
+ * @param signers the signers that will be checked agains
+ * BundleSignerCondition.
+ * @return an AccessControlContext that has the Permissions associated with
+ * the signer.
+ */
+ AccessControlContext getAccessControlContext(String signers[]);
+}
Added: incubator/oscar/trunk/src/org/osgi/service/condpermadmin/ConditionalPermissionInfo.java
URL: http://svn.apache.org/viewcvs/incubator/oscar/trunk/src/org/osgi/service/condpermadmin/ConditionalPermissionInfo.java?rev=233031&view=auto
==============================================================================
--- incubator/oscar/trunk/src/org/osgi/service/condpermadmin/ConditionalPermissionInfo.java (added)
+++ incubator/oscar/trunk/src/org/osgi/service/condpermadmin/ConditionalPermissionInfo.java Tue Aug 16 11:33:34 2005
@@ -0,0 +1,45 @@
+/*
+ * $Header: /cvshome/build/org.osgi.service.condpermadmin/src/org/osgi/service/condpermadmin/ConditionalPermissionInfo.java,v 1.7 2005/07/14 10:47:13 pkriens Exp $
+ *
+ * Copyright (c) OSGi Alliance (2004, 2005). All Rights Reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this
+ * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html.
+ */
+
+package org.osgi.service.condpermadmin;
+
+import org.osgi.service.permissionadmin.PermissionInfo;
+
+/**
+ * This interface describes a binding of a set of Conditions to a set of
+ * Permissions. Instances of this interface are obtained from the
+ * ConditionalPermissionAdmin service. This interface is also used to remove
+ * ConditionalPermissionCollections from ConditionPermissionAdmin.
+ */
+public interface ConditionalPermissionInfo {
+ /**
+ * Returns the ConditionInfos for the Conditions that must be satisfied to
+ * enable this ConditionalPermissionCollection.
+ */
+ ConditionInfo[] getConditionInfos();
+
+ /**
+ * Returns the PermissionInfos for the Permission in this
+ * ConditionalPermissionCollection.
+ */
+ PermissionInfo[] getPermissionInfos();
+
+ /**
+ * Removes the ConditionalPermissionCollection from the
+ * ConditionalPermissionAdmin.
+ */
+ void delete();
+
+ /**
+ * Return the name of this Conditional Permission Info object.
+ *
+ */
+ String getName();
+}
Added: incubator/oscar/trunk/src/org/osgi/service/packageadmin/ExportedPackage.java
URL: http://svn.apache.org/viewcvs/incubator/oscar/trunk/src/org/osgi/service/packageadmin/ExportedPackage.java?rev=233031&view=auto
==============================================================================
--- incubator/oscar/trunk/src/org/osgi/service/packageadmin/ExportedPackage.java (added)
+++ incubator/oscar/trunk/src/org/osgi/service/packageadmin/ExportedPackage.java Tue Aug 16 11:33:34 2005
@@ -0,0 +1,90 @@
+/*
+ * $Header: /cvshome/build/org.osgi.service.packageadmin/src/org/osgi/service/packageadmin/ExportedPackage.java,v 1.8 2005/05/13 20:32:34 hargrave Exp $
+ *
+ * Copyright (c) OSGi Alliance (2001, 2005). All Rights Reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this
+ * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html.
+ */
+
+package org.osgi.service.packageadmin;
+
+import org.osgi.framework.Bundle;
+
+/**
+ * An exported package.
+ *
+ * Instances implementing this interface are created by the Package Admin
+ * service.
+ *
+ * <p>
+ * The information about an exported package provided by this object is valid
+ * only until the next time <code>PackageAdmin.refreshPackages()</code> is called.
+ * If an <code>ExportedPackage</code> object becomes stale (that is, the package
+ * it references has been updated or removed as a result of calling
+ * <code>PackageAdmin.refreshPackages()</code>), its <code>getName()</code> and
+ * <code>getSpecificationVersion()</code> continue to return their old values,
+ * <code>isRemovalPending()</code> returns <code>true</code>, and
+ * <code>getExportingBundle()</code> and <code>getImportingBundles()</code> return
+ * <code>null</code>.
+ *
+ * @version $Revision: 1.8 $
+ */
+public interface ExportedPackage {
+ /**
+ * Returns the name of the package associated with this
+ * <code>ExportedPackage</code> object.
+ *
+ * @return The name of this <code>ExportedPackage</code> object.
+ */
+ public String getName();
+
+ /**
+ * Returns the bundle exporting the package associated with this
+ * <code>ExportedPackage</code> object.
+ *
+ * @return The exporting bundle, or <code>null</code> if this
+ * <code>ExportedPackage</code> object has become stale.
+ */
+ public Bundle getExportingBundle();
+
+ /**
+ * Returns the resolved bundles that are currently importing the package
+ * associated with this <code>ExportedPackage</code> object.
+ *
+ * <p>
+ * Bundles which require the exporting bundle associated with this
+ * <code>ExportedPackage</code> object are considered to be importing bundles
+ * and are included in the returned array. See
+ * {@link RequiredBundle#getRequiringBundles()}
+ *
+ * @return The array of resolved bundles currently importing the package
+ * associated with this <code>ExportedPackage</code> object, or
+ * <code>null</code> if this <code>ExportedPackage</code> object has
+ * become stale.
+ */
+ public Bundle[] getImportingBundles();
+
+ /**
+ * Returns the specification version of this <code>ExportedPackage</code>, as
+ * specified in the exporting bundle's manifest file.
+ *
+ * @return The specification version of this <code>ExportedPackage</code>
+ * object, or <code>null</code> if no version information is
+ * available.
+ */
+ public String getSpecificationVersion();
+
+ /**
+ * Returns <code>true</code> if the package associated with this
+ * <code>ExportedPackage</code> object has been exported by a bundle that has
+ * been updated or uninstalled.
+ *
+ * @return <code>true</code> if the associated package is being exported by a
+ * bundle that has been updated or uninstalled, or if this
+ * <code>ExportedPackage</code> object has become stale;
+ * <code>false</code> otherwise.
+ */
+ public boolean isRemovalPending();
+}
\ No newline at end of file