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 * https://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 */ 020package org.apache.directory.api.ldap.extras.extended.endTransaction; 021 022 023import org.apache.directory.api.ldap.model.message.AbstractExtendedRequest; 024import org.apache.directory.api.util.Strings; 025 026 027/** 028 * The EndTransactionRequest implementation. This is for the RFC 5805 End Transaction Request, 029 * which grammar is : 030 * <pre> 031 * ExtendedRequest ::= [APPLICATION 23] SEQUENCE { 032 * requestName [0] LDAPOID, 033 * requestValue [1] OCTET STRING OPTIONAL } 034 * </pre> 035 * 036 * where 'requestName' is 1.3.6.1.1.21.3 and requestValue is a BER encoded value. The 037 * syntax for this value is : 038 * 039 * <pre> 040 * txnEndReq ::= SEQUENCE { 041 * commit BOOLEAN DEFAULT TRUE, 042 * identifier OCTET STRING } 043 * </pre> 044 * 045 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 046 */ 047public class EndTransactionRequestImpl extends AbstractExtendedRequest implements EndTransactionRequest 048{ 049 /** The transaction ID received from the StartTransactionResponse */ 050 private byte[] transactionId; 051 052 /** A flag telling of we should commit or rollback the transaction */ 053 private boolean commit = true; 054 055 /** 056 * Creates a new instance of EndTransactionRequestImpl. 057 * 058 * @param messageId the message id 059 */ 060 public EndTransactionRequestImpl( int messageId ) 061 { 062 super( messageId ); 063 setRequestName( EXTENSION_OID ); 064 } 065 066 067 /** 068 * Creates a new instance of EndTransactionRequestImpl. 069 */ 070 public EndTransactionRequestImpl() 071 { 072 setRequestName( EXTENSION_OID ); 073 } 074 075 076 /** 077 * {@inheritDoc} 078 */ 079 @Override 080 public EndTransactionResponse getResultResponse() 081 { 082 if ( getResponse() == null ) 083 { 084 setResponse( new EndTransactionResponseImpl() ); 085 } 086 087 return ( EndTransactionResponse ) getResponse(); 088 } 089 090 091 /** 092 * {@inheritDoc} 093 */ 094 @Override 095 public boolean getCommit() 096 { 097 return commit; 098 } 099 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}