View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    * 
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   * 
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License.
18   * 
19   */
20  package org.apache.directory.api.ldap.model.message.controls;
21  
22  
23  import org.apache.directory.api.ldap.model.message.Control;
24  import org.apache.directory.api.util.Strings;
25  
26  
27  /**
28   * A final {@link Control} implementation intended specifically for handling
29   * controls who's values cannot be encoded or decoded by the codec service.
30   * This situation results when no Control factory is found to be
31   * registered for this control's OID. Hence additional opaque value handling
32   * methods are included to manage the opaque control value.
33   * 
34   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
35   */
36  public final class OpaqueControl extends AbstractControl implements Control
37  {
38      /** The opaque encoded value */
39      private byte[] value;
40  
41  
42      /**
43       * Creates a Control with a specific OID.
44       *
45       * @param oid The OID of this Control.
46       */
47      public OpaqueControl( String oid )
48      {
49          super( oid );
50      }
51  
52  
53      /**
54       * Creates a Control with a specific OID, and criticality set.
55       *
56       * @param oid The OID of this Control.
57       * @param criticality true if this Control is critical, false otherwise.
58       */
59      public OpaqueControl( String oid, boolean criticality )
60      {
61          super( oid, criticality );
62      }
63  
64  
65      /**
66       * @return The encoded value
67       */
68      public byte[] getEncodedValue()
69      {
70          return value;
71      }
72  
73  
74      /**
75       * Stores an opaque value into the control.
76       * 
77       * @param value The opaque value to store
78       */
79      public void setEncodedValue( byte[] value )
80      {
81          this.value = Strings.copy( value );
82      }
83  
84  
85      /**
86       * Tells if the control has a stored value. Note that if the
87       * control has an empty value, this method will return true.
88       * 
89       * @return true if the control has a value
90       */
91      public boolean hasEncodedValue()
92      {
93          return value != null;
94      }
95  }