1package org.bouncycastle.jce.provider; 2 3import java.security.cert.PolicyNode; 4import java.util.ArrayList; 5import java.util.HashSet; 6import java.util.Iterator; 7import java.util.List; 8import java.util.Set; 9 10public class PKIXPolicyNode 11 implements PolicyNode 12{ 13 protected List children; 14 protected int depth; 15 protected Set expectedPolicies; 16 protected PolicyNode parent; 17 protected Set policyQualifiers; 18 protected String validPolicy; 19 protected boolean critical; 20 21 /* 22 * 23 * CONSTRUCTORS 24 * 25 */ 26 27 public PKIXPolicyNode( 28 List _children, 29 int _depth, 30 Set _expectedPolicies, 31 PolicyNode _parent, 32 Set _policyQualifiers, 33 String _validPolicy, 34 boolean _critical) 35 { 36 children = _children; 37 depth = _depth; 38 expectedPolicies = _expectedPolicies; 39 parent = _parent; 40 policyQualifiers = _policyQualifiers; 41 validPolicy = _validPolicy; 42 critical = _critical; 43 } 44 45 public void addChild( 46 PKIXPolicyNode _child) 47 { 48 children.add(_child); 49 _child.setParent(this); 50 } 51 52 public Iterator getChildren() 53 { 54 return children.iterator(); 55 } 56 57 public int getDepth() 58 { 59 return depth; 60 } 61 62 public Set getExpectedPolicies() 63 { 64 return expectedPolicies; 65 } 66 67 public PolicyNode getParent() 68 { 69 return parent; 70 } 71 72 public Set getPolicyQualifiers() 73 { 74 return policyQualifiers; 75 } 76 77 public String getValidPolicy() 78 { 79 return validPolicy; 80 } 81 82 public boolean hasChildren() 83 { 84 return !children.isEmpty(); 85 } 86 87 public boolean isCritical() 88 { 89 return critical; 90 } 91 92 public void removeChild(PKIXPolicyNode _child) 93 { 94 children.remove(_child); 95 } 96 97 public void setCritical(boolean _critical) 98 { 99 critical = _critical; 100 } 101 102 public void setParent(PKIXPolicyNode _parent) 103 { 104 parent = _parent; 105 } 106 107 public String toString() 108 { 109 return toString(""); 110 } 111 112 public String toString(String _indent) 113 { 114 StringBuffer _buf = new StringBuffer(); 115 _buf.append(_indent); 116 _buf.append(validPolicy); 117 _buf.append(" {\n"); 118 119 for(int i = 0; i < children.size(); i++) 120 { 121 _buf.append(((PKIXPolicyNode)children.get(i)).toString(_indent + " ")); 122 } 123 124 _buf.append(_indent); 125 _buf.append("}\n"); 126 return _buf.toString(); 127 } 128 129 public Object clone() 130 { 131 return copy(); 132 } 133 134 public PKIXPolicyNode copy() 135 { 136 Set _expectedPolicies = new HashSet(); 137 Iterator _iter = expectedPolicies.iterator(); 138 while (_iter.hasNext()) 139 { 140 _expectedPolicies.add(new String((String)_iter.next())); 141 } 142 143 Set _policyQualifiers = new HashSet(); 144 _iter = policyQualifiers.iterator(); 145 while (_iter.hasNext()) 146 { 147 _policyQualifiers.add(new String((String)_iter.next())); 148 } 149 150 PKIXPolicyNode _node = new PKIXPolicyNode(new ArrayList(), 151 depth, 152 _expectedPolicies, 153 null, 154 _policyQualifiers, 155 new String(validPolicy), 156 critical); 157 158 _iter = children.iterator(); 159 while (_iter.hasNext()) 160 { 161 PKIXPolicyNode _child = ((PKIXPolicyNode)_iter.next()).copy(); 162 _child.setParent(_node); 163 _node.addChild(_child); 164 } 165 166 return _node; 167 } 168} 169