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.model.message.controls;
021
022
023/**
024 * A persistence search object
025 * 
026 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
027 */
028public class PersistentSearchImpl extends AbstractControl implements PersistentSearch
029{
030
031    /**
032     * If changesOnly is TRUE, the server MUST NOT return any existing entries
033     * that match the search criteria. Entries are only returned when they are
034     * changed (added, modified, deleted, or subject to a modifyDN operation).
035     */
036    private boolean changesOnly = true;
037
038    /**
039     * If returnECs is TRUE, the server MUST return an Entry Change Notification
040     * control with each entry returned as the result of changes.
041     */
042    private boolean returnECs = false;
043
044    /**
045     * As changes are made to the server, the effected entries MUST be returned
046     * to the client if they match the standard search criteria and if the
047     * operation that caused the change is included in the changeTypes field.
048     * The changeTypes field is the logical OR of one or more of these values:
049     * add    (1),
050     * delete (2),
051     * modify (4),
052     * modDN  (8).
053     */
054    private int changeTypes = CHANGE_TYPES_MAX;
055
056
057    /**
058     * Default constructor
059     *
060     */
061    public PersistentSearchImpl()
062    {
063        super( OID );
064    }
065
066
067    /**
068     * {@inheritDoc}
069     */
070    @Override
071    public void setChangesOnly( boolean changesOnly )
072    {
073        this.changesOnly = changesOnly;
074    }
075
076
077    /**
078     * {@inheritDoc}
079     */
080    @Override
081    public boolean isChangesOnly()
082    {
083        return changesOnly;
084    }
085
086
087    /**
088     * {@inheritDoc}
089     */
090    @Override
091    public void setReturnECs( boolean returnECs )
092    {
093        this.returnECs = returnECs;
094    }
095
096
097    /**
098     * {@inheritDoc}
099     */
100    @Override
101    public boolean isReturnECs()
102    {
103        return returnECs;
104    }
105
106
107    /**
108     * {@inheritDoc}
109     */
110    @Override
111    public void setChangeTypes( int changeTypes )
112    {
113        this.changeTypes = changeTypes;
114    }
115
116
117    /**
118     * {@inheritDoc}
119     */
120    @Override
121    public int getChangeTypes()
122    {
123        return changeTypes;
124    }
125
126
127    /**
128     * {@inheritDoc}
129     */
130    @Override
131    public boolean isNotificationEnabled( ChangeType changeType )
132    {
133        return ( changeType.getValue() & changeTypes ) > 0;
134    }
135
136
137    /**
138     * {@inheritDoc}
139     */
140    @Override
141    public void enableNotification( ChangeType changeType )
142    {
143        changeTypes |= changeType.getValue();
144    }
145
146
147    /**
148     * {@inheritDoc}
149     */
150    @Override
151    public void disableNotification( ChangeType changeType )
152    {
153        changeTypes &= ~changeType.getValue();
154    }
155
156
157    /**
158     * Return a String representing this PSearchControl.
159     */
160    @Override
161    public String toString()
162    {
163        StringBuilder sb = new StringBuilder();
164
165        sb.append( "    Persistant Search Control\n" );
166        sb.append( "        oid : " ).append( getOid() ).append( '\n' );
167        sb.append( "        critical : " ).append( isCritical() ).append( '\n' );
168        sb.append( "        changeTypes : '" ).append( changeTypes ).append( "'\n" );
169        sb.append( "        changesOnly : '" ).append( changesOnly ).append( "'\n" );
170        sb.append( "        returnECs   : '" ).append( returnECs ).append( "'\n" );
171
172        return sb.toString();
173    }
174}