1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.ldap.codec;
21
22
23 import org.apache.directory.api.i18n.I18n;
24 import org.apache.directory.api.ldap.codec.api.LdapCodecConstants;
25 import org.apache.directory.api.ldap.model.entry.Value;
26 import org.apache.directory.api.util.Strings;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 public class AttributeValueAssertion
44 {
45
46 private String attributeDesc;
47
48
49 private byte[] assertion;
50
51
52
53
54
55
56
57
58 public static String dumpObject( Object object )
59 {
60 if ( object != null )
61 {
62 if ( object instanceof String )
63 {
64 return ( String ) object;
65 }
66 else if ( object instanceof byte[] )
67 {
68 return Strings.dumpBytes( ( byte[] ) object );
69 }
70 else if ( object instanceof Value )
71 {
72 return ( ( Value ) object ).getString();
73 }
74 else
75 {
76 return "<unknown type>";
77 }
78 }
79 else
80 {
81 return "";
82 }
83 }
84
85
86
87
88
89
90
91 public String getAttributeDesc()
92 {
93 return attributeDesc;
94 }
95
96
97
98
99
100
101
102 public void setAttributeDesc( String attributeDesc )
103 {
104 this.attributeDesc = attributeDesc;
105 }
106
107
108
109
110
111
112
113
114 public String toString( String tabs )
115 {
116 StringBuilder sb = new StringBuilder();
117
118 sb.append( tabs ).append( "AttributeValueAssertion\n" );
119 sb.append( tabs ).append( " Assertion description : '" );
120 sb.append( attributeDesc != null ? attributeDesc : "null" );
121 sb.append( "'\n" );
122 sb.append( tabs ).append( " Assertion value : '" ).append( dumpObject( assertion ) ).append( "'\n" );
123
124 return sb.toString();
125 }
126
127
128
129
130
131
132
133
134
135 public String toStringRFC2254( int filterType )
136 {
137 StringBuilder sb = new StringBuilder();
138
139 sb.append( attributeDesc );
140
141 switch ( filterType )
142 {
143 case LdapCodecConstants.EQUALITY_MATCH_FILTER:
144 sb.append( '=' );
145 break;
146
147 case LdapCodecConstants.LESS_OR_EQUAL_FILTER:
148 sb.append( "<=" );
149 break;
150
151 case LdapCodecConstants.GREATER_OR_EQUAL_FILTER:
152 sb.append( ">=" );
153 break;
154
155 case LdapCodecConstants.APPROX_MATCH_FILTER:
156 sb.append( "~=" );
157 break;
158
159 default:
160 throw new IllegalArgumentException( I18n.err( I18n.ERR_05503_UNEXPECTED_FILTER_TYPE, filterType ) );
161 }
162
163 sb.append( dumpObject( assertion ) );
164
165 return sb.toString();
166 }
167
168
169
170
171
172 public byte[] getAssertion()
173 {
174 return assertion;
175 }
176
177
178
179
180
181 public void setAssertion( byte[] assertion )
182 {
183 if ( assertion != null )
184 {
185 this.assertion = new byte[assertion.length];
186 System.arraycopy( assertion, 0, this.assertion, 0, assertion.length );
187 }
188 }
189
190
191
192
193
194
195
196 @Override
197 public String toString()
198 {
199 return toString( "" );
200 }
201 }