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 import java.io.UnsupportedEncodingException;
025
026 import org.apache.directory.server.i18n.I18n;
027
028
029 /**
030 * The Dynamic Host Configuration Protocol (DHCP) provides a framework for
031 * passing configuration information to hosts on a TCP/IP network. Configuration
032 * parameters and other control information are carried in tagged data items
033 * that are stored in the 'options' field of the DHCP message. The data items
034 * themselves are also called "options."
035 *
036 * This abstract base class is for options
037 * that carry a string.
038 *
039 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
040 * @version $Rev: 551805 $, $Date: 2007-06-29 00:57:04 -0500 (Fr, 29 Jun 2007) $
041 */
042 public abstract class StringOption extends DhcpOption
043 {
044 private String string;
045
046
047 /*
048 * @see org.apache.directory.server.dhcp.options.DhcpOption#setData(byte[])
049 */
050 public void setData( byte[] data )
051 {
052 try
053 {
054 string = new String( data, "ASCII" );
055 }
056 catch ( UnsupportedEncodingException e )
057 {
058 // should not happen
059 throw new RuntimeException( I18n.err( I18n.ERR_642 ) );
060 }
061 }
062
063
064 /*
065 * @see org.apache.directory.server.dhcp.options.DhcpOption#getData()
066 */
067 public byte[] getData()
068 {
069 if ( null == string )
070 return new byte[]
071 {};
072
073 try
074 {
075 return string.getBytes( "ASCII" );
076 }
077 catch ( UnsupportedEncodingException e )
078 {
079 // should not happen
080 throw new RuntimeException( I18n.err( I18n.ERR_642 ) );
081 }
082 }
083
084
085 public String getString()
086 {
087 return string;
088 }
089
090
091 public void setString( String string )
092 {
093 this.string = string;
094 }
095 }