001 /*
002 * Copyright (c) 2005 Your Corporation. All Rights Reserved.
003 */
004 package org.activemq.transport.stomp;
005
006 import org.activemq.message.TransactionInfo;
007 import org.activemq.message.TransactionType;
008
009 import java.io.DataInput;
010 import java.io.IOException;
011 import java.util.Properties;
012 import java.net.ProtocolException;
013
014 public class Begin implements Command
015 {
016 private StompWireFormat format;
017 private static final HeaderParser parser = new HeaderParser();
018
019 public Begin(StompWireFormat format)
020 {
021 this.format = format;
022 }
023
024 public PacketEnvelope build(String commandLine, DataInput in) throws IOException
025 {
026 Properties headers = parser.parse(in);
027 while (in.readByte() != 0) {}
028
029 TransactionInfo tx = new TransactionInfo();
030 String user_tx_id = headers.getProperty(Stomp.Headers.TRANSACTION);
031 if (!headers.containsKey(Stomp.Headers.TRANSACTION))
032 {
033 throw new ProtocolException("Must specify the transaction you are beginning");
034 }
035 String tx_id = StompWireFormat.clientIds.generateId();
036 format.registerTransactionId(user_tx_id, tx_id);
037 tx.setTransactionId(tx_id);
038 tx.setType(TransactionType.START);
039 return new PacketEnvelope(tx, headers);
040 }
041 }