001: package org.bouncycastle.jce.provider;
002:
003: import java.security.cert.PolicyNode;
004: import java.util.ArrayList;
005: import java.util.HashSet;
006: import java.util.Iterator;
007: import java.util.List;
008: import java.util.Set;
009:
010: public class PKIXPolicyNode implements PolicyNode {
011: protected List children;
012: protected int depth;
013: protected Set expectedPolicies;
014: protected PolicyNode parent;
015: protected Set policyQualifiers;
016: protected String validPolicy;
017: protected boolean critical;
018:
019: /*
020: *
021: * CONSTRUCTORS
022: *
023: */
024:
025: public PKIXPolicyNode(List _children, int _depth,
026: Set _expectedPolicies, PolicyNode _parent,
027: Set _policyQualifiers, String _validPolicy,
028: boolean _critical) {
029: children = _children;
030: depth = _depth;
031: expectedPolicies = _expectedPolicies;
032: parent = _parent;
033: policyQualifiers = _policyQualifiers;
034: validPolicy = _validPolicy;
035: critical = _critical;
036: }
037:
038: public void addChild(PKIXPolicyNode _child) {
039: children.add(_child);
040: _child.setParent(this );
041: }
042:
043: public Iterator getChildren() {
044: return children.iterator();
045: }
046:
047: public int getDepth() {
048: return depth;
049: }
050:
051: public Set getExpectedPolicies() {
052: return expectedPolicies;
053: }
054:
055: public PolicyNode getParent() {
056: return parent;
057: }
058:
059: public Set getPolicyQualifiers() {
060: return policyQualifiers;
061: }
062:
063: public String getValidPolicy() {
064: return validPolicy;
065: }
066:
067: public boolean hasChildren() {
068: return !children.isEmpty();
069: }
070:
071: public boolean isCritical() {
072: return critical;
073: }
074:
075: public void removeChild(PKIXPolicyNode _child) {
076: children.remove(_child);
077: }
078:
079: public void setCritical(boolean _critical) {
080: critical = _critical;
081: }
082:
083: public void setParent(PKIXPolicyNode _parent) {
084: parent = _parent;
085: }
086:
087: public String toString() {
088: return toString("");
089: }
090:
091: public String toString(String _indent) {
092: StringBuffer _buf = new StringBuffer();
093: _buf.append(_indent);
094: _buf.append(validPolicy);
095: _buf.append(" {\n");
096:
097: for (int i = 0; i < children.size(); i++) {
098: _buf.append(((PKIXPolicyNode) children.get(i))
099: .toString(_indent + " "));
100: }
101:
102: _buf.append(_indent);
103: _buf.append("}\n");
104: return _buf.toString();
105: }
106:
107: public Object clone() {
108: return copy();
109: }
110:
111: public PKIXPolicyNode copy() {
112: Set _expectedPolicies = new HashSet();
113: Iterator _iter = expectedPolicies.iterator();
114: while (_iter.hasNext()) {
115: _expectedPolicies.add(new String((String) _iter.next()));
116: }
117:
118: Set _policyQualifiers = new HashSet();
119: _iter = policyQualifiers.iterator();
120: while (_iter.hasNext()) {
121: _policyQualifiers.add(new String((String) _iter.next()));
122: }
123:
124: PKIXPolicyNode _node = new PKIXPolicyNode(new ArrayList(),
125: depth, _expectedPolicies, null, _policyQualifiers,
126: new String(validPolicy), critical);
127:
128: _iter = children.iterator();
129: while (_iter.hasNext()) {
130: PKIXPolicyNode _child = ((PKIXPolicyNode) _iter.next())
131: .copy();
132: _child.setParent(_node);
133: _node.addChild(_child);
134: }
135:
136: return _node;
137: }
138: }
|