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.shared.ldap.filter; 021 022 023 import org.apache.directory.shared.ldap.entry.Value; 024 025 026 /** 027 * Filter expression tree node for extensible assertions. 028 * 029 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 030 * @version $Revision: 896579 $ 031 */ 032 public class ExtensibleNode extends LeafNode 033 { 034 /** The value of the attribute to match for */ 035 private Value<?> value; 036 037 /** The matching rules id */ 038 private String matchingRuleId; 039 040 /** The name of the dn attributes */ 041 private boolean dnAttributes = false; 042 043 044 /** 045 * Creates a new emptyExtensibleNode object. 046 * 047 * @param attribute the attribute associated with this node 048 */ 049 public ExtensibleNode( String attribute ) 050 { 051 super( attribute, AssertionType.EXTENSIBLE ); 052 053 dnAttributes = false; 054 } 055 056 /** 057 * Creates a new ExtensibleNode object. 058 * 059 * @param attribute the attribute used for the extensible assertion 060 * @param value the value to match for 061 * @param matchingRuleId the OID of the matching rule 062 * @param dnAttributes the dn attributes 063 */ 064 public ExtensibleNode( String attribute, Value<?> value, String matchingRuleId, boolean dnAttributes ) 065 { 066 super( attribute, AssertionType.EXTENSIBLE ); 067 068 this.value = value; 069 this.matchingRuleId = matchingRuleId; 070 this.dnAttributes = dnAttributes; 071 } 072 073 /** 074 * Makes a full clone in new memory space of the current node and children 075 * 076 * @return the clone 077 */ 078 @Override public ExprNode clone() 079 { 080 ExprNode clone = (ExprNode)super.clone(); 081 082 // Copy the value 083 if ( value != null ) 084 { 085 ((ExtensibleNode)clone).value = value.clone(); 086 } 087 088 return clone; 089 } 090 091 /** 092 * Gets the Dn attributes. 093 * 094 * @return the dn attributes 095 */ 096 public boolean hasDnAttributes() 097 { 098 return dnAttributes; 099 } 100 101 102 /** 103 * Set the dnAttributes flag 104 * 105 * @param dnAttributes The flag to set 106 */ 107 public void setDnAttributes( boolean dnAttributes ) 108 { 109 this.dnAttributes = dnAttributes; 110 } 111 112 113 /** 114 * Gets the matching rule id as an OID string. 115 * 116 * @return the OID 117 */ 118 public String getMatchingRuleId() 119 { 120 return matchingRuleId; 121 } 122 123 124 /** 125 * Sets the matching rule id as an OID string. 126 * 127 * @param matchingRuleId The maching rule ID 128 */ 129 public void setMatchingRuleId( String matchingRuleId ) 130 { 131 this.matchingRuleId = matchingRuleId; 132 } 133 134 135 /** 136 * Gets the value. 137 * 138 * @return the value 139 */ 140 public final Value<?> getValue() 141 { 142 return value; 143 } 144 145 146 /** 147 * @return representation of value, escaped for use in a filter if required 148 */ 149 public Value<?> getEscapedValue() 150 { 151 if ( !value.isBinary() ) 152 { 153 return AbstractExprNode.escapeFilterValue( value ); 154 } 155 156 return value; 157 } 158 159 160 /** 161 * Sets the value. 162 * 163 * @param value the value 164 */ 165 public final void setValue( Value<?> value) 166 { 167 this.value = value; 168 } 169 170 171 /** 172 * @see Object#hashCode() 173 * @return the instance's hash code 174 */ 175 public int hashCode() 176 { 177 int h = 37; 178 179 h = h*17 + super.hashCode(); 180 h = h*17 + ( dnAttributes ? 1 : 0 ); 181 h = h*17 + matchingRuleId.hashCode(); 182 h = h*17 + value.hashCode(); 183 184 return h; 185 } 186 187 188 /** 189 * @see java.lang.Object#toString() 190 * @return A string representing the AndNode 191 */ 192 public String toString() 193 { 194 StringBuilder buf = new StringBuilder(); 195 196 buf.append( '(' ).append( getAttribute() ); 197 buf.append( "-" ); 198 buf.append( dnAttributes ); 199 buf.append( "-EXTENSIBLE-" ); 200 buf.append( matchingRuleId ); 201 buf.append( "-" ); 202 buf.append( value ); 203 204 buf.append( super.toString() ); 205 206 buf.append( ')' ); 207 208 return buf.toString(); 209 } 210 }