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  import java.util.Arrays;
25  import java.util.Collections;
26  import java.util.List;
27  
28  
29  /**
30   * Reference Identifier: This is a 32-bit bitstring identifying the
31   * particular reference source. In the case of NTP Version 3 or Version
32   * 4 stratum-0 (unspecified) or stratum-1 (primary) servers, this is a
33   * four-character ASCII string, left justified and zero padded to 32
34   * bits. In NTP Version 3 secondary servers, this is the 32-bit IPv4
35   * address of the reference source. In NTP Version 4 secondary servers,
36   * this is the low order 32 bits of the latest transmit timestamp of the
37   * reference source. NTP primary (stratum 1) servers should set this
38   * field to a code identifying the external reference source according
39   * to the following list. If the external reference is one of those
40   * listed, the associated code should be used. Codes for sources not
41   * listed can be contrived as appropriate.
42   * 
43   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
44   * @version $Rev: 586763 $, $Date: 2007-10-20 19:26:29 +0200 (Sa, 20 Okt 2007) $
45   */
46  public class ReferenceIdentifier implements Comparable<ReferenceIdentifier>
47  {
48      /**
49       * Constant for the "INIT" reference identifier type.
50       */
51      public static final ReferenceIdentifier INIT = new ReferenceIdentifier( 0, "INIT", "initializing" );
52  
53      /**
54       * Constant for the "LOCL" reference identifier type.
55       */
56      public static final ReferenceIdentifier LOCL = new ReferenceIdentifier( 1, "LOCL", "uncalibrated local clock" );
57  
58      /**
59       * Constant for the "PPL" reference identifier type.
60       */
61      public static final ReferenceIdentifier PPS = new ReferenceIdentifier( 2, "PPL", "pulse-per-second source" );
62  
63      /**
64       * Constant for the "ACTS" reference identifier type.
65       */
66      public static final ReferenceIdentifier ACTS = new ReferenceIdentifier( 3, "ACTS", "NIST dialup modem service" );
67  
68      /**
69       * Constant for the "USNO" reference identifier type.
70       */
71      public static final ReferenceIdentifier USNO = new ReferenceIdentifier( 4, "USNO", "USNO modem service" );
72  
73      /**
74       * Constant for the "PTB" reference identifier type.
75       */
76      public static final ReferenceIdentifier PTB = new ReferenceIdentifier( 5, "PTB", "PTB (Germany) modem service" );
77  
78      /**
79       * Constant for the "TDF" reference identifier type.
80       */
81      public static final ReferenceIdentifier TDF = new ReferenceIdentifier( 6, "TDF", "Allouis (France) Radio 164 kHz" );
82  
83      /**
84       * Constant for the "DCF" reference identifier type.
85       */
86      public static final ReferenceIdentifier DCF = new ReferenceIdentifier( 7, "DCF",
87          "Mainflingen (Germany) Radio 77.5 kHz" );
88  
89      /**
90       * Constant for the "MSF" reference identifier type.
91       */
92      public static final ReferenceIdentifier MSF = new ReferenceIdentifier( 8, "MSF", "Rugby (UK) Radio 60 kHz" );
93  
94      /**
95       * Constant for the "WWV" reference identifier type.
96       */
97      public static final ReferenceIdentifier WWV = new ReferenceIdentifier( 9, "WWV",
98          "Ft. Collins (US) Radio 2.5, 5, 10, 15, 20 MHz" );
99  
100     /**
101      * Constant for the "WWVB" reference identifier type.
102      */
103     public static final ReferenceIdentifier WWVB = new ReferenceIdentifier( 10, "WWVB", "Boulder (US) Radio 60 kHz" );
104 
105     /**
106      * Constant for the "WWVH" reference identifier type.
107      */
108     public static final ReferenceIdentifier WWVH = new ReferenceIdentifier( 11, "WWVH",
109         "Kaui Hawaii (US) Radio 2.5, 5, 10, 15 MHz" );
110 
111     /**
112      * Constant for the "CHU" reference identifier type.
113      */
114     public static final ReferenceIdentifier CHU = new ReferenceIdentifier( 12, "CHU",
115         "Ottawa (Canada) Radio 3330, 7335, 14670 kHz" );
116 
117     /**
118      * Constant for the "LORC" reference identifier type.
119      */
120     public static final ReferenceIdentifier LORC = new ReferenceIdentifier( 13, "LORC",
121         "LORAN-C radionavigation system" );
122 
123     /**
124      * Constant for the "OMEG" reference identifier type.
125      */
126     public static final ReferenceIdentifier OMEG = new ReferenceIdentifier( 14, "OMEG", "OMEGA radionavigation system" );
127 
128     /**
129      * Constant for the "GPS" reference identifier type.
130      */
131     public static final ReferenceIdentifier GPS = new ReferenceIdentifier( 15, "GPS", "Global Positioning Service" );
132 
133     /**
134      * Constant for the "GOES" reference identifier type.
135      */
136     public static final ReferenceIdentifier GOES = new ReferenceIdentifier( 16, "GOES",
137         "Geostationary Orbit Environment Satellite" );
138 
139     /**
140      * Constant for the "CDMA" reference identifier type.
141      */
142     public static final ReferenceIdentifier CDMA = new ReferenceIdentifier( 17, "CDMA",
143         "CDMA mobile cellular/PCS telephone system" );
144 
145     /**
146      * Array for building a List of VALUES.
147      */
148     private static final ReferenceIdentifier[] values =
149         { INIT, LOCL, PPS, ACTS, USNO, PTB, TDF, DCF, MSF, WWV, WWVB, WWVH, CHU, LORC, OMEG, GPS, GOES, CDMA };
150 
151     /**
152      * A list of all the reference identifier type constants.
153      */
154     public static final List<ReferenceIdentifier> VALUES = Collections.unmodifiableList( Arrays.asList( values ) );
155 
156     /**
157      * The value/code for the reference identifier type.
158      */
159     private final int ordinal;
160 
161     /**
162      * The name of the reference identifier type.
163      */
164     private final String name;
165 
166     /**
167      * The code of the reference identifier type.
168      */
169     private final String code;
170 
171 
172     /**
173      * Private constructor prevents construction outside of this class.
174      */
175     private ReferenceIdentifier( int ordinal, String code, String name )
176     {
177         this.ordinal = ordinal;
178         this.code = code;
179         this.name = name;
180     }
181 
182 
183     /**
184      * Returns the reference identifier type when specified by its ordinal.
185      *
186      * @param type
187      * @return The reference identifier type.
188      */
189     public static ReferenceIdentifier getTypeByOrdinal( int type )
190     {
191         for ( int ii = 0; ii < values.length; ii++ )
192         {
193             if ( values[ii].ordinal == type )
194             {
195                 return values[ii];
196             }
197         }
198 
199         return LOCL;
200     }
201 
202 
203     /**
204      * Returns the reference identifier type when specified by its name.
205      *
206      * @param type
207      * @return The reference identifier type.
208      */
209     public static ReferenceIdentifier getTypeByName( String type )
210     {
211         for ( int ii = 0; ii < values.length; ii++ )
212         {
213             if ( values[ii].code.equalsIgnoreCase( type ) )
214             {
215                 return values[ii];
216             }
217         }
218 
219         return LOCL;
220     }
221 
222 
223     /**
224      * Returns the code associated with this reference identifier type.
225      *
226      * @return The reference identifier type code.
227      */
228     public String getCode()
229     {
230         return code;
231     }
232 
233 
234     /**
235      * Returns the number associated with this reference identifier type.
236      *
237      * @return The reference identifier type ordinal.
238      */
239     public int getOrdinal()
240     {
241         return ordinal;
242     }
243 
244 
245     public int compareTo( ReferenceIdentifier that )
246     {
247         return ordinal - that.ordinal;
248     }
249 
250 
251     public String toString()
252     {
253         return name;
254     }
255 }