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 import org.apache.directory.shared.i18n.I18n; 023 024 025 /** 026 * Node used for the application of arbitrary predicates on return candidates. 027 * Applies dynamic and programatic criteria for the selection of candidates for 028 * return. Nodes of this type may be introduced into the filter expression to 029 * provided the opportunity to constrain the search further without altering the 030 * search algorithm. 031 * 032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 033 * @version $Revision: 912436 $ 034 */ 035 public abstract class AssertionNode extends AbstractExprNode 036 { 037 /** The assertion or predicate to apply */ 038 private final Assertion assertion; 039 040 /** Description of assertion for polish printouts */ 041 private final String desc; 042 043 044 // ------------------------------------------------------------------------ 045 // C O N S T R U C T O R S 046 // ------------------------------------------------------------------------ 047 048 049 /** 050 * Creates an AssertionNode using an arbitrary candidate assertion. 051 * 052 * @param assertion the arbitrary selection logic. 053 */ 054 public AssertionNode( Assertion assertion ) 055 { 056 this( assertion, "ASSERTION" ); 057 } 058 059 060 /** 061 * Creates an AssertionNode using an arbitrary candidate assertion with a 062 * descriptions used for filter AST walker dumps. 063 * 064 * @param assertion the arbitrary selection logic. 065 * @param desc the printout representation for filter prints. 066 */ 067 public AssertionNode( Assertion assertion, String desc ) 068 { 069 super( AssertionType.ASSERTION ); 070 this.desc = desc; 071 this.assertion = assertion; 072 073 /* 074 * We never want this node to ever make it to the point of becoming a 075 * candidate for use in an enumeration so we set the scan count to the 076 * maximum value. 077 */ 078 set( "count", Long.MAX_VALUE ); 079 } 080 081 /** 082 * Makes a full clone in new memory space of the current node and children 083 * 084 * @return the clone 085 */ 086 @Override public ExprNode clone() 087 { 088 return (ExprNode)super.clone(); 089 } 090 091 092 093 /** 094 * Gets the Assertion used by this assertion node. 095 * 096 * @return the assertion used by this node 097 */ 098 public Assertion getAssertion() 099 { 100 return assertion; 101 } 102 103 104 // ------------------------------------------------------------------------ 105 // A B S T R A C T M E T H O D I M P L E M E N T A T I O N S 106 // ------------------------------------------------------------------------ 107 108 109 /** 110 * Always returns true since an AssertionNode has no children. 111 * 112 * @see org.apache.directory.shared.ldap.filter.ExprNode#isLeaf() 113 * @return true if the node is a leaf,false otherwise 114 */ 115 public boolean isLeaf() 116 { 117 return true; 118 } 119 120 121 /** 122 * @see ExprNode#printRefinementToBuffer(StringBuilder) 123 */ 124 public StringBuilder printRefinementToBuffer( StringBuilder buf ) throws UnsupportedOperationException 125 { 126 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04145 ) ); 127 } 128 129 130 /** 131 * @see Object#hashCode() 132 * @return the instance's hash code 133 */ 134 public int hashCode() 135 { 136 int h = 37; 137 138 h = h*17 + super.hashCode(); 139 h = h*17 + ( assertion != null ? assertion.hashCode() : 0 ); 140 h = h*17 + ( desc != null ? desc.hashCode() : 0 ); 141 142 return h; 143 } 144 145 146 /** 147 * @see org.apache.directory.shared.ldap.filter.ExprNode#accept( 148 * org.apache.directory.shared.ldap.filter.FilterVisitor) 149 */ 150 public Object accept( FilterVisitor visitor ) 151 { 152 return visitor.visit( this ); 153 } 154 155 156 /** 157 * @see Object#toString 158 * @return A string representing the AndNode 159 */ 160 public String toString() 161 { 162 StringBuilder buf = new StringBuilder(); 163 164 buf.append( "(@" ); 165 buf.append( desc ); 166 buf.append( super.toString() ); 167 buf.append( ')' ); 168 169 return buf.toString(); 170 } 171 }