001 /*
002 * Copyright 2008-2013 UnboundID Corp.
003 * All Rights Reserved.
004 */
005 /*
006 * Copyright (C) 2008-2013 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 import com.unboundid.util.Extensible;
028 import com.unboundid.util.ThreadSafety;
029 import com.unboundid.util.ThreadSafetyLevel;
030
031 import static com.unboundid.util.Debug.*;
032
033
034
035 /**
036 * This class provides a common matching rule framework that may be extended by
037 * matching rule implementations in which equality, ordering, and substring
038 * matching can all be made based on byte-for-byte comparisons of the normalized
039 * value, and any value is acceptable.
040 */
041 @Extensible()
042 @ThreadSafety(level=ThreadSafetyLevel.INTERFACE_THREADSAFE)
043 public abstract class AcceptAllSimpleMatchingRule
044 extends SimpleMatchingRule
045 {
046 /**
047 * The serial version UID for this serializable class.
048 */
049 private static final long serialVersionUID = -7450007924568660003L;
050
051
052
053 /**
054 * {@inheritDoc}
055 */
056 @Override()
057 public boolean valuesMatch(final ASN1OctetString value1,
058 final ASN1OctetString value2)
059 {
060 return normalize(value1).equals(normalize(value2));
061 }
062
063
064
065 /**
066 * {@inheritDoc}
067 */
068 @Override()
069 public boolean matchesSubstring(final ASN1OctetString value,
070 final ASN1OctetString subInitial,
071 final ASN1OctetString[] subAny,
072 final ASN1OctetString subFinal)
073 {
074 try
075 {
076 return super.matchesSubstring(value, subInitial, subAny, subFinal);
077 }
078 catch (LDAPException le)
079 {
080 debugException(le);
081
082 // This should never happen, as the only reason the superclass version of
083 // this method will throw an exception is if an exception is thrown by
084 // normalize or normalizeSubstring.
085 return false;
086 }
087 }
088
089
090
091 /**
092 * {@inheritDoc}
093 */
094 @Override()
095 public int compareValues(final ASN1OctetString value1,
096 final ASN1OctetString value2)
097 {
098 try
099 {
100 return super.compareValues(value1, value2);
101 }
102 catch (LDAPException le)
103 {
104 debugException(le);
105
106 // This should never happen, as the only reason the superclass version of
107 // this method will throw an exception is if an exception is thrown by
108 // normalize or normalizeSubstring.
109 return 0;
110 }
111 }
112
113
114
115 /**
116 * {@inheritDoc} This variant of the {@code normalize} method is not allowed
117 * to throw exceptions.
118 */
119 @Override()
120 public abstract ASN1OctetString normalize(final ASN1OctetString value);
121
122
123
124 /**
125 * {@inheritDoc} This variant of the {@code normalizeSubstring} method is not
126 * allowed to throw exceptions.
127 */
128 @Override()
129 public abstract ASN1OctetString normalizeSubstring(
130 final ASN1OctetString value,
131 final byte substringType);
132 }