KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nanocontainer > ClassPathElement


1 /*****************************************************************************
2  * Copyright (C) NanoContainer Organization. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  *****************************************************************************/

8 package org.nanocontainer;
9
10 import java.io.Serializable JavaDoc;
11 import java.net.URL JavaDoc;
12 import java.security.Permission JavaDoc;
13 import java.security.PermissionCollection JavaDoc;
14 import java.security.Permissions JavaDoc;
15 import java.util.ArrayList JavaDoc;
16 import java.util.List JavaDoc;
17
18 /**
19  * ClassPathElement denotes an element in a classpath allowing to grant permissions.
20  *
21  * @author Paul Hammant
22  */

23 public class ClassPathElement implements Serializable JavaDoc {
24
25     private final URL JavaDoc url;
26     private PermissionCollection JavaDoc permissionCollection;
27     private final List JavaDoc permissions = new ArrayList JavaDoc();
28     
29     public ClassPathElement(URL JavaDoc url) {
30         this.url = url;
31     }
32
33     public Permission JavaDoc grantPermission(Permission JavaDoc permission) {
34         if (permission == null) {
35             throw new NullPointerException JavaDoc();
36         }
37         permissions.add(permission);
38         return permission;
39     }
40
41     public URL JavaDoc getUrl() {
42         return url;
43     }
44
45     public PermissionCollection JavaDoc getPermissionCollection() {
46         if (permissionCollection == null) {
47             permissionCollection = new Permissions JavaDoc();
48             for (int i = 0; i < permissions.size(); i++) {
49                 Permission JavaDoc permission = (Permission JavaDoc) permissions.get(i);
50                 permissionCollection.add(permission);
51             }
52         }
53         return permissionCollection;
54     }
55
56     public String JavaDoc toString() {
57         return "[" + System.identityHashCode(this) + " " + url + " " + permissions.size() +"]";
58     }
59
60 }
61
Popular Tags