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