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.components;
021
022
023 import java.util.Arrays;
024 import java.util.Collections;
025 import java.util.List;
026
027
028 /**
029 * Type-safe enumerator for message component types.
030 *
031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
032 * @version $Rev: 557095 $, $Date: 2007-07-18 03:28:32 +0300 (Wed, 18 Jul 2007) $
033 */
034 public class MessageComponentType implements Comparable<MessageComponentType>
035 {
036 /**
037 * Constant for the "null" message component type.
038 */
039 public static final MessageComponentType NULL = new MessageComponentType( 0, "null" );
040
041 /**
042 * Constant for the "ticket" message component type.
043 */
044 public static final MessageComponentType KRB_TKT = new MessageComponentType( 1, "ticket" );
045
046 /**
047 * Constant for the "authenticator" message component type.
048 */
049 public static final MessageComponentType KRB_AUTHENTICATOR = new MessageComponentType( 2, "authenticator" );
050
051 /**
052 * Constant for the "encrypted ticket part" message component type.
053 */
054 public static final MessageComponentType KRB_ENC_TKT_PART = new MessageComponentType( 3, "encrypted ticket part" );
055
056 /**
057 * Constant for the "encrypted initial authentication part" message component type.
058 */
059 public static final MessageComponentType KRB_ENC_AS_REP_PART = new MessageComponentType( 25,
060 "encrypted initial authentication part" );
061
062 /**
063 * Constant for the "encrypted TGS request part" message component type.
064 */
065 public static final MessageComponentType KRB_ENC_TGS_REP_PART = new MessageComponentType( 26,
066 "encrypted TGS request part" );
067
068 /**
069 * Constant for the "encrypted application request part" message component type.
070 */
071 public static final MessageComponentType KRB_ENC_AP_REP_PART = new MessageComponentType( 27,
072 "encrypted application request part" );
073
074 /**
075 * Constant for the "encrypted application message part" message component type.
076 */
077 public static final MessageComponentType KRB_ENC_KRB_PRIV_PART = new MessageComponentType( 28,
078 "encrypted application message part" );
079
080 /**
081 * Constant for the "encrypted credentials forward part" message component type.
082 */
083 public static final MessageComponentType KRB_ENC_KRB_CRED_PART = new MessageComponentType( 29,
084 "encrypted credentials forward part" );
085
086 /**
087 * Array for building a List of VALUES.
088 */
089 private static final MessageComponentType[] values =
090 { NULL, KRB_TKT, KRB_AUTHENTICATOR, KRB_ENC_TKT_PART, KRB_ENC_AS_REP_PART, KRB_ENC_TGS_REP_PART,
091 KRB_ENC_AP_REP_PART, KRB_ENC_KRB_PRIV_PART, KRB_ENC_KRB_CRED_PART };
092
093 /**
094 * A List of all the message component type constants.
095 */
096 public static final List<MessageComponentType> VALUES = Collections.unmodifiableList( Arrays.asList( values ) );
097
098 /**
099 * The name of the message component type.
100 */
101 private final String name;
102
103 /**
104 * The value/code for the message component type.
105 */
106 private final int ordinal;
107
108
109 /**
110 * Private constructor prevents construction outside of this class.
111 */
112 private MessageComponentType( int ordinal, String name )
113 {
114 this.ordinal = ordinal;
115 this.name = name;
116 }
117
118
119 /**
120 * Returns the message component type when specified by its ordinal.
121 *
122 * @param type
123 * @return The message component type.
124 */
125 public static MessageComponentType getTypeByOrdinal( int type )
126 {
127 for ( int ii = 0; ii < values.length; ii++ )
128 {
129 if ( values[ii].ordinal == type )
130 {
131 return values[ii];
132 }
133 }
134
135 return NULL;
136 }
137
138
139 /**
140 * Returns the number associated with this message component type.
141 *
142 * @return The message component type ordinal.
143 */
144 public int getOrdinal()
145 {
146 return ordinal;
147 }
148
149
150 public int compareTo( MessageComponentType that )
151 {
152 return ordinal - that.ordinal;
153 }
154
155
156 public String toString()
157 {
158 return name + " (" + ordinal + ")";
159 }
160 }