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 021 package org.apache.directory.server.ntp.messages; 022 023 024 import java.util.Arrays; 025 import java.util.Collections; 026 import java.util.List; 027 028 029 /** 030 * Reference Identifier: This is a 32-bit bitstring identifying the 031 * particular reference source. In the case of NTP Version 3 or Version 032 * 4 stratum-0 (unspecified) or stratum-1 (primary) servers, this is a 033 * four-character ASCII string, left justified and zero padded to 32 034 * bits. In NTP Version 3 secondary servers, this is the 32-bit IPv4 035 * address of the reference source. In NTP Version 4 secondary servers, 036 * this is the low order 32 bits of the latest transmit timestamp of the 037 * reference source. NTP primary (stratum 1) servers should set this 038 * field to a code identifying the external reference source according 039 * to the following list. If the external reference is one of those 040 * listed, the associated code should be used. Codes for sources not 041 * listed can be contrived as appropriate. 042 * 043 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 044 * @version $Rev: 586763 $, $Date: 2007-10-20 19:26:29 +0200 (Sat, 20 Oct 2007) $ 045 */ 046 public class ReferenceIdentifier implements Comparable<ReferenceIdentifier> 047 { 048 /** 049 * Constant for the "INIT" reference identifier type. 050 */ 051 public static final ReferenceIdentifier INIT = new ReferenceIdentifier( 0, "INIT", "initializing" ); 052 053 /** 054 * Constant for the "LOCL" reference identifier type. 055 */ 056 public static final ReferenceIdentifier LOCL = new ReferenceIdentifier( 1, "LOCL", "uncalibrated local clock" ); 057 058 /** 059 * Constant for the "PPL" reference identifier type. 060 */ 061 public static final ReferenceIdentifier PPS = new ReferenceIdentifier( 2, "PPL", "pulse-per-second source" ); 062 063 /** 064 * Constant for the "ACTS" reference identifier type. 065 */ 066 public static final ReferenceIdentifier ACTS = new ReferenceIdentifier( 3, "ACTS", "NIST dialup modem service" ); 067 068 /** 069 * Constant for the "USNO" reference identifier type. 070 */ 071 public static final ReferenceIdentifier USNO = new ReferenceIdentifier( 4, "USNO", "USNO modem service" ); 072 073 /** 074 * Constant for the "PTB" reference identifier type. 075 */ 076 public static final ReferenceIdentifier PTB = new ReferenceIdentifier( 5, "PTB", "PTB (Germany) modem service" ); 077 078 /** 079 * Constant for the "TDF" reference identifier type. 080 */ 081 public static final ReferenceIdentifier TDF = new ReferenceIdentifier( 6, "TDF", "Allouis (France) Radio 164 kHz" ); 082 083 /** 084 * Constant for the "DCF" reference identifier type. 085 */ 086 public static final ReferenceIdentifier DCF = new ReferenceIdentifier( 7, "DCF", 087 "Mainflingen (Germany) Radio 77.5 kHz" ); 088 089 /** 090 * Constant for the "MSF" reference identifier type. 091 */ 092 public static final ReferenceIdentifier MSF = new ReferenceIdentifier( 8, "MSF", "Rugby (UK) Radio 60 kHz" ); 093 094 /** 095 * Constant for the "WWV" reference identifier type. 096 */ 097 public static final ReferenceIdentifier WWV = new ReferenceIdentifier( 9, "WWV", 098 "Ft. Collins (US) Radio 2.5, 5, 10, 15, 20 MHz" ); 099 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 }