Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright (c) OSGi Alliance (2004, 2010). 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
  * 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 class implements permissions for manipulating applications and their instances.

ApplicationAdminPermission can be targeted to applications that matches the specified filter.

ApplicationAdminPermission may be granted for different actions: lifecycle, schedule and lock. The permission schedule implies the permission lifecycle.

$Id: 8c7941578972d6f61ed9aeffac374a0b8c294056 $
 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. schedule implies lifecycle
 	public static final String SCHEDULE_ACTION = "schedule";

Allows setting/unsetting the locking state of the target applications.
 	public static final String LOCK_ACTION = "lock";
Constructs an ApplicationAdminPermission. The filter specifies the target application. The filter is an LDAP-style filter, the recognized properties are signer and pid. The pattern specified in the signer 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 pid is matched with the PID of the application according to the filter string rules.

If the filter is null then it matches "*". If actions is "*" then it identifies all the possible actions.

filter filter to identify application. The value null is equivalent to "*" and it indicates "all application".
actions comma-separated list of the desired actions granted on the applications or "*" means all the actions. It must not be null. The order of the actions in the list is not significant.
org.osgi.framework.InvalidSyntaxException is thrown if the specified filter is not syntactically correct.
java.lang.NullPointerException is thrown if the actions parameter is null
See also:
 	public ApplicationAdminPermission(String filterString actionsthrows InvalidSyntaxException {
		super(filter == null ? "*" : filter);
		iffilter == null )
			filter = "*";
		ifactions == null )
			throw new NullPointerException"Action string cannot be null!" );
		this. = null;
		this. = (filter == null ? "*" : filter);
		this. = actions;
		if( !filter.equals"*" ) && !filter.equals"<<SELF>>" ) )
			FrameworkUtil.createFilterthis. ); // check if the filter is valid

This contructor should be used when creating ApplicationAdminPermission instance for checkPermission call.

application the tareget of the operation, it must not be null
actions the required operation. it must not be null
java.lang.NullPointerException if any of the arguments is null.
	public ApplicationAdminPermission(ApplicationDescriptor applicationString actions) {
		ifapplication == null || actions == null )
			throw new NullPointerException"ApplicationDescriptor and action string cannot be null!" );
		this. = application.getApplicationId();
		this. = application;
		this. = actions;

This method can be used in the implementation in the implies method to insert the application ID of the current application into the permission being checked. This enables the evaluation of the &lt;&lt;SELF&gt;&gt; pseudo targets.

applicationId the ID of the current application.
the permission updated with the ID of the current application
		ApplicationAdminPermission newPerm = null;
		ifthis. == null ) {
			try {
				newPerm = new ApplicationAdminPermissionthis.this. );
			}catchInvalidSyntaxException e ) {
				throw new RuntimeException(e); /* this can never happen */
		    newPerm = new ApplicationAdminPermissionthis.this. );
		newPerm.applicationID = applicationId;
		return newPerm;

Checks if the specified permission is implied by this permission. The method returns true under the following conditions: Otherwise the method returns false.

otherPermission the implied permission
true if this permission implies the otherPermission, false otherwise.
  public boolean implies(Permission otherPermission) {
  	  ifotherPermission == null )
  	  	return false;
      if(!(otherPermission instanceof ApplicationAdminPermission))
          return false;
      ApplicationAdminPermission other = (ApplicationAdminPermissionotherPermission;
      if( !.equals("*") ) {
       	ifother.applicationDescriptor == null )
       		return false;
      	if.equals"<<SELF>>") ) {
            ifother.applicationID == null )
          		return false/* it cannot be, this might be a bug */
      		if( !other.applicationID.equalsother.applicationDescriptor.getApplicationId() ) )
      			return false;
      	else {
      		Hashtable props = new Hashtable();
      		props.put"pid"other.applicationDescriptor.getApplicationId() );
      		props.put"signer"new SignerWrapperother.applicationDescriptor ) );
      		Filter flt = getFilter();
      		ifflt == null )
      			return false;
      		if( !flt.matchprops ) )
      			return false;
      if( !.containsAllother.actionsVector ) )
      	return false;
      return true;
  public boolean equals(Object with) {
  	ifwith == null || !(with instanceof ApplicationAdminPermission) )
  		return false;
  	// Compare actions:
  	ifother.actionsVector.size() != .size() )
  		return false;
  	forint i=0; i != .size(); i++ )
  		if( !other.actionsVector.contains.geti ) ) )
  			return false;
  	return equal(this.other.filter ) && equal(this.other.applicationDescriptor)
  			&& equal(this.other.applicationID);
Compares parameters for equality. If both object are null, they are considered equal.

a object to compare
b other object to compare
true if both objects are equal or both are null
  private static boolean equal(Object aObject 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.
	  ifa == b ) {
		  return true;
	  return a.equals(b);
  public int hashCode() {
	  int hc = 0;
	  forint i=0; i != .size(); i++ )
		  hc ^= ((String).geti )).hashCode();
	  hc ^= (null == this. )? 0 : this..hashCode();
	  hc ^= (null == this.) ? 0 : this..hashCode();
	  hc ^= (null == this.) ? 0 : this..hashCode();
	  return hc;

Returns the actions of this permission.

the actions specified when this permission was created
  public String getActions() {
  	return ;
  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 {
  private static Vector actionsVector(String actions) {
      Vector v = new Vector();
      StringTokenizer t = new StringTokenizer(actions.toUpperCase(), ",");
      while (t.hasMoreTokens()) {
          String action = t.nextToken().trim();
      ifv.contains ) && !v.contains ) )
    	  v.add );
      return v;
  private static class SignerWrapper extends Object {
  	private String pattern;
  	private ApplicationDescriptor appDesc;

  	public SignerWrapper(String pattern) {
  		this. = pattern;    			
  		this. = appDesc;
  	public boolean equals(Object o) {
  		if (!(o instanceof SignerWrapper))
  			return false;
  		SignerWrapper other = (SignerWrappero;
  		ApplicationDescriptor matchAppDesc = (ApplicationDescriptor) ( != null ?  : other.appDesc);
  		String matchPattern =  != null ? other.pattern : ;
  		return matchAppDesc.matchDNChain(matchPattern);
  private void init() {
		if ( .equals("*") )
      throw new IllegalArgumentException("Illegal action!");
		 = null;
  private Filter getFilter() {
  	if ( == null) {
  		try {
  			 = FrameworkUtil.createFilter();
catch (InvalidSyntaxException e) {
			//we will return null
  	return ;
New to GrepCode? Check out our FAQ X