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.codec; 021 022 import org.apache.directory.shared.ldap.entry.Value; 023 import org.apache.directory.shared.ldap.util.StringTools; 024 025 026 /** 027 * A class to store an attribute value assertion. 028 * The grammar is : 029 * 030 * AttributeValueAssertion ::= SEQUENCE { 031 * attributeDesc AttributeDescription, 032 * assertionValue AssertionValue } 033 * 034 * AttributeDescription ::= LDAPString 035 * 036 * AssertionValue ::= OCTET STRING 037 * 038 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 039 * @version $Rev: 664290 $, $Date: 2008-06-07 08:28:06 +0200 (Sat, 07 Jun 2008) $, 040 */ 041 public class AttributeValueAssertion 042 { 043 // ~ Instance fields 044 // ---------------------------------------------------------------------------- 045 046 /** The attribute description */ 047 private String attributeDesc; 048 049 /** The assertion value */ 050 private Value<?> assertionValue; 051 052 053 // ~ Methods 054 // ------------------------------------------------------------------------------------ 055 056 /** 057 * Get the assertion value 058 * 059 * @return Returns the assertionValue. 060 */ 061 public Value<?> getAssertionValue() 062 { 063 return assertionValue; 064 } 065 066 067 /** 068 * Set the assertion value 069 * 070 * @param assertionValue The assertionValue to set. 071 */ 072 public void setAssertionValue( Value<?> assertionValue ) 073 { 074 this.assertionValue = assertionValue; 075 } 076 077 078 /** 079 * Get the attribute description 080 * 081 * @return Returns the attributeDesc. 082 */ 083 public String getAttributeDesc() 084 { 085 return attributeDesc; 086 } 087 088 089 /** 090 * Set the attribute description 091 * 092 * @param attributeDesc The attributeDesc to set. 093 */ 094 public void setAttributeDesc( String attributeDesc ) 095 { 096 this.attributeDesc = attributeDesc; 097 } 098 099 100 /** 101 * Get a String representation of an AttributeValueAssertion 102 * 103 * @param tabs The spacing to be put before the string 104 * @return An AttributeValueAssertion String 105 */ 106 public String toString( String tabs ) 107 { 108 StringBuffer sb = new StringBuffer(); 109 110 sb.append( tabs ).append( "AttributeValueAssertion\n" ); 111 sb.append( tabs ).append( " Assertion description : '" ); 112 sb.append( attributeDesc != null ? attributeDesc : "null" ); 113 sb.append( "'\n" ); 114 sb.append( tabs ).append( " Assertion value : '" ).append( StringTools.dumpObject( assertionValue ) ).append( "'\n" ); 115 116 return sb.toString(); 117 } 118 119 120 /** 121 * Get a String representation of an AttributeValueAssertion, as of RFC 122 * 2254. 123 * 124 * @param filterType The filter type 125 * @return An AttributeValueAssertion String 126 */ 127 public String toStringRFC2254( int filterType ) 128 { 129 StringBuffer sb = new StringBuffer(); 130 131 sb.append( attributeDesc ); 132 133 switch ( filterType ) 134 { 135 case LdapConstants.EQUALITY_MATCH_FILTER: 136 sb.append( '=' ); 137 break; 138 139 case LdapConstants.LESS_OR_EQUAL_FILTER: 140 sb.append( "<=" ); 141 break; 142 143 case LdapConstants.GREATER_OR_EQUAL_FILTER: 144 sb.append( ">=" ); 145 break; 146 147 case LdapConstants.APPROX_MATCH_FILTER: 148 sb.append( "~=" ); 149 break; 150 } 151 152 sb.append( StringTools.dumpObject( assertionValue ) ); 153 154 return sb.toString(); 155 } 156 157 158 /** 159 * Get a String representation of an AttributeValueAssertion 160 * 161 * @return An AttributeValueAssertion String 162 */ 163 public String toString() 164 { 165 return toString( "" ); 166 } 167 }