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