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