1package org.bouncycastle.asn1; 2 3/** 4 * Class for breaking up an OID into it's component tokens, ala 5 * java.util.StringTokenizer. We need this class as some of the 6 * lightweight Java environment don't support classes like 7 * StringTokenizer. 8 */ 9public class OIDTokenizer 10{ 11 private String oid; 12 private int index; 13 14 /** 15 * Base constructor. 16 * 17 * @param oid the string representation of the OID. 18 */ 19 public OIDTokenizer( 20 String oid) 21 { 22 this.oid = oid; 23 this.index = 0; 24 } 25 26 /** 27 * Return whether or not there are more tokens in this tokenizer. 28 * 29 * @return true if there are more tokens, false otherwise. 30 */ 31 public boolean hasMoreTokens() 32 { 33 return (index != -1); 34 } 35 36 /** 37 * Return the next token in the underlying String. 38 * 39 * @return the next token. 40 */ 41 public String nextToken() 42 { 43 if (index == -1) 44 { 45 return null; 46 } 47 48 String token; 49 int end = oid.indexOf('.', index); 50 51 if (end == -1) 52 { 53 token = oid.substring(index); 54 index = -1; 55 return token; 56 } 57 58 token = oid.substring(index, end); 59 60 index = end + 1; 61 return token; 62 } 63} 64