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 * https://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 */ 020package org.apache.directory.api.ldap.model.filter; 021 022 023import org.apache.directory.api.i18n.I18n; 024import org.apache.directory.api.ldap.model.entry.Value; 025import org.apache.directory.api.ldap.model.exception.LdapSchemaException; 026import org.apache.directory.api.ldap.model.schema.AttributeType; 027 028 029/** 030 * A assertion value node for LessOrEqual. 031 * 032 * @param <T> The Value type 033 * 034 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 035 */ 036public class LessEqNode<T> extends SimpleNode<T> 037{ 038 /** 039 * Creates a new LessEqNode object. 040 * 041 * @param attributeType the attributeType 042 * @param value the value to test for 043 * @throws LdapSchemaException If the AttributeType does not have an ORDERING MatchingRule 044 */ 045 public LessEqNode( AttributeType attributeType, Value value ) throws LdapSchemaException 046 { 047 super( attributeType, value, AssertionType.LESSEQ ); 048 049 // Check if the AttributeType has an Ordering MR 050 if ( ( attributeType != null ) && ( attributeType.getOrdering() == null ) ) 051 { 052 throw new LdapSchemaException( I18n.err( I18n.ERR_13301_NO_ORDERING_MR_FOR_AT, attributeType.getName() ) ); 053 } 054 } 055 056 057 /** 058 * Creates a new LessEqNode object. 059 * 060 * @param attribute the attribute name 061 * @param value the value to test for 062 * @throws LdapSchemaException If the AttributeType does not have an ORDERING MatchingRule 063 */ 064 public LessEqNode( String attribute, byte[] value ) throws LdapSchemaException 065 { 066 super( attribute, value, AssertionType.LESSEQ ); 067 068 // Check if the AttributeType has an Ordering MR 069 if ( ( attributeType != null ) && ( attributeType.getOrdering() == null ) ) 070 { 071 throw new LdapSchemaException( I18n.err( I18n.ERR_13301_NO_ORDERING_MR_FOR_AT, attributeType.getName() ) ); 072 } 073 } 074 075 076 /** 077 * Creates a new LessEqNode object. 078 * 079 * @param attribute the attribute name 080 * @param value the value to test for 081 * @throws LdapSchemaException If the AttributeType does not have an ORDERING MatchingRule 082 */ 083 public LessEqNode( String attribute, String value ) throws LdapSchemaException 084 { 085 super( attribute, value, AssertionType.LESSEQ ); 086 087 // Check if the AttributeType has an Ordering MR 088 if ( ( attributeType != null ) && ( attributeType.getOrdering() == null ) ) 089 { 090 throw new LdapSchemaException( I18n.err( I18n.ERR_13301_NO_ORDERING_MR_FOR_AT, attributeType.getName() ) ); 091 } 092 } 093 094 095 /** 096 * @see Object#toString() 097 * @return A string representing the AndNode 098 */ 099 @Override 100 public String toString() 101 { 102 StringBuilder buf = new StringBuilder(); 103 104 buf.append( '(' ); 105 106 if ( attributeType != null ) 107 { 108 buf.append( attributeType.getName() ); 109 } 110 else 111 { 112 buf.append( attribute ); 113 } 114 115 buf.append( "<=" ); 116 117 String escapedValue = getEscapedValue(); 118 119 if ( escapedValue != null ) 120 { 121 buf.append( escapedValue ); 122 } 123 124 buf.append( super.toString() ); 125 126 buf.append( ')' ); 127 128 return buf.toString(); 129 } 130}