01: /*
02: * $Id: NamespacePermission.java,v 1.2 2002/09/16 08:05:06 jkl Exp $
03: *
04: * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
05: *
06: * Use is subject to license terms, as defined in
07: * Anvil Sofware License, Version 1.1. See LICENSE
08: * file, or http://njet.org/license-1.1.txt
09: */
10: package anvil.server;
11:
12: import java.security.Permission;
13:
14: /**
15: * class NamespacePermission
16: *
17: * @author: Jani Lehtimäki
18: */
19: public final class NamespacePermission extends Permission {
20:
21: private boolean _writable = false;
22:
23: public NamespacePermission(String name) {
24: super (name);
25: }
26:
27: public NamespacePermission(String name, String actions) {
28: super (name);
29: if (actions.indexOf("writable") >= 0) {
30: _writable = true;
31: }
32: }
33:
34: public NamespacePermission(String name, boolean writable) {
35: super (name);
36: _writable = writable;
37: }
38:
39: public int hashCode() {
40: return getName().hashCode();
41: }
42:
43: public String getActions() {
44: if (_writable) {
45: return "writable";
46: }
47: return "";
48: }
49:
50: public boolean equals(Object o) {
51: if (o instanceof NamespacePermission) {
52: NamespacePermission p = (NamespacePermission) o;
53: if (p._writable == _writable) {
54: return p.getName().equals(getName());
55: }
56: }
57: return false;
58: }
59:
60: public boolean implies(Permission perm) {
61: if (perm instanceof NamespacePermission) {
62: NamespacePermission p = (NamespacePermission) perm;
63: if (p._writable && !_writable) {
64: return false;
65: }
66: return getName().equals(p.getName());
67: }
68: return false;
69: }
70:
71: }
|