You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2018/01/26 06:26:40 UTC
[directory-ldap-api] branch master updated: Added the
EndTransactionRequest decoder
This is an automated email from the ASF dual-hosted git repository.
elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git
The following commit(s) were added to refs/heads/master by this push:
new 7390752 Added the EndTransactionRequest decoder
7390752 is described below
commit 73907522c1fd9ab48306d469bd0065498cf903d0
Author: Emmanuel Lécharny <el...@symas.com>
AuthorDate: Fri Jan 26 07:26:31 2018 +0100
Added the EndTransactionRequest decoder
---
.../java/org/apache/directory/api/i18n/I18n.java | 1 +
.../apache/directory/api/i18n/errors.properties | 2 +
.../endTransaction/EndTransactionRequest.java | 4 +-
.../endTransaction/EndTransactionFactory.java | 118 +++++++++++
.../EndTransactionRequestContainer.java | 79 ++++++++
.../EndTransactionRequestDecoder.java | 62 ++++++
.../EndTransactionRequestDecorator.java | 138 +++++++++++++
.../EndTransactionRequestGrammar.java | 225 +++++++++++++++++++++
.../EndTransactionRequestStatesEnum.java | 94 +++++++++
.../EndTransactionResponseDecorator.java | 80 ++++++++
10 files changed, 801 insertions(+), 2 deletions(-)
diff --git a/i18n/src/main/java/org/apache/directory/api/i18n/I18n.java b/i18n/src/main/java/org/apache/directory/api/i18n/I18n.java
index f60a365..4c2bf02 100644
--- a/i18n/src/main/java/org/apache/directory/api/i18n/I18n.java
+++ b/i18n/src/main/java/org/apache/directory/api/i18n/I18n.java
@@ -628,6 +628,7 @@ public enum I18n
ERR_04487_ATTRIBUTE_IS_SINGLE_VALUED("ERR_04487_ATTRIBUTE_IS_SINGLE_VALUED"),
ERR_04488_NULL_ATTRIBUTE_TYPE("ERR_04488_NULL_ATTRIBUTE_TYPE"),
ERR_04489_SYNTAX_INVALID("ERR_04489_SYNTAX_INVALID"),
+ ERR_04490_BAD_END_TRANSACTION_COMMIT("ERR_04490_BAD_END_TRANSACTION_COMMIT"),
// ldap-constants
ERR_05001_UNKNOWN_AUTHENT_LEVEL("ERR_05001_UNKNOWN_AUTHENT_LEVEL"),
diff --git a/i18n/src/main/resources/org/apache/directory/api/i18n/errors.properties b/i18n/src/main/resources/org/apache/directory/api/i18n/errors.properties
index 1573f8b..ca14fd9 100644
--- a/i18n/src/main/resources/org/apache/directory/api/i18n/errors.properties
+++ b/i18n/src/main/resources/org/apache/directory/api/i18n/errors.properties
@@ -615,6 +615,8 @@ ERR_04486_VALUE_ALREADY_EXISTS=The value ''{0}'' already exists in the attribute
ERR_04487_ATTRIBUTE_IS_SINGLE_VALUED=The attribute ''{0}'' is single valued, we can't add no more values into it
ERR_04488_NULL_ATTRIBUTE_TYPE=The AttributeType cannot be null
ERR_04489_SYNTAX_INVALID=Syntax invalid for ''{0}''
+ERR_04490_BAD_END_TRANSACTION_COMMIT=The EndTransactionRequest Commit value {0} is invalid: {1}. It should be 0 or 255
+
# ldap-constants
ERR_05001_UNKNOWN_AUTHENT_LEVEL=Unknown AuthenticationLevel {0}
diff --git a/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/endTransaction/EndTransactionRequest.java b/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/endTransaction/EndTransactionRequest.java
index 5e159b6..a160db1 100644
--- a/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/endTransaction/EndTransactionRequest.java
+++ b/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/endTransaction/EndTransactionRequest.java
@@ -57,7 +57,7 @@ public interface EndTransactionRequest extends ExtendedRequest
/**
* Set the Commit flag for this transaction.
*
- * @param commit <tt>true</tt> if teh transaction should be committed, <tt>false</tt> if
+ * @param commit <tt>true</tt> if the transaction should be committed, <tt>false</tt> if
* it should be rollbacked.
*/
void setCommit( boolean commit );
@@ -71,7 +71,7 @@ public interface EndTransactionRequest extends ExtendedRequest
/**
* Set the transaction ID to commit or rollback
*
- * @param transactionId The transaction ID we got from teh startTransaction response
+ * @param transactionId The transaction ID we got from the startTransaction response
*/
void setTransactionId( byte[] transactionId );
}
\ No newline at end of file
diff --git a/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionFactory.java b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionFactory.java
new file mode 100644
index 0000000..08367eb
--- /dev/null
+++ b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionFactory.java
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.api.ldap.extras.extended.ads_impl.endTransaction;
+
+
+import org.apache.directory.api.asn1.DecoderException;
+import org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory;
+import org.apache.directory.api.ldap.codec.api.LdapApiService;
+import org.apache.directory.api.ldap.extras.extended.cancel.CancelRequest;
+import org.apache.directory.api.ldap.extras.extended.endTransaction.EndTransactionRequest;
+import org.apache.directory.api.ldap.extras.extended.endTransaction.EndTransactionRequestImpl;
+import org.apache.directory.api.ldap.extras.extended.endTransaction.EndTransactionResponse;
+import org.apache.directory.api.ldap.extras.extended.endTransaction.EndTransactionResponseImpl;
+import org.apache.directory.api.ldap.model.message.ExtendedRequest;
+import org.apache.directory.api.ldap.model.message.ExtendedResponse;
+
+
+/**
+ * An {@link ExtendedOperationFactory} for creating EndTransaction extended request response
+ * pairs.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EndTransactionFactory implements ExtendedOperationFactory
+{
+ private LdapApiService codec;
+
+
+ /**
+ * Creates a new instance of EndTransactionFactory.
+ *
+ * @param codec The codec for this factory.
+ */
+ public EndTransactionFactory( LdapApiService codec )
+ {
+ this.codec = codec;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getOid()
+ {
+ return CancelRequest.EXTENSION_OID;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public EndTransactionResponse newResponse( byte[] encodedValue ) throws DecoderException
+ {
+ EndTransactionResponseDecorator response = new EndTransactionResponseDecorator( codec, new EndTransactionResponseImpl() );
+ response.setResponseValue( encodedValue );
+
+ return response;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public EndTransactionRequest newRequest( byte[] value )
+ {
+ return new EndTransactionRequestDecorator( codec, new EndTransactionRequestImpl() );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public EndTransactionRequestDecorator decorate( ExtendedRequest modelRequest )
+ {
+ if ( modelRequest instanceof EndTransactionRequestDecorator )
+ {
+ return ( EndTransactionRequestDecorator ) modelRequest;
+ }
+
+ return new EndTransactionRequestDecorator( codec, null );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public EndTransactionResponseDecorator decorate( ExtendedResponse decoratedMessage )
+ {
+ if ( decoratedMessage instanceof EndTransactionResponseDecorator )
+ {
+ return ( EndTransactionResponseDecorator ) decoratedMessage;
+ }
+
+ return new EndTransactionResponseDecorator( codec, null );
+ }
+}
diff --git a/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionRequestContainer.java b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionRequestContainer.java
new file mode 100644
index 0000000..58d6765
--- /dev/null
+++ b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionRequestContainer.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.api.ldap.extras.extended.ads_impl.endTransaction;
+
+
+import org.apache.directory.api.asn1.ber.AbstractContainer;
+
+
+/**
+ * A container for EndTransactionRequest codec.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EndTransactionRequestContainer extends AbstractContainer
+{
+ /** EndTransactionRequest decorator*/
+ private EndTransactionRequestDecorator endTransactionRequest;
+
+
+ /**
+ * Creates a new EndTransactionContainer object. We will store one
+ * grammar, it's enough ...
+ */
+ public EndTransactionRequestContainer()
+ {
+ super();
+ setGrammar( EndTransactionRequestGrammar.getInstance() );
+ setTransition( EndTransactionRequestStatesEnum.START_STATE );
+ }
+
+
+ /**
+ * @return Returns the EndTransactionRequest instance.
+ */
+ public EndTransactionRequestDecorator getEndTransactionRequest()
+ {
+ return endTransactionRequest;
+ }
+
+
+ /**
+ * Set a EndTransactionRequest Object into the container. It will be completed by
+ * the ldapDecoder.
+ *
+ * @param endTransactionRequestDecorator the EndTransactionRequest to set.
+ */
+ public void setEndTransactionRequest( EndTransactionRequestDecorator endTransactionRequestDecorator )
+ {
+ this.endTransactionRequest = endTransactionRequestDecorator;
+ }
+
+
+ /**
+ * Clean the container for the next decoding.
+ */
+ @Override
+ public void clean()
+ {
+ super.clean();
+ endTransactionRequest = null;
+ }
+}
diff --git a/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionRequestDecoder.java b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionRequestDecoder.java
new file mode 100644
index 0000000..012fca9
--- /dev/null
+++ b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionRequestDecoder.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.api.ldap.extras.extended.ads_impl.endTransaction;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.api.asn1.DecoderException;
+import org.apache.directory.api.asn1.ber.Asn1Decoder;
+import org.apache.directory.api.ldap.extras.extended.endTransaction.EndTransactionRequest;
+
+
+/**
+ *
+ * A decoder for EndTransactionRequest.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EndTransactionRequestDecoder extends Asn1Decoder
+{
+ /** The decoder */
+ private static final Asn1Decoder DECODER = new Asn1Decoder();
+
+
+ /**
+ * Decode a PDU which must contain a EndTransactionRequest extended operation.
+ * Note that the stream of bytes much contain a full PDU, not a partial one.
+ *
+ * @param stream The bytes to be decoded
+ * @return a EndTransactionRequest object
+ * @throws org.apache.directory.api.asn1.DecoderException If the decoding failed
+ */
+ public EndTransactionRequest decode( byte[] stream ) throws DecoderException
+ {
+ ByteBuffer bb = ByteBuffer.wrap( stream );
+ EndTransactionRequestContainer container = new EndTransactionRequestContainer();
+ DECODER.decode( bb, container );
+ EndTransactionRequestDecorator endTransactionRequest = container.getEndTransactionRequest();
+
+ // Clean the container for the next decoding
+ container.clean();
+
+ return endTransactionRequest;
+ }
+}
diff --git a/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionRequestDecorator.java b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionRequestDecorator.java
new file mode 100644
index 0000000..985ff84
--- /dev/null
+++ b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionRequestDecorator.java
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.api.ldap.extras.extended.ads_impl.endTransaction;
+
+
+import org.apache.directory.api.asn1.DecoderException;
+import org.apache.directory.api.i18n.I18n;
+import org.apache.directory.api.ldap.codec.api.ExtendedRequestDecorator;
+import org.apache.directory.api.ldap.codec.api.LdapApiService;
+import org.apache.directory.api.ldap.extras.extended.endTransaction.EndTransactionRequest;
+import org.apache.directory.api.ldap.extras.extended.endTransaction.EndTransactionResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A Decorator for EndTransaction request.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EndTransactionRequestDecorator extends ExtendedRequestDecorator<EndTransactionRequest> implements
+ EndTransactionRequest
+{
+ private static final Logger LOG = LoggerFactory.getLogger( EndTransactionRequestDecorator.class );
+
+ /** The internal EndTransaction request */
+ private EndTransactionRequest endTransactionRequest;
+
+
+ /**
+ * Creates a new instance of EndTransactionRequestDecorator.
+ *
+ * @param codec The LDAP Service to use
+ * @param decoratedMessage The canceled request
+ */
+ public EndTransactionRequestDecorator( LdapApiService codec, EndTransactionRequest decoratedMessage )
+ {
+ super( codec, decoratedMessage );
+ endTransactionRequest = decoratedMessage;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public EndTransactionResponse getResultResponse()
+ {
+ return ( EndTransactionResponse ) endTransactionRequest.getResultResponse();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean getCommit()
+ {
+ return endTransactionRequest.getCommit();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setCommit( boolean commit )
+ {
+ endTransactionRequest.setCommit( commit );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public byte[] getTransactionId()
+ {
+ return endTransactionRequest.getTransactionId();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setTransactionId( byte[] transactionId )
+ {
+ endTransactionRequest.setTransactionId( transactionId );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setRequestValue( byte[] requestValue )
+ {
+ EndTransactionRequestDecoder decoder = new EndTransactionRequestDecoder();
+
+ try
+ {
+ if ( requestValue != null )
+ {
+ endTransactionRequest = decoder.decode( requestValue );
+
+ this.requestValue = new byte[requestValue.length];
+ System.arraycopy( requestValue, 0, this.requestValue, 0, requestValue.length );
+ }
+ else
+ {
+ this.requestValue = null;
+ }
+ }
+ catch ( DecoderException e )
+ {
+ LOG.error( I18n.err( I18n.ERR_04165 ), e );
+ throw new RuntimeException( e );
+ }
+ }
+}
diff --git a/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionRequestGrammar.java b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionRequestGrammar.java
new file mode 100644
index 0000000..13b62e9
--- /dev/null
+++ b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionRequestGrammar.java
@@ -0,0 +1,225 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.api.ldap.extras.extended.ads_impl.endTransaction;
+
+
+import org.apache.directory.api.asn1.DecoderException;
+import org.apache.directory.api.asn1.ber.grammar.AbstractGrammar;
+import org.apache.directory.api.asn1.ber.grammar.Grammar;
+import org.apache.directory.api.asn1.ber.grammar.GrammarAction;
+import org.apache.directory.api.asn1.ber.grammar.GrammarTransition;
+import org.apache.directory.api.asn1.ber.tlv.BerValue;
+import org.apache.directory.api.asn1.ber.tlv.BooleanDecoder;
+import org.apache.directory.api.asn1.ber.tlv.BooleanDecoderException;
+import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.api.i18n.I18n;
+import org.apache.directory.api.ldap.codec.api.LdapApiServiceFactory;
+import org.apache.directory.api.ldap.extras.extended.endTransaction.EndTransactionRequestImpl;
+import org.apache.directory.api.util.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the EndTransactionRequest extended operation's ASN.1 grammer.
+ * All the actions are declared in this class. As it is a singleton,
+ * these declaration are only done once. The grammar is :
+ *
+ * <pre>
+ * txnEndReq ::= SEQUENCE {
+ * commit BOOLEAN DEFAULT TRUE,
+ * identifier OCTET STRING }
+ * </pre>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+
+public class EndTransactionRequestGrammar extends AbstractGrammar<EndTransactionRequestContainer>
+{
+
+ /** logger */
+ private static final Logger LOG = LoggerFactory.getLogger( EndTransactionRequestGrammar.class );
+
+ /** Speedup for logs */
+ static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+ /** The instance of grammar. EndTransactionRequestGrammar is a singleton */
+ private static Grammar<EndTransactionRequestContainer> instance = new EndTransactionRequestGrammar();
+
+
+ /**
+ * Creates a new EndTransactionRequestGrammar object.
+ */
+ @SuppressWarnings("unchecked")
+ public EndTransactionRequestGrammar()
+ {
+ setName( EndTransactionRequestGrammar.class.getName() );
+
+ // Create the transitions table
+ super.transitions = new GrammarTransition[EndTransactionRequestStatesEnum.LAST_STATE
+ .ordinal()][256];
+
+ /**
+ * Transition from init state to EndTransactionRequest Sequence
+ *
+ * txnEndReq ::= SEQUENCE {
+ * ...
+ *
+ * Creates the EndTransactionRequest object
+ */
+ super.transitions[EndTransactionRequestStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
+ new GrammarTransition<EndTransactionRequestContainer>(
+ EndTransactionRequestStatesEnum.START_STATE,
+ EndTransactionRequestStatesEnum.SEQUENCE_STATE,
+ UniversalTag.SEQUENCE.getValue(),
+ new GrammarAction<EndTransactionRequestContainer>( "Init EndTransactionRequest" )
+ {
+ public void action( EndTransactionRequestContainer container )
+ {
+ EndTransactionRequestDecorator endTransactionRequestDecorator = new EndTransactionRequestDecorator(
+ LdapApiServiceFactory.getSingleton(), new EndTransactionRequestImpl() );
+ container.setEndTransactionRequest( endTransactionRequestDecorator );
+ }
+ } );
+
+ /**
+ * Transition from Sequence to commit flag
+ *
+ * txnEndReq ::= SEQUENCE {
+ * commit BOOLEAN DEFAULT TRUE,
+ * ...
+ *
+ * Set the commit flag into the EndTransactionRequest instance.
+ */
+ super.transitions[EndTransactionRequestStatesEnum.SEQUENCE_STATE.ordinal()][UniversalTag.BOOLEAN.getValue()] =
+ new GrammarTransition<EndTransactionRequestContainer>(
+ EndTransactionRequestStatesEnum.SEQUENCE_STATE,
+ EndTransactionRequestStatesEnum.COMMIT_STATE,
+ UniversalTag.BOOLEAN.getValue(),
+ new GrammarAction<EndTransactionRequestContainer>( "Set EndTransactionRequest commit flag" )
+ {
+ public void action( EndTransactionRequestContainer container ) throws DecoderException
+ {
+ BerValue value = container.getCurrentTLV().getValue();
+
+ try
+ {
+ container.getEndTransactionRequest().setCommit( BooleanDecoder.parse( value ) );
+ }
+ catch ( BooleanDecoderException bde )
+ {
+ LOG.error( I18n
+ .err( I18n.ERR_04490_BAD_END_TRANSACTION_COMMIT, Strings.dumpBytes( value.getData() ), bde.getMessage() ) );
+
+ // This will generate a PROTOCOL_ERROR
+ throw new DecoderException( bde.getMessage(), bde );
+ }
+ }
+ } );
+
+ /**
+ * Transition from Sequence to identifier
+ *
+ * txnEndReq ::= SEQUENCE {
+ * identifier OCTET STRING }
+ *
+ * Set the commit flag into the EndTransactionRequest instance.
+ */
+ super.transitions[EndTransactionRequestStatesEnum.SEQUENCE_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] =
+ new GrammarTransition<EndTransactionRequestContainer>(
+ EndTransactionRequestStatesEnum.SEQUENCE_STATE,
+ EndTransactionRequestStatesEnum.IDENTFIER_STATE,
+ UniversalTag.OCTET_STRING.getValue(),
+ new GrammarAction<EndTransactionRequestContainer>( "Set EndTransactionRequest identifier" )
+ {
+ public void action( EndTransactionRequestContainer container ) throws DecoderException
+ {
+ BerValue value = container.getCurrentTLV().getValue();
+
+ byte[] identifier = value.getData();
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "Identifier = {}", Strings.dumpBytes( identifier ) );
+ }
+
+ if ( identifier == null )
+ {
+ identifier = Strings.EMPTY_BYTES;
+ }
+
+ container.getEndTransactionRequest().setTransactionId( identifier );
+
+ // We may have nothing left
+ container.setGrammarEndAllowed( true );
+ }
+ } );
+
+ /**
+ * Transition from commit flag to identifier
+ *
+ * txnEndReq ::= SEQUENCE {
+ * commit BOOLEAN DEFAULT TRUE,
+ * identifier OCTET STRING }
+ *
+ * Set the identifier into the EndTransactionRequest instance.
+ */
+ super.transitions[EndTransactionRequestStatesEnum.COMMIT_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] =
+ new GrammarTransition<EndTransactionRequestContainer>(
+ EndTransactionRequestStatesEnum.COMMIT_STATE,
+ EndTransactionRequestStatesEnum.IDENTFIER_STATE,
+ UniversalTag.OCTET_STRING.getValue(),
+ new GrammarAction<EndTransactionRequestContainer>( "Set EndTransactionRequest identifier" )
+ {
+ public void action( EndTransactionRequestContainer container ) throws DecoderException
+ {
+ BerValue value = container.getCurrentTLV().getValue();
+
+ byte[] identifier = value.getData();
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "Identifier = {}", Strings.dumpBytes( identifier ) );
+ }
+
+ if ( identifier == null )
+ {
+ identifier = Strings.EMPTY_BYTES;
+ }
+
+ container.getEndTransactionRequest().setTransactionId( identifier );
+
+ // We may have nothing left
+ container.setGrammarEndAllowed( true );
+ }
+ } );
+ }
+
+
+ /**
+ * This class is a singleton.
+ *
+ * @return An instance on this grammar
+ */
+ public static Grammar<EndTransactionRequestContainer> getInstance()
+ {
+ return instance;
+ }
+}
diff --git a/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionRequestStatesEnum.java b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionRequestStatesEnum.java
new file mode 100644
index 0000000..d28be3c
--- /dev/null
+++ b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionRequestStatesEnum.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.api.ldap.extras.extended.ads_impl.endTransaction;
+
+
+import org.apache.directory.api.asn1.ber.grammar.States;
+
+
+/**
+ * This class store the EndTransactionRequest's grammar constants. It is also used
+ * for debugging purposes.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum EndTransactionRequestStatesEnum implements States
+{
+ /** The END_STATE */
+ END_STATE,
+
+ /** start state*/
+ START_STATE,
+
+ /** The initial SEQUENCE */
+ SEQUENCE_STATE,
+
+ /** The commit flag */
+ COMMIT_STATE,
+
+ /** he identifier state */
+ IDENTFIER_STATE,
+
+ /** Last state */
+ LAST_STATE;
+
+
+ /**
+ * Get the grammar name
+ *
+ * @return The grammar name
+ */
+ public String getGrammarName()
+ {
+ return "END_TRANSACTION_REQUEST_GRAMMER";
+ }
+
+
+ /**
+ * Get the string representing the state
+ *
+ * @param state The state number
+ * @return The String representing the state
+ */
+ public String getState( int state )
+ {
+ return ( state == END_STATE.ordinal() ) ? "END_TRANSACTION_REQUEST_GRAMMER" : name();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isEndState()
+ {
+ return this == END_STATE;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public EndTransactionRequestStatesEnum getStartState()
+ {
+ return START_STATE;
+ }
+}
diff --git a/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionResponseDecorator.java b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionResponseDecorator.java
new file mode 100644
index 0000000..860c225
--- /dev/null
+++ b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionResponseDecorator.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.api.ldap.extras.extended.ads_impl.endTransaction;
+
+
+import java.util.List;
+
+import org.apache.directory.api.ldap.codec.api.ExtendedResponseDecorator;
+import org.apache.directory.api.ldap.codec.api.LdapApiService;
+import org.apache.directory.api.ldap.extras.extended.endTransaction.EndTransactionResponse;
+import org.apache.directory.api.ldap.extras.extended.endTransaction.UpdateControls;
+import org.apache.directory.api.util.Strings;
+
+
+/**
+ * A Decorator for EndTransaction response.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EndTransactionResponseDecorator extends ExtendedResponseDecorator<EndTransactionResponse> implements EndTransactionResponse
+{
+ /** The endTransaction response */
+ private EndTransactionResponse endTransactionResponse;
+
+ /**
+ * Creates a new instance of EndTransactionResponseDecorator.
+ *
+ * @param codec The LDAP service instance
+ * @param decoratedMessage The decorated message
+ */
+ public EndTransactionResponseDecorator( LdapApiService codec, EndTransactionResponse decoratedMessage )
+ {
+ super( codec, decoratedMessage );
+ endTransactionResponse = decoratedMessage;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setResponseValue( byte[] responseValue )
+ {
+ this.responseValue = Strings.copy( responseValue );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getFailedMessageId()
+ {
+ return endTransactionResponse.getFailedMessageId();
+ }
+
+
+ @Override
+ public List<UpdateControls> getUpdateControls()
+ {
+ return endTransactionResponse.getUpdateControls();
+ }
+}
--
To stop receiving notification emails like this one, please contact
elecharny@apache.org.