View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    https://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.api.ldap.model.filter;
21  
22  
23  import org.apache.directory.api.i18n.I18n;
24  import org.apache.directory.api.ldap.model.entry.Value;
25  import org.apache.directory.api.ldap.model.exception.LdapSchemaException;
26  import org.apache.directory.api.ldap.model.schema.AttributeType;
27  
28  
29  /**
30   * A assertion value node for LessOrEqual.
31   * 
32   * @param <T> The Value type
33   * 
34   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
35   */
36  public class LessEqNode<T> extends SimpleNode<T>
37  {
38      /**
39       * Creates a new LessEqNode object.
40       * 
41       * @param attributeType the attributeType
42       * @param value the value to test for
43       * @throws LdapSchemaException If the AttributeType does not have an ORDERING MatchingRule
44       */
45      public LessEqNode( AttributeType attributeType, Value value ) throws LdapSchemaException
46      {
47          super( attributeType, value, AssertionType.LESSEQ );
48          
49          // Check if the AttributeType has an Ordering MR
50          if ( ( attributeType != null ) && ( attributeType.getOrdering() == null ) )
51          {
52              throw new LdapSchemaException( I18n.err( I18n.ERR_13301_NO_ORDERING_MR_FOR_AT, attributeType.getName() ) );
53          }
54      }
55  
56  
57      /**
58       * Creates a new LessEqNode object.
59       * 
60       * @param attribute the attribute name
61       * @param value the value to test for
62       * @throws LdapSchemaException If the AttributeType does not have an ORDERING MatchingRule
63       */
64      public LessEqNode( String attribute, byte[] value ) throws LdapSchemaException
65      {
66          super( attribute, value, AssertionType.LESSEQ );
67  
68          // Check if the AttributeType has an Ordering MR
69          if ( ( attributeType != null ) && ( attributeType.getOrdering() == null ) )
70          {
71              throw new LdapSchemaException( I18n.err( I18n.ERR_13301_NO_ORDERING_MR_FOR_AT, attributeType.getName() ) );
72          }
73      }
74  
75  
76      /**
77       * Creates a new LessEqNode object.
78       * 
79       * @param attribute the attribute name
80       * @param value the value to test for
81       * @throws LdapSchemaException If the AttributeType does not have an ORDERING MatchingRule
82       */
83      public LessEqNode( String attribute, String value ) throws LdapSchemaException
84      {
85          super( attribute, value, AssertionType.LESSEQ );
86  
87          // Check if the AttributeType has an Ordering MR
88          if ( ( attributeType != null ) && ( attributeType.getOrdering() == null ) )
89          {
90              throw new LdapSchemaException( I18n.err( I18n.ERR_13301_NO_ORDERING_MR_FOR_AT, attributeType.getName() ) );
91          }
92      }
93  
94  
95      /**
96       * @see Object#toString()
97       * @return A string representing the AndNode
98       */
99      @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 }