001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020 package org.apache.directory.server.core.interceptor.context;
021
022
023 import org.apache.directory.server.core.CoreSession;
024 import org.apache.directory.shared.ldap.codec.MessageTypeEnum;
025 import org.apache.directory.shared.ldap.codec.controls.ManageDsaITControl;
026 import org.apache.directory.shared.ldap.entry.BinaryValue;
027 import org.apache.directory.shared.ldap.entry.Value;
028 import org.apache.directory.shared.ldap.message.internal.InternalCompareRequest;
029 import org.apache.directory.shared.ldap.name.DN;
030 import org.apache.directory.shared.ldap.util.StringTools;
031
032
033 /**
034 * A Compare context used for Interceptors. It contains all the informations
035 * needed for the compare operation, and used by all the interceptors
036 *
037 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
038 * @version $Rev$, $Date$
039 */
040 public class CompareOperationContext extends AbstractOperationContext
041 {
042 /** The entry OID */
043 private String oid;
044
045 /** The value to be compared */
046 private Value<?> value;
047
048
049 /**
050 *
051 * Creates a new instance of CompareOperationContext.
052 *
053 */
054 public CompareOperationContext( CoreSession session )
055 {
056 super( session );
057 }
058
059
060 /**
061 *
062 * Creates a new instance of CompareOperationContext.
063 *
064 */
065 public CompareOperationContext( CoreSession session, DN dn )
066 {
067 super( session, dn );
068 }
069
070
071 /**
072 *
073 * Creates a new instance of LookupOperationContext.
074 *
075 */
076 public CompareOperationContext( CoreSession session, String oid )
077 {
078 super( session );
079 this.oid = oid;
080 }
081
082
083 /**
084 *
085 * Creates a new instance of LookupOperationContext.
086 *
087 */
088 public CompareOperationContext( CoreSession session, DN dn, String oid )
089 {
090 super( session, dn );
091 this.oid = oid;
092 }
093
094
095 /**
096 *
097 * Creates a new instance of LookupOperationContext.
098 *
099 */
100 public CompareOperationContext( CoreSession session, DN dn, String oid, Value<?> value )
101 {
102 super( session, dn );
103 this.oid = oid;
104 this.value = value;
105 }
106
107
108 public CompareOperationContext( CoreSession session, InternalCompareRequest compareRequest )
109 {
110 super( session, compareRequest.getName() );
111 this.oid = compareRequest.getAttributeId();
112 this.value = compareRequest.getAssertionValue();
113 this.requestControls = compareRequest.getControls();
114
115 if ( requestControls.containsKey( ManageDsaITControl.CONTROL_OID ) )
116 {
117 ignoreReferral();
118 }
119 else
120 {
121 throwReferral();
122 }
123 }
124
125
126 /**
127 * @return The compared OID
128 */
129 public String getOid()
130 {
131 return oid;
132 }
133
134
135 /**
136 * Set the compared OID
137 * @param oid The compared OID
138 */
139 public void setOid( String oid )
140 {
141 this.oid = oid;
142 }
143
144
145 /**
146 * @return The value to compare
147 */
148 public Value<?> getValue()
149 {
150 return value;
151 }
152
153
154 /**
155 * Set the value to compare
156 * @param value The value to compare
157 */
158 public void setValue( Value<?> value )
159 {
160 this.value = value;
161 }
162
163
164 /**
165 * @return the operation name
166 */
167 public String getName()
168 {
169 return MessageTypeEnum.COMPARE_REQUEST.name();
170 }
171
172
173 /**
174 * @see Object#toString()
175 */
176 public String toString()
177 {
178 return "CompareContext for DN '" + getDn().getName() + "'" +
179 ( ( oid != null ) ? ", oid : <" + oid + ">" : "" ) +
180 ( ( value != null ) ? ", value :'" +
181 ( ( !value.isBinary() ) ?
182 value.getString() :
183 ( ( value.isBinary() ) ?
184 StringTools.dumpBytes( ((BinaryValue)value).getReference() ) :
185 "unknown value type" ) )
186 + "'"
187 : "" );
188 }
189 }