001 /**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one or more
004 * contributor license agreements. See the NOTICE file distributed with
005 * this work for additional information regarding copyright ownership.
006 * The ASF licenses this file to You under the Apache License, Version 2.0
007 * (the "License"); you may not use this file except in compliance with
008 * the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package org.apache.geronimo.util.asn1;
020
021 /**
022 * class for breaking up an OID into it's component tokens, ala
023 * java.util.StringTokenizer. We need this class as some of the
024 * lightweight Java environment don't support classes like
025 * StringTokenizer.
026 */
027 public class OIDTokenizer
028 {
029 private String oid;
030 private int index;
031
032 public OIDTokenizer(
033 String oid)
034 {
035 this.oid = oid;
036 this.index = 0;
037 }
038
039 public boolean hasMoreTokens()
040 {
041 return (index != -1);
042 }
043
044 public String nextToken()
045 {
046 if (index == -1)
047 {
048 return null;
049 }
050
051 String token;
052 int end = oid.indexOf('.', index);
053
054 if (end == -1)
055 {
056 token = oid.substring(index);
057 index = -1;
058 return token;
059 }
060
061 token = oid.substring(index, end);
062
063 index = end + 1;
064 return token;
065 }
066 }