01: /*****************************************************************************
02: * Copyright (C) NanoContainer Organization. All rights reserved. *
03: * ------------------------------------------------------------------------- *
04: * The software in this package is published under the terms of the BSD *
05: * style license a copy of which has been included with this distribution in *
06: * the LICENSE.txt file. *
07: *****************************************************************************/package org.nanocontainer;
08:
09: import java.io.Serializable;
10: import java.net.URL;
11: import java.security.Permission;
12: import java.security.PermissionCollection;
13: import java.security.Permissions;
14: import java.util.ArrayList;
15: import java.util.List;
16:
17: /**
18: * ClassPathElement denotes an element in a classpath allowing to grant permissions.
19: *
20: * @author Paul Hammant
21: */
22: public class ClassPathElement implements Serializable {
23:
24: private final URL url;
25: private PermissionCollection permissionCollection;
26: private final List permissions = new ArrayList();
27:
28: public ClassPathElement(URL url) {
29: this .url = url;
30: }
31:
32: public Permission grantPermission(Permission permission) {
33: if (permission == null) {
34: throw new NullPointerException();
35: }
36: permissions.add(permission);
37: return permission;
38: }
39:
40: public URL getUrl() {
41: return url;
42: }
43:
44: public PermissionCollection getPermissionCollection() {
45: if (permissionCollection == null) {
46: permissionCollection = new Permissions();
47: for (int i = 0; i < permissions.size(); i++) {
48: Permission permission = (Permission) permissions.get(i);
49: permissionCollection.add(permission);
50: }
51: }
52: return permissionCollection;
53: }
54:
55: public String toString() {
56: return "[" + System.identityHashCode(this ) + " " + url + " "
57: + permissions.size() + "]";
58: }
59:
60: }
|