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)
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
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
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 gnu.java.lang.CPStringBuilder;
43 import java.security.cert.PolicyNode;
44 import java.security.cert.PolicyQualifierInfo;
46 import java.util.Collection;
47 import java.util.Collections;
48 import java.util.HashSet;
49 import java.util.Iterator;
52 public final class PolicyNodeImpl implements PolicyNode
56 // -------------------------------------------------------------------------
58 private String policy;
59 private final Set expectedPolicies;
60 private final Set qualifiers;
61 private final Set children;
62 private PolicyNodeImpl parent;
64 private boolean critical;
65 private boolean readOnly;
68 // -------------------------------------------------------------------------
70 public PolicyNodeImpl()
72 expectedPolicies = new HashSet();
73 qualifiers = new HashSet();
74 children = new HashSet();
80 // -------------------------------------------------------------------------
82 public void addChild(PolicyNodeImpl node)
85 throw new IllegalStateException("read only");
86 if (node.getParent() != null)
87 throw new IllegalStateException("already a child node");
89 node.setDepth(depth + 1);
93 public Iterator getChildren()
95 return Collections.unmodifiableSet(children).iterator();
103 public void setDepth(int depth)
106 throw new IllegalStateException("read only");
110 public void addAllExpectedPolicies(Set policies)
113 throw new IllegalStateException("read only");
114 expectedPolicies.addAll(policies);
117 public void addExpectedPolicy(String policy)
120 throw new IllegalStateException("read only");
121 expectedPolicies.add(policy);
124 public Set getExpectedPolicies()
126 return Collections.unmodifiableSet(expectedPolicies);
129 public PolicyNode getParent()
134 public void addAllPolicyQualifiers (Collection qualifiers)
136 for (Iterator it = qualifiers.iterator(); it.hasNext(); )
138 if (!(it.next() instanceof PolicyQualifierInfo))
139 throw new IllegalArgumentException ("can only add PolicyQualifierInfos");
141 qualifiers.addAll (qualifiers);
144 public void addPolicyQualifier (PolicyQualifierInfo qualifier)
147 throw new IllegalStateException("read only");
148 qualifiers.add(qualifier);
151 public Set getPolicyQualifiers()
153 return Collections.unmodifiableSet(qualifiers);
156 public String getValidPolicy()
161 public void setValidPolicy(String policy)
164 throw new IllegalStateException("read only");
165 this.policy = policy;
168 public boolean isCritical()
173 public void setCritical(boolean critical)
176 throw new IllegalStateException("read only");
177 this.critical = critical;
180 public void setReadOnly()
185 for (Iterator it = getChildren(); it.hasNext(); )
186 ((PolicyNodeImpl) it.next()).setReadOnly();
189 public String toString()
191 CPStringBuilder buf = new CPStringBuilder();
192 for (int i = 0; i < depth; i++)
195 buf.append(PolicyNodeImpl.class.getName());
196 buf.append(" (oid ");
198 buf.append(") (depth ");
200 buf.append(") (qualifiers ");
201 buf.append(qualifiers);
202 buf.append(") (critical ");
203 buf.append(critical);
204 buf.append(") (expectedPolicies ");
205 buf.append(expectedPolicies);
206 buf.append(") (children (");
207 final String nl = System.getProperty("line.separator");
208 for (Iterator it = getChildren(); it.hasNext(); )
211 buf.append(it.next().toString());
214 return buf.toString();