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.dhcp.options;
022    
023    /**
024     * The Dynamic Host Configuration Protocol (DHCP) provides a framework for
025     * passing configuration information to hosts on a TCP/IP network. Configuration
026     * parameters and other control information are carried in tagged data items
027     * that are stored in the 'options' field of the DHCP message. The data items
028     * themselves are also called "options."
029     * 
030     * This abstract base class is for options that carry an unsigned short value
031     * (16 bit).
032     *  
033     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034     * @version $Rev: 551805 $, $Date: 2007-06-29 00:57:04 -0500 (Fr, 29 Jun 2007) $
035     * 
036     */
037    public abstract class ByteOption extends DhcpOption {
038        /**
039         * The byte value (represented as a short because of the unsignedness).
040         */
041        private short byteValue;
042    
043        /*
044         * @see org.apache.directory.server.dhcp.options.DhcpOption#setData(byte[])
045         */
046        public void setData(byte[] data) {
047            byteValue = (short) (data[0] & 0xff);
048        }
049    
050        /*
051         * @see org.apache.directory.server.dhcp.options.DhcpOption#getData()
052         */
053        public byte[] getData() {
054            return new byte[]{(byte) (byteValue & 0xff)};
055        }
056    
057        public short getByteValue() {
058            return byteValue;
059        }
060    
061        public void setShortValue(short shortValue) {
062            this.byteValue = shortValue;
063        }
064    }