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.syncStateValue.SyncStateValueControlCodec;
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 implements the SyncStateValue Control, as described by RFC 4533.
030 * The structure for this control is :
031 *
032 * syncStateValue ::= SEQUENCE {
033 * state ENUMERATED {
034 * present (0),
035 * add (1),
036 * modify (2),
037 * delete (3)
038 * },
039 * entryUUID syncUUID,
040 * cookie syncCookie OPTIONAL
041 * }
042 *
043 * This control OID is 1.3.6.1.4.1.4203.1.9.1.2
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 SyncStateValueControl extends InternalAbstractControl
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( SyncStateValueControl.class );
057
058 /** This control OID */
059 public static final String CONTROL_OID = "1.3.6.1.4.1.4203.1.9.1.2";
060
061 /** The synchronization state type */
062 private SyncStateTypeEnum syncStateType;
063
064 /** the entryUUID */
065 private byte[] entryUUID;
066
067 /** The cookie */
068 private byte[] cookie;
069
070
071 /**
072 * @return the syncState's type
073 */
074 public SyncStateTypeEnum getSyncStateType()
075 {
076 return syncStateType;
077 }
078
079
080 /**
081 * set the syncState's type
082 *
083 * @param syncStateType the syncState's type
084 */
085 public void setSyncStateType( SyncStateTypeEnum syncStateType )
086 {
087 this.syncStateType = syncStateType;
088 }
089
090
091 /**
092 * @return the entryUUID
093 */
094 public byte[] getEntryUUID()
095 {
096 return entryUUID;
097 }
098
099
100 /**
101 * set the entryUUID
102 *
103 * @param entryUUID the entryUUID
104 */
105 public void setEntryUUID( byte[] entryUUID )
106 {
107 this.entryUUID = entryUUID;
108 }
109
110
111 /**
112 * @return the cookie
113 */
114 public byte[] getCookie()
115 {
116 return cookie;
117 }
118
119
120 /**
121 * @param syncCookie the syncCookie to set
122 */
123 public void setCookie( byte[] cookie )
124 {
125 this.cookie = cookie;
126 }
127
128
129 /**
130 * {@inheritDoc}
131 */
132 @Override
133 public String getID()
134 {
135 return CONTROL_OID;
136 }
137
138
139 /**
140 * {@inheritDoc}
141 */
142 public byte[] getEncodedValue()
143 {
144 SyncStateValueControlCodec syncStateValueCtlCodec = new SyncStateValueControlCodec();
145 syncStateValueCtlCodec.setSyncStateType( syncStateType );
146 syncStateValueCtlCodec.setEntryUUID( entryUUID );
147 syncStateValueCtlCodec.setCookie( cookie );
148
149 try
150 {
151 return syncStateValueCtlCodec.encode( null ).array();
152 }
153 catch ( EncoderException e )
154 {
155 LOG.error( "Failed to encode syncStateValue control", e );
156 throw new IllegalStateException( "Failed to encode control with encoder.", e );
157 }
158 }
159 }