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    import java.util.ArrayList;
023    import java.util.List;
024    
025    import org.apache.directory.shared.asn1.codec.EncoderException;
026    import org.apache.directory.shared.ldap.codec.controls.replication.syncInfoValue.SyncInfoValueControlCodec;
027    import org.apache.directory.shared.ldap.message.control.InternalAbstractControl;
028    import org.slf4j.Logger;
029    import org.slf4j.LoggerFactory;
030    
031    /**
032     * This class implement the SyncInfoValue interface, and represent the forth
033     * choice : syncIdSet.
034     * The structure for this control is :
035     * 
036     * syncInfoValue ::= CHOICE {
037     *     ...
038     *     syncIdSet      [3] SEQUENCE {
039     *         cookie         syncCookie OPTIONAL,
040     *         refreshDeletes BOOLEAN DEFAULT FALSE,
041     *         syncUUIDs      SET OF syncUUID
042     *     }
043     * }
044     *
045     * @see <a href="http://www.faqs.org/rfcs/rfc4533.html">RFC 4533</a>
046     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
047     * @version $Rev: $
048     *
049     */
050    public class SyncInfoValueSyncIdSetControl extends InternalAbstractControl implements SyncInfoValueControl 
051    {
052        /** As this class is serializable, defined its serialVersionUID */ 
053        private static final long serialVersionUID = 1L;
054    
055        /** The Logger for this class */
056        private static final Logger LOG = LoggerFactory.getLogger( SyncInfoValueSyncIdSetControl.class );
057    
058        /** The cookie */
059        private byte[] cookie;
060        
061        
062        /** The refreshDeletesflag, default to false */
063        private boolean refreshDeletes= true;
064        
065        /** The list of UUIDs */
066        private List<byte[]> syncUUIDs = new ArrayList<byte[]>();
067        
068        
069        /**
070         * {@inheritDoc}
071         */
072        public byte[] getCookie()
073        {
074            return cookie;
075        }
076        
077        
078        /**
079         * {@inheritDoc}
080         */
081        public void setCookie( byte[] cookie )
082        {
083            this.cookie = cookie;
084        }
085    
086    
087        /**
088         * @return the refreshDeletes
089         */
090        public boolean isRefreshDeletes()
091        {
092            return refreshDeletes;
093        }
094    
095    
096        /**
097         * @param refreshDone the refreshDeletes to set
098         */
099        public void setRefreshDeletes( boolean refreshDeletes )
100        {
101            this.refreshDeletes = refreshDeletes;
102        }
103        
104        
105        /**
106         * @return the syncUUIDs
107         */
108        public List<byte[]> getSyncUUIDs()
109        {
110            return syncUUIDs;
111        }
112    
113    
114        /**
115         * @param syncUUIDs the syncUUIDs to set
116         */
117        public void addSyncUUID( byte[] syncUUID )
118        {
119            syncUUIDs.add( syncUUID );
120        }
121    
122        
123        /**
124         * {@inheritDoc}
125         */
126        @Override
127        public String getID()
128        {
129            return CONTROL_OID;
130        }
131    
132        
133        /**
134         * {@inheritDoc}
135         */
136        public byte[] getEncodedValue()
137        {
138            SyncInfoValueControlCodec syncInfoValueCtlCodec = 
139                new SyncInfoValueControlCodec( SynchronizationInfoEnum.SYNC_ID_SET );
140            syncInfoValueCtlCodec.setCookie( cookie );
141    
142            try
143            {
144                return syncInfoValueCtlCodec.encode( null ).array();
145            }
146            catch ( EncoderException e )
147            {
148                LOG.error( "Failed to encode syncInfoValue control", e );
149                throw new IllegalStateException( "Failed to encode control with encoder.", e );
150            }
151        }
152    }