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