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