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.entry;
21  
22  
23  import java.io.Externalizable;
24  
25  import org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException;
26  import org.apache.directory.api.ldap.model.schema.AttributeType;
27  import org.apache.directory.api.ldap.model.schema.SyntaxChecker;
28  
29  
30  /**
31   * A interface for wrapping attribute values stored into an EntryAttribute. These
32   * values can be a String or a byte[].
33   *
34   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
35   */
36  public interface Value<T> extends Cloneable, Externalizable, Comparable<Value<T>>
37  {
38      /** Two flags used to tell if the value is HR or not in serialization */
39      static final boolean STRING = true;
40      static final boolean BINARY = false;
41  
42  
43      /**
44       * Clone a Value
45       * 
46       * @return A cloned value
47       */
48      Value<T> clone();
49  
50  
51      /**
52       * Check if the contained value is null or not
53       * 
54       * @return <code>true</code> if the inner value is null.
55       */
56      boolean isNull();
57  
58  
59      /**
60       * Get the associated AttributeType
61       * 
62       * @return The AttributeType
63       */
64      AttributeType getAttributeType();
65  
66  
67      /**
68       * Check if the value is stored into an instance of the given
69       * AttributeType, or one of its ascendant.
70       * 
71       * For instance, if the Value is associated with a CommonName,
72       * checking for Name will match.
73       * 
74       * @param attributeType The AttributeType we are looking at
75       * @return <code>true</code> if the value is associated with the given
76       * attributeType or one of its ascendant
77       */
78      boolean isInstanceOf( AttributeType attributeType );
79  
80  
81      /**
82       * Get the wrapped value. It will return a copy, not a reference.
83       *
84       * @return a copy of the wrapped value
85       */
86      T getValue();
87  
88  
89      /**
90       * Get the wrapped value as a byte[]. If the original value
91       * is binary, this method will return a copy of the wrapped byte[]
92       *
93       * @return the wrapped value as a byte[]
94       */
95      byte[] getBytes();
96  
97  
98      /**
99       * Get the wrapped value as a String. If the original value
100      * is binary, this method will return the value as if it was
101      * an UTF-8 encoded String.
102      *
103      * @return the wrapped value as a String
104      */
105     String getString();
106 
107 
108     /**
109      * Gets a reference to the wrapped value.
110      * 
111      * Warning ! The value is not copied !!!
112      *
113      * @return a direct handle on the value that is wrapped
114      */
115     T getReference();
116 
117 
118     /**
119      * Tells if the value is schema aware or not.
120      *
121      * @return <code>true</code> if the value is sxhema aware
122      */
123     boolean isSchemaAware();
124 
125 
126     /**
127      * Uses the syntaxChecker associated with the attributeType to check if the
128      * value is valid.
129      * 
130      * @param checker the SyntaxChecker to use to validate the value
131      * @return <code>true</code> if the value is valid
132      * @exception LdapInvalidAttributeValueException if the value cannot be validated
133      */
134     boolean isValid( SyntaxChecker checker ) throws LdapInvalidAttributeValueException;
135 
136 
137     /**
138      * Gets the normalized (canonical) representation for the wrapped string.
139      * If the wrapped String is null, null is returned, otherwise the normalized
140      * form is returned.  If the normalizedValue is null, then this method
141      * will attempt to generate it from the wrapped value.
142      *
143      * @return gets the normalized value
144      */
145     T getNormValue();
146 
147 
148     /**
149      * Gets a reference to the the normalized (canonical) representation
150      * for the wrapped value.
151      *
152      * @return gets a reference to the normalized value
153      */
154     T getNormReference();
155 
156 
157     /**
158      * Tells if the current value is Human Readable
159      * 
160      * @return <code>true</code> if the value is a String, <code>false</code> otherwise
161      */
162     boolean isHumanReadable();
163 
164 
165     /**
166      * @return The length of the interned value
167      */
168     int length();
169 }