/*
 * $Header$
 * 
 * Copyright (c) OSGi Alliance (2005). All Rights Reserved.
 * 
 * Implementation of certain elements of the OSGi Specification may be subject
 * to third party intellectual property rights, including without limitation,
 * patent rights (such a third party may or may not be a member of the OSGi
 * Alliance). The OSGi Alliance is not responsible and shall not be held
 * responsible in any manner for identifying or failing to identify any or all
 * such third party intellectual property rights.
 * 
 * This document and the information contained herein are provided on an "AS IS"
 * basis and THE OSGI ALLIANCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
 * HEREIN WILL NOT INFRINGE ANY RIGHTS AND ANY IMPLIED WARRANTIES OF
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL THE
 * OSGI ALLIANCE BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF BUSINESS, LOSS OF
 * USE OF DATA, INTERRUPTION OF BUSINESS, OR FOR DIRECT, INDIRECT, SPECIAL OR
 * EXEMPLARY, INCIDENTIAL, PUNITIVE OR CONSEQUENTIAL DAMAGES OF ANY KIND IN
 * CONNECTION WITH THIS DOCUMENT OR THE INFORMATION CONTAINED HEREIN, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH LOSS OR DAMAGE.
 * 
 * All Company, brand and product names may be trademarks that are the sole
 * property of their respective owners. All rights reserved.
 */

package org.osgi.service.deploymentadmin;

import java.lang.reflect.Constructor;
import java.security.AccessController;
import java.security.Permission;
import java.security.PermissionCollection;
import java.security.PrivilegedAction;

/**
 * The <code>DeploymentCustomizerPermission</code> permission gives the right to 
 * Resource Processors to access a bundle's private area.<p>
 * The Resource Processor that has this permission is allowed to access the bundle's 
 * private area by calling the {@link DeploymentSession#getDataFile} method. The 
 * Resource Processor will have <code>FilePermission</code> with "read", "write" and "delete" 
 * actions for the returned {@link java.io.File} and its subdirectories.
 */
public class DeploymentCustomizerPermission extends Permission {
    
    /**
     * Constant String to the "privatearea" action.
     */
    public static final String ACTION_PRIVATEAREA = "privatearea";

    private static final String      delegateProperty = "org.osgi.vendor.deploymentadmin";
    private static final Constructor constructor;
    private final        Permission  delegate;
    static {
        constructor = (Constructor) AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                String pckg = System.getProperty(delegateProperty);
                if (null == pckg)
                    throw new RuntimeException("Property '" + delegateProperty + "' is not set");
                try {
                    Class c = Class.forName(pckg + ".DeploymentCustomizerPermission");
                    return c.getConstructor(new Class[] {String.class, String.class});    
                }
                catch (Exception e) {
                    throw new RuntimeException(e.getMessage());
                }
            }});
    }

    /**
     * Creates a new <code>DeploymentCustomizerPermission</code> object for the given 
     * <code>name</code> and <code>action</code>.<p>
     * The name parameter is a filter string. This filter has the same syntax as an OSGi filter 
     * but only the "name" attribute is allowed. The value of the attribute  
     * is a bundle Symbolic Name that represents a bundle. The only allowed action is the 
     * "privatearea" action. E.g.<p>
     * <pre>
     * 		Permission perm = new DeploymentCustomizerPermission("(name=com.acme.bundle)", "privatearea");
     * </pre>
     * The Resource Processor that has this permission is allowed to access the bundle's 
     * private area by calling the {@link DeploymentSession#getDataFile} method. The 
     * Resource Processor will have <code>FilePermission</code> with "read", "write" and "delete" 
     * actions for the returned {@link java.io.File} and its subdirectories.
     * @param name Symbolic name of the target bundle, must not be null.
     * @param action Action string (only the "privatearea" action is valid), must not be null.
     * @throws IllegalArgumentException if the filter is invalid or the list of actions 
     *         contains unknown operations
     */
    public DeploymentCustomizerPermission(String name, String actions) {
        super(name);
        try {
            delegate = (Permission) constructor.newInstance(new Object[] {name, actions});
        }
		catch (RuntimeException e) {
			throw e;
		}
		catch (Exception e) {
			throw new RuntimeException(e.toString());
		}
    }

    /**
     * Checks two DeploymentCustomizerPermission objects for equality. 
     * Two permission objects are equal if: <p>
     * - their target filters 
     * are equal and<p>
     * - their actions are the same. 
     * @param obj The reference object with which to compare.
     * @return true if the two objects are equal.
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public boolean equals(Object obj) {
        if (obj == this)
        	return true;
        if (!(obj instanceof DeploymentCustomizerPermission))
            return false;
        DeploymentCustomizerPermission dcp = (DeploymentCustomizerPermission) obj;
        return delegate.equals(dcp.delegate);
    }

    /**
     * Returns hash code for this permission object.
     * @return Hash code for this permission object.
     * @see java.lang.Object#hashCode()
     */
    public int hashCode() {
        return delegate.hashCode();
    }

    /**
     * Returns the String representation of the action list.
     * @return Action list of this permission instance. This is a comma-separated 
     * list that reflects the action parameter of the constructor.
     * @see java.security.Permission#getActions()
     */
    public String getActions() {
        return delegate.getActions();
    }

    /**
     * Checks if this DeploymentCustomizerPermission would imply the parameter permission.
     * @param permission Permission to check.
     * @return true if this DeploymentCustomizerPermission object implies the 
     * specified permission.
     * @see java.security.Permission#implies(java.security.Permission)
     */
    public boolean implies(Permission permission) {
        if (!(permission instanceof DeploymentCustomizerPermission))
    		return false;
    	        
        DeploymentCustomizerPermission dcp = (DeploymentCustomizerPermission) permission;
        
        return delegate.implies(dcp.delegate);
    }

    /**
     * Returns a new PermissionCollection object for storing DeploymentCustomizerPermission 
     * objects. 
     * @return The new PermissionCollection.
     * @see java.security.Permission#newPermissionCollection()
     */
    public PermissionCollection newPermissionCollection() {
        return delegate.newPermissionCollection();
    }

}

@@ -12,16 +12,20 @@
 er$%0A * %0A
+ * %0A
  * Copyr
@@ -32,16 +32,20 @@
 ight (c)
+ The
  OSGi Al
@@ -91,1328 +91,227 @@
 %0A * 
-Implementation of certain elements of the OSGi Specification may be subject%0A * to third party intellectual property rights, including without limitation,%0A * patent rights (such a third party may or may not be a member of the OSGi%0A * Alliance). The OSGi Alliance is not responsi
+This program and the accompanying materials are made availa
 ble 
-and shall not be held%0A * responsible in any manner for identifying or failing to identify any or all%0A * such third party intellectual property rights.%0A * %0A * This document and the information contained herein are provided on an %22AS IS%22%0A * basis and THE OSGI ALLIANCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,%0A * INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION%0A * HEREIN WILL NOT INFRINGE ANY RIGHTS AND ANY IMPLIED WARRANTIES OF%0A * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL THE%0A * OSGI ALLIANCE BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF BUSINESS, LOSS OF%0A * USE OF DATA, INTERRUPTION OF BUSINESS, OR FOR DIRECT, INDIRECT, SPECIAL OR%0A * EXEMPLARY, INCIDENTIAL, PUNITIVE OR CONSEQUENTIAL DAMAGES OF ANY KIND IN%0A * CONNECTION WITH THIS DOCUMENT OR THE INFORMATION CONTAINED HEREIN, EVEN IF%0A * ADVISED OF THE POSSIBILITY OF SUCH LOSS OR DAMAGE.%0A * %0A * All Company, brand and product names may be trademarks that are the sole%0A * property of their respective owners. All rights reserved
+under the%0A * terms of the Eclipse Public License v1.0 which accompanies this %0A * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
 .%0A *

update notice