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