01: /*
02: * $Id: RuntimePermission.java,v 1.3 2002/09/16 08:05:02 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.core;
11:
12: import java.security.BasicPermission;
13: import java.security.Permission;
14: import anvil.java.security.ExtendedBasicPermission;
15:
16: public final class RuntimePermission extends ExtendedBasicPermission {
17:
18: private boolean _writable = false;
19:
20: public RuntimePermission(String name) {
21: super (name);
22: }
23:
24: public RuntimePermission(String name, String actions) {
25: super (name);
26: if (actions.indexOf("writable") >= 0) {
27: _writable = true;
28: }
29: }
30:
31: public RuntimePermission(String name, boolean writable) {
32: super (name);
33: _writable = writable;
34: }
35:
36: public int hashCode() {
37: return getName().hashCode() ^ (_writable ? 37 : 0);
38: }
39:
40: public boolean equals(Object o) {
41: if (o instanceof RuntimePermission) {
42: RuntimePermission rp = (RuntimePermission) o;
43: if (_writable == rp._writable) {
44: return getName().equals(rp.getName());
45: }
46: }
47: return false;
48: }
49:
50: public boolean implies(Permission p) {
51: if (p instanceof RuntimePermission) {
52: RuntimePermission rp = (RuntimePermission) p;
53: if (rp._writable && !_writable) {
54: return false;
55: }
56: return super .implies(rp);
57: }
58: return false;
59: }
60:
61: public String getActions() {
62: if (_writable) {
63: return "writable";
64: }
65: return "";
66:
67: }
68:
69: public boolean isWritable() {
70: return _writable;
71: }
72:
73: }
|