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