Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2005-12-20 21:26:05 +0000
committerThomas Watson2005-12-20 21:26:05 +0000
commit460fc21757cbdd238ca8dd073de75edeaf75a7e0 (patch)
tree13e9283d3d27342b07d65152ddbf01b16aa6581c
parent1c9d18b95b5ecd12d33e8773f2284c77a43c0206 (diff)
downloadrt.equinox.bundles-460fc21757cbdd238ca8dd073de75edeaf75a7e0.tar.gz
rt.equinox.bundles-460fc21757cbdd238ca8dd073de75edeaf75a7e0.tar.xz
rt.equinox.bundles-460fc21757cbdd238ca8dd073de75edeaf75a7e0.zip
Latest MEG API updates from OSGi.
-rwxr-xr-xbundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/EclipseAppHandle.java2
-rwxr-xr-xbundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationAdminPermission.java27
-rwxr-xr-xbundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationDescriptor.java63
-rwxr-xr-xbundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationException.java105
-rwxr-xr-xbundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationHandle.java14
5 files changed, 175 insertions, 36 deletions
diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/EclipseAppHandle.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/EclipseAppHandle.java
index e8ffe6636..e211a6d86 100755
--- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/EclipseAppHandle.java
+++ b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/EclipseAppHandle.java
@@ -51,7 +51,7 @@ public class EclipseAppHandle extends ApplicationHandle implements IAppContext {
}
- protected void destroySpecific() throws Exception {
+ protected void destroySpecific() {
// when this method is called we must force the application to exit.
// first set the status to stopping
setAppStatus(IAppContext.STOPPING);
diff --git a/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationAdminPermission.java b/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationAdminPermission.java
index 059380c7f..4cbab14c9 100755
--- a/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationAdminPermission.java
+++ b/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationAdminPermission.java
@@ -1,5 +1,5 @@
/*
- * $Header: /cvshome/build/org.osgi.service.application/src/org/osgi/service/application/ApplicationAdminPermission.java,v 1.29 2005/12/19 15:57:16 ckarai Exp $
+ * $Header: /cvshome/build/org.osgi.service.application/src/org/osgi/service/application/ApplicationAdminPermission.java,v 1.31 2005/12/20 11:23:39 ckarai Exp $
*
* Copyright (c) OSGi Alliance (2004, 2005). All Rights Reserved.
*
@@ -101,7 +101,7 @@ public class ApplicationAdminPermission extends Permission {
this.filter = (filter == null ? "*" : filter);
this.actions = actions;
- if( !filter.equals( "*" ) )
+ if( !filter.equals( "*" ) && !filter.equals( "<<SELF>>" ) )
FrameworkUtil.createFilter( this.filter ); // check if the filter is valid
init();
}
@@ -136,11 +136,17 @@ public class ApplicationAdminPermission extends Permission {
* @return the permission updated with the ID of the current application
*/
public ApplicationAdminPermission setCurrentApplicationId(String applicationId) {
- if( this.applicationDescriptor == null )
- throw new NullPointerException("No application descriptor found!");
-
- ApplicationAdminPermission newPerm = new ApplicationAdminPermission( this.applicationDescriptor,
- this.actions );
+ ApplicationAdminPermission newPerm = null;
+
+ if( this.applicationDescriptor == null ) {
+ try {
+ newPerm = new ApplicationAdminPermission( this.filter, this.actions );
+ }catch( InvalidSyntaxException e ) {
+ throw new RuntimeException( "Internal error" ); /* this can never happen */
+ }
+ }
+ else
+ newPerm = new ApplicationAdminPermission( this.applicationDescriptor, this.actions );
newPerm.applicationID = applicationId;
@@ -176,6 +182,9 @@ public class ApplicationAdminPermission extends Permission {
ApplicationAdminPermission other = (ApplicationAdminPermission) otherPermission;
if( !filter.equals("*") ) {
+ if( other.applicationDescriptor == null )
+ return false;
+
if( filter.equals( "<<SELF>>") ) {
if( other.applicationID == null )
return false; /* it cannot be, this might be a bug */
@@ -185,8 +194,6 @@ public class ApplicationAdminPermission extends Permission {
}
else {
Hashtable props = new Hashtable();
- if( other.applicationDescriptor == null )
- return false;
props.put( "pid", other.applicationDescriptor.getApplicationId() );
props.put( "signer", new SignerWrapper( other.applicationDescriptor ) );
@@ -195,7 +202,7 @@ public class ApplicationAdminPermission extends Permission {
return false;
if( !flt.match( props ) )
- return false;
+ return false;
}
}
diff --git a/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationDescriptor.java b/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationDescriptor.java
index be3e5c360..62718966c 100755
--- a/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationDescriptor.java
+++ b/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationDescriptor.java
@@ -1,5 +1,5 @@
/*
- * $Header: /cvsroot/eclipse/equinox-incubator/runtime-split/org.eclipse.equinox.appcontainer/src/org/osgi/service/application/ApplicationDescriptor.java,v 1.3 2005/12/14 18:52:01 twatson Exp $
+ * $Header: /cvsroot/eclipse/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationDescriptor.java,v 1.1 2005/12/14 22:17:04 twatson Exp $
*
* Copyright (c) OSGi Alliance (2004, 2005). All Rights Reserved.
*
@@ -10,9 +10,8 @@
package org.osgi.service.application;
-import java.io.IOException;
+import java.util.Iterator;
import java.util.Map;
-
import org.eclipse.equinox.internal.app.AppManager;
import org.osgi.framework.Constants;
import org.osgi.framework.InvalidSyntaxException;
@@ -241,7 +240,8 @@ public abstract class ApplicationDescriptor {
* <P>
* The <code>Map</code> argument of the launch method contains startup
* arguments for the
- * application. The keys used in the Map can be standard or application
+ * application. The keys used in the Map must be non-null, non-empty <code>String<code>
+ * objects. They can be standard or application
* specific. OSGi defines the <code>org.osgi.triggeringevent</code>
* key to be used to
* pass the triggering event to a scheduled application, however
@@ -270,23 +270,39 @@ public abstract class ApplicationDescriptor {
* @throws SecurityException
* if the caller doesn't have "lifecycle"
* ApplicationAdminPermission for the application.
- * @throws Exception
+ * @throws ApplicationException
* if starting the application failed
* @throws IllegalStateException
* if the application descriptor is unregistered
+ * @throws IllegalArgumentException
+ * if the specified <code>Map</code> contains invalid keys
+ * (null objects, empty <code>String</code> or a key that is not
+ * <code>String</code>)
*/
public final ApplicationHandle launch(Map arguments)
- throws Exception {
+ throws ApplicationException {
SecurityManager sm = System.getSecurityManager();
if (sm!= null)
sm.checkPermission(new ApplicationAdminPermission(this, ApplicationAdminPermission.LIFECYCLE_ACTION));
synchronized (locked) {
if (locked[0])
- throw new Exception("Application is locked, can't launch!");
+ throw new ApplicationException(ApplicationException.APPLICATION_LOCKED, "Application is locked, can't launch!");
}
if( !isLaunchableSpecific() )
- throw new Exception("Cannot launch the application!");
- return launchSpecific(arguments);
+ throw new ApplicationException(ApplicationException.APPLICAITON_NOT_LAUNCHABLE,
+ "Cannot launch the application!");
+ checkArgs(arguments);
+ try {
+ return launchSpecific(arguments);
+ } catch(IllegalStateException ise) {
+ throw ise;
+ } catch(SecurityException se) {
+ throw se;
+ } catch( ApplicationException ae) {
+ throw ae;
+ } catch(Exception t) {
+ throw new ApplicationException(ApplicationException.APPLICATION_INTERNAL_ERROR, t);
+ }
}
/**
@@ -333,6 +349,10 @@ public abstract class ApplicationDescriptor {
* should be stored in a persistent storage. The method registers a
* {@link ScheduledApplication} service in Service Registry, representing
* the created scheduling.
+ * <p>
+ * The <code>Map</code> argument of the method contains startup
+ * arguments for the application. The keys used in the Map must be non-null,
+ * non-empty <code>String<code> objects.
*
* @param arguments
* the startup arguments for the scheduled application, may be
@@ -354,10 +374,6 @@ public abstract class ApplicationDescriptor {
*
* @throws NullPointerException
* if the topic is <code>null</code>
- * @throws IOException
- * may be thrown if writing the information about the scheduled
- * application requires operation on the permanent storage and
- * I/O problem occurred.
* @throws InvalidSyntaxException
* if the specified <code>eventFilter</code> is not syntactically correct
* @throws SecurityException
@@ -365,9 +381,14 @@ public abstract class ApplicationDescriptor {
* ApplicationAdminPermission for the application.
* @throws IllegalStateException
* if the application descriptor is unregistered
+ * @throws IllegalArgumentException
+ * if the specified <code>Map</code> contains invalid keys
+ * (null objects, empty <code>String</code> or a key that is not
+ * <code>String</code>)
*/
public final ScheduledApplication schedule(Map arguments, String topic,
- String eventFilter, boolean recurring) throws IOException, InvalidSyntaxException {
+ String eventFilter, boolean recurring) throws InvalidSyntaxException {
+ checkArgs(arguments);
isLaunchableSpecific(); // checks if the ApplicationDescriptor was already unregistered
return AppManager.addScheduledApp(this, arguments, topic, eventFilter, recurring);
}
@@ -452,7 +473,7 @@ public abstract class ApplicationDescriptor {
ScheduledApplication schedule(Map args, String topic, String filter,
boolean recurs) throws InvalidSyntaxException;
- void launch(Map arguments) throws Exception;
+ void launch(Map arguments) throws ApplicationException;
}
private void saveLock(boolean locked) {
@@ -463,6 +484,18 @@ public abstract class ApplicationDescriptor {
return AppManager.isLocked(this);
}
+ private void checkArgs(Map arguments) {
+ if (arguments == null)
+ return;
+ for (Iterator keys = arguments.keySet().iterator(); keys.hasNext();) {
+ Object key = keys.next();
+ if (!(key instanceof String))
+ throw new IllegalArgumentException("Invalid key type: " + key == null ? "<null>" : key.getClass().getName());
+ if ("".equals(key))
+ throw new IllegalArgumentException("Empty string is an invalid key");
+ }
+ }
+
String pid;
private boolean[] locked = {false};
}
diff --git a/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationException.java b/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationException.java
new file mode 100755
index 000000000..46e1f7fa6
--- /dev/null
+++ b/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationException.java
@@ -0,0 +1,105 @@
+package org.osgi.service.application;
+
+/**
+ * This exception is used to indicate problems related to application
+ * lifecycle management
+ *
+ * <p>
+ * <code>ApplicationException</code> object is created by the Application Admin to denote
+ * an exception condition in the lifecycle of an application.
+ * <code>ApplicationException</code>s should not be created by developers.
+ * <p>
+ * <code>ApplicationException</code>s are associated with an error code. This code
+ * describes the type of problem reported in this exception. The possible codes are:
+ * <ul>
+ * <li> {@link #APPLICATION_LOCKED} - The application couldn't be launched because it is locked.
+ * <li> {@link #APPLICAITON_NOT_LAUNCHABLE} - The application is not in launchable state.
+ * <li> {@link #APPLICATION_INTERNAL_ERROR} - An exception was thrown by the application or its
+ * container during launch.
+ * </ul>
+ *
+ */
+public class ApplicationException extends Exception {
+ private static final long serialVersionUID = -7173190453622508207L;
+ private final Throwable cause;
+ private final int errorCode;
+
+ /**
+ * The application couldn't be launched because it is locked.
+ */
+ public static final int APPLICATION_LOCKED = 0x01;
+
+ /**
+ * The application is not in launchable state, it's
+ * {@link ApplicationDescriptor#APPLICATION_LAUNCHABLE}
+ * attribute is false.
+ */
+ public static final int APPLICAITON_NOT_LAUNCHABLE = 0x02;
+
+ /**
+ * An exception was thrown by the application or the corresponding
+ * container during launch. The exception is available in {@link #getCause()}.
+ */
+ public static final int APPLICATION_INTERNAL_ERROR = 0x03;
+
+ /**
+ * Creates an <code>ApplicationException</code> with the specified error code.
+ * @param errorCode The code of the error
+ */
+ public ApplicationException(int errorCode) {
+ this(errorCode,(Throwable) null);
+ }
+
+ /**
+ * Creates a <code>ApplicationException</code> that wraps another exception.
+ *
+ * @param errorCode The code of the error
+ * @param cause The cause of this exception.
+ */
+ public ApplicationException(int errorCode, Throwable cause) {
+ super();
+ this.cause = cause;
+ this.errorCode = errorCode;
+ }
+
+ /**
+ * Creates an <code>ApplicationException</code> with the specified error code.
+ * @param errorCode The code of the error
+ * @param message The associated message
+ */
+ public ApplicationException(int errorCode, String message) {
+ this(errorCode, message,null);
+ }
+
+ /**
+ * Creates a <code>ApplicationException</code> that wraps another exception.
+ *
+ * @param errorCode The code of the error
+ * @param message The associated message.
+ * @param cause The cause of this exception.
+ */
+ public ApplicationException(int errorCode, String message, Throwable cause) {
+ super(message);
+ this.cause = cause;
+ this.errorCode = errorCode;
+ }
+
+ /**
+ * 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.
+ */
+ public Throwable getCause() {
+ return cause;
+ }
+
+ /**
+ * Returns the error code associcated with this exception.
+ * @return The error code of this exception.
+ */
+ public int getErrorCode() {
+ return errorCode;
+ }
+}
diff --git a/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationHandle.java b/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationHandle.java
index aaee13807..502a2e6c9 100755
--- a/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationHandle.java
+++ b/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationHandle.java
@@ -1,5 +1,5 @@
/*
- * $Header: /cvsroot/eclipse/equinox-incubator/runtime-split/org.eclipse.equinox.appcontainer/src/org/osgi/service/application/ApplicationHandle.java,v 1.2 2005/11/29 19:48:02 twatson Exp $
+ * $Header: /cvsroot/eclipse/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationHandle.java,v 1.1 2005/12/14 22:17:04 twatson Exp $
*
* Copyright (c) OSGi Alliance (2004, 2005). All Rights Reserved.
*
@@ -140,13 +140,10 @@ public abstract class ApplicationHandle {
* if the caller doesn't have "lifecycle"
* <code>ApplicationAdminPermission</code> for the corresponding application.
*
- * @throws Exception
- * is thrown if an exception or an error occurred during the
- * method execution.
* @throws IllegalStateException
* if the application handle is unregistered
*/
- public final void destroy() throws Exception {
+ public final void destroy() {
if (STOPPING.equals(getState()))
return;
SecurityManager sm = System.getSecurityManager();
@@ -161,11 +158,8 @@ public abstract class ApplicationHandle {
*
* @throws IllegalStateException
* if the application handle is unregistered
- * @throws Exception
- * is thrown if an exception or an error occurred during the
- * method execution.
*/
- protected abstract void destroySpecific() throws Exception;
+ protected abstract void destroySpecific();
ApplicationDescriptor descriptor;
@@ -175,6 +169,6 @@ public abstract class ApplicationHandle {
*/
public interface Delegate {
void setApplicationHandle(ApplicationHandle d, ApplicationDescriptor.Delegate descriptor );
- void destroy() throws Exception;
+ void destroy();
}
}

Back to the top