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.shared.ldap.model.message.controls; 021 022 023import org.apache.directory.shared.ldap.model.message.Control; 024import org.apache.directory.shared.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 * Creates a Control with a specific OID. 043 * 044 * @param oid The OID of this Control. 045 */ 046 public OpaqueControl( String oid ) 047 { 048 super( oid ); 049 } 050 051 052 /** 053 * Creates a Control with a specific OID, and criticality set. 054 * 055 * @param oid The OID of this Control. 056 * @param criticality true if this Control is critical, false otherwise. 057 */ 058 public OpaqueControl( String oid, boolean criticality ) 059 { 060 super( oid, criticality); 061 } 062 063 064 /** 065 * @return The encoded value 066 */ 067 public byte[] getEncodedValue() 068 { 069 return value; 070 } 071 072 073 /** 074 * Stores an opaque value into the control. 075 * 076 * @param value The opaque value to store 077 */ 078 public void setEncodedValue( byte[] value ) 079 { 080 this.value = Strings.copy( value ); 081 } 082 083 084 /** 085 * Tells if the control has a stored value. Note that if the 086 * control has an empty value, this method will return true. 087 * 088 * @return true if the control has a value 089 */ 090 public boolean hasEncodedValue() 091 { 092 return value != null; 093 } 094}