Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / gnu / java / security / x509 / PolicyNodeImpl.java
blob72cb4a9ea91d13457937a040c42a322c2edc5143
1 /* PolicyNodeImpl.java -- An implementation of a policy tree node.
2 Copyright (C) 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu.java.security.x509;
41 import java.security.cert.PolicyNode;
42 import java.security.cert.PolicyQualifierInfo;
44 import java.util.Collection;
45 import java.util.Collections;
46 import java.util.HashSet;
47 import java.util.Iterator;
48 import java.util.Set;
50 public final class PolicyNodeImpl implements PolicyNode
53 // Fields.
54 // -------------------------------------------------------------------------
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;
65 // Constructors.
66 // -------------------------------------------------------------------------
68 public PolicyNodeImpl()
70 expectedPolicies = new HashSet();
71 qualifiers = new HashSet();
72 children = new HashSet();
73 readOnly = false;
74 critical = false;
77 // Instance methods.
78 // -------------------------------------------------------------------------
80 public void addChild(PolicyNodeImpl node)
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);
91 public Iterator getChildren()
93 return Collections.unmodifiableSet(children).iterator();
96 public int getDepth()
98 return depth;
101 public void setDepth(int depth)
103 if (readOnly)
104 throw new IllegalStateException("read only");
105 this.depth = depth;
108 public void addAllExpectedPolicies(Set policies)
110 if (readOnly)
111 throw new IllegalStateException("read only");
112 expectedPolicies.addAll(policies);
115 public void addExpectedPolicy(String policy)
117 if (readOnly)
118 throw new IllegalStateException("read only");
119 expectedPolicies.add(policy);
122 public Set getExpectedPolicies()
124 return Collections.unmodifiableSet(expectedPolicies);
127 public PolicyNode getParent()
129 return parent;
132 public void addAllPolicyQualifiers (Collection qualifiers)
134 for (Iterator it = qualifiers.iterator(); it.hasNext(); )
136 if (!(it.next() instanceof PolicyQualifierInfo))
137 throw new IllegalArgumentException ("can only add PolicyQualifierInfos");
139 qualifiers.addAll (qualifiers);
142 public void addPolicyQualifier (PolicyQualifierInfo qualifier)
144 if (readOnly)
145 throw new IllegalStateException("read only");
146 qualifiers.add(qualifier);
149 public Set getPolicyQualifiers()
151 return Collections.unmodifiableSet(qualifiers);
154 public String getValidPolicy()
156 return policy;
159 public void setValidPolicy(String policy)
161 if (readOnly)
162 throw new IllegalStateException("read only");
163 this.policy = policy;
166 public boolean isCritical()
168 return critical;
171 public void setCritical(boolean critical)
173 if (readOnly)
174 throw new IllegalStateException("read only");
175 this.critical = critical;
178 public void setReadOnly()
180 if (readOnly)
181 return;
182 readOnly = true;
183 for (Iterator it = getChildren(); it.hasNext(); )
184 ((PolicyNodeImpl) it.next()).setReadOnly();
187 public String toString()
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(); )
208 buf.append(nl);
209 buf.append(it.next().toString());
211 buf.append(")))");
212 return buf.toString();