Author: erodriguez Date: Sun Jan 9 03:18:51 2005 New Revision: 124726 URL: http://svn.apache.org/viewcvs?view=rev&rev=124726 Log: Typesafe enumerators used by DNS messages. Added: incubator/directory/dns/trunk/core/src/java/org/apache/dns/messages/value/MessageType.java incubator/directory/dns/trunk/core/src/java/org/apache/dns/messages/value/OpCode.java (contents, props changed) incubator/directory/dns/trunk/core/src/java/org/apache/dns/messages/value/ResponseCode.java (contents, props changed)
Added: incubator/directory/dns/trunk/core/src/java/org/apache/dns/messages/value/MessageType.java Url: http://svn.apache.org/viewcvs/incubator/directory/dns/trunk/core/src/java/org/apache/dns/messages/value/MessageType.java?view=auto&rev=124726 ============================================================================== --- (empty file) +++ incubator/directory/dns/trunk/core/src/java/org/apache/dns/messages/value/MessageType.java Sun Jan 9 03:18:51 2005 @@ -0,0 +1,77 @@ +/* + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.dns.messages.value; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + + +public final class MessageType implements Comparable +{ + /** + * Enumeration elements are constructed once upon class loading. + * Order of appearance here determines the order of compareTo. + */ + public static final MessageType QUERY = new MessageType( 0, "Query" ); + public static final MessageType RESPONSE = new MessageType( 1, "Response" ); + + public String toString() + { + return name; + } + + public int compareTo( Object that ) + { + return ordinal - ( (MessageType) that ).ordinal; + } + + public static MessageType getTypeByOrdinal( int type ) + { + for ( int ii = 0; ii < values.length; ii++ ) + if ( values[ ii ].ordinal == type ) + return values[ ii ]; + return QUERY; + } + + public int getOrdinal() + { + return ordinal; + } + + /// PRIVATE ///// + private final String name; + private final int ordinal; + + /** + * Private constructor prevents construction outside of this class. + */ + private MessageType( int ordinal, String name ) + { + this.ordinal = ordinal; + this.name = name; + } + + /** + * These two lines are all that's necessary to export a List of VALUES. + */ + private static final MessageType[] values = { QUERY, RESPONSE }; + // VALUES needs to be located here, otherwise illegal forward reference + public static final List VALUES = Collections.unmodifiableList( Arrays.asList( values ) ); +} + Added: incubator/directory/dns/trunk/core/src/java/org/apache/dns/messages/value/OpCode.java Url: http://svn.apache.org/viewcvs/incubator/directory/dns/trunk/core/src/java/org/apache/dns/messages/value/OpCode.java?view=auto&rev=124726 ============================================================================== --- (empty file) +++ incubator/directory/dns/trunk/core/src/java/org/apache/dns/messages/value/OpCode.java Sun Jan 9 03:18:51 2005 @@ -0,0 +1,80 @@ +/* + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.dns.messages.value; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + + +public final class OpCode implements Comparable +{ + /** + * Enumeration elements are constructed once upon class loading. + * Order of appearance here determines the order of compareTo. + */ + public static final OpCode QUERY = new OpCode( 0, "Standard query" ); + public static final OpCode IQUERY = new OpCode( 1, "Inverse query" ); + public static final OpCode STATUS = new OpCode( 2, "Server status request" ); + public static final OpCode NOTIFY = new OpCode( 4, "Zone transfer notification" ); + public static final OpCode UPDATE = new OpCode( 5, "Dynamic update message" ); + + public String toString() + { + return name; + } + + public int compareTo( Object that ) + { + return ordinal - ( (OpCode) that ).ordinal; + } + + public static OpCode getTypeByOrdinal( int type ) + { + for ( int ii = 0; ii < values.length; ii++ ) + if ( values[ ii ].ordinal == type ) + return values[ ii ]; + return QUERY; + } + + public int getOrdinal() + { + return ordinal; + } + + /// PRIVATE ///// + private final String name; + private final int ordinal; + + /** + * Private constructor prevents construction outside of this class. + */ + private OpCode( int ordinal, String name ) + { + this.ordinal = ordinal; + this.name = name; + } + + /** + * These two lines are all that's necessary to export a List of VALUES. + */ + private static final OpCode[] values = { QUERY, IQUERY, STATUS, NOTIFY, UPDATE }; + // VALUES needs to be located here, otherwise illegal forward reference + public static final List VALUES = Collections.unmodifiableList( Arrays.asList( values ) ); +} + Added: incubator/directory/dns/trunk/core/src/java/org/apache/dns/messages/value/ResponseCode.java Url: http://svn.apache.org/viewcvs/incubator/directory/dns/trunk/core/src/java/org/apache/dns/messages/value/ResponseCode.java?view=auto&rev=124726 ============================================================================== --- (empty file) +++ incubator/directory/dns/trunk/core/src/java/org/apache/dns/messages/value/ResponseCode.java Sun Jan 9 03:18:51 2005 @@ -0,0 +1,82 @@ +/* + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.dns.messages.value; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + + +public final class ResponseCode implements Comparable +{ + /** + * Enumeration elements are constructed once upon class loading. + * Order of appearance here determines the order of compareTo. + */ + public static final ResponseCode NO_ERROR = new ResponseCode( 0, "No error condition." ); + public static final ResponseCode FORMAT_ERROR = new ResponseCode( 1, "The name server was unable to interpret the query." ); + public static final ResponseCode SERVER_FAILURE = new ResponseCode( 2, "The name server was unable to process this query due to a problem with the name server." ); + public static final ResponseCode NAME_ERROR = new ResponseCode( 3, "The domain name referenced in the query does not exist." ); + public static final ResponseCode NOT_IMPLEMENTED = new ResponseCode( 4, "The name server does not support the requested kind of query." ); + public static final ResponseCode REFUSED = new ResponseCode( 5, "The name server refuses to perform the specified operation for policy reasons." ); + + public String toString() + { + return name; + } + + public int compareTo( Object that ) + { + return ordinal - ( (ResponseCode) that ).ordinal; + } + + public static ResponseCode getTypeByOrdinal( int type ) + { + for ( int ii = 0; ii < values.length; ii++ ) + if ( values[ ii ].ordinal == type ) + return values[ ii ]; + return NO_ERROR; + } + + public int getOrdinal() + { + return ordinal; + } + + /// PRIVATE ///// + private final String name; + private final int ordinal; + + /** + * Private constructor prevents construction outside of this class. + */ + private ResponseCode( int ordinal, String name ) + { + this.ordinal = ordinal; + this.name = name; + } + + /** + * These two lines are all that's necessary to export a List of VALUES. + */ + private static final ResponseCode[] values = { NO_ERROR, FORMAT_ERROR, SERVER_FAILURE, + NAME_ERROR, NOT_IMPLEMENTED, REFUSED }; + // VALUES needs to be located here, otherwise illegal forward reference + public static final List VALUES = Collections.unmodifiableList( Arrays.asList( values ) ); +} +
