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.model.message.controls;
021
022
023import org.apache.directory.api.ldap.model.message.Control;
024import org.apache.directory.api.util.Strings;
025
026
027/**
028 * A final {@link Control} implementation intended specifically for handling
029 * controls who's values cannot be encoded or decoded by the codec service.
030 * This situation results when no Control factory is found to be
031 * registered for this control's OID. Hence additional opaque value handling
032 * methods are included to manage the opaque control value.
033 * 
034 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
035 */
036public final class OpaqueControl extends AbstractControl implements Control
037{
038    /** The opaque encoded value */
039    private byte[] value;
040
041
042    /**
043     * Creates a Control with a specific OID.
044     *
045     * @param oid The OID of this Control.
046     */
047    public OpaqueControl( String oid )
048    {
049        super( oid );
050    }
051
052
053    /**
054     * Creates a Control with a specific OID, and criticality set.
055     *
056     * @param oid The OID of this Control.
057     * @param criticality true if this Control is critical, false otherwise.
058     */
059    public OpaqueControl( String oid, boolean criticality )
060    {
061        super( oid, criticality );
062    }
063
064
065    /**
066     * @return The encoded value
067     */
068    public byte[] getEncodedValue()
069    {
070        return value;
071    }
072
073
074    /**
075     * Stores an opaque value into the control.
076     * 
077     * @param value The opaque value to store
078     */
079    public void setEncodedValue( byte[] value )
080    {
081        this.value = Strings.copy( value );
082    }
083
084
085    /**
086     * Tells if the control has a stored value. Note that if the
087     * control has an empty value, this method will return true.
088     * 
089     * @return true if the control has a value
090     */
091    public boolean hasEncodedValue()
092    {
093        return value != null;
094    }
095}