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