01: package org.osbl.authorization;
02:
03: import java.security.Permission;
04:
05: class Pattern extends Permission implements Comparable<Pattern> {
06: PatternType type;
07: String action;
08:
09: public Pattern(PatternType type, String action, String pattern) {
10: super (pattern);
11: this .type = type;
12: this .action = action;
13: }
14:
15: public PatternType getType() {
16: return type;
17: }
18:
19: public String getAction() {
20: return action;
21: }
22:
23: public String getPattern() {
24: return getName();
25: }
26:
27: public boolean implies(Permission permission) {
28: return false;
29: }
30:
31: public String getActions() {
32: return action;
33: }
34:
35: public boolean equals(Object o) {
36: if (this == o)
37: return true;
38: if (o == null || getClass() != o.getClass())
39: return false;
40:
41: Pattern pattern1 = (Pattern) o;
42:
43: if (!action.equals(pattern1.action))
44: return false;
45: if (!getName().equals(pattern1.getName()))
46: return false;
47: if (type != pattern1.type)
48: return false;
49:
50: return true;
51: }
52:
53: public int hashCode() {
54: int result;
55: result = type.hashCode();
56: result = 31 * result + action.hashCode();
57: result = 31 * result + getName().hashCode();
58: return result;
59: }
60:
61: public String toString() {
62: return getName() + '[' + action + ']';
63: }
64:
65: public int compareTo(Pattern o) {
66: PatternType t1 = getType();
67: PatternType t2 = o.getType();
68:
69: String a1 = getAction();
70: String a2 = o.getAction();
71: int difference = a1.compareTo(a2);
72: if (difference != 0)
73: return difference;
74:
75: if (t1 == PatternType.INCLUDE && t2 == PatternType.EXCLUDE)
76: return -1;
77: if (t1 == PatternType.EXCLUDE && t2 == PatternType.INCLUDE)
78: return 1;
79:
80: String s1 = getPattern();
81: String s2 = o.getPattern();
82: if (s1 == null || s2 == null)
83: return 0;
84:
85: int l1 = s1.length();
86: int l2 = s2.length();
87: int lengthDifference = (l1 < l2 ? -1 : (l1 == l2 ? 0 : 1));
88: return t1 == PatternType.INCLUDE ? lengthDifference
89: : -lengthDifference;
90: }
91: }
|