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 */
020package org.apache.directory.api.ldap.codec.search;
021
022
023import java.nio.ByteBuffer;
024
025import org.apache.directory.api.asn1.EncoderException;
026
027
028/**
029 * An abstract Asn1Object used to store the filter. A filter is seen as a tree
030 * with a root. This class does nothing, it's just the root of all the different
031 * filters.
032 * 
033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034 */
035public abstract class Filter
036{
037    /** The identifier of the associated TLV */
038    int tlvId;
039
040    /** The parent TLV id */
041    protected int parentTlvId;
042
043    /** The parent Filter */
044    protected Filter parent;
045
046
047    /**
048     * The constructor.
049     * 
050     * @param tlvId The TLV identifier
051     */
052    public Filter( int tlvId )
053    {
054        this.tlvId = tlvId;
055    }
056
057
058    /**
059     * The constructor.
060     */
061    public Filter()
062    {
063    }
064
065
066    /**
067     * Get the parent
068     * 
069     * @return Returns the parent.
070     */
071    public Filter getParent()
072    {
073        return parent;
074    }
075
076
077    /**
078     * Get the parent
079     * 
080     * @return Returns the parent.
081     */
082    public int getParentTlvId()
083    {
084        return parentTlvId;
085    }
086
087
088    /**
089     * Set the parent
090     * 
091     * @param parent The parent to set.
092     * @param parentTlvId The Parent TLV identifier
093     */
094    public void setParent( Filter parent, int parentTlvId )
095    {
096        this.parent = parent;
097        this.parentTlvId = parentTlvId;
098    }
099
100
101    /**
102     * @return The TLV identifier
103     */
104    public int getTlvId()
105    {
106        return tlvId;
107    }
108
109
110    /**
111     * Compute the Filter length 
112     * 
113     * @return the encoded length
114     */
115    public abstract int computeLength();
116
117
118    /**
119     * Encode the Filter message to a PDU. 
120     * 
121     * @param buffer The buffer where to put the PDU
122     * @return The PDU.
123     * @throws EncoderException If the encoding failed
124     */
125    public abstract ByteBuffer encode( ByteBuffer buffer ) throws EncoderException;
126}