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 /** 024 * Abstract base class for leaf nodes within the expression filter tree. 025 * 026 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 027 * @version $Rev: 746607 $ 028 */ 029 public class LeafNode extends AbstractExprNode 030 { 031 /** attribute on which this leaf is based */ 032 private String attribute; 033 034 035 /** 036 * Creates a leaf node. 037 * 038 * @param attribute the attribute this node is based on 039 * @param assertionType the type of this leaf node 040 */ 041 protected LeafNode( String attribute, AssertionType assertionType ) 042 { 043 super( assertionType ); 044 this.attribute = attribute; 045 } 046 047 /** 048 * Makes a full clone in new memory space of the current node and children 049 * 050 * @return the clone 051 */ 052 @Override public ExprNode clone() 053 { 054 return super.clone(); 055 } 056 057 058 /** 059 * Gets whether this node is a leaf - the answer is always true here. 060 * 061 * @return true always 062 */ 063 public final boolean isLeaf() 064 { 065 return true; 066 } 067 068 069 /** 070 * Gets the attribute this leaf node is based on. 071 * 072 * @return the attribute asserted 073 */ 074 public final String getAttribute() 075 { 076 return attribute; 077 } 078 079 080 /** 081 * Sets the attribute this leaf node is based on. 082 * 083 * @param attribute the attribute that is asserted by this filter node 084 */ 085 public void setAttribute( String attribute ) 086 { 087 this.attribute = attribute; 088 } 089 090 091 /** 092 * @see org.apache.directory.shared.ldap.filter.ExprNode#accept( 093 * org.apache.directory.shared.ldap.filter.FilterVisitor) 094 * 095 * @param visitor the filter expression tree structure visitor 096 * @return The modified element 097 */ 098 public final Object accept( FilterVisitor visitor ) 099 { 100 if ( visitor.canVisit( this ) ) 101 { 102 return visitor.visit( this ); 103 } 104 else 105 { 106 return null; 107 } 108 } 109 110 111 /** 112 * @see Object#hashCode() 113 * @return the instance's hash code 114 */ 115 public int hashCode() 116 { 117 int h = 37; 118 119 h = h*17 + super.hashCode(); 120 h = h*17 + attribute.hashCode(); 121 122 return h; 123 } 124 125 126 /* 127 * (non-Javadoc) 128 * 129 * @see java.lang.Object#equals(java.lang.Object) 130 */ 131 public boolean equals( Object other ) 132 { 133 if ( this == other ) 134 { 135 return true; 136 } 137 138 if ( !( other instanceof LeafNode ) ) 139 { 140 return false; 141 } 142 143 //noinspection SimplifiableIfStatement 144 if ( other.getClass() != this.getClass() ) 145 { 146 return false; 147 } 148 149 return attribute.equals( ( ( LeafNode ) other ).getAttribute() ); 150 } 151 }