1: 
  37: 
  38: 
  39: package ;
  40: 
  41: import ;
  42: 
  43: import ;
  44: import ;
  45: 
  46: import ;
  47: import ;
  48: import ;
  49: import ;
  50: import ;
  51: 
  52: public final class PolicyNodeImpl implements PolicyNode
  53: {
  54: 
  55:   
  56:   
  57: 
  58:   private String policy;
  59:   private final Set expectedPolicies;
  60:   private final Set qualifiers;
  61:   private final Set children;
  62:   private PolicyNodeImpl parent;
  63:   private int depth;
  64:   private boolean critical;
  65:   private boolean readOnly;
  66: 
  67:   
  68:   
  69: 
  70:   public PolicyNodeImpl()
  71:   {
  72:     expectedPolicies = new HashSet();
  73:     qualifiers = new HashSet();
  74:     children = new HashSet();
  75:     readOnly = false;
  76:     critical = false;
  77:   }
  78: 
  79:   
  80:   
  81: 
  82:   public void addChild(PolicyNodeImpl node)
  83:   {
  84:     if (readOnly)
  85:       throw new IllegalStateException("read only");
  86:     if (node.getParent() != null)
  87:       throw new IllegalStateException("already a child node");
  88:     node.parent = this;
  89:     node.setDepth(depth + 1);
  90:     children.add(node);
  91:   }
  92: 
  93:   public Iterator getChildren()
  94:   {
  95:     return Collections.unmodifiableSet(children).iterator();
  96:   }
  97: 
  98:   public int getDepth()
  99:   {
 100:     return depth;
 101:   }
 102: 
 103:   public void setDepth(int depth)
 104:   {
 105:     if (readOnly)
 106:       throw new IllegalStateException("read only");
 107:     this.depth = depth;
 108:   }
 109: 
 110:   public void addAllExpectedPolicies(Set policies)
 111:   {
 112:     if (readOnly)
 113:       throw new IllegalStateException("read only");
 114:     expectedPolicies.addAll(policies);
 115:   }
 116: 
 117:   public void addExpectedPolicy(String policy)
 118:   {
 119:     if (readOnly)
 120:       throw new IllegalStateException("read only");
 121:     expectedPolicies.add(policy);
 122:   }
 123: 
 124:   public Set getExpectedPolicies()
 125:   {
 126:     return Collections.unmodifiableSet(expectedPolicies);
 127:   }
 128: 
 129:   public PolicyNode getParent()
 130:   {
 131:     return parent;
 132:   }
 133: 
 134:   public void addAllPolicyQualifiers (Collection qualifiers)
 135:   {
 136:     for (Iterator it = qualifiers.iterator(); it.hasNext(); )
 137:       {
 138:         if (!(it.next() instanceof PolicyQualifierInfo))
 139:           throw new IllegalArgumentException ("can only add PolicyQualifierInfos");
 140:       }
 141:     qualifiers.addAll (qualifiers);
 142:   }
 143: 
 144:   public void addPolicyQualifier (PolicyQualifierInfo qualifier)
 145:   {
 146:     if (readOnly)
 147:       throw new IllegalStateException("read only");
 148:     qualifiers.add(qualifier);
 149:   }
 150: 
 151:   public Set getPolicyQualifiers()
 152:   {
 153:     return Collections.unmodifiableSet(qualifiers);
 154:   }
 155: 
 156:   public String getValidPolicy()
 157:   {
 158:     return policy;
 159:   }
 160: 
 161:   public void setValidPolicy(String policy)
 162:   {
 163:     if (readOnly)
 164:       throw new IllegalStateException("read only");
 165:     this.policy = policy;
 166:   }
 167: 
 168:   public boolean isCritical()
 169:   {
 170:     return critical;
 171:   }
 172: 
 173:   public void setCritical(boolean critical)
 174:   {
 175:     if (readOnly)
 176:       throw new IllegalStateException("read only");
 177:     this.critical = critical;
 178:   }
 179: 
 180:   public void setReadOnly()
 181:   {
 182:     if (readOnly)
 183:       return;
 184:     readOnly = true;
 185:     for (Iterator it = getChildren(); it.hasNext(); )
 186:       ((PolicyNodeImpl) it.next()).setReadOnly();
 187:   }
 188: 
 189:   public String toString()
 190:   {
 191:     CPStringBuilder buf = new CPStringBuilder();
 192:     for (int i = 0; i < depth; i++)
 193:       buf.append("  ");
 194:     buf.append("(");
 195:     buf.append(PolicyNodeImpl.class.getName());
 196:     buf.append(" (oid ");
 197:     buf.append(policy);
 198:     buf.append(") (depth ");
 199:     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(); )
 209:       {
 210:         buf.append(nl);
 211:         buf.append(it.next().toString());
 212:       }
 213:     buf.append(")))");
 214:     return buf.toString();
 215:   }
 216: }