summaryrefslogtreecommitdiffstats
path: root/bcprov/src/main/java/org/bouncycastle/jce/provider/PKIXPolicyNode.java
blob: 34376055011d12d181fe7b63e6e722b474853dee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package org.bouncycastle.jce.provider;

import java.security.cert.PolicyNode;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class PKIXPolicyNode
    implements PolicyNode
{
    protected List       children;
    protected int        depth;
    protected Set        expectedPolicies;
    protected PolicyNode parent;
    protected Set        policyQualifiers;
    protected String     validPolicy;
    protected boolean    critical;
    
    /*  
     *  
     *  CONSTRUCTORS
     *  
     */ 
    
    public PKIXPolicyNode(
        List       _children,
        int        _depth,
        Set        _expectedPolicies,
        PolicyNode _parent,
        Set        _policyQualifiers,
        String     _validPolicy,
        boolean    _critical)
    {
        children         = _children;
        depth            = _depth;
        expectedPolicies = _expectedPolicies;
        parent           = _parent;
        policyQualifiers = _policyQualifiers;
        validPolicy      = _validPolicy;
        critical         = _critical;
    }
    
    public void addChild(
        PKIXPolicyNode _child)
    {
        children.add(_child);
        _child.setParent(this);
    }
    
    public Iterator getChildren()
    {
        return children.iterator();
    }
    
    public int getDepth()
    {
        return depth;
    }
    
    public Set getExpectedPolicies()
    {
        return expectedPolicies;
    }
    
    public PolicyNode getParent()
    {
        return parent;
    }
    
    public Set getPolicyQualifiers()
    {
        return policyQualifiers;
    }
    
    public String getValidPolicy()
    {
        return validPolicy;
    }
    
    public boolean hasChildren()
    {
        return !children.isEmpty();
    }
    
    public boolean isCritical()
    {
        return critical;
    }
    
    public void removeChild(PKIXPolicyNode _child)
    {
        children.remove(_child);
    }
    
    public void setCritical(boolean _critical)
    {
        critical = _critical;
    }
    
    public void setParent(PKIXPolicyNode _parent)
    {
        parent = _parent;
    }
    
    public String toString()
    {
        return toString("");
    }
    
    public String toString(String _indent)
    {
        StringBuffer _buf = new StringBuffer();
        _buf.append(_indent);
        _buf.append(validPolicy);
        _buf.append(" {\n");
        
        for(int i = 0; i < children.size(); i++)
        {
            _buf.append(((PKIXPolicyNode)children.get(i)).toString(_indent + "    "));
        }
        
        _buf.append(_indent);
        _buf.append("}\n");
        return _buf.toString();
    }
    
    public Object clone()
    {
        return copy();
    }
    
    public PKIXPolicyNode copy()
    {
        Set     _expectedPolicies = new HashSet();
        Iterator _iter = expectedPolicies.iterator();
        while (_iter.hasNext())
        {
            _expectedPolicies.add(new String((String)_iter.next()));
        }
        
        Set     _policyQualifiers = new HashSet();
        _iter = policyQualifiers.iterator();
        while (_iter.hasNext())
        {
            _policyQualifiers.add(new String((String)_iter.next()));
        }
        
        PKIXPolicyNode _node = new PKIXPolicyNode(new ArrayList(),
                                                  depth,
                                                  _expectedPolicies,
                                                  null,
                                                  _policyQualifiers,
                                                  new String(validPolicy),
                                                  critical);
        
        _iter = children.iterator();
        while (_iter.hasNext())
        {
            PKIXPolicyNode _child = ((PKIXPolicyNode)_iter.next()).copy();
            _child.setParent(_node);
            _node.addChild(_child);
        }
        
        return _node;
    }
}