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 */
020package org.apache.directory.api.ldap.extras.extended.storedProcedure;
021
022
023import org.apache.directory.api.util.Strings;
024
025
026/**
027 * Bean for representing a Stored Procedure Parameter
028 * 
029 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
030 */
031public class StoredProcedureParameter
032{
033    /** the type of the parameter */
034    private byte[] type;
035
036    /** the value of the parameter */
037    private byte[] value;
038
039
040    /**
041     * Gets the type as a UTF8 String.
042     *
043     * @return The type as a UTF8 String.
044     */
045    public String getTypeString()
046    {
047        return Strings.utf8ToString( type );
048    }
049
050
051    /**
052     * Gets the value as a UTF8 String.
053     *
054     * @return The value as a UTF8 String.
055     */
056    public String getValueString()
057    {
058        return Strings.utf8ToString( value );
059    }
060
061
062    /**
063     * Gets the type as a byte[].
064     *
065     * @return The type as a byte[].
066     */
067    public byte[] getType()
068    {
069        if ( type == null )
070        {
071            return null;
072        }
073
074        final byte[] copy = new byte[type.length];
075        System.arraycopy( type, 0, copy, 0, type.length );
076        return copy;
077    }
078
079
080    /**
081     * Sets the type.
082     * 
083     * @param type The type as a byte[].
084     */
085    public void setType( byte[] type )
086    {
087        if ( type != null )
088        {
089            this.type = new byte[type.length];
090            System.arraycopy( type, 0, this.type, 0, type.length );
091        }
092        else
093        {
094            this.type = null;
095        }
096    }
097
098
099    /**
100     * Gets the value as a byte[].
101     *
102     * @return The value as a byte[].
103     */
104    public byte[] getValue()
105    {
106        if ( value == null )
107        {
108            return null;
109        }
110
111        final byte[] copy = new byte[value.length];
112        System.arraycopy( value, 0, copy, 0, value.length );
113        return copy;
114    }
115
116
117    /**
118     * Sets the value.
119     * 
120     * @param value The value as a byte[].
121     */
122    public void setValue( byte[] value )
123    {
124        if ( value != null )
125        {
126            this.value = new byte[value.length];
127            System.arraycopy( value, 0, this.value, 0, value.length );
128        }
129        else
130        {
131            this.value = null;
132        }
133    }
134}