All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.picocontainer.classname.ClassPathElement Maven / Gradle / Ivy

There is a newer version: 2.15
Show newest version
/*******************************************************************************
 * Copyright (C) PicoContainer Organization. All rights reserved. 
 * ---------------------------------------------------------------------------
 * The software in this package is published under the terms of the BSD style
 * license a copy of which has been included with this distribution in the
 * LICENSE.txt file. 
 ******************************************************************************/
package org.picocontainer.classname;

import java.io.Serializable;
import java.net.URL;
import java.security.Permission;
import java.security.Permissions;
import java.util.ArrayList;
import java.util.List;

/**
 * ClassPathElement denotes an element in a classpath allowing to grant permissions.
 * 
 * @author Paul Hammant
 */
@SuppressWarnings("serial")
public class ClassPathElement implements Serializable {

    private final URL url;
    private Permissions permissionCollection;
    private final List permissions = new ArrayList();
    
    public ClassPathElement(URL url) {
        this.url = url;
    }

    public Permission grantPermission(Permission permission) {
        if (permission == null) {
            throw new NullPointerException();
        }
        permissions.add(permission);
        return permission;
    }

    public URL getUrl() {
        return url;
    }

    public Permissions getPermissionCollection() {
        if (permissionCollection == null) {
            permissionCollection = new Permissions();
            for (Permission permission : permissions) {
                permissionCollection.add(permission);
            }
        }
        return permissionCollection;
    }

    public String toString() {
        return "[" + System.identityHashCode(this) + " " + url + " " + permissions.size() +"]";
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy