diff options
Diffstat (limited to 'bundles/org.eclipse.equinox.app/src/org/osgi/service')
5 files changed, 0 insertions, 1425 deletions
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 deleted file mode 100755 index 561514806..000000000 --- a/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationAdminPermission.java +++ /dev/null @@ -1,407 +0,0 @@ -/* - * $Header: /cvshome/build/org.osgi.service.application/src/org/osgi/service/application/ApplicationAdminPermission.java,v 1.34 2006/07/12 21:22:11 hargrave Exp $ - * - * Copyright (c) OSGi Alliance (2004, 2006). 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.service.application; - -import java.security.Permission; -import java.util.*; - -import org.osgi.framework.*; - -/** - * This class implements permissions for manipulating applications and - * their instances. - * <P> - * ApplicationAdminPermission can be targeted to applications that matches the - * specified filter. - * <P> - * ApplicationAdminPermission may be granted for different actions: - * <code>lifecycle</code>, <code>schedule</code> and <code>lock</code>. - * The permission <code>schedule</code> implies the permission - * <code>lifecycle</code>. - */ -public class ApplicationAdminPermission extends Permission { - private static final long serialVersionUID = 1L; - - /** - * Allows the lifecycle management of the target applications. - */ - public static final String LIFECYCLE_ACTION = "lifecycle"; - - /** - * Allows scheduling of the target applications. The permission to - * schedule an application implies that the scheduler can also - * manage the lifecycle of that application i.e. <code>schedule</code> - * implies <code>lifecycle</code> - */ - public static final String SCHEDULE_ACTION = "schedule"; - - /** - * Allows setting/unsetting the locking state of the target applications. - */ - public static final String LOCK_ACTION = "lock"; - - private ApplicationDescriptor applicationDescriptor; - - /** - * Constructs an ApplicationAdminPermission. The <code>filter</code> - * specifies the target application. The <code>filter</code> is an - * LDAP-style filter, the recognized properties are <code>signer</code> - * and <code>pid</code>. The pattern specified in the <code>signer</code> - * is matched with the Distinguished Name chain used to sign the application. - * Wildcards in a DN are not matched according to the filter string rules, - * but according to the rules defined for a DN chain. The attribute - * <code>pid</code> is matched with the PID of the application according to - * the filter string rules. - * <p> - * If the <code>filter</code> is <code>null</code> then it matches - * <code>"*"</code>. If - * <code>actions</code> is <code>"*"</code> then it identifies all the - * possible actions. - * - * @param filter - * filter to identify application. The value <code>null</code> - * is equivalent to <code>"*"</code> and it indicates "all application". - * @param actions - * comma-separated list of the desired actions granted on the - * applications or "*" means all the actions. It must not be - * <code>null</code>. The order of the actions in the list is - * not significant. - * @throws InvalidSyntaxException - * is thrown if the specified <code>filter</code> is not syntactically - * correct. - * - * @exception NullPointerException - * is thrown if the actions parameter is <code>null</code> - * - * @see ApplicationDescriptor - * @see org.osgi.framework.AdminPermission - */ - public ApplicationAdminPermission(String filter, String actions) throws InvalidSyntaxException { - super(filter == null ? "*" : filter); - - if( filter == null ) - filter = "*"; - - if( actions == null ) - throw new NullPointerException( "Action string cannot be null!" ); - - this.applicationDescriptor = null; - this.filter = (filter == null ? "*" : filter); - this.actions = actions; - - if( !filter.equals( "*" ) && !filter.equals( "<<SELF>>" ) ) - FrameworkUtil.createFilter( this.filter ); // check if the filter is valid - init(); - } - - /** - * This contructor should be used when creating <code>ApplicationAdminPermission</code> - * instance for <code>checkPermission</code> call. - * @param application the tareget of the operation, it must not be <code>null</code> - * @param actions the required operation. it must not be <code>null</code> - * @throws NullPointerException if any of the arguments is null. - */ - public ApplicationAdminPermission(ApplicationDescriptor application, String actions) { - super(application.getApplicationId()); - - if( application == null || actions == null ) - throw new NullPointerException( "ApplicationDescriptor and action string cannot be null!" ); - - this.filter = application.getApplicationId(); - this.applicationDescriptor = application; - this.actions = actions; - - init(); - } - - /** - * This method can be used in the {@link java.security.ProtectionDomain} - * implementation in the <code>implies</code> method to insert the - * application ID of the current application into the permission being - * checked. This enables the evaluation of the - * <code><<SELF>></code> pseudo targets. - * @param applicationId the ID of the current application. - * @return the permission updated with the ID of the current application - */ - public ApplicationAdminPermission setCurrentApplicationId(String applicationId) { - 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; - - return newPerm; - } - - /** - * Checks if the specified <code>permission</code> is implied by this permission. - * The method returns true under the following conditions: - * <UL> - * <LI> This permission was created by specifying a filter (see {@link #ApplicationAdminPermission(String, String)}) - * <LI> The implied <code>otherPermission</code> was created for a particular {@link ApplicationDescriptor} - * (see {@link #ApplicationAdminPermission(ApplicationDescriptor, String)}) - * <LI> The <code>filter</code> of this permission mathes the <code>ApplicationDescriptor</code> specified - * in the <code>otherPermission</code>. If the filter in this permission is the - * <code><<SELF>></code> pseudo target, then the currentApplicationId set in the - * <code>otherPermission</code> is compared to the application Id of the target - * <code>ApplicationDescriptor</code>. - * <LI> The list of permitted actions in this permission contains all actions required in the - * <code>otherPermission</code> - * </UL> - * Otherwise the method returns false. - * @param otherPermission the implied permission - * @return true if this permission implies the <code>otherPermission</code>, false otherwise. - */ - public boolean implies(Permission otherPermission) { - if( otherPermission == null ) - return false; - - if(!(otherPermission instanceof ApplicationAdminPermission)) - return false; - - 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 */ - - if( !other.applicationID.equals( other.applicationDescriptor.getApplicationId() ) ) - return false; - } - else { - Hashtable props = new Hashtable(); - props.put( "pid", other.applicationDescriptor.getApplicationId() ); - props.put( "signer", new SignerWrapper( other.applicationDescriptor ) ); - - Filter flt = getFilter(); - if( flt == null ) - return false; - - if( !flt.match( props ) ) - return false; - } - } - - if( !actionsVector.containsAll( other.actionsVector ) ) - return false; - - return true; - } - - public boolean equals(Object with) { - if( with == null || !(with instanceof ApplicationAdminPermission) ) - return false; - - ApplicationAdminPermission other = (ApplicationAdminPermission)with; - - // Compare actions: - if( other.actionsVector.size() != actionsVector.size() ) - return false; - - for( int i=0; i != actionsVector.size(); i++ ) - if( !other.actionsVector.contains( actionsVector.get( i ) ) ) - return false; - - - return equal(this.filter, other.filter ) && equal(this.applicationDescriptor, other.applicationDescriptor) - && equal(this.applicationID, other.applicationID); - } - - /** - * Compares parameters for equality. If both object are null, they are considered - * equal. - * @param a object to compare - * @param b other object to compare - * @return true if both objects are equal or both are null - */ - private static boolean equal(Object a, Object b) { - // This equation is true if both references are null or both point - // to the same object. In both cases they are considered as equal. - if( a == b ) { - return true; - } - - return a.equals(b); - } - - public int hashCode() { - int hc = 0; - for( int i=0; i != actionsVector.size(); i++ ) - hc ^= ((String)actionsVector.get( i )).hashCode(); - hc ^= (null == this.filter )? 0 : this.filter.hashCode(); - hc ^= (null == this.applicationDescriptor) ? 0 : this.applicationDescriptor.hashCode(); - hc ^= (null == this.applicationID) ? 0 : this.applicationID.hashCode(); - return hc; - } - - /** - * Returns the actions of this permission. - * @return the actions specified when this permission was created - */ - public String getActions() { - return actions; - } - - private String applicationID; - - private static final Vector ACTIONS = new Vector(); - private Vector actionsVector; - private final String filter; - private final String actions; - private Filter appliedFilter = null; - - static { - ACTIONS.add(LIFECYCLE_ACTION); - ACTIONS.add(SCHEDULE_ACTION); - ACTIONS.add(LOCK_ACTION); - } - - private static Vector actionsVector(String actions) { - Vector v = new Vector(); - StringTokenizer t = new StringTokenizer(actions.toUpperCase(), ","); - while (t.hasMoreTokens()) { - String action = t.nextToken().trim(); - v.add(action.toLowerCase()); - } - - if( v.contains( SCHEDULE_ACTION ) && !v.contains( LIFECYCLE_ACTION ) ) - v.add( LIFECYCLE_ACTION ); - - return v; - } - - - private static class SignerWrapper extends Object { - private String pattern; - private ApplicationDescriptor appDesc; - - public SignerWrapper(String pattern) { - this.pattern = pattern; - } - - SignerWrapper(ApplicationDescriptor appDesc) { - this.appDesc = appDesc; - } - - public boolean equals(Object o) { - if (!(o instanceof SignerWrapper)) - return false; - SignerWrapper other = (SignerWrapper) o; - ApplicationDescriptor matchAppDesc = (ApplicationDescriptor) (appDesc != null ? appDesc : other.appDesc); - String matchPattern = appDesc != null ? other.pattern : pattern; - return matchAppDesc.matchDNChain(matchPattern); - } - } - - private void init() { - actionsVector = actionsVector( actions ); - - if ( actions.equals("*") ) - actionsVector = actionsVector( LIFECYCLE_ACTION + "," + SCHEDULE_ACTION + "," + LOCK_ACTION ); - else if (!ACTIONS.containsAll(actionsVector)) - throw new IllegalArgumentException("Illegal action!"); - - applicationID = null; - } - - private Filter getFilter() { - String transformedFilter = filter; - - if (appliedFilter == null) { - try { - int pos = filter.indexOf("signer"); //$NON-NLS-1$ - if (pos != -1){ - - //there may be a signer attribute - StringBuffer filterBuf = new StringBuffer(filter); - int numAsteriskFound = 0; //use as offset to replace in buffer - - int walkbackPos; //temp pos - - //find occurences of (signer= and escape out *'s - while (pos != -1) { - - //walk back and look for '(' to see if this is an attr - walkbackPos = pos-1; - - //consume whitespace - while(walkbackPos >= 0 && Character.isWhitespace(filter.charAt(walkbackPos))) { - walkbackPos--; - } - if (walkbackPos <0) { - //filter is invalid - FilterImpl will throw error - break; - } - - //check to see if we have unescaped '(' - if (filter.charAt(walkbackPos) != '(' || (walkbackPos > 0 && filter.charAt(walkbackPos-1) == '\\')) { - //'(' was escaped or not there - pos = filter.indexOf("signer",pos+6); //$NON-NLS-1$ - continue; - } - pos+=6; //skip over 'signer' - - //found signer - consume whitespace before '=' - while (Character.isWhitespace(filter.charAt(pos))) { - pos++; - } - - //look for '=' - if (filter.charAt(pos) != '=') { - //attr was signerx - keep looking - pos = filter.indexOf("signer",pos); //$NON-NLS-1$ - continue; - } - pos++; //skip over '=' - - //found signer value - escape '*'s - while (!(filter.charAt(pos) == ')' && filter.charAt(pos-1) != '\\')) { - if (filter.charAt(pos) == '*') { - filterBuf.insert(pos+numAsteriskFound,'\\'); - numAsteriskFound++; - } - pos++; - } - - //end of signer value - look for more? - pos = filter.indexOf("signer",pos); //$NON-NLS-1$ - } //end while (pos != -1) - transformedFilter = filterBuf.toString(); - } //end if (pos != -1) - - appliedFilter = FrameworkUtil.createFilter( transformedFilter ); - } catch (InvalidSyntaxException e) { - //we will return null - } - } - return appliedFilter; - } -} 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 deleted file mode 100755 index 1c41ecbbb..000000000 --- a/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationDescriptor.java +++ /dev/null @@ -1,525 +0,0 @@ -/* - * $Header: /cvshome/build/org.osgi.service.application/src/org/osgi/service/application/ApplicationDescriptor.java,v 1.61 2006/07/10 12:02:31 hargrave Exp $ - * - * Copyright (c) OSGi Alliance (2004, 2006). 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.service.application; - -import java.util.Iterator; -import java.util.Map; -import org.eclipse.equinox.internal.app.AppPersistence; -import org.osgi.framework.Constants; -import org.osgi.framework.InvalidSyntaxException; - -/** - * An OSGi service that represents an installed application and stores - * information about it. The application descriptor can be used for instance - * creation. - */ - -public abstract class ApplicationDescriptor { - /* - * NOTE: An implementor may also choose to replace this class in - * their distribution with a class that directly interfaces with the - * org.osgi.service.application implementation. This replacement class MUST NOT alter the - * public/protected signature of this class. - */ - - /** - * The property key for the localized name of the application. - */ - public static final String APPLICATION_NAME = "application.name"; - - /** - * The property key for the localized icon of the application. - */ - public static final String APPLICATION_ICON = "application.icon"; - - /** - * The property key for the unique identifier (PID) of the application. - */ - public static final String APPLICATION_PID = Constants.SERVICE_PID; - - /** - * The property key for the version of the application. - */ - public static final String APPLICATION_VERSION = "application.version"; - - /** - * The property key for the name of the application vendor. - */ - public static final String APPLICATION_VENDOR = Constants.SERVICE_VENDOR; - - - /** - * The property key for the visibility property of the application. - */ - public static final String APPLICATION_VISIBLE = "application.visible"; - - /** - * The property key for the launchable property of the application. - */ - public static final String APPLICATION_LAUNCHABLE = "application.launchable"; - - /** - * The property key for the locked property of the application. - */ - public static final String APPLICATION_LOCKED = "application.locked"; - - /** - * The property key for the localized description of the application. - */ - public static final String APPLICATION_DESCRIPTION = "application.description"; - - /** - * The property key for the localized documentation of the application. - */ - public static final String APPLICATION_DOCUMENTATION = "application.documentation"; - - /** - * The property key for the localized copyright notice of the application. - */ - public static final String APPLICATION_COPYRIGHT = "application.copyright"; - - /** - * The property key for the localized license of the application. - */ - public static final String APPLICATION_LICENSE = "application.license"; - - /** - * The property key for the application container of the application. - */ - public static final String APPLICATION_CONTAINER = "application.container"; - - /** - * The property key for the location of the application. - */ - public static final String APPLICATION_LOCATION = "application.location"; - - - private final String pid; - - private boolean[] locked = {false}; - - /** - * Constructs the <code>ApplicationDescriptor</code>. - * - * @param applicationId - * The identifier of the application. Its value is also available - * as the <code>service.pid</code> service property of this - * <code>ApplicationDescriptor</code> service. This parameter must not - * be <code>null</code>. - * @throws NullPointerException if the specified <code>applicationId</code> is null. - */ - protected ApplicationDescriptor(String applicationId) { - if(null == applicationId ) { - throw new NullPointerException("Application ID must not be null!"); - } - - this.pid = applicationId; - locked[0] = isLocked(); - } - - /** - * Returns the identifier of the represented application. - * - * @return the identifier of the represented application - */ - public final String getApplicationId() { - return pid; - } - - /** - * This method verifies whether the specified <code>pattern</code> - * matches the Distinguished Names of any of the certificate chains - * used to authenticate this application. - * <P> - * The <code>pattern</code> must adhere to the - * syntax defined in {@link org.osgi.service.application.ApplicationAdminPermission} - * for signer attributes. - * <p> - * This method is used by {@link ApplicationAdminPermission#implies(java.security.Permission)} method - * to match target <code>ApplicationDescriptor</code> and filter. - * - * @param pattern a pattern for a chain of Distinguished Names. It must not be null. - * @return <code>true</code> if the specified pattern matches at least - * one of the certificate chains used to authenticate this application - * @throws NullPointerException if the specified <code>pattern</code> is null. - * @throws IllegalStateException if the application descriptor was - * unregistered - */ - public abstract boolean matchDNChain( String pattern ); - - /** - * Returns the properties of the application descriptor as key-value pairs. - * The return value contains the locale aware and unaware properties as - * well. The returned <code>Map</code> will include the service - * properties of this <code>ApplicationDescriptor</code> as well. - * <p> - * This method will call the <code>getPropertiesSpecific</code> method - * to enable the container implementation to insert application model and/or - * container implementation specific properties. - * <P> - * The returned {@link java.util.Map} will contain the standard OSGi service - * properties as well - * (e.g. service.id, service.vendor etc.) and specialized application - * descriptors may offer further service properties. The returned Map contains - * a snapshot of the properties. It will not reflect further changes in the - * property values nor will the update of the Map change the corresponding - * service property. - * - * @param locale - * the locale string, it may be null, the value null means the - * default locale. If the provided locale is the empty String - * (<code>""</code>)then raw (non-localized) values are returned. - * - * @return copy of the service properties of this application descriptor service, - * according to the specified locale. If locale is null then the - * default locale's properties will be returned. (Since service - * properties are always exist it cannot return null.) - * - * @throws IllegalStateException - * if the application descriptor is unregistered - */ - public final Map getProperties(String locale) { - Map props = getPropertiesSpecific( locale ); - Boolean containerLocked = (Boolean) props.remove( APPLICATION_LOCKED ); - synchronized (locked) { - if (containerLocked != null && containerLocked.booleanValue() != locked[0]) { - if (locked[0]) - lockSpecific(); - else - unlockSpecific(); - } - } - props.put( APPLICATION_LOCKED, new Boolean( locked[0] ) ); - return props; - } - - /** - * Container implementations can provide application model specific - * and/or container implementation specific properties via this - * method. - * - * Localizable properties must be returned localized if the provided - * <code>locale</code> argument is not the empty String. The value - * <code>null</code> indicates to use the default locale, for other - * values the specified locale should be used. - * - * The returned {@link java.util.Map} must contain the standard OSGi service - * properties as well - * (e.g. service.id, service.vendor etc.) and specialized application - * descriptors may offer further service properties. - * The returned <code>Map</code> - * contains a snapshot of the properties. It will not reflect further changes in the - * property values nor will the update of the Map change the corresponding - * service property. - - * @param locale the locale to be used for localizing the properties. - * If <code>null</code> the default locale should be used. If it is - * the empty String (<code>""</code>) then raw (non-localized) values - * should be returned. - * - * @return the application model specific and/or container implementation - * specific properties of this application descriptor. - * - * @throws IllegalStateException - * if the application descriptor is unregistered - */ - protected abstract Map getPropertiesSpecific(String locale); - - /** - * Launches a new instance of an application. The <code>args</code> parameter specifies - * the startup parameters for the instance to be launched, it may be null. - * <p> - * The following steps are made: - * <UL> - * <LI>Check for the appropriate permission. - * <LI>Check the locking state of the application. If locked then return - * null otherwise continue. - * <LI>Calls the <code>launchSpecific()</code> method to create and start an application - * instance. - * <LI>Returns the <code>ApplicationHandle</code> returned by the - * launchSpecific() - * </UL> - * The caller has to have ApplicationAdminPermission(applicationPID, - * "launch") in order to be able to perform this operation. - * <P> - * The <code>Map</code> argument of the launch method contains startup - * arguments for the - * 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 - * in the future it is possible that other well-known keys will be defined. - * To avoid unwanted clashes of keys, the following rules should be applied: - * <ul> - * <li>The keys starting with the dash (-) character are application - * specific, no well-known meaning should be associated with them.</li> - * <li>Well-known keys should follow the reverse domain name based naming. - * In particular, the keys standardized in OSGi should start with - * <code>org.osgi.</code>.</li> - * </ul> - * <P> - * The method is synchonous, it return only when the application instance was - * successfully started or the attempt to start it failed. - * <P> - * This method never returns <code>null</code>. If launching an application fails, - * the appropriate exception is thrown. - * - * @param arguments - * Arguments for the newly launched application, may be null - * - * @return the registered ApplicationHandle, which represents the newly - * launched application instance. Never returns <code>null</code>. - * - * @throws SecurityException - * if the caller doesn't have "lifecycle" - * ApplicationAdminPermission for the application. - * @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 ApplicationException { - SecurityManager sm = System.getSecurityManager(); - if (sm!= null) - sm.checkPermission(new ApplicationAdminPermission(this, ApplicationAdminPermission.LIFECYCLE_ACTION)); - synchronized (locked) { - if (locked[0]) - throw new ApplicationException(ApplicationException.APPLICATION_LOCKED, "Application is locked, can't launch!"); - } - if( !isLaunchableSpecific() ) - throw new ApplicationException(ApplicationException.APPLICATION_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); - } - } - - /** - * Called by launch() to create and start a new instance in an application - * model specific way. It also creates and registeres the application handle - * to represent the newly created and started instance and registeres it. - * The method is synchonous, it return only when the application instance was - * successfully started or the attempt to start it failed. - * <P> - * This method must not return <code>null</code>. If launching the application - * failed, and exception must be thrown. - * - * @param arguments - * the startup parameters of the new application instance, may be - * null - * - * @return the registered application model - * specific application handle for the newly created and started - * instance. - * - * @throws IllegalStateException - * if the application descriptor is unregistered - * @throws Exception - * if any problem occures. - */ - protected abstract ApplicationHandle launchSpecific(Map arguments) - throws Exception; - - /** - * This method is called by launch() to verify that according to the - * container, the application is launchable. - * - * @return true, if the application is launchable according to the - * container, false otherwise. - * - * @throws IllegalStateException - * if the application descriptor is unregistered - */ - protected abstract boolean isLaunchableSpecific(); - - /** - * Schedules the application at a specified event. Schedule information - * should not get lost even if the framework or the device restarts so it - * should be stored in a persistent storage. The method registers a - * {@link ScheduledApplication} service in Service Registry, representing - * the created schedule. - * <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. - * <p> - * The created schedules have a unique identifier within the scope of this - * <code>ApplicationDescriptor</code>. This identifier can be specified - * in the <code>scheduleId</code> argument. If this argument is <code>null</code>, - * the identifier is automatically generated. - * - * @param scheduleId - * the identifier of the created schedule. It can be <code>null</code>, - * in this case the identifier is automatically generated. - * @param arguments - * the startup arguments for the scheduled application, may be - * null - * @param topic - * specifies the topic of the triggering event, it may contain a - * trailing asterisk as wildcard, the empty string is treated as - * "*", must not be null - * @param eventFilter - * specifies and LDAP filter to filter on the properties of the - * triggering event, may be null - * @param recurring - * if the recurring parameter is false then the application will - * be launched only once, when the event firstly occurs. If the - * parameter is true then scheduling will take place for every - * event occurrence; i.e. it is a recurring schedule - * - * @return the registered scheduled application service - * - * @throws NullPointerException - * if the topic is <code>null</code> - * @throws InvalidSyntaxException - * if the specified <code>eventFilter</code> is not syntactically correct - * @throws ApplicationException - * if the schedule couldn't be created. The possible error - * codes are - * <ul> - * <li> {@link ApplicationException#APPLICATION_DUPLICATE_SCHEDULE_ID} - * if the specified <code>scheduleId</code> is already used - * for this <code>ApplicationDescriptor</code> - * <li> {@link ApplicationException#APPLICATION_SCHEDULING_FAILED} - * if the scheduling failed due to some internal reason - * (e.g. persistent storage error). - * </ul> - * @throws SecurityException - * if the caller doesn't have "schedule" - * 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(String scheduleId, Map arguments, String topic, - String eventFilter, boolean recurring) throws InvalidSyntaxException, - ApplicationException { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkPermission(new ApplicationAdminPermission(this, ApplicationAdminPermission.SCHEDULE_ACTION)); - checkArgs(arguments); - isLaunchableSpecific(); // checks if the ApplicationDescriptor was already unregistered - return AppPersistence.addScheduledApp(this, scheduleId, arguments, topic, eventFilter, recurring); - } - - /** - * Sets the lock state of the application. If an application is locked then - * launching a new instance is not possible. It does not affect the already - * launched instances. - * - * @throws SecurityException - * if the caller doesn't have "lock" ApplicationAdminPermission - * for the application. - * @throws IllegalStateException - * if the application descriptor is unregistered - */ - public final void lock() { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkPermission(new ApplicationAdminPermission(this, ApplicationAdminPermission.LOCK_ACTION)); - synchronized (locked) { - if (locked[0]) - return; - locked[0] = true; - lockSpecific(); - saveLock(true); - } - } - - /** - * This method is used to notify the container implementation that the - * corresponding application has been locked and it should update the - * <code>application.locked</code> service property accordingly. - * @throws IllegalStateException - * if the application descriptor is unregistered - */ - protected abstract void lockSpecific(); - - /** - * Unsets the lock state of the application. - * - * @throws SecurityException - * if the caller doesn't have "lock" ApplicationAdminPermission - * for the application. - * @throws IllegalStateException - * if the application descriptor is unregistered - */ - public final void unlock() { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkPermission(new ApplicationAdminPermission(this, ApplicationAdminPermission.LOCK_ACTION)); - synchronized (locked) { - if (!locked[0]) - return; - locked[0] = false; - unlockSpecific(); - saveLock(false); - } - } - - /** - * This method is used to notify the container implementation that the - * corresponding application has been unlocked and it should update the - * <code>application.locked</code> service property accordingly. - - * @throws IllegalStateException - * if the application descriptor is unregistered - */ - protected abstract void unlockSpecific(); - - private void saveLock(boolean locked) { - AppPersistence.saveLock(this, locked); - } - - private boolean isLocked() { - return AppPersistence.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)) //$NON-NLS-1$ - throw new IllegalArgumentException("Empty string is an invalid key"); - } - } - - -}
\ No newline at end of file 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 deleted file mode 100755 index c30e112b1..000000000 --- a/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationException.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * $Header: /cvshome/build/org.osgi.service.application/src/org/osgi/service/application/ApplicationException.java,v 1.10 2006/07/10 11:49:12 hargrave Exp $ - * - * Copyright (c) OSGi Alliance (2005, 2006). 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.service.application; - -/** - * This exception is used to indicate problems related to application - * lifecycle management. - * - * <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. - * <br/> - * <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> - * <li> {@link #APPLICATION_NOT_LAUNCHABLE} - The application is not in launchable state.</li> - * <li> {@link #APPLICATION_INTERNAL_ERROR} - An exception was thrown by the application or its - * container during launch.</li> - * <li> {@link #APPLICATION_SCHEDULING_FAILED} - The scheduling of an application - * failed. - * </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 APPLICATION_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; - - /** - * The application schedule could not be created due to some internal error - * (for example, the schedule information couldn't be saved). - */ - public static final int APPLICATION_SCHEDULING_FAILED = 0x04; - - /** - * The application scheduling failed because the specified identifier - * is already in use. - */ - public static final int APPLICATION_DUPLICATE_SCHEDULE_ID = 0x05; - - /** - * 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 deleted file mode 100755 index 110d8a7c0..000000000 --- a/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ApplicationHandle.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * $Header: /cvshome/build/org.osgi.service.application/src/org/osgi/service/application/ApplicationHandle.java,v 1.41 2006/07/10 12:02:31 hargrave Exp $ - * - * Copyright (c) OSGi Alliance (2004, 2006). 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.service.application; - -import org.osgi.framework.Constants; - -/** - * ApplicationHandle is an OSGi service interface which represents an instance - * of an application. It provides the functionality to query and manipulate the - * lifecycle state of the represented application instance. It defines constants - * for the lifecycle states. - */ -public abstract class ApplicationHandle { - /* - * NOTE: An implementor may also choose to replace this class in - * their distribution with a class that directly interfaces with the - * org.osgi.service.application implementation. This replacement class MUST NOT alter the - * public/protected signature of this class. - */ - - /** - * The property key for the unique identifier (PID) of the application - * instance. - */ - public static final String APPLICATION_PID = Constants.SERVICE_PID; - - /** - * The property key for the pid of the corresponding application descriptor. - */ - public final static String APPLICATION_DESCRIPTOR = "application.descriptor"; - - /** - * The property key for the state of this appliction instance. - */ - public final static String APPLICATION_STATE = "application.state"; - - /** - * The application instance is running. This is the initial state of a newly - * created application instance. - */ - public final static String RUNNING = "RUNNING"; - - /** - * The application instance is being stopped. This is the state of the - * application instance during the execution of the <code>destroy()</code> - * method. - */ - public final static String STOPPING = "STOPPING"; - - private final String instanceId; - - private final ApplicationDescriptor descriptor; - - /** - * Application instance identifier is specified by the container when the - * instance is created. The instance identifier must remain static for the - * lifetime of the instance, it must remain the same even across framework - * restarts for the same application instance. This value must be the same - * as the <code>service.pid</code> service property of this application - * handle. - * <p> - * The instance identifier should follow the following scheme: - * <<i>application descriptor PID</i>>.<<i>index</i>> - * where <<i>application descriptor PID</i>> is the PID of the - * corresponding <code>ApplicationDescriptor</code> and <<i>index</i>> - * is a unique integer index assigned by the application container. - * Even after destroying the application index the same index value should not - * be reused in a reasonably long timeframe. - * - * @param instanceId the instance identifier of the represented application - * instance. It must not be null. - * - * @param descriptor the <code>ApplicationDescriptor</code> of the represented - * application instance. It must not be null. - * - * @throws NullPointerException if any of the arguments is null. - */ - protected ApplicationHandle(String instanceId, ApplicationDescriptor descriptor ) { - if( (null == instanceId) || (null == descriptor) ) { - throw new NullPointerException("Parameters must not be null!"); - } - - this.instanceId = instanceId; - this.descriptor = descriptor; - } - - /** - * Retrieves the <code>ApplicationDescriptor</code> to which this - * <code>ApplicationHandle</code> belongs. - * - * @return The corresponding <code>ApplicationDescriptor</code> - */ - public final ApplicationDescriptor getApplicationDescriptor() { - return descriptor; - } - - /** - * Get the state of the application instance. - * - * @return the state of the application. - * - * @throws IllegalStateException - * if the application handle is unregistered - */ - public abstract String getState(); - - /** - * Returns the unique identifier of this instance. This value is also - * available as a service property of this application handle's service.pid. - * - * @return the unique identifier of the instance - */ - public final String getInstanceId() { - return instanceId; - } - - /** - * The application instance's lifecycle state can be influenced by this - * method. It lets the application instance perform operations to stop - * the application safely, e.g. saving its state to a permanent storage. - * <p> - * The method must check if the lifecycle transition is valid; a STOPPING - * application cannot be stopped. If it is invalid then the method must - * exit. Otherwise the lifecycle state of the application instance must be - * set to STOPPING. Then the destroySpecific() method must be called to - * perform any application model specific steps for safe stopping of the - * represented application instance. - * <p> - * At the end the <code>ApplicationHandle</code> must be unregistered. - * This method should free all the resources related to this - * <code>ApplicationHandle</code>. - * <p> - * When this method is completed the application instance has already made - * its operations for safe stopping, the ApplicationHandle has been - * unregistered and its related resources has been freed. Further calls on - * this application should not be made because they may have unexpected - * results. - * - * @throws SecurityException - * if the caller doesn't have "lifecycle" - * <code>ApplicationAdminPermission</code> for the corresponding application. - * - * @throws IllegalStateException - * if the application handle is unregistered - */ - public final void destroy() { - if (STOPPING.equals(getState())) - return; - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkPermission(new ApplicationAdminPermission(getApplicationDescriptor(), ApplicationAdminPermission.LIFECYCLE_ACTION)); - destroySpecific(); - } - - /** - * Called by the destroy() method to perform application model specific - * steps to stop and destroy an application instance safely. - * - * @throws IllegalStateException - * if the application handle is unregistered - */ - protected abstract void destroySpecific(); - - -} diff --git a/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ScheduledApplication.java b/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ScheduledApplication.java deleted file mode 100755 index 46cfe5e66..000000000 --- a/bundles/org.eclipse.equinox.app/src/org/osgi/service/application/ScheduledApplication.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * $Header: /cvshome/build/org.osgi.service.application/src/org/osgi/service/application/ScheduledApplication.java,v 1.20 2006/07/06 14:59:29 sboshev Exp $ - * - * Copyright (c) OSGi Alliance (2004, 2006). 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.service.application; - -import java.util.Map; - -/** - * It is allowed to schedule an application based on a specific event. - * ScheduledApplication service keeps the schedule information. When the - * specified event is fired a new instance must be launched. Note that launching - * operation may fail because e.g. the application is locked. - * <p> - * Each <code>ScheduledApplication</code> instance has an identifier which is - * unique within the scope of the application being scheduled. - * <p> - * <code>ScheduledApplication</code> instances are registered as services. - * The {@link #APPLICATION_PID} service property contains the PID of the - * application being scheduled, the {@link #SCHEDULE_ID} service property - * contains the schedule identifier. - */ -public interface ScheduledApplication { - - /** - * The property key for the identifier of the application being scheduled. - */ - public static final String APPLICATION_PID = ApplicationDescriptor.APPLICATION_PID; - - /** - * The property key for the schedule identifier. The identifier is unique - * within the scope of the application being scheduled. - */ - public static final String SCHEDULE_ID = "schedule.id"; - - /** - * The key for the startup argument used to pass the event object that - * triggered the schedule to launch the application instance. - * The event is passed in a {@link java.security.GuardedObject} - * protected by the corresponding - * {@link org.osgi.service.event.TopicPermission}. - */ - public static final String TRIGGERING_EVENT = "org.osgi.triggeringevent"; - - /** - * The topic name for the virtual timer topic. Time based schedules - * should be created using this topic. - */ - public static final String TIMER_TOPIC = "org/osgi/application/timer"; - - /** - * The name of the <i>year</i> attribute of a virtual timer event. The value is - * defined by {@link java.util.Calendar#YEAR}. - */ - public static final String YEAR = "year"; - - /** - * The name of the <i>month</i> attribute of a virtual timer event. The value is - * defined by {@link java.util.Calendar#MONTH}. - */ - public static final String MONTH = "month"; - - /** - * The name of the <i>day of month</i> attribute of a virtual timer event. The value is - * defined by {@link java.util.Calendar#DAY_OF_MONTH}. - */ - public static final String DAY_OF_MONTH = "day_of_month"; - - /** - * The name of the <i>day of week</i> attribute of a virtual timer event. The value is - * defined by {@link java.util.Calendar#DAY_OF_WEEK}. - */ - public static final String DAY_OF_WEEK = "day_of_week"; - - /** - * The name of the <i>hour of day</i> attribute of a virtual timer event. The value is - * defined by {@link java.util.Calendar#HOUR_OF_DAY}. - */ - public static final String HOUR_OF_DAY = "hour_of_day"; - - /** - * The name of the <i>minute</i> attribute of a virtual timer event. The value is - * defined by {@link java.util.Calendar#MINUTE}. - */ - public static final String MINUTE = "minute"; - - - /** - * Returns the identifier of this schedule. The identifier is unique within - * the scope of the application that the schedule is related to. - * @return the identifier of this schedule - * - */ - public String getScheduleId(); - - /** - * Queries the topic of the triggering event. The topic may contain a - * trailing asterisk as wildcard. - * - * @return the topic of the triggering event - * - * @throws IllegalStateException - * if the scheduled application service is unregistered - */ - public String getTopic(); - - /** - * Queries the event filter for the triggering event. - * - * @return the event filter for triggering event - * - * @throws IllegalStateException - * if the scheduled application service is unregistered - */ - public String getEventFilter(); - - /** - * Queries if the schedule is recurring. - * - * @return true if the schedule is recurring, otherwise returns false - * - * @throws IllegalStateException - * if the scheduled application service is unregistered - */ - public boolean isRecurring(); - - /** - * Retrieves the ApplicationDescriptor which represents the application and - * necessary for launching. - * - * @return the application descriptor that - * represents the scheduled application - * - * @throws IllegalStateException - * if the scheduled application service is unregistered - */ - public ApplicationDescriptor getApplicationDescriptor(); - - /** - * Queries the startup arguments specified when the application was - * scheduled. The method returns a copy of the arguments, it is not possible - * to modify the arguments after scheduling. - * - * @return the startup arguments of the scheduled application. It may be - * null if null argument was specified. - * - * @throws IllegalStateException - * if the scheduled application service is unregistered - */ - public Map getArguments(); - - /** - * Cancels this schedule of the application. - * - * @throws SecurityException - * if the caller doesn't have "schedule" - * ApplicationAdminPermission for the scheduled application. - * @throws IllegalStateException - * if the scheduled application service is unregistered - */ - public void remove(); -} |