001    /*
002     *  Licensed to the Apache Software Foundation (ASF) under one
003     *  or more contributor license agreements.  See the NOTICE file
004     *  distributed with this work for additional information
005     *  regarding copyright ownership.  The ASF licenses this file
006     *  to you under the Apache License, Version 2.0 (the
007     *  "License"); you may not use this file except in compliance
008     *  with 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,
013     *  software distributed under the License is distributed on an
014     *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     *  KIND, either express or implied.  See the License for the
016     *  specific language governing permissions and limitations
017     *  under the License. 
018     *  
019     */
020    package org.apache.directory.server.kerberos.shared.messages.value;
021    
022    
023    import java.util.Arrays;
024    import java.util.Collections;
025    import java.util.List;
026    
027    import org.apache.directory.shared.ldap.constants.AuthenticationLevel;
028    
029    
030    /**
031     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
032     * @version $Rev: 586528 $, $Date: 2007-10-19 18:47:06 +0200 (Fri, 19 Oct 2007) $
033     */
034    public final class LastRequestType implements Comparable<LastRequestType>
035    {
036        /**
037         * Constant for the "none" last request type.
038         */
039        public static final LastRequestType NONE = new LastRequestType( 0, AuthenticationLevel.NONE.toString() );
040    
041        /**
042         * Constant for the "time of initial ticket" last request type.
043         */
044        public static final LastRequestType TIME_OF_INITIAL_TGT = new LastRequestType( 1, "time of initial ticket" );
045    
046        /**
047         * Constant for the "time of initial request" last request type.
048         */
049        public static final LastRequestType TIME_OF_INITIAL_REQ = new LastRequestType( 2, "time of initial request" );
050    
051        /**
052         * Constant for the "time of newest ticket" last request type.
053         */
054        public static final LastRequestType TIME_OF_NEWEST_TGT = new LastRequestType( 3, "time of newest ticket" );
055    
056        /**
057         * Constant for the "time of last renewal" last request type.
058         */
059        public static final LastRequestType TIME_OF_LAST_RENEWAL = new LastRequestType( 4, "time of last renewal" );
060    
061        /**
062         * Constant for the "time of last request" last request type.
063         */
064        public static final LastRequestType TIME_OF_LAST_REQ = new LastRequestType( 5, "time of last request" );
065    
066        /**
067         * Constant for the "time of password expiration" last request type.
068         */
069        public static final LastRequestType TIME_OF_PASSWORD_EXP = new LastRequestType( 6, "time of password expiration" );
070    
071        /**
072         * Array for building a List of VALUES.
073         */
074        private static final LastRequestType[] values =
075            { NONE, TIME_OF_INITIAL_TGT, TIME_OF_INITIAL_REQ, TIME_OF_NEWEST_TGT, TIME_OF_LAST_RENEWAL, TIME_OF_LAST_REQ,
076                TIME_OF_PASSWORD_EXP };
077    
078        /**
079         * A List of all the last request type constants.
080         */
081        public static final List<LastRequestType> VALUES = Collections.unmodifiableList( Arrays.asList( values ) );
082    
083        /**
084         * The name of the checksum type.
085         */
086        private final String name;
087    
088        /**
089         * The value/code for the checksum type.
090         */
091        private final int ordinal;
092    
093    
094        /**
095         * Private constructor prevents construction outside of this class.
096         */
097        private LastRequestType( int ordinal, String name )
098        {
099            this.ordinal = ordinal;
100            this.name = name;
101        }
102    
103    
104        /**
105         * Returns the last request type when specified by its ordinal.
106         *
107         * @param type
108         * @return The last request type.
109         */
110        public static LastRequestType getTypeByOrdinal( int type )
111        {
112            for ( int ii = 0; ii < values.length; ii++ )
113            {
114                if ( values[ii].ordinal == type )
115                {
116                    return values[ii];
117                }
118            }
119    
120            return NONE;
121        }
122    
123    
124        /**
125         * Returns the number associated with this last request type.
126         *
127         * @return The last request type ordinal.
128         */
129        public int getOrdinal()
130        {
131            return ordinal;
132        }
133    
134    
135        public int compareTo( LastRequestType that )
136        {
137            return ordinal - that.ordinal;
138        }
139    
140    
141        public String toString()
142        {
143            return name + " (" + ordinal + ")";
144        }
145    }