1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43:
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49:
50: public final class PolicyNodeImpl implements PolicyNode
51: {
52:
53:
54:
55:
56: private String policy;
57: private final Set expectedPolicies;
58: private final Set qualifiers;
59: private final Set children;
60: private PolicyNodeImpl parent;
61: private int depth;
62: private boolean critical;
63: private boolean readOnly;
64:
65:
66:
67:
68: public PolicyNodeImpl()
69: {
70: expectedPolicies = new HashSet();
71: qualifiers = new HashSet();
72: children = new HashSet();
73: readOnly = false;
74: critical = false;
75: }
76:
77:
78:
79:
80: public void addChild(PolicyNodeImpl node)
81: {
82: if (readOnly)
83: throw new IllegalStateException("read only");
84: if (node.getParent() != null)
85: throw new IllegalStateException("already a child node");
86: node.parent = this;
87: node.setDepth(depth + 1);
88: children.add(node);
89: }
90:
91: public Iterator getChildren()
92: {
93: return Collections.unmodifiableSet(children).iterator();
94: }
95:
96: public int getDepth()
97: {
98: return depth;
99: }
100:
101: public void setDepth(int depth)
102: {
103: if (readOnly)
104: throw new IllegalStateException("read only");
105: this.depth = depth;
106: }
107:
108: public void addAllExpectedPolicies(Set policies)
109: {
110: if (readOnly)
111: throw new IllegalStateException("read only");
112: expectedPolicies.addAll(policies);
113: }
114:
115: public void addExpectedPolicy(String policy)
116: {
117: if (readOnly)
118: throw new IllegalStateException("read only");
119: expectedPolicies.add(policy);
120: }
121:
122: public Set getExpectedPolicies()
123: {
124: return Collections.unmodifiableSet(expectedPolicies);
125: }
126:
127: public PolicyNode getParent()
128: {
129: return parent;
130: }
131:
132: public void addAllPolicyQualifiers (Collection qualifiers)
133: {
134: for (Iterator it = qualifiers.iterator(); it.hasNext(); )
135: {
136: if (!(it.next() instanceof PolicyQualifierInfo))
137: throw new IllegalArgumentException ("can only add PolicyQualifierInfos");
138: }
139: qualifiers.addAll (qualifiers);
140: }
141:
142: public void addPolicyQualifier (PolicyQualifierInfo qualifier)
143: {
144: if (readOnly)
145: throw new IllegalStateException("read only");
146: qualifiers.add(qualifier);
147: }
148:
149: public Set getPolicyQualifiers()
150: {
151: return Collections.unmodifiableSet(qualifiers);
152: }
153:
154: public String getValidPolicy()
155: {
156: return policy;
157: }
158:
159: public void setValidPolicy(String policy)
160: {
161: if (readOnly)
162: throw new IllegalStateException("read only");
163: this.policy = policy;
164: }
165:
166: public boolean isCritical()
167: {
168: return critical;
169: }
170:
171: public void setCritical(boolean critical)
172: {
173: if (readOnly)
174: throw new IllegalStateException("read only");
175: this.critical = critical;
176: }
177:
178: public void setReadOnly()
179: {
180: if (readOnly)
181: return;
182: readOnly = true;
183: for (Iterator it = getChildren(); it.hasNext(); )
184: ((PolicyNodeImpl) it.next()).setReadOnly();
185: }
186:
187: public String toString()
188: {
189: StringBuffer buf = new StringBuffer();
190: for (int i = 0; i < depth; i++)
191: buf.append(" ");
192: buf.append("(");
193: buf.append(PolicyNodeImpl.class.getName());
194: buf.append(" (oid ");
195: buf.append(policy);
196: buf.append(") (depth ");
197: buf.append(depth);
198: buf.append(") (qualifiers ");
199: buf.append(qualifiers);
200: buf.append(") (critical ");
201: buf.append(critical);
202: buf.append(") (expectedPolicies ");
203: buf.append(expectedPolicies);
204: buf.append(") (children (");
205: final String nl = System.getProperty("line.separator");
206: for (Iterator it = getChildren(); it.hasNext(); )
207: {
208: buf.append(nl);
209: buf.append(it.next().toString());
210: }
211: buf.append(")))");
212: return buf.toString();
213: }
214: }