View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  
21  package org.apache.directory.server.ntp.messages;
22  
23  
24  /**
25   * Mode: This is a three-bit integer indicating the mode, with values
26   * defined as follows:
27   *
28   *    Mode     Meaning
29   *    ------------------------------------
30   *    0        reserved
31   *    1        symmetric active
32   *    2        symmetric passive
33   *    3        client
34   *    4        server
35   *    5        broadcast
36   *    6        reserved for NTP control message
37   *    7        reserved for private use
38   * 
39   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
40   */
41  public enum ModeType
42  {
43      /**
44       * Constant for the "Reserved mode" mode type.
45       */
46      RESERVED(0, "Reserved mode."),
47  
48      /**
49       * Constant for the "Symmetric active mode" mode type.
50       */
51      SYMMETRIC_ACTIVE(1, "Symmetric active mode."),
52  
53      /**
54       * Constant for the "Symmetric passive mode" mode type.
55       */
56      RESERVED_PASSIVE(2, "Symmetric passive mode."),
57  
58      /**
59       * Constant for the "Client mode" mode type.
60       */
61      CLIENT(3, "Client mode."),
62  
63      /**
64       * Constant for the "Server mode" mode type.
65       */
66      SERVER(4, "Server mode."),
67  
68      /**
69       * Constant for the "Broadcast mode" mode type.
70       */
71      BROADCAST(5, "Broadcast mode."),
72  
73      /**
74       * Constant for the "Reserved for NTP control message" mode type.
75       */
76      RESERVED_FOR_NTP_CONTROL(6, "Reserved for NTP control message."),
77  
78      /**
79       * Constant for the "Reserved for private use" mode type.
80       */
81      RESERVED_FOR_PRIVATE_USE(7, "Reserved for private use.");
82  
83      /**
84       * The name of the mode type.
85       */
86      private String name;
87  
88      /**
89       * The value/code for the mode type.
90       */
91      private int ordinal;
92  
93  
94      /**
95       * Private constructor prevents construction outside of this class.
96       */
97      ModeType( int ordinal, String name )
98      {
99          this.ordinal = ordinal;
100         this.name = name;
101     }
102 
103 
104     /**
105      * Returns the mode type when specified by its ordinal.
106      *
107      * @param type
108      * @return The mode type.
109      */
110     public static ModeType getTypeByOrdinal( int type )
111     {
112         for ( ModeType mt : ModeType.values() )
113         {
114             if ( type == mt.getOrdinal() )
115             {
116                 return mt;
117             }
118         }
119 
120         return SERVER;
121     }
122 
123 
124     /**
125      * Returns the number associated with this mode type.
126      *
127      * @return The mode type ordinal.
128      */
129     public int getOrdinal()
130     {
131         return ordinal;
132     }
133 
134 
135     /**
136      * {@inheritDoc}
137      */
138     @Override
139     public String toString()
140     {
141         return name;
142     }
143 }