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 2006/03/16 16:57:43 UTC

svn commit: r386363 [6/10] - in /incubator/felix/trunk/org.osgi/src/main/java/org/osgi: framework/ service/condpermadmin/ service/packageadmin/ service/startlevel/ service/url/ util/tracker/

Modified: incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/FrameworkEvent.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/FrameworkEvent.java?rev=386363&r1=386362&r2=386363&view=diff
==============================================================================
--- incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/FrameworkEvent.java (original)
+++ incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/FrameworkEvent.java Thu Mar 16 07:57:37 2006
@@ -1,199 +1,207 @@
-/*
- * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/FrameworkEvent.java,v 1.9 2005/05/13 20:32:56 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.EventObject;
-
-/**
- * A general Framework event.
- * 
- * <p>
- * <code>FrameworkEvent</code> is the event class used when notifying listeners of
- * general events occuring within the OSGI environment. A type code is used to
- * identify the event type for future extendability.
- * 
- * <p>
- * OSGi Alliance reserves the right to extend the set of event types.
- * 
- * @version $Revision: 1.9 $
- */
-
-public class FrameworkEvent extends EventObject {
-	static final long		serialVersionUID	= 207051004521261705L;
-	/**
-	 * Bundle related to the event.
-	 */
-	private Bundle			bundle;
-
-	/**
-	 * Exception related to the event.
-	 */
-	private Throwable		throwable;
-
-	/**
-	 * Type of event.
-	 */
-	private int				type;
-
-	/**
-	 * The Framework has started.
-	 * 
-	 * <p>
-	 * This event is broadcast when the Framework has started after all
-	 * installed bundles that are marked to be started have been started and the
-	 * Framework has reached the intitial start level.
-	 * 
-	 * <p>
-	 * The value of <code>STARTED</code> is 0x00000001.
-	 * 
-	 * @see "<code>StartLevel</code>"
-	 */
-	public final static int	STARTED				= 0x00000001;
-
-	/**
-	 * An error has occurred.
-	 * 
-	 * <p>
-	 * There was an error associated with a bundle.
-	 * 
-	 * <p>
-	 * The value of <code>ERROR</code> is 0x00000002.
-	 */
-	public final static int	ERROR				= 0x00000002;
-
-	/**
-	 * A PackageAdmin.refreshPackage operation has completed.
-	 * 
-	 * <p>
-	 * This event is broadcast when the Framework has completed the refresh
-	 * packages operation initiated by a call to the
-	 * PackageAdmin.refreshPackages method.
-	 * 
-	 * <p>
-	 * The value of <code>PACKAGES_REFRESHED</code> is 0x00000004.
-	 * 
-	 * @since 1.2
-	 * @see "<code>PackageAdmin.refreshPackages</code>"
-	 */
-	public final static int	PACKAGES_REFRESHED	= 0x00000004;
-
-	/**
-	 * A StartLevel.setStartLevel operation has completed.
-	 * 
-	 * <p>
-	 * This event is broadcast when the Framework has completed changing the
-	 * active start level initiated by a call to the StartLevel.setStartLevel
-	 * method.
-	 * 
-	 * <p>
-	 * The value of <code>STARTLEVEL_CHANGED</code> is 0x00000008.
-	 * 
-	 * @since 1.2
-	 * @see "<code>StartLevel</code>"
-	 */
-	public final static int	STARTLEVEL_CHANGED	= 0x00000008;
-
-	/**
-	 * A warning has occurred.
-	 * 
-	 * <p>
-	 * There was a warning associated with a bundle.
-	 * 
-	 * <p>
-	 * The value of <code>WARNING</code> is 0x00000010.
-	 * 
-	 * @since 1.3
-	 */
-	public final static int	WARNING				= 0x00000010;
-
-	/**
-	 * An informational event has occurred.
-	 * 
-	 * <p>
-	 * There was an informational event associated with a bundle.
-	 * 
-	 * <p>
-	 * The value of <code>INFO</code> is 0x00000020.
-	 * 
-	 * @since 1.3
-	 */
-	public final static int	INFO				= 0x00000020;
-
-	/**
-	 * Creates a Framework event.
-	 * 
-	 * @param type The event type.
-	 * @param source The event source object. This may not be <code>null</code>.
-	 * @deprecated Since 1.2. This constructor is deprecated in favor of using
-	 *             the other constructor with the System Bundle as the event
-	 *             source.
-	 */
-	public FrameworkEvent(int type, Object source) {
-		super(source);
-		this.type = type;
-		this.bundle = null;
-		this.throwable = null;
-	}
-
-	/**
-	 * Creates a Framework event regarding the specified bundle.
-	 * 
-	 * @param type The event type.
-	 * @param bundle The event source.
-	 * @param throwable The related exception. This argument may be
-	 *        <code>null</code> if there is no related exception.
-	 */
-	public FrameworkEvent(int type, Bundle bundle, Throwable throwable) {
-		super(bundle);
-		this.type = type;
-		this.bundle = bundle;
-		this.throwable = throwable;
-	}
-
-	/**
-	 * Returns the exception related to this event.
-	 * 
-	 * @return The related exception or <code>null</code> if none.
-	 */
-	public Throwable getThrowable() {
-		return throwable;
-	}
-
-	/**
-	 * Returns the bundle associated with the event. This bundle is also the
-	 * source of the event.
-	 * 
-	 * @return The bundle associated with the event.
-	 */
-	public Bundle getBundle() {
-		return bundle;
-	}
-
-	/**
-	 * Returns the type of framework event.
-	 * <p>
-	 * The type values are:
-	 * <ul>
-	 * <li>{@link #STARTED}
-	 * <li>{@link #ERROR}
-	 * <li>{@link #WARNING}
-	 * <li>{@link #INFO}
-	 * <li>{@link #PACKAGES_REFRESHED}
-	 * <li>{@link #STARTLEVEL_CHANGED}
-	 * </ul>
-	 * 
-	 * @return The type of state change.
-	 */
-
-	public int getType() {
-		return type;
-	}
-}
+/*
+ * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/FrameworkEvent.java,v 1.12 2006/03/14 01:21:02 hargrave Exp $
+ * 
+ * Copyright (c) OSGi Alliance (2004, 2005). 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;
+
+import java.util.EventObject;
+
+/**
+ * A general event from the Framework.
+ * 
+ * <p>
+ * <code>FrameworkEvent</code> is the event class used when notifying
+ * listeners of general events occuring within the OSGI environment. A type code
+ * is used to identify the event type for future extendability.
+ * 
+ * <p>
+ * OSGi Alliance reserves the right to extend the set of event types.
+ * 
+ * @version $Revision: 1.12 $
+ */
+
+public class FrameworkEvent extends EventObject {
+	static final long		serialVersionUID	= 207051004521261705L;
+	/**
+	 * Bundle related to the event.
+	 */
+	private Bundle			bundle;
+
+	/**
+	 * Exception related to the event.
+	 */
+	private Throwable		throwable;
+
+	/**
+	 * Type of event.
+	 */
+	private int				type;
+
+	/**
+	 * The Framework has started.
+	 * 
+	 * <p>
+	 * This event is fired when the Framework has started after all
+	 * installed bundles that are marked to be started have been started and the
+	 * Framework has reached the intitial start level.
+	 * 
+	 * <p>
+	 * The value of <code>STARTED</code> is 0x00000001.
+	 * 
+	 * @see "<code>StartLevel</code>"
+	 */
+	public final static int	STARTED				= 0x00000001;
+
+	/**
+	 * An error has occurred.
+	 * 
+	 * <p>
+	 * There was an error associated with a bundle.
+	 * 
+	 * <p>
+	 * The value of <code>ERROR</code> is 0x00000002.
+	 */
+	public final static int	ERROR				= 0x00000002;
+
+	/**
+	 * A PackageAdmin.refreshPackage operation has completed.
+	 * 
+	 * <p>
+	 * This event is fired when the Framework has completed the refresh
+	 * packages operation initiated by a call to the
+	 * PackageAdmin.refreshPackages method.
+	 * 
+	 * <p>
+	 * The value of <code>PACKAGES_REFRESHED</code> is 0x00000004.
+	 * 
+	 * @since 1.2
+	 * @see "<code>PackageAdmin.refreshPackages</code>"
+	 */
+	public final static int	PACKAGES_REFRESHED	= 0x00000004;
+
+	/**
+	 * A StartLevel.setStartLevel operation has completed.
+	 * 
+	 * <p>
+	 * This event is fired when the Framework has completed changing the
+	 * active start level initiated by a call to the StartLevel.setStartLevel
+	 * method.
+	 * 
+	 * <p>
+	 * The value of <code>STARTLEVEL_CHANGED</code> is 0x00000008.
+	 * 
+	 * @since 1.2
+	 * @see "<code>StartLevel</code>"
+	 */
+	public final static int	STARTLEVEL_CHANGED	= 0x00000008;
+
+	/**
+	 * A warning has occurred.
+	 * 
+	 * <p>
+	 * There was a warning associated with a bundle.
+	 * 
+	 * <p>
+	 * The value of <code>WARNING</code> is 0x00000010.
+	 * 
+	 * @since 1.3
+	 */
+	public final static int	WARNING				= 0x00000010;
+
+	/**
+	 * An informational event has occurred.
+	 * 
+	 * <p>
+	 * There was an informational event associated with a bundle.
+	 * 
+	 * <p>
+	 * The value of <code>INFO</code> is 0x00000020.
+	 * 
+	 * @since 1.3
+	 */
+	public final static int	INFO				= 0x00000020;
+
+	/**
+	 * Creates a Framework event.
+	 * 
+	 * @param type The event type.
+	 * @param source The event source object. This may not be <code>null</code>.
+	 * @deprecated Since 1.2. This constructor is deprecated in favor of using
+	 *             the other constructor with the System Bundle as the event
+	 *             source.
+	 */
+	public FrameworkEvent(int type, Object source) {
+		super(source);
+		this.type = type;
+		this.bundle = null;
+		this.throwable = null;
+	}
+
+	/**
+	 * Creates a Framework event regarding the specified bundle.
+	 * 
+	 * @param type The event type.
+	 * @param bundle The event source.
+	 * @param throwable The related exception. This argument may be
+	 *        <code>null</code> if there is no related exception.
+	 */
+	public FrameworkEvent(int type, Bundle bundle, Throwable throwable) {
+		super(bundle);
+		this.type = type;
+		this.bundle = bundle;
+		this.throwable = throwable;
+	}
+
+	/**
+	 * Returns the exception related to this event.
+	 * 
+	 * @return The related exception or <code>null</code> if none.
+	 */
+	public Throwable getThrowable() {
+		return throwable;
+	}
+
+	/**
+	 * Returns the bundle associated with the event. This bundle is also the
+	 * source of the event.
+	 * 
+	 * @return The bundle associated with the event.
+	 */
+	public Bundle getBundle() {
+		return bundle;
+	}
+
+	/**
+	 * Returns the type of framework event.
+	 * <p>
+	 * The type values are:
+	 * <ul>
+	 * <li>{@link #STARTED}
+	 * <li>{@link #ERROR}
+	 * <li>{@link #WARNING}
+	 * <li>{@link #INFO}
+	 * <li>{@link #PACKAGES_REFRESHED}
+	 * <li>{@link #STARTLEVEL_CHANGED}
+	 * </ul>
+	 * 
+	 * @return The type of state change.
+	 */
+
+	public int getType() {
+		return type;
+	}
+}

Modified: incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/FrameworkListener.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/FrameworkListener.java?rev=386363&r1=386362&r2=386363&view=diff
==============================================================================
--- incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/FrameworkListener.java (original)
+++ incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/FrameworkListener.java Thu Mar 16 07:57:37 2006
@@ -1,39 +1,48 @@
-/*
- * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/FrameworkListener.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;
-
-import java.util.EventListener;
-
-/**
- * A <code>FrameworkEvent</code> listener.
- * 
- * <p>
- * <code>FrameworkListener</code> is a listener interface that may be implemented
- * by a bundle developer. A <code>FrameworkListener</code> object is registered
- * with the Framework using the {@link BundleContext#addFrameworkListener}
- * method. <code>FrameworkListener</code> objects are called with a
- * <code>FrameworkEvent</code> objects when the Framework starts and when
- * asynchronous errors occur.
- * 
- * @version $Revision: 1.6 $
- * @see FrameworkEvent
- */
-
-public abstract interface FrameworkListener extends EventListener {
-
-	/**
-	 * Receives notification of a general <code>FrameworkEvent</code> object.
-	 * 
-	 * @param event The <code>FrameworkEvent</code> object.
-	 */
-	public abstract void frameworkEvent(FrameworkEvent event);
-}
-
+/*
+ * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/FrameworkListener.java,v 1.9 2006/03/14 01:21:02 hargrave Exp $
+ * 
+ * Copyright (c) OSGi Alliance (2000, 2005). 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;
+
+import java.util.EventListener;
+
+/**
+ * A <code>FrameworkEvent</code> listener. When a <code>FrameworkEvent</code> is
+ * fired, it is asynchronously delivered to a <code>FrameworkListener</code>.
+ * 
+ * <p>
+ * <code>FrameworkListener</code> is a listener interface that may be
+ * implemented by a bundle developer. A <code>FrameworkListener</code> object
+ * is registered with the Framework using the
+ * {@link BundleContext#addFrameworkListener} method.
+ * <code>FrameworkListener</code> objects are called with a
+ * <code>FrameworkEvent</code> objects when the Framework starts and when
+ * asynchronous errors occur.
+ * 
+ * @version $Revision: 1.9 $
+ * @see FrameworkEvent
+ */
+
+public interface FrameworkListener extends EventListener {
+
+	/**
+	 * Receives notification of a general <code>FrameworkEvent</code> object.
+	 * 
+	 * @param event The <code>FrameworkEvent</code> object.
+	 */
+	public void frameworkEvent(FrameworkEvent event);
+}

Modified: incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/FrameworkUtil.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/FrameworkUtil.java?rev=386363&r1=386362&r2=386363&view=diff
==============================================================================
--- incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/FrameworkUtil.java (original)
+++ incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/FrameworkUtil.java Thu Mar 16 07:57:37 2006
@@ -1,85 +1,141 @@
-/*
- * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/FrameworkUtil.java,v 1.1 2005/07/14 20:32:46 hargrave 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.framework;
-
-
-import java.lang.reflect.Constructor;
-
-
-/**
- * Framework Utility class.
- * 
- * <p>
- * This class contains utility methods which access Framework functions that may
- * be useful to bundles.
- * 
- * @version $Revision: 1.1 $
- * @since 1.3
- */
-public class FrameworkUtil 
-{
-    private static final Class[] CONST_ARGS = new Class[] { String.class };
-    private static final String FILTER_IMPL_FQCN = "org.osgi.framework.filterImplFQCN";
-    private static final String FILTER_IMPL_DEFAULT = "org.apache.felix.framework.FilterImpl";
-    private static Class filterImplClass;
-
-
-    /**
-	 * Creates a <code>Filter</code> object. This <code>Filter</code> object
-	 * may be used to match a <code>ServiceReference</code> object or a
-	 * <code>Dictionary</code> object.
-	 * 
-	 * <p>
-	 * If the filter cannot be parsed, an {@link InvalidSyntaxException} will be
-	 * thrown with a human readable message where the filter became unparsable.
-	 * 
-	 * @param filter The filter string.
-	 * @return A <code>Filter</code> object encapsulating the filter string.
-	 * @throws InvalidSyntaxException If <code>filter</code> contains an
-	 *            invalid filter string that cannot be parsed.
-	 * @throws NullPointerException If <code>filter</code> is null.
-	 * 
-	 * @see Filter
-	 */
-	public static Filter createFilter( String filter ) throws InvalidSyntaxException 
-    {
-        if ( filterImplClass == null )
-        {
-            String fqcn = System.getProperty( FILTER_IMPL_FQCN );
-            if ( fqcn == null )
-            {
-                fqcn = FILTER_IMPL_DEFAULT;
-            }
-            
-            try
-            {
-                filterImplClass = Class.forName( fqcn );
-            }
-            catch ( ClassNotFoundException e )
-            {
-                throw new RuntimeException( "Failed to load filter implementation class: " + fqcn );
-            }
-        }
-        
-        Constructor constructor;
-        try
-        {
-            constructor = filterImplClass.getConstructor( CONST_ARGS );
-            Filter instance = ( Filter ) constructor.newInstance( new Object[] { filter } );
-            return instance;
-        }
-        catch ( Exception e )
-        {
-            throw new RuntimeException( "Failed to instantiate filter using implementation class: " 
-                + filterImplClass.getName() );
-        }
-	}
-}
+/*
+ * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/FrameworkUtil.java,v 1.5 2006/03/14 01:21:02 hargrave Exp $
+ * 
+ * Copyright (c) OSGi Alliance (2005). 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;
+
+import java.lang.reflect.*;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Framework Utility class.
+ * 
+ * <p>
+ * This class contains utility methods which access Framework functions that may
+ * be useful to bundles.
+ * 
+ * @version $Revision: 1.5 $
+ * @since 1.3
+ */
+public class FrameworkUtil {
+	/*
+	 * NOTE: A framework implementor may also choose to replace this class in
+	 * their distribution with a class that directly interfaces with the
+	 * framework implementation.
+	 */
+
+	/*
+	 * This class will load the FrameworkUtil class in the package named by the
+	 * org.osgi.vendor.framework package. For each instance of this class, an
+	 * instance of the vendor FrameworkUtil class will be created and this class
+	 * will delegate method calls to the vendor FrameworkUtil instance.
+	 */
+	private static final String	packageProperty	= "org.osgi.vendor.framework";
+
+	/*
+	 * This is the delegate method used by createFilter.
+	 */
+	private final static Method	createFilter;
+
+	static {
+		createFilter = (Method) AccessController
+				.doPrivileged(new PrivilegedAction() {
+					public Object run() {
+						String packageName = System
+								.getProperty(packageProperty);
+						if (packageName == null) {
+							throw new NoClassDefFoundError(packageProperty
+									+ " property not set");
+						}
+
+						Class delegateClass;
+						try {
+							delegateClass = Class.forName(packageName
+									+ ".FrameworkUtil");
+						}
+						catch (ClassNotFoundException e) {
+							throw new NoClassDefFoundError(e.toString());
+						}
+
+						Method result;
+						try {
+							result = delegateClass.getMethod("createFilter",
+									new Class[] {String.class});
+						}
+						catch (NoSuchMethodException e) {
+							throw new NoSuchMethodError(e.toString());
+						}
+
+						if (!Modifier.isStatic(result.getModifiers())) {
+							throw new NoSuchMethodError(
+									"createFilter method must be static");
+						}
+
+						return result;
+					}
+				});
+	}
+
+	
+	/**
+	 * FrameworkUtil objects may not be constructed. 
+	 */
+	private FrameworkUtil() {}
+	
+	/**
+	 * Creates a <code>Filter</code> object. This <code>Filter</code> object
+	 * may be used to match a <code>ServiceReference</code> object or a
+	 * <code>Dictionary</code> object.
+	 * 
+	 * <p>
+	 * If the filter cannot be parsed, an {@link InvalidSyntaxException} will be
+	 * thrown with a human readable message where the filter became unparsable.
+	 * 
+	 * @param filter The filter string.
+	 * @return A <code>Filter</code> object encapsulating the filter string.
+	 * @throws InvalidSyntaxException If <code>filter</code> contains an
+	 *         invalid filter string that cannot be parsed.
+	 * @throws NullPointerException If <code>filter</code> is null.
+	 * 
+	 * @see Filter
+	 */
+	public static Filter createFilter(String filter)
+			throws InvalidSyntaxException {
+		try {
+			try {
+				return (Filter) createFilter
+						.invoke(null, new Object[] {filter});
+			}
+			catch (InvocationTargetException e) {
+				throw e.getTargetException();
+			}
+		}
+		catch (InvalidSyntaxException e) {
+			throw e;
+		}
+		catch (Error e) {
+			throw e;
+		}
+		catch (RuntimeException e) {
+			throw e;
+		}
+		catch (Throwable e) {
+			throw new RuntimeException(e.toString());
+		}
+	}
+}

Modified: incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/InvalidSyntaxException.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/InvalidSyntaxException.java?rev=386363&r1=386362&r2=386363&view=diff
==============================================================================
--- incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/InvalidSyntaxException.java (original)
+++ incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/InvalidSyntaxException.java Thu Mar 16 07:57:37 2006
@@ -1,107 +1,118 @@
-/*
- * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/InvalidSyntaxException.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;
-
-/**
- * A Framework exception.
- * 
- * <p>
- * An <code>InvalidSyntaxException</code> object indicates that a filter string
- * parameter has an invalid syntax and cannot be parsed.
- * 
- * <p>
- * See {@link Filter} for a description of the filter string syntax.
- * 
- * @version $Revision: 1.10 $
- */
-
-public class InvalidSyntaxException extends Exception {
-	static final long	serialVersionUID	= -4295194420816491875L;
-	/**
-	 * The invalid filter string.
-	 */
-	private String		filter;
-	/**
-	 * Nested exception.
-	 */
-	private Throwable	cause;
-
-	/**
-	 * Creates an exception of type <code>InvalidSyntaxException</code>.
-	 * 
-	 * <p>
-	 * This method creates an <code>InvalidSyntaxException</code> object with the
-	 * specified message and the filter string which generated the exception.
-	 * 
-	 * @param msg The message.
-	 * @param filter The invalid filter string.
-	 */
-	public InvalidSyntaxException(String msg, String filter) {
-		super(msg);
-		this.filter = filter;
-		this.cause = null;
-	}
-
-	/**
-	 * Creates an exception of type <code>InvalidSyntaxException</code>.
-	 * 
-	 * <p>
-	 * This method creates an <code>InvalidSyntaxException</code> object with the
-	 * specified message and the filter string which generated the exception.
-	 * 
-	 * @param msg The message.
-	 * @param filter The invalid filter string.
-	 * @param cause The cause of this exception.
-	 * @since 1.3
-	 */
-	public InvalidSyntaxException(String msg, String filter, Throwable cause) {
-		super(msg);
-		this.filter = filter;
-		this.cause = cause;
-	}
-
-	/**
-	 * Returns the filter string that generated the
-	 * <code>InvalidSyntaxException</code> object.
-	 * 
-	 * @return The invalid filter string.
-	 * @see BundleContext#getServiceReferences
-	 * @see BundleContext#addServiceListener(ServiceListener,String)
-	 */
-	public String getFilter() {
-		return filter;
-	}
-
-	/**
-	 * Returns the cause of this exception or <code>null</code> if no cause was
-	 * specified when this exception was created.
-	 * 
-	 * @return The cause of this exception or <code>null</code> if no cause was
-	 *         specified.
-	 * @since 1.3
-	 */
-	public Throwable getCause() {
-		return cause;
-	}
-
-	/**
-	 * The cause of this exception can only be set when constructed.
-	 * 
-	 * @throws java.lang.IllegalStateException This method will always throw an
-	 *         <code>IllegalStateException</code> since the cause of this
-	 *         exception can only be set when constructed.
-	 * @since 1.3
-	 */
-	public Throwable initCause(Throwable cause) {
-		throw new IllegalStateException();
-	}
-}
-
+/*
+ * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/InvalidSyntaxException.java,v 1.13 2006/03/14 01:21:02 hargrave Exp $
+ * 
+ * Copyright (c) OSGi Alliance (2000, 2005). 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;
+
+/**
+ * A Framework exception.
+ * 
+ * <p>
+ * An <code>InvalidSyntaxException</code> object indicates that a filter
+ * string parameter has an invalid syntax and cannot be parsed.
+ * 
+ * <p>
+ * See {@link Filter} for a description of the filter string syntax.
+ * 
+ * @version $Revision: 1.13 $
+ */
+
+public class InvalidSyntaxException extends Exception {
+	static final long	serialVersionUID	= -4295194420816491875L;
+	/**
+	 * The invalid filter string.
+	 */
+	private String		filter;
+	/**
+	 * Nested exception.
+	 */
+	private Throwable	cause;
+
+	/**
+	 * Creates an exception of type <code>InvalidSyntaxException</code>.
+	 * 
+	 * <p>
+	 * This method creates an <code>InvalidSyntaxException</code> object with
+	 * the specified message and the filter string which generated the
+	 * exception.
+	 * 
+	 * @param msg The message.
+	 * @param filter The invalid filter string.
+	 */
+	public InvalidSyntaxException(String msg, String filter) {
+		super(msg);
+		this.filter = filter;
+		this.cause = null;
+	}
+
+	/**
+	 * Creates an exception of type <code>InvalidSyntaxException</code>.
+	 * 
+	 * <p>
+	 * This method creates an <code>InvalidSyntaxException</code> object with
+	 * the specified message and the filter string which generated the
+	 * exception.
+	 * 
+	 * @param msg The message.
+	 * @param filter The invalid filter string.
+	 * @param cause The cause of this exception.
+	 * @since 1.3
+	 */
+	public InvalidSyntaxException(String msg, String filter, Throwable cause) {
+		super(msg);
+		this.filter = filter;
+		this.cause = cause;
+	}
+
+	/**
+	 * Returns the filter string that generated the
+	 * <code>InvalidSyntaxException</code> object.
+	 * 
+	 * @return The invalid filter string.
+	 * @see BundleContext#getServiceReferences
+	 * @see BundleContext#addServiceListener(ServiceListener,String)
+	 */
+	public String getFilter() {
+		return filter;
+	}
+
+	/**
+	 * Returns the cause of this exception or <code>null</code> if no cause
+	 * was specified when this exception was created.
+	 * 
+	 * @return The cause of this exception or <code>null</code> if no cause
+	 *         was specified.
+	 * @since 1.3
+	 */
+	public Throwable getCause() {
+		return cause;
+	}
+
+	/**
+	 * The cause of this exception can only be set when constructed.
+	 * 
+	 * @param cause Cause of the exception.
+	 * @return This object.
+	 * @throws java.lang.IllegalStateException This method will always throw an
+	 *         <code>IllegalStateException</code> since the cause of this
+	 *         exception can only be set when constructed.
+	 * @since 1.3
+	 */
+	public Throwable initCause(Throwable cause) {
+		throw new IllegalStateException();
+	}
+}

Modified: incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/PackagePermission.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/PackagePermission.java?rev=386363&r1=386362&r2=386363&view=diff
==============================================================================
--- incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/PackagePermission.java (original)
+++ incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/PackagePermission.java Thu Mar 16 07:57:37 2006
@@ -1,535 +1,541 @@
-/*
- * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/PackagePermission.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;
-
-/**
- * A bundle's authority to import or export a package.
- * 
- * <p>
- * A package is a dot-separated string that defines a fully qualified Java
- * package.
- * <p>
- * For example:
- * 
- * <pre>
- * <code>
- * org.osgi.service.http
- * </code>
- * </pre>
- * 
- * <p>
- * <code>PackagePermission</code> has two actions: <code>EXPORT</code> and
- * <code>IMPORT</code>. The <code>EXPORT</code> action implies the <code>IMPORT</code>
- * action.
- * 
- * @version $Revision: 1.10 $
- */
-
-public final class PackagePermission extends BasicPermission {
-	static final long			serialVersionUID	= -5107705877071099135L;
-	/**
-	 * The action string <code>export</code>.
-	 */
-	public final static String	EXPORT				= "export";
-
-	/**
-	 * The action string <code>import</code>.
-	 */
-	public final static String	IMPORT				= "import";
-
-	private final static int	ACTION_EXPORT		= 0x00000001;
-	private final static int	ACTION_IMPORT		= 0x00000002;
-	private final static int	ACTION_ALL			= ACTION_EXPORT
-															| ACTION_IMPORT;
-	private final static int	ACTION_NONE			= 0;
-//  NOT USED
-//  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;
-
-	/**
-	 * Defines the authority to import and/or export a package within the OSGi
-	 * environment.
-	 * <p>
-	 * The name is specified as a normal Java package name: a dot-separated
-	 * string. Wildcards may be used. For example:
-	 * 
-	 * <pre>
-	 * 
-	 *  org.osgi.service.http
-	 *  javax.servlet.*
-	 *  *
-	 *  
-	 * </pre>
-	 * 
-	 * <p>
-	 * Package Permissions are granted over all possible versions of a package.
-	 * 
-	 * A bundle that needs to export a package must have the appropriate
-	 * <code>PackagePermission</code> for that package; similarly, a bundle that
-	 * needs to import a package must have the appropriate
-	 * <code>PackagePermssion</code> for that package.
-	 * <p>
-	 * Permission is granted for both classes and resources.
-	 * 
-	 * @param name Package name.
-	 * @param actions <code>EXPORT</code>,<code>IMPORT</code> (canonical order).
-	 */
-
-	public PackagePermission(String name, String actions) {
-		this(name, getMask(actions));
-	}
-
-	/**
-	 * Package private constructor used by PackagePermissionCollection.
-	 * 
-	 * @param name class name
-	 * @param mask action mask
-	 */
-	PackagePermission(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 >= 5 && (a[i - 5] == 'i' || a[i - 5] == 'I')
-					&& (a[i - 4] == 'm' || a[i - 4] == 'M')
-					&& (a[i - 3] == 'p' || a[i - 3] == 'P')
-					&& (a[i - 2] == 'o' || a[i - 2] == 'O')
-					&& (a[i - 1] == 'r' || a[i - 1] == 'R')
-					&& (a[i] == 't' || a[i] == 'T')) {
-				matchlen = 6;
-				mask |= ACTION_IMPORT;
-
-			}
-			else
-				if (i >= 5 && (a[i - 5] == 'e' || a[i - 5] == 'E')
-						&& (a[i - 4] == 'x' || a[i - 4] == 'X')
-						&& (a[i - 3] == 'p' || a[i - 3] == 'P')
-						&& (a[i - 2] == 'o' || a[i - 2] == 'O')
-						&& (a[i - 1] == 'r' || a[i - 1] == 'R')
-						&& (a[i] == 't' || a[i] == 'T')) {
-					matchlen = 6;
-					mask |= ACTION_EXPORT | ACTION_IMPORT;
-
-				}
-				else {
-					// parse error
-					throw new IllegalArgumentException("invalid permission: "
-							+ actions);
-				}
-
-			// make sure we didn't just match the tail of a word
-			// like "ackbarfimport". 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 the specified permission is implied by this object.
-	 * 
-	 * <p>
-	 * This method checks that the package name of the target is implied by the
-	 * package name of this object. The list of <code>PackagePermission</code>
-	 * actions must either match or allow for the list of the target object to
-	 * imply the target <code>PackagePermission</code> action.
-	 * <p>
-	 * The permission to export a package implies the permission to import the
-	 * named package.
-	 * 
-	 * <pre>
-	 *  x.y.*,&quot;export&quot; -&gt; x.y.z,&quot;export&quot; is true
-	 *  *,&quot;import&quot; -&gt; x.y, &quot;import&quot;      is true
-	 *  *,&quot;export&quot; -&gt; x.y, &quot;import&quot;      is true
-	 *  x.y,&quot;export&quot; -&gt; x.y.z, &quot;export&quot;  is false
-	 * </pre>
-	 * 
-	 * @param p The target permission to interrogate.
-	 * @return <code>true</code> if the specified <code>PackagePermission</code>
-	 *         action is implied by this object; <code>false</code> otherwise.
-	 */
-
-	public boolean implies(Permission p) {
-		if (p instanceof PackagePermission) {
-			PackagePermission target = (PackagePermission) p;
-
-			return (((action_mask & target.action_mask) == target.action_mask) && super
-					.implies(p));
-		}
-
-		return (false);
-	}
-
-	/**
-	 * Returns the canonical string representation of the
-	 * <code>PackagePermission</code> actions.
-	 * 
-	 * <p>
-	 * Always returns present <code>PackagePermission</code> actions in the
-	 * following order: <code>EXPORT</code>,<code>IMPORT</code>.
-	 * 
-	 * @return Canonical string representation of the <code>PackagePermission</code>
-	 *         actions.
-	 */
-
-	public String getActions() {
-		if (actions == null) {
-			StringBuffer sb = new StringBuffer();
-			boolean comma = false;
-
-			if ((action_mask & ACTION_EXPORT) == ACTION_EXPORT) {
-				sb.append(EXPORT);
-				comma = true;
-			}
-
-			if ((action_mask & ACTION_IMPORT) == ACTION_IMPORT) {
-				if (comma)
-					sb.append(',');
-				sb.append(IMPORT);
-			}
-
-			actions = sb.toString();
-		}
-
-		return (actions);
-	}
-
-	/**
-	 * Returns a new <code>PermissionCollection</code> object suitable for storing
-	 * <code>PackagePermission</code> objects.
-	 * 
-	 * @return A new <code>PermissionCollection</code> object.
-	 */
-	public PermissionCollection newPermissionCollection() {
-		return (new PackagePermissionCollection());
-	}
-
-	/**
-	 * Determines the equality of two <code>PackagePermission</code> objects.
-	 * 
-	 * This method checks that specified package has the same package name and
-	 * <code>PackagePermission</code> actions as this <code>PackagePermission</code>
-	 * object.
-	 * 
-	 * @param obj The object to test for equality with this
-	 *        <code>PackagePermission</code> object.
-	 * @return <code>true</code> if <code>obj</code> is a <code>PackagePermission</code>,
-	 *         and has the same package name and actions as this
-	 *         <code>PackagePermission</code> object; <code>false</code> otherwise.
-	 */
-	public boolean equals(Object obj) {
-		if (obj == this) {
-			return (true);
-		}
-
-		if (!(obj instanceof PackagePermission)) {
-			return (false);
-		}
-
-		PackagePermission p = (PackagePermission) obj;
-
-		return ((action_mask == p.action_mask) && getName().equals(p.getName()));
-	}
-
-	/**
-	 * Returns the hash code value for this object.
-	 * 
-	 * @return A hash code value for this object.
-	 */
-
-	public int hashCode() {
-		return (getName().hashCode() ^ getActions().hashCode());
-	}
-
-	/**
-	 * Returns the current action mask.
-	 * <p>
-	 * Used by the PackagePermissionCollection class.
-	 * 
-	 * @return Current action mask.
-	 */
-	int getMask() {
-		return (action_mask);
-	}
-
-	/**
-	 * WriteObject is called to save the state of this permission object 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 <code>PackagePermission</code> permissions.
- * 
- * @see java.security.Permission
- * @see java.security.Permissions
- * @see java.security.PermissionCollection
- */
-
-final class PackagePermissionCollection extends PermissionCollection {
-	static final long	serialVersionUID	= -3350758995234427603L;
-	/**
-	 * Table of permissions.
-	 * 
-	 * @serial
-	 */
-	private Hashtable	permissions;
-
-	/**
-	 * Boolean saying if "*" is in the collection.
-	 * 
-	 * @serial
-	 */
-	private boolean		all_allowed;
-
-	/**
-	 * Create an empty PackagePermissions object.
-	 *  
-	 */
-
-	public PackagePermissionCollection() {
-		permissions = new Hashtable();
-		all_allowed = false;
-	}
-
-	/**
-	 * Adds a permission to the <code>PackagePermission</code> objects. The key
-	 * for the hash is the name.
-	 * 
-	 * @param permission The <code>PackagePermission</code> object to add.
-	 * 
-	 * @exception IllegalArgumentException If the permission is not a
-	 *            <code>PackagePermission</code> instance.
-	 * 
-	 * @exception SecurityException If this <code>PackagePermissionCollection</code>
-	 *            object has been marked read-only.
-	 */
-
-	public void add(Permission permission) {
-		if (!(permission instanceof PackagePermission))
-			throw new IllegalArgumentException("invalid permission: "
-					+ permission);
-		if (isReadOnly())
-			throw new SecurityException("attempt to add a Permission to a "
-					+ "readonly PermissionCollection");
-
-		PackagePermission pp = (PackagePermission) permission;
-		String name = pp.getName();
-
-		PackagePermission existing = (PackagePermission) permissions.get(name);
-
-		if (existing != null) {
-			int oldMask = existing.getMask();
-			int newMask = pp.getMask();
-			if (oldMask != newMask) {
-				permissions.put(name, new PackagePermission(name, oldMask
-						| newMask));
-
-			}
-		}
-		else {
-			permissions.put(name, permission);
-		}
-
-		if (!all_allowed) {
-			if (name.equals("*"))
-				all_allowed = true;
-		}
-	}
-
-	/**
-	 * Determines if the specified permissions implies the permissions expressed
-	 * in <code>permission</code>.
-	 * 
-	 * @param permission The Permission object to compare with this
-	 *        <code>PackagePermission</code> object.
-	 * 
-	 * @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 PackagePermission))
-			return (false);
-
-		PackagePermission pp = (PackagePermission) permission;
-		PackagePermission x;
-
-		int desired = pp.getMask();
-		int effective = 0;
-
-		// short circuit if the "*" Permission was added
-		if (all_allowed) {
-			x = (PackagePermission) 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 = pp.getName();
-
-		x = (PackagePermission) 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 = (PackagePermission) 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 <code>PackagePermission</code> objects in the
-	 * container.
-	 * 
-	 * @return Enumeration of all <code>PackagePermission</code> objects.
-	 */
-
-	public Enumeration elements() {
-		return (permissions.elements());
-	}
-}
-
+/*
+ * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/PackagePermission.java,v 1.13 2006/03/14 01:21:02 hargrave Exp $
+ * 
+ * Copyright (c) OSGi Alliance (2000, 2005). 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;
+
+import java.io.IOException;
+import java.security.*;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+/**
+ * A bundle's authority to import or export a package.
+ * 
+ * <p>
+ * A package is a dot-separated string that defines a fully qualified Java
+ * package.
+ * <p>
+ * For example:
+ * 
+ * <pre>
+ * <code>
+ * org.osgi.service.http
+ * </code>
+ * </pre>
+ * 
+ * <p>
+ * <code>PackagePermission</code> has two actions: <code>EXPORT</code> and
+ * <code>IMPORT</code>. The <code>EXPORT</code> action implies the
+ * <code>IMPORT</code> action.
+ * 
+ * @version $Revision: 1.13 $
+ */
+
+public final class PackagePermission extends BasicPermission {
+	static final long			serialVersionUID	= -5107705877071099135L;
+	/**
+	 * The action string <code>export</code>.
+	 */
+	public final static String	EXPORT				= "export";
+
+	/**
+	 * The action string <code>import</code>.
+	 */
+	public final static String	IMPORT				= "import";
+
+	private final static int	ACTION_EXPORT		= 0x00000001;
+	private final static int	ACTION_IMPORT		= 0x00000002;
+	private final static int	ACTION_ALL			= ACTION_EXPORT
+															| ACTION_IMPORT;
+	private final static int	ACTION_NONE			= 0;
+	/**
+	 * The actions mask.
+	 */
+	private transient int		action_mask			= ACTION_NONE;
+
+	/**
+	 * The actions in canonical form.
+	 * 
+	 * @serial
+	 */
+	private String				actions				= null;
+
+	/**
+	 * Defines the authority to import and/or export a package within the OSGi
+	 * environment.
+	 * <p>
+	 * The name is specified as a normal Java package name: a dot-separated
+	 * string. Wildcards may be used. For example:
+	 * 
+	 * <pre>
+	 * org.osgi.service.http
+	 * javax.servlet.*
+	 * *
+	 * </pre>
+	 * 
+	 * <p>
+	 * Package Permissions are granted over all possible versions of a package.
+	 * 
+	 * A bundle that needs to export a package must have the appropriate
+	 * <code>PackagePermission</code> for that package; similarly, a bundle
+	 * that needs to import a package must have the appropriate
+	 * <code>PackagePermssion</code> for that package.
+	 * <p>
+	 * Permission is granted for both classes and resources.
+	 * 
+	 * @param name Package name.
+	 * @param actions <code>EXPORT</code>,<code>IMPORT</code> (canonical
+	 *        order).
+	 */
+
+	public PackagePermission(String name, String actions) {
+		this(name, getMask(actions));
+	}
+
+	/**
+	 * Package private constructor used by PackagePermissionCollection.
+	 * 
+	 * @param name class name
+	 * @param mask action mask
+	 */
+	PackagePermission(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 >= 5 && (a[i - 5] == 'i' || a[i - 5] == 'I')
+					&& (a[i - 4] == 'm' || a[i - 4] == 'M')
+					&& (a[i - 3] == 'p' || a[i - 3] == 'P')
+					&& (a[i - 2] == 'o' || a[i - 2] == 'O')
+					&& (a[i - 1] == 'r' || a[i - 1] == 'R')
+					&& (a[i] == 't' || a[i] == 'T')) {
+				matchlen = 6;
+				mask |= ACTION_IMPORT;
+
+			}
+			else
+				if (i >= 5 && (a[i - 5] == 'e' || a[i - 5] == 'E')
+						&& (a[i - 4] == 'x' || a[i - 4] == 'X')
+						&& (a[i - 3] == 'p' || a[i - 3] == 'P')
+						&& (a[i - 2] == 'o' || a[i - 2] == 'O')
+						&& (a[i - 1] == 'r' || a[i - 1] == 'R')
+						&& (a[i] == 't' || a[i] == 'T')) {
+					matchlen = 6;
+					mask |= ACTION_EXPORT | ACTION_IMPORT;
+
+				}
+				else {
+					// parse error
+					throw new IllegalArgumentException("invalid permission: "
+							+ actions);
+				}
+
+			// make sure we didn't just match the tail of a word
+			// like "ackbarfimport". 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 the specified permission is implied by this object.
+	 * 
+	 * <p>
+	 * This method checks that the package name of the target is implied by the
+	 * package name of this object. The list of <code>PackagePermission</code>
+	 * actions must either match or allow for the list of the target object to
+	 * imply the target <code>PackagePermission</code> action.
+	 * <p>
+	 * The permission to export a package implies the permission to import the
+	 * named package.
+	 * 
+	 * <pre>
+	 * x.y.*,&quot;export&quot; -&gt; x.y.z,&quot;export&quot; is true
+	 * *,&quot;import&quot; -&gt; x.y, &quot;import&quot;      is true
+	 * *,&quot;export&quot; -&gt; x.y, &quot;import&quot;      is true
+	 * x.y,&quot;export&quot; -&gt; x.y.z, &quot;export&quot;  is false
+	 * </pre>
+	 * 
+	 * @param p The target permission to interrogate.
+	 * @return <code>true</code> if the specified
+	 *         <code>PackagePermission</code> action is implied by this
+	 *         object; <code>false</code> otherwise.
+	 */
+
+	public boolean implies(Permission p) {
+		if (p instanceof PackagePermission) {
+			PackagePermission target = (PackagePermission) p;
+
+			return (((action_mask & target.action_mask) == target.action_mask) && super
+					.implies(p));
+		}
+
+		return (false);
+	}
+
+	/**
+	 * Returns the canonical string representation of the
+	 * <code>PackagePermission</code> actions.
+	 * 
+	 * <p>
+	 * Always returns present <code>PackagePermission</code> actions in the
+	 * following order: <code>EXPORT</code>,<code>IMPORT</code>.
+	 * 
+	 * @return Canonical string representation of the
+	 *         <code>PackagePermission</code> actions.
+	 */
+
+	public String getActions() {
+		if (actions == null) {
+			StringBuffer sb = new StringBuffer();
+			boolean comma = false;
+
+			if ((action_mask & ACTION_EXPORT) == ACTION_EXPORT) {
+				sb.append(EXPORT);
+				comma = true;
+			}
+
+			if ((action_mask & ACTION_IMPORT) == ACTION_IMPORT) {
+				if (comma)
+					sb.append(',');
+				sb.append(IMPORT);
+			}
+
+			actions = sb.toString();
+		}
+
+		return (actions);
+	}
+
+	/**
+	 * Returns a new <code>PermissionCollection</code> object suitable for
+	 * storing <code>PackagePermission</code> objects.
+	 * 
+	 * @return A new <code>PermissionCollection</code> object.
+	 */
+	public PermissionCollection newPermissionCollection() {
+		return (new PackagePermissionCollection());
+	}
+
+	/**
+	 * Determines the equality of two <code>PackagePermission</code> objects.
+	 * 
+	 * This method checks that specified package has the same package name and
+	 * <code>PackagePermission</code> actions as this
+	 * <code>PackagePermission</code> object.
+	 * 
+	 * @param obj The object to test for equality with this
+	 *        <code>PackagePermission</code> object.
+	 * @return <code>true</code> if <code>obj</code> is a
+	 *         <code>PackagePermission</code>, and has the same package name
+	 *         and actions as this <code>PackagePermission</code> object;
+	 *         <code>false</code> otherwise.
+	 */
+	public boolean equals(Object obj) {
+		if (obj == this) {
+			return (true);
+		}
+
+		if (!(obj instanceof PackagePermission)) {
+			return (false);
+		}
+
+		PackagePermission p = (PackagePermission) obj;
+
+		return ((action_mask == p.action_mask) && getName().equals(p.getName()));
+	}
+
+	/**
+	 * Returns the hash code value for this object.
+	 * 
+	 * @return A hash code value for this object.
+	 */
+
+	public int hashCode() {
+		return (getName().hashCode() ^ getActions().hashCode());
+	}
+
+	/**
+	 * Returns the current action mask.
+	 * <p>
+	 * Used by the PackagePermissionCollection class.
+	 * 
+	 * @return Current action mask.
+	 */
+	int getMask() {
+		return (action_mask);
+	}
+
+	/**
+	 * WriteObject is called to save the state of this permission object 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 <code>PackagePermission</code> permissions.
+ * 
+ * @see java.security.Permission
+ * @see java.security.Permissions
+ * @see java.security.PermissionCollection
+ */
+
+final class PackagePermissionCollection extends PermissionCollection {
+	static final long	serialVersionUID	= -3350758995234427603L;
+	/**
+	 * Table of permissions.
+	 * 
+	 * @serial
+	 */
+	private Hashtable	permissions;
+
+	/**
+	 * Boolean saying if "*" is in the collection.
+	 * 
+	 * @serial
+	 */
+	private boolean		all_allowed;
+
+	/**
+	 * Create an empty PackagePermissions object.
+	 */
+
+	public PackagePermissionCollection() {
+		permissions = new Hashtable();
+		all_allowed = false;
+	}
+
+	/**
+	 * Adds a permission to the <code>PackagePermission</code> objects. The
+	 * key for the hash is the name.
+	 * 
+	 * @param permission The <code>PackagePermission</code> object to add.
+	 * 
+	 * @throws IllegalArgumentException If the permission is not a
+	 *         <code>PackagePermission</code> instance.
+	 * 
+	 * @throws SecurityException If this
+	 *         <code>PackagePermissionCollection</code> object has been marked
+	 *         read-only.
+	 */
+
+	public void add(Permission permission) {
+		if (!(permission instanceof PackagePermission))
+			throw new IllegalArgumentException("invalid permission: "
+					+ permission);
+		if (isReadOnly())
+			throw new SecurityException("attempt to add a Permission to a "
+					+ "readonly PermissionCollection");
+
+		PackagePermission pp = (PackagePermission) permission;
+		String name = pp.getName();
+
+		PackagePermission existing = (PackagePermission) permissions.get(name);
+
+		if (existing != null) {
+			int oldMask = existing.getMask();
+			int newMask = pp.getMask();
+			if (oldMask != newMask) {
+				permissions.put(name, new PackagePermission(name, oldMask
+						| newMask));
+
+			}
+		}
+		else {
+			permissions.put(name, permission);
+		}
+
+		if (!all_allowed) {
+			if (name.equals("*"))
+				all_allowed = true;
+		}
+	}
+
+	/**
+	 * Determines if the specified permissions implies the permissions expressed
+	 * in <code>permission</code>.
+	 * 
+	 * @param permission The Permission object to compare with this
+	 *        <code>PackagePermission</code> object.
+	 * 
+	 * @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 PackagePermission))
+			return (false);
+
+		PackagePermission pp = (PackagePermission) permission;
+		PackagePermission x;
+
+		int desired = pp.getMask();
+		int effective = 0;
+
+		// short circuit if the "*" Permission was added
+		if (all_allowed) {
+			x = (PackagePermission) 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 = pp.getName();
+
+		x = (PackagePermission) 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 = (PackagePermission) 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 <code>PackagePermission</code> objects in
+	 * the container.
+	 * 
+	 * @return Enumeration of all <code>PackagePermission</code> objects.
+	 */
+
+	public Enumeration elements() {
+		return (permissions.elements());
+	}
+}

Modified: incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/ServiceEvent.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/ServiceEvent.java?rev=386363&r1=386362&r2=386363&view=diff
==============================================================================
--- incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/ServiceEvent.java (original)
+++ incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/ServiceEvent.java Thu Mar 16 07:57:37 2006
@@ -1,129 +1,136 @@
-/*
- * $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);
-	}
-}
-
+/*
+ * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/ServiceEvent.java,v 1.13 2006/03/14 01:21:02 hargrave Exp $
+ * 
+ * Copyright (c) OSGi Alliance (2000, 2005). 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;
+
+import java.util.EventObject;
+
+/**
+ * An event from the Framework describing a service lifecycle change.
+ * <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.13 $
+ * @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,java.util.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;
+	}
+}

Modified: incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/ServiceFactory.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/ServiceFactory.java?rev=386363&r1=386362&r2=386363&view=diff
==============================================================================
--- incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/ServiceFactory.java (original)
+++ incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/ServiceFactory.java Thu Mar 16 07:57:37 2006
@@ -1,89 +1,99 @@
-/*
- * $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);
-}
-
+/*
+ * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/ServiceFactory.java,v 1.8 2006/03/14 01:21:02 hargrave Exp $
+ * 
+ * Copyright (c) OSGi Alliance (2000, 2005). 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;
+
+/**
+ * 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.8 $
+ * @see BundleContext#getService
+ */
+
+public 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 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 void ungetService(Bundle bundle,
+			ServiceRegistration registration, Object service);
+}

Modified: incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/ServiceListener.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/ServiceListener.java?rev=386363&r1=386362&r2=386363&view=diff
==============================================================================
--- incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/ServiceListener.java (original)
+++ incubator/felix/trunk/org.osgi/src/main/java/org/osgi/framework/ServiceListener.java Thu Mar 16 07:57:37 2006
@@ -1,51 +1,63 @@
-/*
- * $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);
-}
-
-
+/*
+ * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/ServiceListener.java,v 1.11 2006/03/14 01:21:02 hargrave Exp $
+ * 
+ * Copyright (c) OSGi Alliance (2000, 2005). 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;
+
+import java.util.EventListener;
+
+/**
+ * A <code>ServiceEvent</code> listener. When a <code>ServiceEvent</code> is
+ * fired, it is synchronously delivered to a <code>BundleListener</code>.
+ * 
+ * <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.11 $
+ * @see ServiceEvent
+ * @see ServicePermission
+ */
+
+public interface ServiceListener extends EventListener {
+	/**
+	 * Receives notification that a service has had a lifecycle change.
+	 * 
+	 * @param event The <code>ServiceEvent</code> object.
+	 */
+	public void serviceChanged(ServiceEvent event);
+}