001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2009 Sun Microsystems, Inc.
025 */
026
027package org.forgerock.opendj.ldap;
028
029import java.util.List;
030
031/**
032 * An abstract filter visitor whose default implementation for all
033 * {@code Visitor} methods is to invoke {@link #visitDefaultFilter(Object)}.
034 * <p>
035 * Implementations can override the methods on a case by case behavior.
036 *
037 * @param <R>
038 *            The return type of this visitor's methods. Use
039 *            {@link java.lang.Void} for visitors that do not need to return
040 *            results.
041 * @param <P>
042 *            The type of the additional parameter to this visitor's methods.
043 *            Use {@link java.lang.Void} for visitors that do not need an
044 *            additional parameter.
045 */
046public abstract class AbstractFilterVisitor<R, P> implements FilterVisitor<R, P> {
047
048    /**
049     * Default constructor.
050     */
051    protected AbstractFilterVisitor() {
052        // Nothing to do.
053    }
054
055    /**
056     * {@inheritDoc}
057     * <p>
058     * The default implementation is to call {@link #visitDefaultFilter(Object)}.
059     */
060    public R visitAndFilter(final P p, final List<Filter> subFilters) {
061        return visitDefaultFilter(p);
062    }
063
064    /**
065     * {@inheritDoc}
066     * <p>
067     * The default implementation is to call {@link #visitDefaultFilter(Object)}.
068     */
069    public R visitApproxMatchFilter(final P p, final String attributeDescription,
070            final ByteString assertionValue) {
071        return visitDefaultFilter(p);
072    }
073
074    /**
075     * Visits any filters which are not explicitly handled by other visitor
076     * methods.
077     * <p>
078     * The default implementation of this method is to return {@code null}.
079     *
080     * @param p
081     *            A visitor specified parameter.
082     * @return A visitor specified result.
083     */
084    public R visitDefaultFilter(final P p) {
085        return null;
086    }
087
088    /**
089     * {@inheritDoc}
090     * <p>
091     * The default implementation is to call {@link #visitDefaultFilter(Object)}.
092     */
093    public R visitEqualityMatchFilter(final P p, final String attributeDescription,
094            final ByteString assertionValue) {
095        return visitDefaultFilter(p);
096    }
097
098    /**
099     * {@inheritDoc}
100     * <p>
101     * The default implementation is to call {@link #visitDefaultFilter(Object)}.
102     */
103    public R visitExtensibleMatchFilter(final P p, final String matchingRule,
104            final String attributeDescription, final ByteString assertionValue,
105            final boolean dnAttributes) {
106        return visitDefaultFilter(p);
107    }
108
109    /**
110     * {@inheritDoc}
111     * <p>
112     * The default implementation is to call {@link #visitDefaultFilter(Object)}.
113     */
114    public R visitGreaterOrEqualFilter(final P p, final String attributeDescription,
115            final ByteString assertionValue) {
116        return visitDefaultFilter(p);
117    }
118
119    /**
120     * {@inheritDoc}
121     * <p>
122     * The default implementation is to call {@link #visitDefaultFilter(Object)}.
123     */
124    public R visitLessOrEqualFilter(final P p, final String attributeDescription,
125            final ByteString assertionValue) {
126        return visitDefaultFilter(p);
127    }
128
129    /**
130     * {@inheritDoc}
131     * <p>
132     * The default implementation is to call {@link #visitDefaultFilter(Object)}.
133     */
134    public R visitNotFilter(final P p, final Filter subFilter) {
135        return visitDefaultFilter(p);
136    }
137
138    /**
139     * {@inheritDoc}
140     * <p>
141     * The default implementation is to call {@link #visitDefaultFilter(Object)}.
142     */
143    public R visitOrFilter(final P p, final List<Filter> subFilters) {
144        return visitDefaultFilter(p);
145    }
146
147    /**
148     * {@inheritDoc}
149     * <p>
150     * The default implementation is to call {@link #visitDefaultFilter(Object)}.
151     */
152    public R visitPresentFilter(final P p, final String attributeDescription) {
153        return visitDefaultFilter(p);
154    }
155
156    /**
157     * {@inheritDoc}
158     * <p>
159     * The default implementation is to call {@link #visitDefaultFilter(Object)}.
160     */
161    public R visitSubstringsFilter(final P p, final String attributeDescription,
162            final ByteString initialSubstring, final List<ByteString> anySubstrings,
163            final ByteString finalSubstring) {
164        return visitDefaultFilter(p);
165    }
166
167    /**
168     * {@inheritDoc}
169     * <p>
170     * The default implementation is to call {@link #visitDefaultFilter(Object)}.
171     */
172    public R visitUnrecognizedFilter(final P p, final byte filterTag, final ByteString filterBytes) {
173        return visitDefaultFilter(p);
174    }
175}