001 /* 002 * Copyright 2008-2015 UnboundID Corp. 003 * All Rights Reserved. 004 */ 005 /* 006 * Copyright (C) 2008-2015 UnboundID Corp. 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (GPLv2 only) 010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 011 * as published by the Free Software Foundation. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with this program; if not, see <http://www.gnu.org/licenses>. 020 */ 021 package com.unboundid.ldap.matchingrules; 022 023 024 025 import com.unboundid.asn1.ASN1OctetString; 026 import com.unboundid.ldap.sdk.LDAPException; 027 028 import static com.unboundid.util.Debug.*; 029 030 031 032 /** 033 * This class provides a common matching rule framework that may be extended by 034 * matching rule implementations in which equality, ordering, and substring 035 * matching can all be made based on byte-for-byte comparisons of the normalized 036 * value, and any value is acceptable. 037 */ 038 public abstract class AcceptAllSimpleMatchingRule 039 extends SimpleMatchingRule 040 { 041 /** 042 * The serial version UID for this serializable class. 043 */ 044 private static final long serialVersionUID = -7450007924568660003L; 045 046 047 048 /** 049 * {@inheritDoc} 050 */ 051 @Override() 052 public boolean valuesMatch(final ASN1OctetString value1, 053 final ASN1OctetString value2) 054 { 055 return normalize(value1).equals(normalize(value2)); 056 } 057 058 059 060 /** 061 * {@inheritDoc} 062 */ 063 @Override() 064 public boolean matchesSubstring(final ASN1OctetString value, 065 final ASN1OctetString subInitial, 066 final ASN1OctetString[] subAny, 067 final ASN1OctetString subFinal) 068 { 069 try 070 { 071 return super.matchesSubstring(value, subInitial, subAny, subFinal); 072 } 073 catch (LDAPException le) 074 { 075 debugException(le); 076 077 // This should never happen, as the only reason the superclass version of 078 // this method will throw an exception is if an exception is thrown by 079 // normalize or normalizeSubstring. 080 return false; 081 } 082 } 083 084 085 086 /** 087 * {@inheritDoc} 088 */ 089 @Override() 090 public int compareValues(final ASN1OctetString value1, 091 final ASN1OctetString value2) 092 { 093 try 094 { 095 return super.compareValues(value1, value2); 096 } 097 catch (LDAPException le) 098 { 099 debugException(le); 100 101 // This should never happen, as the only reason the superclass version of 102 // this method will throw an exception is if an exception is thrown by 103 // normalize or normalizeSubstring. 104 return 0; 105 } 106 } 107 108 109 110 /** 111 * {@inheritDoc} This variant of the {@code normalize} method is not allowed 112 * to throw exceptions. 113 */ 114 @Override() 115 public abstract ASN1OctetString normalize(final ASN1OctetString value); 116 117 118 119 /** 120 * {@inheritDoc} This variant of the {@code normalizeSubstring} method is not 121 * allowed to throw exceptions. 122 */ 123 @Override() 124 public abstract ASN1OctetString normalizeSubstring( 125 final ASN1OctetString value, 126 final byte substringType); 127 }