View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    https://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.api.ldap.extras.extended.endTransaction;
21  
22  
23  import org.apache.directory.api.ldap.model.message.OpaqueExtendedRequest;
24  import org.apache.directory.api.util.Strings;
25  
26  
27  /**
28   * The EndTransactionRequest implementation. This is for the RFC 5805 End Transaction Request,
29   * which grammar is :
30   * <pre>
31   * ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
32   *              requestName      [0] LDAPOID,
33   *              requestValue     [1] OCTET STRING OPTIONAL }
34   * </pre>
35   * 
36   * where 'requestName' is 1.3.6.1.1.21.3 and requestValue is a BER encoded value. The 
37   * syntax for this value is :
38   * 
39   * <pre>
40   * txnEndReq ::= SEQUENCE {
41   *         commit         BOOLEAN DEFAULT TRUE,
42   *         identifier     OCTET STRING }
43   * </pre>
44   *
45   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
46   */
47  public class EndTransactionRequestImpl extends OpaqueExtendedRequest implements EndTransactionRequest
48  {
49      /** The transaction ID received from the StartTransactionResponse */
50      private byte[] transactionId;
51      
52      /** A flag telling of we should commit or rollback the transaction */
53      private boolean commit = true;
54      
55      /**
56       * Creates a new instance of EndTransactionRequestImpl.
57       *
58       * @param messageId the message id
59       */
60      public EndTransactionRequestImpl( int messageId )
61      {
62          super( messageId );
63          setRequestName( EXTENSION_OID );
64      }
65  
66  
67      /**
68       * Creates a new instance of EndTransactionRequestImpl.
69       */
70      public EndTransactionRequestImpl()
71      {
72          setRequestName( EXTENSION_OID );
73      }
74  
75  
76      /**
77       * {@inheritDoc}
78       */
79      @Override
80      public EndTransactionResponse getResultResponse()
81      {
82          if ( getResponse() == null )
83          {
84              setResponse( new EndTransactionResponseImpl() );
85          }
86  
87          return ( EndTransactionResponse ) getResponse();
88      }
89  
90  
91      /**
92       * {@inheritDoc}
93       */
94      @Override
95      public boolean getCommit()
96      {
97          return commit;
98      }
99  
100 
101     /**
102      * {@inheritDoc}
103      */
104     @Override
105     public void setCommit( boolean commit )
106     {
107         this.commit = commit;
108     }
109 
110 
111     /**
112      * {@inheritDoc}
113      */
114     @Override
115     public byte[] getTransactionId()
116     {
117         return Strings.copy( transactionId );
118     }
119 
120 
121     /**
122      * {@inheritDoc}
123      */
124     @Override
125     public void setTransactionId( byte[] transactionId )
126     {
127         this.transactionId = Strings.copy( transactionId );
128     }
129 
130 
131     /**
132      * @see Object#toString()
133      */
134     @Override
135     public String toString()
136     {
137         StringBuilder sb = new StringBuilder();
138 
139         sb.append( "EndTransactionRequest :" );
140         sb.append( "\n    commit : " ).append( commit );
141 
142         sb.append( "\n    transactionId : " );
143 
144         if ( transactionId != null )
145         {
146             sb.append( Strings.dumpBytes( transactionId ) );
147         }
148         else
149         {
150             sb.append( "null" );
151         }
152 
153         return sb.toString();
154     }
155 }