1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *
19 */
20 package org.apache.directory.server.core.interceptor.context;
21
22
23 import org.apache.directory.server.core.CoreSession;
24 import org.apache.directory.shared.ldap.message.CompareRequest;
25 import org.apache.directory.shared.ldap.message.MessageTypeEnum;
26 import org.apache.directory.shared.ldap.name.LdapDN;
27 import org.apache.directory.shared.ldap.util.StringTools;
28
29
30 /**
31 * A Compare context used for Interceptors. It contains all the informations
32 * needed for the compare operation, and used by all the interceptors
33 *
34 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
35 * @version $Rev$, $Date$
36 */
37 public class CompareOperationContext extends AbstractOperationContext
38 {
39 /** The entry OID */
40 private String oid;
41
42 /** The value to be compared */
43 private Object value;
44
45
46 /**
47 *
48 * Creates a new instance of CompareOperationContext.
49 *
50 */
51 public CompareOperationContext( CoreSession session )
52 {
53 super( session );
54 }
55
56
57 /**
58 *
59 * Creates a new instance of CompareOperationContext.
60 *
61 */
62 public CompareOperationContext( CoreSession session, LdapDN dn )
63 {
64 super( session, dn );
65 }
66
67
68 /**
69 *
70 * Creates a new instance of LookupOperationContext.
71 *
72 */
73 public CompareOperationContext( CoreSession session, String oid )
74 {
75 super( session );
76 this.oid = oid;
77 }
78
79
80 /**
81 *
82 * Creates a new instance of LookupOperationContext.
83 *
84 */
85 public CompareOperationContext( CoreSession session, LdapDN dn, String oid )
86 {
87 super( session, dn );
88 this.oid = oid;
89 }
90
91
92 /**
93 *
94 * Creates a new instance of LookupOperationContext.
95 *
96 */
97 public CompareOperationContext( CoreSession session, LdapDN dn, String oid, Object value )
98 {
99 super( session, dn );
100 this.oid = oid;
101 this.value = value;
102 }
103
104
105 public CompareOperationContext( CoreSession session, CompareRequest compareRequest )
106 {
107 super( session, compareRequest.getName() );
108 this.oid = compareRequest.getAttributeId();
109 this.value = compareRequest.getAssertionValue();
110 this.requestControls = compareRequest.getControls();
111 }
112
113
114 /**
115 * @return The compared OID
116 */
117 public String getOid()
118 {
119 return oid;
120 }
121
122
123 /**
124 * Set the compared OID
125 * @param oid The compared OID
126 */
127 public void setOid( String oid )
128 {
129 this.oid = oid;
130 }
131
132
133 /**
134 * @return The value to compare
135 */
136 public Object getValue()
137 {
138 return value;
139 }
140
141
142 /**
143 * Set the value to compare
144 * @param value The value to compare
145 */
146 public void setValue( Object value )
147 {
148 this.value = value;
149 }
150
151
152 /**
153 * @return the operation name
154 */
155 public String getName()
156 {
157 return MessageTypeEnum.COMPARE_REQUEST.name();
158 }
159
160
161 /**
162 * @see Object#toString()
163 */
164 public String toString()
165 {
166 return "CompareContext for DN '" + getDn().getUpName() + "'" +
167 ( ( oid != null ) ? ", oid : <" + oid + ">" : "" ) +
168 ( ( value != null ) ? ", value :'" +
169 ( ( value instanceof String ) ?
170 value :
171 ( ( value instanceof byte[] ) ?
172 StringTools.dumpBytes( (byte[])value ) :
173 "unknown value type" ) )
174 + "'"
175 : "" );
176 }
177 }