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     */
020    package org.apache.directory.shared.ldap.message.control.replication;
021    
022    
023    import org.apache.directory.shared.asn1.codec.EncoderException;
024    import org.apache.directory.shared.ldap.codec.controls.replication.syncDoneValue.SyncDoneValueControlCodec;
025    import org.apache.directory.shared.ldap.message.control.InternalAbstractControl;
026    import org.slf4j.Logger;
027    import org.slf4j.LoggerFactory;
028    
029    
030    /**
031     * 
032     * An implementation of syncDoneValue Contol as described in rfc 4533.
033     * The structure of this control is:
034     * 
035     *  syncDoneValue ::= SEQUENCE 
036     *  {
037     *       cookie          syncCookie OPTIONAL,
038     *       refreshDeletes  BOOLEAN DEFAULT FALSE
039     *  }
040     * 
041     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
042     * @version $Rev$, $Date$
043     */
044    public class SyncDoneValueControl extends InternalAbstractControl
045    {
046        /** As this class is serializable, defined its serialVersionUID */
047        private static final long serialVersionUID = 1L;
048    
049        /** The Logger for this class */
050        private static final Logger LOG = LoggerFactory.getLogger( SyncRequestValueControl.class );
051    
052        /** This control OID */
053        public static final String CONTROL_OID = "1.3.6.1.4.1.4203.1.9.1.3";
054    
055        /** The cookie */
056        private byte[] cookie;
057    
058        /** the refreshDeletes flag */
059        private boolean refreshDeletes;
060    
061    
062        /**
063         * @return the cookie
064         */
065        public byte[] getCookie()
066        {
067            return cookie;
068        }
069    
070    
071        /**
072         * @param cookie cookie to be set
073         */
074        public void setCookie( byte[] cookie )
075        {
076            this.cookie = cookie;
077        }
078    
079    
080        /**
081         * @return true, if refreshDeletes flag is set, false otherwise
082         */
083        public boolean isRefreshDeletes()
084        {
085            return refreshDeletes;
086        }
087    
088    
089        /**
090         * @param refreshDeletes set the refreshDeletes flag 
091         */
092        public void setRefreshDeletes( boolean refreshDeletes )
093        {
094            this.refreshDeletes = refreshDeletes;
095        }
096    
097    
098        /**
099         * {@inheritDoc}
100         */
101        @Override
102        public String getID()
103        {
104            return CONTROL_OID;
105        }
106    
107    
108        /**
109         * {@inheritDoc}
110         */
111        public byte[] getEncodedValue()
112        {
113            SyncDoneValueControlCodec codec = new SyncDoneValueControlCodec();
114            codec.setCookie( cookie );
115            codec.setRefreshDeletes( refreshDeletes );
116    
117            try
118            {
119                return codec.encode( null ).array();
120            }
121            catch ( EncoderException e )
122            {
123                LOG.error( "Failed to encode syncDoneValue control", e );
124                throw new IllegalStateException( "Failed to encode control with encoder.", e );
125            }
126        }
127    
128    }