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
021package org.apache.directory.server.ntp.messages;
022
023
024/**
025 * Mode: This is a three-bit integer indicating the mode, with values
026 * defined as follows:
027 *
028 *    Mode     Meaning
029 *    ------------------------------------
030 *    0        reserved
031 *    1        symmetric active
032 *    2        symmetric passive
033 *    3        client
034 *    4        server
035 *    5        broadcast
036 *    6        reserved for NTP control message
037 *    7        reserved for private use
038 * 
039 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
040 */
041public enum ModeType
042{
043    /**
044     * Constant for the "Reserved mode" mode type.
045     */
046    RESERVED(0, "Reserved mode."),
047
048    /**
049     * Constant for the "Symmetric active mode" mode type.
050     */
051    SYMMETRIC_ACTIVE(1, "Symmetric active mode."),
052
053    /**
054     * Constant for the "Symmetric passive mode" mode type.
055     */
056    RESERVED_PASSIVE(2, "Symmetric passive mode."),
057
058    /**
059     * Constant for the "Client mode" mode type.
060     */
061    CLIENT(3, "Client mode."),
062
063    /**
064     * Constant for the "Server mode" mode type.
065     */
066    SERVER(4, "Server mode."),
067
068    /**
069     * Constant for the "Broadcast mode" mode type.
070     */
071    BROADCAST(5, "Broadcast mode."),
072
073    /**
074     * Constant for the "Reserved for NTP control message" mode type.
075     */
076    RESERVED_FOR_NTP_CONTROL(6, "Reserved for NTP control message."),
077
078    /**
079     * Constant for the "Reserved for private use" mode type.
080     */
081    RESERVED_FOR_PRIVATE_USE(7, "Reserved for private use.");
082
083    /**
084     * The name of the mode type.
085     */
086    private String name;
087
088    /**
089     * The value/code for the mode type.
090     */
091    private int ordinal;
092
093
094    /**
095     * Private constructor prevents construction outside of this class.
096     */
097    ModeType( int ordinal, String name )
098    {
099        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}