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