1 2 package com.ca.commons.security.asn1; 3 4 12 public class Sequence extends ASN1Object implements java.io.Serializable 13 { 14 15 private ASN1Object [] component; 16 private int count; 17 private static int initSize = 2; 18 19 22 public Sequence() 23 {} 24 25 28 public void init(ASN1Type type) 29 { 30 asn1Type = type; 31 byteArray = null; 32 count = 0; 33 component = new ASN1Object[initSize]; 34 } 35 36 39 public void addComponent(ASN1Object comp) 40 { 41 addComponent(comp, count); 42 } 43 44 47 public void addComponent(ASN1Object comp, int index) 48 { 49 if (index > count) 50 { 51 throw new IllegalArgumentException ("illegal component index"); 52 } 53 if (component.length <= count) 54 { 55 56 57 ASN1Object [] oldComponent = component; 58 component = new ASN1Object[component.length+2]; 59 System.arraycopy(oldComponent, 0, component, 0, 60 oldComponent.length); 61 } 62 if (index < count) 63 { 64 System.arraycopy(component, index, component, 65 index + 1, count - index); 66 } 67 component[index] = comp; 68 count++; 69 } 70 71 74 public void removeComponent(ASN1Object comp, int index) 75 { 76 77 } 78 79 82 public ASN1Object getComponent(int index) 83 { 84 if (index > count) 85 { 86 throw new IllegalArgumentException ("illegal component index"); 87 } 88 return component[index]; 89 } 90 91 94 public void setComponent(ASN1Object comp, int index) 95 { 96 if (index > count) 97 { 98 throw new IllegalArgumentException ("illegal component index"); 99 } 100 component[index] = comp; 101 } 102 103 106 public int size() 107 { 108 return count; 109 } 110 111 132 133 136 public String toString() 137 { 138 String result = super.toString(); 139 for (int i = 0; i < count; i++) 140 { 141 result += "\n\t[" + i + "]" + component[i].toString(); 142 } 143 return result; 144 } 145 } 146 | Popular Tags |