[jboss-svn-commits] JBL Code SVN: r12674 - in labs/jbosstm/workspace/maciej.machulak/code/demo/app: src and 11 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Jun 18 21:44:18 EDT 2007
Author: maciej.machulak
Date: 2007-06-18 21:44:17 -0400 (Mon, 18 Jun 2007)
New Revision: 12674
Added:
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/clients/
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/clients/JaxWSClientHeaderContextProcessor.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/clients/WeekendClient.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/bistro/
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/bistro/Bistro.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/bistro/BistroEntityImpl.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/bistro/BistroImpl.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/FlightManager.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/FlightView.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/at/
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/at/FlightAT.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/at/FlightATImpl.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/at/FlightParticipantAT.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/ba/
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/ba/FlightBA.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/ba/FlightBAImpl.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/ba/FlightParticipantBA.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/HotelEntityImpl.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/HotelImpl.class
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/HotelView.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/UserDescription.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/at/
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/at/HotelAT.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/at/HotelATImpl.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/ba/
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/ba/HotelBA.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/ba/HotelBAImpl.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantAT.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantATImpl.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantEntityImpl.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantManager.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantParticipantAT.java
labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantView.java
Log:
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/clients/JaxWSClientHeaderContextProcessor.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/clients/JaxWSClientHeaderContextProcessor.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/clients/JaxWSClientHeaderContextProcessor.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,271 @@
+package wstest.clients;
+
+import org.apache.log4j.Logger;
+
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPHandler;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+import javax.xml.namespace.QName;
+import javax.xml.soap.*;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import com.arjuna.mw.wsc.context.Context;
+import com.arjuna.webservices.wscoor.CoordinationConstants;
+import com.arjuna.webservices.wscoor.CoordinationContextType;
+import com.arjuna.webservices.wsat.AtomicTransactionConstants;
+import com.arjuna.webservices.wsba.BusinessActivityConstants;
+import com.arjuna.mw.wst.common.CoordinationContextHelper;
+import com.arjuna.mw.wst.common.SOAPUtil;
+import com.arjuna.mw.wst.*;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: jhalli
+ * Date: Apr 20, 2007
+ * Time: 1:06:28 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class JaxWSClientHeaderContextProcessor implements SOAPHandler
+{
+ private static Logger log = Logger.getLogger(JaxWSClientHeaderContextProcessor.class);
+
+ private String handlerName;
+
+ public String getHandlerName()
+ {
+ return handlerName;
+ }
+
+ public void setHandlerName(String handlerName)
+ {
+ this.handlerName = handlerName;
+ }
+
+ public boolean handleMessage(MessageContext msgContext)
+ {
+ Boolean outbound = (Boolean)msgContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ if (outbound == null)
+ throw new IllegalStateException("Cannot obtain required property: " + MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+
+ return outbound ? handleOutbound(msgContext) : handleInbound(msgContext);
+ }
+
+
+ public boolean handleFault(MessageContext messagecontext)
+ {
+ resumeTransaction(messagecontext) ;
+ return true;
+ }
+
+ public void close(MessageContext messageContext)
+ {
+ }
+
+ public String toString()
+ {
+ return (handlerName != null ? handlerName : super.toString());
+ }
+
+
+
+ // The header blocks that can be processed by this Handler instance
+ private Set<QName> headers = new HashSet<QName>();
+
+ /** Gets the header blocks that can be processed by this Handler instance.
+ */
+ public Set<QName> getHeaders()
+ {
+ log.info("getHeaders");
+
+ Set<QName> headerSet = new HashSet<QName>();
+ headerSet.add(new QName(CoordinationConstants.WSCOOR_NAMESPACE, CoordinationConstants.WSCOOR_ELEMENT_COORDINATION_CONTEXT));
+
+ return headerSet;
+ }
+
+ /** Sets the header blocks that can be processed by this Handler instance.
+ */
+ public void setHeaders(Set<QName> headers)
+ {
+ this.headers = headers;
+ }
+
+
+
+ protected boolean handleInbound(MessageContext msgContext)
+ {
+ log.info("handleInbound");
+ resumeTransaction(msgContext) ;
+
+
+ return true ;
+ }
+
+
+ protected boolean handleOutbound(MessageContext msgContext)
+ {
+ log.info("handleOutbound");
+
+ final SOAPMessageContext soapMessageContext = (SOAPMessageContext)msgContext ;
+ final SOAPMessage soapMessage = soapMessageContext.getMessage() ;
+
+ if (soapMessage == null)
+ {
+ return true ;
+ }
+
+ try
+ {
+ /*
+ * There should either be an Atomic Transaction *or* a Business Activity
+ * associated with the thread.
+ */
+ final TransactionManager transactionManager = TransactionManagerFactory.transactionManager() ;
+ final BusinessActivityManager businessActivityManager = BusinessActivityManagerFactory.businessActivityManager() ;
+
+ final Context atContext ;
+ if (transactionManager != null)
+ {
+ final com.arjuna.mwlabs.wst.at.context.TxContextImple txContext =
+ (com.arjuna.mwlabs.wst.at.context.TxContextImple)transactionManager.currentTransaction() ;
+ atContext = (txContext == null ? null : txContext.context()) ;
+ }
+ else
+ {
+ atContext = null ;
+ }
+
+ final Context baContext ;
+ if (businessActivityManager != null)
+ {
+ final com.arjuna.mwlabs.wst.ba.context.TxContextImple txContext =
+ (com.arjuna.mwlabs.wst.ba.context.TxContextImple)businessActivityManager.currentTransaction() ;
+ baContext = (txContext == null ? null : txContext.context()) ;
+ }
+ else
+ {
+ baContext = null ;
+ }
+
+ final CoordinationContextType coordinationContext ;
+ if (atContext != null)
+ {
+ coordinationContext = atContext.getCoordinationContext() ;
+ }
+ else if (baContext != null)
+ {
+ coordinationContext = baContext.getCoordinationContext() ;
+ }
+ else
+ {
+ coordinationContext = null ;
+ }
+
+ if (coordinationContext != null)
+ {
+ final SOAPEnvelope env = soapMessage.getSOAPPart().getEnvelope() ;
+ SOAPHeader header = env.getHeader() ;
+ if (header == null)
+ {
+ header = env.addHeader() ;
+ }
+ final Name name = env.createName(CoordinationConstants.WSCOOR_ELEMENT_COORDINATION_CONTEXT, CoordinationConstants.WSCOOR_PREFIX, CoordinationConstants.WSCOOR_NAMESPACE) ;
+ final SOAPHeaderElement headerElement = header.addHeaderElement(name) ;
+ headerElement.addNamespaceDeclaration(CoordinationConstants.WSCOOR_PREFIX, CoordinationConstants.WSCOOR_NAMESPACE) ;
+ headerElement.setMustUnderstand(true) ;
+ CoordinationContextHelper.serialise(env, headerElement, coordinationContext) ;
+ }
+ }
+ catch (final Throwable th)
+ {
+ log.warn("handleOutbound: ", th);
+ }
+
+ return true;
+ }
+
+ private void resumeTransaction(final MessageContext messageContext)
+ {
+ final SOAPMessageContext soapMessageContext = (SOAPMessageContext)messageContext ;
+ final SOAPMessage soapMessage = soapMessageContext.getMessage() ;
+
+ if (soapMessage != null)
+ {
+ try
+ {
+ final SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope() ;
+ final SOAPHeaderElement soapHeaderElement = getHeaderElement(soapEnvelope, CoordinationConstants.WSCOOR_NAMESPACE, CoordinationConstants.WSCOOR_ELEMENT_COORDINATION_CONTEXT) ;
+
+ if (soapHeaderElement != null)
+ {
+ final CoordinationContextType cc = CoordinationContextHelper.deserialise(soapEnvelope, soapHeaderElement) ;
+ if (cc != null)
+ {
+ final String coordinationType = cc.getCoordinationType().getValue() ;
+ if (AtomicTransactionConstants.WSAT_PROTOCOL.equals(coordinationType))
+ {
+ final TxContext txContext = new com.arjuna.mwlabs.wst.at.context.TxContextImple(cc) ;
+ TransactionManagerFactory.transactionManager().resume(txContext) ;
+ }
+ else if (BusinessActivityConstants.WSBA_PROTOCOL_ATOMIC_OUTCOME.equals(coordinationType))
+ {
+ final TxContext txContext = new com.arjuna.mwlabs.wst.ba.context.TxContextImple(cc);
+ BusinessActivityManagerFactory.businessActivityManager().resume(txContext) ;
+ }
+ else
+ {
+ log.warn("resumeTransaction: unknown Coordtype");
+ }
+ }
+ }
+ }
+ catch (final Throwable th)
+ {
+ log.warn("resumeTransaction: ", th);
+ }
+ }
+ }
+
+ private SOAPHeaderElement getHeaderElement(final SOAPEnvelope soapEnvelope, final String uri, final String name)
+ throws SOAPException
+ {
+ final SOAPHeader soapHeader = soapEnvelope.getHeader() ;
+ if (soapHeader != null)
+ {
+ final Iterator headerIter = SOAPUtil.getChildElements(soapHeader) ;
+ while(headerIter.hasNext())
+ {
+ final SOAPHeaderElement current = (SOAPHeaderElement)headerIter.next() ;
+ final Name currentName = current.getElementName() ;
+ if ((currentName != null) &&
+ match(name, currentName.getLocalName()) &&
+ match(uri, currentName.getURI()))
+ {
+ return current ;
+ }
+ }
+ }
+ return null ;
+ }
+
+ /**
+ * Do the two references match?
+ * @param lhs The first reference.
+ * @param rhs The second reference.
+ * @return true if the references are both null or if they are equal.
+ */
+ private boolean match(final Object lhs, final Object rhs)
+ {
+ if (lhs == null)
+ {
+ return (rhs == null) ;
+ }
+ else
+ {
+ return lhs.equals(rhs) ;
+ }
+ }
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/clients/WeekendClient.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/clients/WeekendClient.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/clients/WeekendClient.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,399 @@
+package wstest.clients;
+
+import wstest.services.restaurant.RestaurantAT;
+import wstest.services.flight.at.FlightAT;
+import wstest.services.flight.ba.FlightBA;
+import wstest.services.bistro.Bistro;
+import wstest.services.hotel.at.HotelAT;
+import wstest.services.hotel.ba.HotelBA;
+import com.arjuna.mw.wst.UserTransaction;
+import com.arjuna.mw.wst.UserTransactionFactory;
+import com.arjuna.mw.wst.UserBusinessActivity;
+import com.arjuna.mw.wst.UserBusinessActivityFactory;
+import com.arjuna.wst.TransactionRolledBackException;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.handler.Handler;
+import java.io.IOException;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.util.List;
+import java.util.ArrayList;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Author: Maciej Machulak
+ */
+
+public class WeekendClient extends HttpServlet
+{
+
+ private static RestaurantAT restaurantAT;
+ private static FlightAT flightAT;
+ private static FlightBA flightBA;
+ private static Bistro bistroAT;
+ private static HotelAT hotelAT;
+ private static HotelBA hotelBA;
+
+ private static Logger log = Logger.getLogger(WeekendClient.class);
+
+ private ServletContext context;
+
+ public void init(final ServletConfig config) throws ServletException
+ {
+ flightBA = this.getPortFlightBA();
+ flightAT = this.getPortFlight();
+ restaurantAT = this.getPortRestaurant();
+ bistroAT = this.getPortBistro();
+ hotelAT = this.getPortHotelAT();
+ hotelBA = this.getPortHotelBA();
+ context = config.getServletContext();
+ }
+
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ {
+ processRequest(request,response);
+ }
+
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ {
+ processRequest(request,response);
+ }
+
+ private void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ {
+ List<String> methodList = new ArrayList<String>();
+
+ log.info("processRequest()");
+ String username = request.getParameter("username");
+ String password = request.getParameter("password");
+ String roomNumberS = request.getParameter("roomNumber");
+ String reservationNumberS = request.getParameter("reservationNumber");
+ String transactionType = request.getParameter("transactionType");
+ String terminationTypeS = request.getParameter("terminationType");
+ String[] methods = request.getParameterValues("method");
+
+ for(String method : methods)
+ {
+ methodList.add(method);
+ }
+
+ boolean terminationType = true;
+ if (terminationTypeS.equals("cancel"))
+ {
+ terminationType = false;
+ }
+
+ Integer roomNumber = 0;
+ Integer reservationNumber = 0;
+
+ try
+ {
+ roomNumber = new Integer(roomNumberS);
+ }
+ catch (Exception e)
+ {
+ }
+
+ try
+ {
+ reservationNumber = new Integer(reservationNumberS);
+ }
+ catch (Exception e)
+ {
+ }
+
+ try
+ {
+ if (transactionType.equals("at"))
+ {
+ log.info("Testing atomic transaction.");
+ atomicTransaction(username,password,roomNumber,reservationNumber,methodList,terminationType);
+ }
+ else if (transactionType.equals("ba"))
+ {
+ log.info("Testing business activity.");
+ businessActivity(username,password,roomNumber,reservationNumber,methodList,terminationType);
+ }
+ else if (transactionType.equals("none"))
+ {
+ log.info("Testing normal invocation.");
+ noTransaction(username,password,roomNumber,reservationNumber,methodList,terminationType);
+ }
+ else
+ {
+ log.info("Wrong transaction type!");
+ }
+ }
+ catch (TransactionRolledBackException trbe)
+ {
+ log.info("Transaction rolled back: " + trbe.getMessage());
+ }
+ catch (Exception e)
+ {
+ log.info("Transaction failed: ");
+ e.printStackTrace();
+ }
+ context.getRequestDispatcher("/index.jsp").forward(request, response);
+ }
+
+ private void noTransaction(String username, String password, Integer roomNumber, Integer reservationNumber, List<String> methods, boolean terminationType)
+ {
+ log.info("Starting normal invocation...");
+ hotelBA.cancelReservation(username,password,reservationNumber);
+ log.info("Normal invocation completed...");
+ }
+
+ private void atomicTransaction(String username, String password, int roomNumber, int reservationNumber, List<String> methods, boolean terminationType) throws Exception
+ {
+ // Getting user transaction
+ UserTransaction ut = UserTransactionFactory.userTransaction();
+
+ // Starting transaction
+ ut.begin();
+
+ // -- business logic start --
+ //flightAT.bookSeats(noOfSeats);
+ //restaurantAT.bookTables(noOfTables);
+ //bistroAT.getBookingNumber();
+ //bistroAT.bookSeats(noOfSeats);
+ hotelAT.getBookingCount();
+ hotelAT.getHotelInfo();
+ hotelAT.getHotelAddress();
+ //hotelAT.bookRooms(noOfSeats);
+
+ // -- business logic end --
+
+ // Ending the transaction
+ if (terminationType)
+ {
+ ut.commit();
+ }
+ else
+ {
+ ut.rollback();
+ }
+
+ }
+
+ private void businessActivity(String username, String password, int roomNumber, int reservationNumber ,List<String> methodList, boolean terminationType) throws Exception
+ {
+ // Getting user business activity transaction
+ UserBusinessActivity ubaMain = UserBusinessActivityFactory.userBusinessActivity();
+
+ // Starting the transaction
+ ubaMain.begin();
+
+ // -- business logic start --
+ // flightBA.bookSeats(noOfSeats);
+
+ //hotelBA.getHotelInfo("No i jak test?");
+ if (methodList.contains("makeReservation"))
+ {
+ // Getting user business activity transaction
+ //UserBusinessActivity ubaNested = UserBusinessActivityFactory.userBusinessActivity();
+ //ubaNested.begin();
+ //ubaNested.cancel();
+ hotelBA.makeReservation(username,password,roomNumber);
+ }
+ if (methodList.contains("getHotelInfo"))
+ {
+ hotelBA.getHotelInfo(username);
+ }
+ if (methodList.contains("getHotelOwner"))
+ {
+ hotelBA.getHotelOwner();
+ }
+ else if (methodList.contains("cancelReservation"))
+ {
+ hotelBA.cancelReservation(username,password,reservationNumber);
+ }
+ //flightBA.bookRooms(noOfSeats);
+ //restaurantBA.bookTables(noOfTables);
+ // -- business logic end --
+
+ // Ending user business activity transaction
+ // This can be ubaMain.complete() if the participants are enlisted for the Completion
+ // version of the 2PC protocol.
+ if (terminationType)
+ {
+ log.info("Completing business activity.");
+ ubaMain.close();
+ log.info("Completed.");
+ }
+ else
+ {
+ log.info("Cancelling business activity.");
+ ubaMain.cancel();
+ log.info("Cancelled.");
+ }
+ }
+
+ private FlightAT getPortFlight()
+ {
+ // Connect to the Web Service
+ URL wsdlLocation = null;
+ try
+ {
+ wsdlLocation = new URL("http://localhost:8080/FlightATImplService/FlightATImpl?wsdl");
+ }
+ catch (MalformedURLException e)
+ {
+ e.printStackTrace();
+ }
+ QName serviceName = new QName("http://at.flight.services.wstest/","FlightATImplService");
+ Service service = Service.create(wsdlLocation, serviceName);
+ FlightAT port = service.getPort(FlightAT.class);
+
+ // Insert client handler
+ BindingProvider bindingProvider = (BindingProvider)port;
+ List<Handler> handlerChain = new ArrayList<Handler>();
+ handlerChain.add(new JaxWSClientHeaderContextProcessor());
+ bindingProvider.getBinding().setHandlerChain(handlerChain);
+
+ return port;
+
+ }
+
+ private FlightBA getPortFlightBA()
+ {
+ // Connect to the Web Service
+ URL wsdlLocation = null;
+ try
+ {
+ wsdlLocation = new URL("http://localhost:8080/FlightBAImplService/FlightBAImpl?wsdl");
+ }
+ catch (MalformedURLException e)
+ {
+ e.printStackTrace();
+ }
+ QName serviceName = new QName("http://ba.flight.services.wstest/","FlightBAImplService");
+ Service service = Service.create(wsdlLocation, serviceName);
+ FlightBA port = service.getPort(FlightBA.class);
+
+ // Insert client handler
+ BindingProvider bindingProvider = (BindingProvider)port;
+ List<Handler> handlerChain = new ArrayList<Handler>();
+ handlerChain.add(new JaxWSClientHeaderContextProcessor());
+ bindingProvider.getBinding().setHandlerChain(handlerChain);
+
+ return port;
+
+ }
+
+ private RestaurantAT getPortRestaurant()
+ {
+ // Connect to the Web Service
+ URL wsdlLocation = null;
+ try
+ {
+ wsdlLocation = new URL("http://localhost:8080/RestaurantATImplService/RestaurantATImpl?wsdl");
+ }
+ catch (MalformedURLException e)
+ {
+ e.printStackTrace();
+ }
+ QName serviceName = new QName("http://restaurant.services.wstest/","RestaurantATImplService");
+ Service service = Service.create(wsdlLocation, serviceName);
+ RestaurantAT port = service.getPort(RestaurantAT.class);
+
+ // Insert client handler
+ BindingProvider bindingProvider = (BindingProvider)port;
+ List<Handler> handlerChain = new ArrayList<Handler>();
+ handlerChain.add(new JaxWSClientHeaderContextProcessor());
+ bindingProvider.getBinding().setHandlerChain(handlerChain);
+
+ return port;
+
+ }
+
+ private Bistro getPortBistro()
+ {
+ // Connect to the Web Service
+ URL wsdlLocation = null;
+ try
+ {
+ wsdlLocation = new URL("http://localhost:8080/BistroImplService/BistroImpl?wsdl");
+ }
+ catch (MalformedURLException e)
+ {
+ e.printStackTrace();
+ }
+ QName serviceName = new QName("http://bistro.services.wstest/","BistroService");
+ Service service = Service.create(wsdlLocation, serviceName);
+ Bistro port = service.getPort(Bistro.class);
+
+ // Insert client handler
+ BindingProvider bindingProvider = (BindingProvider)port;
+ List<Handler> handlerChain = new ArrayList<Handler>();
+ handlerChain.add(new JaxWSClientHeaderContextProcessor());
+ bindingProvider.getBinding().setHandlerChain(handlerChain);
+
+ return port;
+
+ }
+
+ private HotelAT getPortHotelAT()
+ {
+ // Connect to the Web Service
+ URL wsdlLocation = null;
+ try
+ {
+ wsdlLocation = new URL("http://localhost:8080/HotelATImplService/HotelATImpl?wsdl");
+ }
+ catch (MalformedURLException e)
+ {
+ e.printStackTrace();
+ }
+ QName serviceName = new QName("http://at.hotel.services.wstest/","HotelATService");
+ Service service = Service.create(wsdlLocation, serviceName);
+ HotelAT port = service.getPort(HotelAT.class);
+
+ // Insert client handler
+ BindingProvider bindingProvider = (BindingProvider)port;
+ List<Handler> handlerChain = new ArrayList<Handler>();
+ handlerChain.add(new JaxWSClientHeaderContextProcessor());
+ bindingProvider.getBinding().setHandlerChain(handlerChain);
+
+ return port;
+
+ }
+
+ private HotelBA getPortHotelBA()
+ {
+ // Connect to the Web Service
+ URL wsdlLocation = null;
+ try
+ {
+ wsdlLocation = new URL("http://localhost:8080/HotelBAImplService/HotelBAImpl?wsdl");
+ }
+ catch (MalformedURLException e)
+ {
+ e.printStackTrace();
+ }
+ QName serviceName = new QName("http://ba.hotel.services.wstest/","HotelBAService");
+ Service service = Service.create(wsdlLocation, serviceName);
+ HotelBA port = service.getPort(HotelBA.class);
+
+ // Insert client handler
+ BindingProvider bindingProvider = (BindingProvider)port;
+ List<Handler> handlerChain = new ArrayList<Handler>();
+ handlerChain.add(new JaxWSClientHeaderContextProcessor());
+ bindingProvider.getBinding().setHandlerChain(handlerChain);
+
+ return port;
+
+ }
+
+}
+
+
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/bistro/Bistro.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/bistro/Bistro.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/bistro/Bistro.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,19 @@
+package wstest.services.bistro;
+
+import javax.jws.WebService;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: jhalli
+ * Date: Apr 19, 2007
+ * Time: 10:52:35 AM
+ * To change this template use File | Settings | File Templates.
+ */
+ at WebService
+public interface Bistro {
+ public void bookSeats(int how_many);
+
+ public int getBookingCount();
+
+ public int getBookingNumber();
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/bistro/BistroEntityImpl.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/bistro/BistroEntityImpl.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/bistro/BistroEntityImpl.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,47 @@
+package wstest.services.bistro;
+
+import org.apache.log4j.Logger;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.GeneratedValue;
+
+ at Entity
+ at Table(name = "bistro1")
+public class BistroEntityImpl implements Serializable
+{
+ private static Logger log = Logger.getLogger(BistroEntityImpl.class);
+
+ private int id;
+ private int bookingCount;
+
+ public BistroEntityImpl() { }
+
+ @Id
+ @GeneratedValue
+ public int getId () {
+ return id;
+ }
+
+ public void setId (int id) {
+ this.id = id;
+ }
+
+ public int getBookingCount()
+ {
+ return bookingCount;
+ }
+
+
+ public void setBookingCount(int bookingCount)
+ {
+ this.bookingCount = bookingCount;
+ }
+
+ public void increaseBookingCount(int how_many) {
+ setBookingCount( getBookingCount() + how_many );
+ }
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/bistro/BistroImpl.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/bistro/BistroImpl.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/bistro/BistroImpl.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,63 @@
+package wstest.services.bistro;
+
+import org.apache.log4j.Logger;
+
+import javax.ejb.*;
+import javax.persistence.*;
+import javax.jws.WebService;
+import javax.jws.WebMethod;
+import javax.jws.HandlerChain;
+import javax.jws.soap.SOAPBinding;
+
+ at Stateless
+ at Remote(Bistro.class)
+
+// default is REQUIRED for all methods unless overriden.
+// the container gets first crack at this, so we have to
+// tell it not to create it's own tx as we will do that.
+// TODO: ordering of container vs. registered handlers?
+//@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
+
+ at WebService(name="Bistro") // (name = "Bistro2", targetNamespace = "http://www.jboss.org/txbridgedemoejb", serviceName = "BistroService")
+ at SOAPBinding(style = SOAPBinding.Style.RPC)
+ at HandlerChain(file = "../jaxws-handlers-server.xml") // relative path from the class file
+public class BistroImpl implements Bistro {
+ private static Logger log = Logger.getLogger(BistroImpl.class);
+
+ private static final int BISTRO_ID = 1;
+
+ @PersistenceContext
+ protected EntityManager em;
+
+ @WebMethod
+ public void bookSeats(int how_many) {
+ log.info("bookSeats(how_many="+how_many+")");
+
+ BistroEntityImpl entity = getBistroEntity();
+
+ entity.increaseBookingCount(how_many);
+ }
+
+ @WebMethod
+ public int getBookingCount() {
+ log.info("getBookedSeatCount()");
+
+ return getBistroEntity().getBookingCount();
+ }
+
+ @WebMethod
+ public int getBookingNumber() {
+ return 1;
+ }
+
+ private BistroEntityImpl getBistroEntity() {
+
+ BistroEntityImpl entity = em.find(BistroEntityImpl.class, BISTRO_ID);
+ if(entity == null) {
+ entity = new BistroEntityImpl();
+ em.persist(entity);
+ }
+
+ return entity;
+ }
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/FlightManager.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/FlightManager.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/FlightManager.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,304 @@
+package wstest.services.flight;
+
+import org.apache.log4j.Logger;
+
+import java.util.Hashtable;
+
+/**
+ * Author: Maciej Machulak
+ */
+public class FlightManager
+{
+
+ private static Logger log = Logger.getLogger(FlightManager.class);
+
+ // Default values
+ private final static int SEAT_CAPACITY = 15;
+
+ // It's a singleton pattern so we have only one restaurant manager
+ private static FlightManager flight = null;
+
+ // Those hashSeats will store all the transactions - both prepared and unprepared
+ // A transaction will be stored as a pair:
+ // 1) key (transaction id = txId) - Integer
+ // 2) value (number of Seats) - String
+ private Hashtable preparedTransactions;
+ private Hashtable unpreparedTransactions;
+
+ // I'm still not sure how I will represent resources in the annotation style
+ // programming
+ // Maybe I will have just 3 copies of resources
+ // - total number of Seats
+ private Integer noOfSeats;
+ // - number of free Seats
+ private Integer noOfFreeSeats;
+ // - number of provisionally booked Seats (can be greater > noOfFreeSeats/noOfSeats)
+ private Integer noOfBookedSeats;
+ // - number of prepared Seats
+ private Integer noOfPreparedSeats;
+ // - number of committed Seats
+ private Integer noOfCommittedSeats;
+
+ /**
+ * The auto commit mode.
+ * <p/>
+ * true = automatically commit, false = manually commit
+ */
+ private boolean autoCommitMode;
+
+ /**
+ * The object used for wait/notify in manual commit mode.
+ */
+ private Object preparation;
+
+ /**
+ * The waiting status, when in manual commit mode.
+ */
+ private boolean isPreparationWaiting;
+
+ /**
+ * The user specified outcome when in manual commit mode.
+ */
+ private boolean isCommit;
+
+ private FlightManager()
+ {
+ log.info("New flight manager.");
+ setToDefault();
+ }
+
+ public void setToDefault() {
+ preparedTransactions = new Hashtable();
+ unpreparedTransactions = new Hashtable();
+ noOfSeats = SEAT_CAPACITY;
+ noOfFreeSeats = noOfSeats;
+ noOfBookedSeats = 0;
+ noOfPreparedSeats = 0;
+ noOfCommittedSeats = 0;
+ }
+
+ public static FlightManager getSingletonInstance()
+ {
+ if (flight == null)
+ {
+ flight = new FlightManager();
+ }
+ return flight;
+ }
+
+ public void bookSeats(String txId, int noOfSeats)
+ {
+ // Debug information
+ log.info("bookSeats() : " + noOfSeats);
+
+ // Check if there is already something associated with this transaction
+ Integer request = (Integer) unpreparedTransactions.get(txId);
+
+ if (request == null)
+ {
+ log.info("This is a new transaction.");
+ request = 0;
+ }
+ else
+ {
+ log.info("This transaction is already known.");
+ }
+ noOfBookedSeats = noOfBookedSeats + noOfSeats;
+ unpreparedTransactions.put(txId,request + noOfSeats);
+ log.info("Transaction added to unprepared transactions");
+ }
+
+ public boolean prepare(String txId)
+ {
+ log.info("prepare()");
+
+ // Check if there is such transaction to be prepared
+ Integer request = (Integer) unpreparedTransactions.get(txId);
+ if (request == null)
+ {
+ log.info("No such transaction.");
+ return false;
+ }
+ else
+ {
+ log.info("Request for transaction found - proceeding.");
+ log.info("Request: " + request);
+ }
+
+ // Check if there are enough resources
+ if (request > noOfFreeSeats)
+ {
+ log.info("Cannot prepare - no free resources.");
+ log.info("Request: " + request);
+ log.info("Free: " + noOfFreeSeats);
+ return false;
+ }
+ else
+ {
+ log.info("Resources are available - proceeding.");
+ }
+
+ // Calculate number of new resources
+ noOfFreeSeats = noOfFreeSeats - request;
+ noOfPreparedSeats = noOfPreparedSeats + request;
+
+ // Move transaction to the pool of prepared transactions
+ log.info("Marking transaction as PREPARED.");
+ preparedTransactions.put(txId,request);
+ unpreparedTransactions.remove(txId);
+
+ return true;
+ }
+
+ // Committing the tables - it produces the output (whether committing has been successful
+ // or not -> but the participant is still going to ignore the output of this method)
+ public boolean commit(String txId)
+ {
+
+ log.info("commit()");
+
+ // Initially the method is not successful
+ boolean success = false;
+
+ // There can be 3 situations:
+ // - 2 phase commit protocol
+ if (preparedTransactions.get(txId) != null)
+ {
+ log.info("- 2 phase commit");
+ Integer request = (Integer) preparedTransactions.get(txId);
+ preparedTransactions.remove(txId);
+ noOfPreparedSeats -= request;
+ noOfCommittedSeats += request;
+ success = true;
+ }
+ // - 1 phase commit protocol
+ else if (unpreparedTransactions.get(txId) != null)
+ {
+ log.info("- 1 phase commit");
+ Integer request = (Integer) unpreparedTransactions.get(txId);
+ unpreparedTransactions.remove(txId);
+ noOfPreparedSeats -= request;
+ noOfCommittedSeats += request;
+ success = true;
+ }
+ // - transaction invalid
+ else
+ {
+ log.info("- no such transaction");
+ }
+ return success;
+
+ }
+
+ public boolean rollback(String txId)
+ {
+ log.info("rollback()");
+ boolean success = false;
+
+ // If the transaction has already been told to prepare
+ if (preparedTransactions.containsKey(txId))
+ {
+ log.info("Rolling back prepared transaction.");
+ Integer request = (Integer) preparedTransactions.get(txId);
+ noOfPreparedSeats -= request;
+ noOfFreeSeats += request;
+ noOfBookedSeats -= request;
+ success = true;
+ }
+ else if (unpreparedTransactions.containsKey(txId))
+ {
+ log.info("Rolling back unprepared transaction.");
+ noOfBookedSeats += (Integer) unpreparedTransactions.get(txId);
+ success = true;
+ }
+ else
+ {
+ log.info("No such transaction.");
+ }
+ return success;
+
+ }
+
+ public boolean knowsAbout(Object txID)
+ {
+ log.info("knowsAbout()");
+ return (unpreparedTransactions.containsKey(txID) || preparedTransactions.containsKey(txID));
+ }
+
+
+ public Integer getNTotalSeats() {
+ return noOfSeats;
+ }
+
+ public void setNTotalSeats(Integer noOfSeats) {
+ this.noOfSeats = noOfSeats;
+ }
+
+ public Integer getNFreeSeats() {
+ return noOfFreeSeats;
+ }
+
+ public void setNFreeSeats(Integer noOfFreeSeats) {
+ this.noOfFreeSeats = noOfFreeSeats;
+ }
+
+ public Integer getNBookedSeats() {
+ return noOfBookedSeats;
+ }
+
+ public void setNBookedSeats(Integer noOfBookedSeats) {
+ this.noOfBookedSeats = noOfBookedSeats;
+ }
+
+ public Integer getNPreparedSeats() {
+ return noOfPreparedSeats;
+ }
+
+ public void setNoOfPreparedSeats(Integer noOfPreparedSeats) {
+ this.noOfPreparedSeats = noOfPreparedSeats;
+ }
+
+ public Integer getNCommittedSeats() {
+ return noOfCommittedSeats;
+ }
+
+ public void setNCommittedSeats(Integer noOfCommittedSeats) {
+ this.noOfCommittedSeats = noOfCommittedSeats;
+ }
+
+ public boolean isAutoCommitMode() {
+ return autoCommitMode;
+ }
+
+ public void setAutoCommitMode(boolean autoCommitMode) {
+ this.autoCommitMode = autoCommitMode;
+ }
+
+ public Object getPreparation() {
+ return preparation;
+ }
+
+ public void setPreparation(Object preparation) {
+ this.preparation = preparation;
+ }
+
+ public boolean isPreparationWaiting() {
+ return isPreparationWaiting;
+ }
+
+ public void setPreparationWaiting(boolean preparationWaiting) {
+ isPreparationWaiting = preparationWaiting;
+ }
+
+ public boolean isCommit() {
+ return isCommit;
+ }
+
+ public void setCommit(boolean commit) {
+ isCommit = commit;
+ }
+
+ public void newCapacity(int newCapacity) {
+ noOfSeats = newCapacity;
+ }
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/FlightView.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/FlightView.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/FlightView.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,469 @@
+package wstest.services.flight;
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a full listing
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License, v. 2.0.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License,
+ * v. 2.0 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+/*
+ * FlightView.java
+ *
+ * Copyright (c) 2003 Arjuna Technologies Ltd.
+ *
+ * $Id: FlightView.java,v 1.2 2004/04/21 13:09:18 jhalliday Exp $
+ *
+ */
+
+/**
+ * The visual interface (GUI) for the RestaurantAT Service.
+ *
+ * @author Jonathan Halliday (jonathan.halliday at arjuna.com)
+ * @version $Revision: 1.2 $
+ */
+public class FlightView extends javax.swing.JFrame
+{
+ // Note: Some parts of this file were auto-generated
+ // by NetBeans 3.3 FormEditor (http://www.netbeans.org)
+
+ /**
+ * Create a new FlightView instance.
+ *
+ * @param fManager The {@link FlightManager} instance to bind to
+ */
+ public FlightView(FlightManager fManager)
+ {
+ flightManager = fManager;
+ initComponents();
+ updateFields();
+ backButtonColor = jButtonConfirm.getBackground();
+ }
+
+ /**
+ * Initialize the form.
+ * This is called by the constructor
+ * <p/>
+ * WARNING: Automatically generated code, may be overwritten
+ */
+ private void initComponents()
+ {//GEN-BEGIN:initComponents
+ jPanel2 = new javax.swing.JPanel();
+ jLabel5 = new javax.swing.JLabel();
+ jLabelNBookedSeats = new javax.swing.JLabel();
+ jLabel9 = new javax.swing.JLabel();
+ jLabelNPreparedSeats = new javax.swing.JLabel();
+ jLabel2 = new javax.swing.JLabel();
+ jLabelNConfirmedSeats = new javax.swing.JLabel();
+ jLabel6 = new javax.swing.JLabel();
+ jLabelNFreeSeats = new javax.swing.JLabel();
+ jLabel7 = new javax.swing.JLabel();
+ jButtonResetFields = new javax.swing.JButton();
+ jPanel1 = new javax.swing.JPanel();
+ jLabel8 = new javax.swing.JLabel();
+ jLabel1 = new javax.swing.JLabel();
+ jLabelNTotalSeats = new javax.swing.JLabel();
+ jLabel4 = new javax.swing.JLabel();
+ jLabel3 = new javax.swing.JLabel();
+ jTextFieldNewNTotalSeats = new javax.swing.JTextField();
+ jButtonSetNTotalSeats = new javax.swing.JButton();
+ jPanelLeft = new javax.swing.JPanel();
+ jLabel10 = new javax.swing.JLabel();
+ jLabelDisplayMode = new javax.swing.JLabel();
+ jButtonChangeMode = new javax.swing.JButton();
+ jLabelResponse = new javax.swing.JLabel();
+ jButtonConfirm = new javax.swing.JButton();
+ jButtonCancel = new javax.swing.JButton();
+ jScrollPane1 = new javax.swing.JScrollPane();
+ jTextArea = new javax.swing.JTextArea();
+
+ setTitle("FlightAT Service");
+ setName("flightView");
+ addWindowListener(new java.awt.event.WindowAdapter()
+ {
+ public void windowClosing(java.awt.event.WindowEvent evt)
+ {
+ exitForm(evt);
+ }
+ });
+
+ jPanel2.setBorder(new javax.swing.border.LineBorder(java.awt.Color.black));
+ jLabel5.setText("Seats: ");
+ jLabel5.setFont(new java.awt.Font("Dialog", 1, 14));
+ jPanel2.add(jLabel5);
+
+ jLabelNBookedSeats.setText(Integer.toString(flightManager.getNBookedSeats()));
+ jLabelNBookedSeats.setForeground(java.awt.Color.gray);
+ jLabelNBookedSeats.setFont(new java.awt.Font("Dialog", 1, 18));
+ jPanel2.add(jLabelNBookedSeats);
+
+ jLabel9.setText("Booked, ");
+ jPanel2.add(jLabel9);
+
+ jLabelNPreparedSeats.setText(Integer.toString(flightManager.getNPreparedSeats()));
+ jLabelNPreparedSeats.setForeground(java.awt.Color.darkGray);
+ jLabelNPreparedSeats.setFont(new java.awt.Font("Dialog", 1, 18));
+ jPanel2.add(jLabelNPreparedSeats);
+
+ jLabel2.setText("Prepared, ");
+ jPanel2.add(jLabel2);
+
+ jLabelNConfirmedSeats.setText(Integer.toString(flightManager.getNCommittedSeats()));
+ jLabelNConfirmedSeats.setForeground(new java.awt.Color(0, 51, 204));
+ jLabelNConfirmedSeats.setFont(new java.awt.Font("Dialog", 1, 18));
+ jPanel2.add(jLabelNConfirmedSeats);
+
+ jLabel6.setText("Confirmed, ");
+ jPanel2.add(jLabel6);
+
+ jLabelNFreeSeats.setText(Integer.toString(flightManager.getNFreeSeats()));
+ jLabelNFreeSeats.setForeground(new java.awt.Color(0, 153, 0));
+ jLabelNFreeSeats.setFont(new java.awt.Font("Dialog", 1, 18));
+ jPanel2.add(jLabelNFreeSeats);
+
+ jLabel7.setText("Free ");
+ jPanel2.add(jLabel7);
+
+ jButtonResetFields.setText("Reset Fields");
+ jButtonResetFields.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ jButtonResetFieldsActionPerformed(evt);
+ }
+ });
+
+ jPanel2.add(jButtonResetFields);
+
+ getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
+
+ jPanel1.setBorder(new javax.swing.border.LineBorder(java.awt.Color.black));
+ jLabel8.setText("RestaurantAT ");
+ jLabel8.setForeground(java.awt.Color.red);
+ jLabel8.setFont(new java.awt.Font("Dialog", 1, 24));
+ jPanel1.add(jLabel8);
+
+ jLabel1.setText("Capacity:");
+ jLabel1.setFont(new java.awt.Font("Dialog", 1, 14));
+ jPanel1.add(jLabel1);
+
+ jLabelNTotalSeats.setText(Integer.toString(flightManager.getNTotalSeats()));
+ jLabelNTotalSeats.setForeground(java.awt.Color.darkGray);
+ jLabelNTotalSeats.setFont(new java.awt.Font("Dialog", 1, 18));
+ jPanel1.add(jLabelNTotalSeats);
+
+ jLabel4.setText("Seats");
+ jLabel4.setFont(new java.awt.Font("Dialog", 1, 14));
+ jPanel1.add(jLabel4);
+
+ jLabel3.setText(" New capacity:");
+ jLabel3.setFont(new java.awt.Font("Dialog", 1, 14));
+ jPanel1.add(jLabel3);
+
+ jTextFieldNewNTotalSeats.setFont(new java.awt.Font("Dialog", 0, 18));
+ jTextFieldNewNTotalSeats.setText(Integer.toString(flightManager.getNTotalSeats()));
+ jPanel1.add(jTextFieldNewNTotalSeats);
+
+ jButtonSetNTotalSeats.setFont(new java.awt.Font("Dialog", 1, 14));
+ jButtonSetNTotalSeats.setText("Set");
+ jButtonSetNTotalSeats.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ jButtonSetNTotalSeatsActionPerformed(evt);
+ }
+ });
+
+ jPanel1.add(jButtonSetNTotalSeats);
+
+ getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
+
+ jPanelLeft.setLayout(new javax.swing.BoxLayout(jPanelLeft, javax.swing.BoxLayout.Y_AXIS));
+
+ jLabel10.setText("Mode:");
+ jPanelLeft.add(jLabel10);
+
+ jLabelDisplayMode.setText("Automatic");
+ jLabelDisplayMode.setForeground(java.awt.Color.blue);
+ jLabelDisplayMode.setFont(new java.awt.Font("Dialog", 1, 18));
+ jPanelLeft.add(jLabelDisplayMode);
+
+ jButtonChangeMode.setText("Change mode");
+ jButtonChangeMode.setPreferredSize(new java.awt.Dimension(119, 27));
+ jButtonChangeMode.setMaximumSize(new java.awt.Dimension(119, 27));
+ jButtonChangeMode.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ jButtonChangeModeActionPerformed(evt);
+ }
+ });
+
+ jPanelLeft.add(jButtonChangeMode);
+
+ jLabelResponse.setText("Response:");
+ jPanelLeft.add(jLabelResponse);
+
+ jButtonConfirm.setText("Confirm");
+ jButtonConfirm.setPreferredSize(new java.awt.Dimension(119, 27));
+ jButtonConfirm.setMaximumSize(new java.awt.Dimension(119, 27));
+ jButtonConfirm.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ jButtonConfirmActionPerformed(evt);
+ }
+ });
+
+ jPanelLeft.add(jButtonConfirm);
+
+ jButtonCancel.setText("Cancel");
+ jButtonCancel.setPreferredSize(new java.awt.Dimension(119, 27));
+ jButtonCancel.setMaximumSize(new java.awt.Dimension(119, 27));
+ jButtonCancel.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ jButtonCancelActionPerformed(evt);
+ }
+ });
+
+ jPanelLeft.add(jButtonCancel);
+
+ getContentPane().add(jPanelLeft, java.awt.BorderLayout.WEST);
+
+ jScrollPane1.setAutoscrolls(true);
+ jTextArea.setEditable(false);
+ jTextArea.setRows(10);
+ jTextArea.setMargin(new java.awt.Insets(5, 5, 5, 5));
+ jScrollPane1.setViewportView(jTextArea);
+
+ getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
+
+ pack();
+ }//GEN-END:initComponents
+
+ /**
+ * Reset event handler.
+ */
+ private void jButtonResetFieldsActionPerformed(java.awt.event.ActionEvent evt)
+ {//GEN-FIRST:event_jButtonResetFieldsActionPerformed
+ flightManager.setToDefault();
+ updateFields();
+ }//GEN-LAST:event_jButtonResetFieldsActionPerformed
+
+ /**
+ * Cancel event handler.
+ */
+ private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt)
+ {//GEN-FIRST:event_jButtonCancelActionPerformed
+ if (flightManager.isPreparationWaiting())
+ {
+ Object preparation = flightManager.getPreparation();
+ try
+ {
+ flightManager.setCommit(false);
+ synchronized (preparation)
+ {
+ preparation.notify();
+ }
+ }
+ catch (Exception e)
+ {
+ System.err.println("FlightView.jButtonCancelActionPerformed(): Unable to notify preparation.");
+ }
+ }
+ }//GEN-LAST:event_jButtonCancelActionPerformed
+
+ /**
+ * Confirm event handler.
+ */
+ private void jButtonConfirmActionPerformed(java.awt.event.ActionEvent evt)
+ {//GEN-FIRST:event_jButtonConfirmActionPerformed
+ if (flightManager.isPreparationWaiting())
+ {
+ Object preparation = flightManager.getPreparation();
+ try
+ {
+ flightManager.setCommit(true);
+ synchronized (preparation)
+ {
+ preparation.notify();
+ }
+ }
+ catch (Exception e)
+ {
+ System.err.println("FlightView.jButtonCancelActionPerformed(): Unable to notify preparation.");
+ }
+ }
+ }//GEN-LAST:event_jButtonConfirmActionPerformed
+
+ /**
+ * ChangeMode event handler.
+ */
+ private void jButtonChangeModeActionPerformed(java.awt.event.ActionEvent evt)
+ {//GEN-FIRST:event_jButtonChangeModeActionPerformed
+ if (flightManager.isAutoCommitMode())
+ {
+ flightManager.setAutoCommitMode(false);
+ }
+ else
+ {
+ flightManager.setAutoCommitMode(true);
+ }
+ updateFields();
+ }//GEN-LAST:event_jButtonChangeModeActionPerformed
+
+ /**
+ * Capacity change event handler.
+ */
+ private void jButtonSetNTotalSeatsActionPerformed(java.awt.event.ActionEvent evt)
+ {//GEN-FIRST:event_jButtonSetNTotalSeatsActionPerformed
+ String strNSeats = jTextFieldNewNTotalSeats.getText();
+
+ flightManager.newCapacity(Integer.parseInt(strNSeats));
+ int nFreeSeats = flightManager.getNFreeSeats();
+
+ jLabelNTotalSeats.setText(strNSeats);
+ jLabelNFreeSeats.setText(Integer.toString(nFreeSeats));
+ }//GEN-LAST:event_jButtonSetNTotalSeatsActionPerformed
+
+ /**
+ * Exit the application.
+ */
+ private void exitForm(java.awt.event.WindowEvent evt)
+ {//GEN-FIRST:event_exitForm
+ //System.exit(0); // disabled for embedding in application servers.
+ }//GEN-LAST:event_exitForm
+
+ /**
+ * Add regular text to the central jTextArea.
+ *
+ * @param text The String to add
+ */
+ public void addMessage(java.lang.String text)
+ {
+ jButtonConfirm.setBackground(backButtonColor);
+ jButtonCancel.setBackground(backButtonColor);
+ jTextArea.append(text + "\n");
+ jScrollPane1.getVerticalScrollBar().setValue(jScrollPane1.getVerticalScrollBar().getMaximum());
+ }
+
+ /**
+ * Add status (highlighted) text to the central jTextArea.
+ *
+ * @param text The String to add
+ */
+ public void addPrepareMessage(java.lang.String text)
+ {
+ jButtonConfirm.setBackground(java.awt.Color.red);
+ jButtonCancel.setBackground(java.awt.Color.red);
+ jTextArea.append(text + "\n");
+ jScrollPane1.getVerticalScrollBar().setValue(jScrollPane1.getVerticalScrollBar().getMaximum());
+ }
+
+
+ /**
+ * Synchronise the GUI with the underlying state.
+ */
+ public void updateFields()
+ {
+ jLabelNTotalSeats.setText(Integer.toString(flightManager.getNTotalSeats()));
+ jTextFieldNewNTotalSeats.setText(Integer.toString(flightManager.getNTotalSeats()));
+ jLabelNPreparedSeats.setText(Integer.toString(flightManager.getNPreparedSeats()));
+ jLabelNConfirmedSeats.setText(Integer.toString(flightManager.getNCommittedSeats()));
+ jLabelNFreeSeats.setText(Integer.toString(flightManager.getNFreeSeats()));
+ jLabelNBookedSeats.setText(Integer.toString(flightManager.getNBookedSeats()));
+
+ //update fields related to interactive mode.
+ if (flightManager.isAutoCommitMode())
+ {
+ jLabelResponse.setVisible(false);
+ jButtonConfirm.setVisible(false);
+ jButtonCancel.setVisible(false);
+ jLabelDisplayMode.setText("automatic");
+ }
+ else
+ {
+ jLabelResponse.setVisible(true);
+ jButtonConfirm.setVisible(true);
+ jButtonCancel.setVisible(true);
+ jLabelDisplayMode.setText("interactive");
+ }
+ }
+
+ /**
+ * Allow use of a singleton model for web services demo.
+ */
+ public static FlightView getSingletonInstance()
+ {
+ if (singletonInstance == null)
+ {
+ singletonInstance = new FlightView(FlightManager.getSingletonInstance());
+ }
+
+ singletonInstance.show();
+ return singletonInstance;
+ }
+
+ /**
+ * A singleton instance of this class.
+ */
+ private static FlightView singletonInstance;
+
+
+ // Variables declaration - automatically generated - do not modify
+
+ private javax.swing.JPanel jPanel2;
+ private javax.swing.JLabel jLabel5;
+ private javax.swing.JLabel jLabelNBookedSeats;
+ private javax.swing.JLabel jLabel9;
+ private javax.swing.JLabel jLabelNPreparedSeats;
+ private javax.swing.JLabel jLabel2;
+ private javax.swing.JLabel jLabelNConfirmedSeats;
+ private javax.swing.JLabel jLabel6;
+ private javax.swing.JLabel jLabelNFreeSeats;
+ private javax.swing.JLabel jLabel7;
+ private javax.swing.JButton jButtonResetFields;
+ private javax.swing.JPanel jPanel1;
+ private javax.swing.JLabel jLabel8;
+ private javax.swing.JLabel jLabel1;
+ private javax.swing.JLabel jLabelNTotalSeats;
+ private javax.swing.JLabel jLabel4;
+ private javax.swing.JLabel jLabel3;
+ private javax.swing.JTextField jTextFieldNewNTotalSeats;
+ private javax.swing.JButton jButtonSetNTotalSeats;
+ private javax.swing.JPanel jPanelLeft;
+ private javax.swing.JLabel jLabel10;
+ private javax.swing.JLabel jLabelDisplayMode;
+ private javax.swing.JButton jButtonChangeMode;
+ private javax.swing.JLabel jLabelResponse;
+ private javax.swing.JButton jButtonConfirm;
+ private javax.swing.JButton jButtonCancel;
+ private javax.swing.JScrollPane jScrollPane1;
+ private javax.swing.JTextArea jTextArea;
+
+ // End of automatically generated variables declarations
+
+ /**
+ * The {@link FlightManager} instance this view is bound to.
+ */
+ private FlightManager flightManager;
+
+ /**
+ * The current color of the back button.
+ */
+ private java.awt.Color backButtonColor;
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/at/FlightAT.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/at/FlightAT.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/at/FlightAT.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,15 @@
+package wstest.services.flight.at;
+
+import javax.jws.WebService;
+
+/**
+ * Author: Maciej Machulak
+ */
+ at WebService
+public interface FlightAT {
+
+ public void bookSeats(int noOfSeats);
+
+
+
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/at/FlightATImpl.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/at/FlightATImpl.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/at/FlightATImpl.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,77 @@
+package wstest.services.flight.at;
+
+import org.apache.log4j.Logger;
+import com.arjuna.mw.wst.UserTransactionFactory;
+import com.arjuna.mw.wst.TransactionManagerFactory;
+import com.arjuna.ats.arjuna.common.Uid;
+
+import javax.ejb.Stateless;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.jws.WebService;
+import javax.jws.HandlerChain;
+import javax.jws.soap.SOAPBinding;
+
+import wstest.services.flight.FlightManager;
+
+/**
+ * Author: Maciej Machulak
+ */
+ at Stateless
+ at WebService(endpointInterface = "wstest.services.flight.at.FlightAT")
+ at SOAPBinding(style=SOAPBinding.Style.RPC)
+ at HandlerChain(file="jaxws-hotel-handlers-server.xml")
+public class FlightATImpl implements FlightAT {
+
+ private static Logger log = Logger.getLogger(FlightATImpl.class);
+
+ private static FlightManager flight = FlightManager.getSingletonInstance();
+
+ FlightATImpl()
+ {
+
+ }
+
+ @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
+ public void bookSeats(int noOfSeats)
+ {
+
+ // Debug information
+ log.info("bookRooms()");
+
+ // Getting the transaction identifier
+ String txId = UserTransactionFactory.userTransaction().transactionIdentifier();
+ log.info("Transaction identifier: " + txId);
+
+ // Checking if this is a transaction we are aware of
+ if (flight.knowsAbout(txId))
+ {
+ log.info("Transaction known.");
+ }
+ else
+ {
+ // Creating a participant for a new transaction
+ try
+ {
+ log.info("New transaction.");
+
+ // Creating a participant
+ log.info("Creating participant.");
+ FlightParticipantAT participant = new FlightParticipantAT(txId);
+
+ // Enlisting the participant
+ log.info("Enlisting participant.");
+ TransactionManagerFactory.transactionManager().enlistForDurableTwoPhase(participant,new Uid().toString());
+ log.info("Participant successfully enlisted.");
+ }
+ catch (Exception e)
+ {
+ log.error("Participant could not be enlisted.");
+ }
+ }
+ // Calling a bookTables method on the flight manager
+ flight.bookSeats(txId,noOfSeats);
+
+ }
+
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/at/FlightParticipantAT.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/at/FlightParticipantAT.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/at/FlightParticipantAT.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,94 @@
+package wstest.services.flight.at;
+
+import com.arjuna.wst.*;
+import org.apache.log4j.Logger;
+import wstest.services.flight.FlightManager;
+import wstest.services.flight.FlightView;
+
+/**
+ * Author: Maciej Machulak
+ */
+public class FlightParticipantAT implements Durable2PCParticipant
+{
+
+ // Logger
+ private static Logger log = Logger.getLogger(FlightParticipantAT.class);
+
+ // Transaction identifier
+ String txId;
+
+ // Business logic
+ private FlightManager flightManager;
+ // View
+ private FlightView flightView;
+
+
+ public FlightParticipantAT(String txId)
+ {
+ log.info("Constructor.");
+ flightManager = FlightManager.getSingletonInstance();
+ flightView = FlightView.getSingletonInstance();
+ this.txId = txId;
+ flightView.addMessage("Transaction: " + txId);
+ }
+
+ public Vote prepare() throws WrongStateException, SystemException
+ {
+ log.info("prepare()");
+
+ // Executing perform logic
+ boolean success = flightManager.prepare(txId);
+
+ // Checking if the logic has been executed successfully
+ if ( success )
+ {
+ log.info("prepare() successful");
+ return new Prepared();
+ }
+ log.info("prepare() failed");
+ return new Aborted();
+ }
+
+ public void commit() throws WrongStateException, SystemException
+ {
+ log.info("commit()");
+
+ // Executing commit logic
+ boolean success = flightManager.commit(txId);
+
+ // Checking if the logic has been executed succesfully
+ if ( success )
+ {
+ log.info("commit() succesful");
+ }
+ else
+ {
+ log.info("commit() failed");
+ }
+ }
+
+ public void rollback() throws WrongStateException, SystemException
+ {
+ log.info("rollback()");
+
+ // Executing rollback
+ boolean success = flightManager.rollback(txId);
+ if ( success )
+ {
+ log.info("rollback() successful");
+ }
+ else
+ {
+ log.info("rollback() failed");
+ }
+ }
+
+ public void unknown() throws SystemException
+ {
+ log.info("uknown()");
+ }
+
+ public void error() throws SystemException {
+ log.info("error()");
+ }
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/ba/FlightBA.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/ba/FlightBA.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/ba/FlightBA.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,12 @@
+package wstest.services.flight.ba;
+
+import javax.jws.WebService;
+
+/**
+ * Author: Maciej Machulak
+ */
+ at WebService
+public interface FlightBA {
+
+ public boolean bookSeats(int noOfSeats);
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/ba/FlightBAImpl.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/ba/FlightBAImpl.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/ba/FlightBAImpl.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,88 @@
+package wstest.services.flight.ba;
+
+import org.apache.log4j.Logger;
+import com.arjuna.mw.wst.BusinessActivityManager;
+import com.arjuna.wst.SystemException;
+import com.arjuna.wst.BAParticipantManager;
+import com.arjuna.ats.arjuna.common.Uid;
+
+import javax.ejb.Stateless;
+import javax.jws.WebService;
+import javax.jws.HandlerChain;
+import javax.jws.soap.SOAPBinding;
+
+import wstest.services.flight.FlightView;
+import wstest.services.flight.FlightManager;
+
+/**
+ * Author: Maciej Machulak
+ */
+ at Stateless
+ at WebService(endpointInterface = "wstest.services.flight.ba.FlightBA")
+ at SOAPBinding(style=SOAPBinding.Style.RPC)
+ at HandlerChain(file="../../jaxws-ba-handlers-server.xml")
+public class FlightBAImpl implements FlightBA
+{
+ private static Logger log = Logger.getLogger(FlightBAImpl.class);
+
+ public FlightBAImpl()
+ {
+ }
+
+ public boolean bookSeats(int noOfSeats)
+ {
+ FlightView flightView = FlightView.getSingletonInstance();
+ FlightManager flightManager = FlightManager.getSingletonInstance();
+
+ BusinessActivityManager businessActivityManager = BusinessActivityManager.getBusinessActivityManager();
+
+ String txId = null;
+ try
+ {
+ txId = businessActivityManager.currentTransaction().toString();
+ }
+ catch (SystemException se)
+ {
+ se.printStackTrace();
+ return false;
+ }
+
+ flightManager.bookSeats(txId,noOfSeats);
+
+ if (flightManager.prepare(txId))
+ {
+ FlightParticipantBA flightParticipantBA = new FlightParticipantBA(txId,noOfSeats);
+
+ BAParticipantManager participantManager = null;
+
+ try
+ {
+ participantManager = businessActivityManager.enlistForBusinessAgreementWithParticipantCompletion(flightParticipantBA,new Uid().toString());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ return false;
+ }
+
+ flightManager.commit(txId);
+ try
+ {
+ participantManager.completed();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ return false;
+ }
+ }
+ else
+ {
+ flightManager.rollback(txId);
+ return false;
+ }
+
+ return true;
+
+ }
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/ba/FlightParticipantBA.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/ba/FlightParticipantBA.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/flight/ba/FlightParticipantBA.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,94 @@
+package wstest.services.flight.ba;
+
+import com.arjuna.wst.*;
+import com.arjuna.ats.arjuna.common.Uid;
+import org.apache.log4j.Logger;
+import wstest.services.flight.FlightManager;
+
+/**
+ * Author: Maciej Machulak
+ */
+public class FlightParticipantBA implements BusinessAgreementWithParticipantCompletionParticipant
+{
+
+ private static Logger log = Logger.getLogger(FlightParticipantBA.class);
+
+ private String txId;
+ private int noOfSeats;
+ private static FlightManager flightManager;
+
+
+ public FlightParticipantBA(String txId, int noOfSeats)
+ {
+ log.info("constructor()");
+ log.info("Transaction: " + txId + " with " + noOfSeats + "seats");
+ flightManager = FlightManager.getSingletonInstance();
+ this.txId = txId;
+ this.noOfSeats = noOfSeats;
+ }
+
+ public void close() throws WrongStateException, SystemException
+ {
+ log.info("close()");
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void cancel() throws WrongStateException, SystemException
+ {
+ log.info("cancel()");
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void compensate() throws FaultedException, WrongStateException, SystemException
+ {
+ log.info("compensate()");
+ if (noOfSeats > 0)
+ {
+ String compensatingTxId = new Uid().toString();
+
+ log.info("compensate() - unbooking");
+ flightManager.bookSeats(compensatingTxId,0-noOfSeats);
+ boolean success = false;
+
+ if (flightManager.prepare(compensatingTxId))
+ {
+ log.info("prepared");
+ if(flightManager.commit(compensatingTxId))
+ {
+ log.info("committed");
+ success = true;
+ }
+ }
+ else
+ {
+ log.info("could not prepare - rolling back");
+ flightManager.rollback(compensatingTxId);
+ }
+
+ if (!success)
+ {
+ throw new SystemException("Compensation failed.");
+ }
+ }
+
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String status() throws SystemException
+ {
+ log.info("status()");
+ return Status.STATUS_ACTIVE;
+ }
+
+ public void unknown() throws SystemException
+ {
+ log.info("uknown()");
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void error() throws SystemException
+ {
+ log.info("error()");
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/HotelEntityImpl.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/HotelEntityImpl.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/HotelEntityImpl.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,51 @@
+package wstest.services.hotel;
+
+import org.apache.log4j.Logger;
+
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+/**
+ * Author: Maciej Machulak
+ */
+ at Entity
+ at Table(name = "hotel")
+public class HotelEntityImpl
+{
+ private static Logger log = Logger.getLogger(HotelEntityImpl.class);
+
+ private int id;
+ private int bookingCount;
+
+ public HotelEntityImpl() { }
+
+ @Id
+ @GeneratedValue
+ public int getId ()
+ {
+ return id;
+ }
+
+ public void setId (int id)
+ {
+ this.id = id;
+ }
+
+ public int getBookingCount()
+ {
+ return bookingCount;
+ }
+
+
+ public void setBookingCount(int bookingCount)
+ {
+ this.bookingCount = bookingCount;
+ }
+
+ public void increaseBookingCount(int how_many)
+ {
+ setBookingCount( getBookingCount() + how_many );
+ }
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/HotelImpl.class
===================================================================
(Binary files differ)
Property changes on: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/HotelImpl.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/HotelView.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/HotelView.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/HotelView.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,56 @@
+package wstest.services.hotel;
+
+import javax.swing.*;
+import java.awt.*;
+
+/**
+ * Author: Maciej Machulak
+ */
+public class HotelView extends JFrame
+{
+ private volatile static HotelView hotelView;
+
+ private JTextArea textArea;
+ private JScrollPane scrollPane;
+
+ private HotelView()
+ {
+ setLayout(new BorderLayout());
+ setSize(600,300);
+
+ textArea = new JTextArea(40,20);
+ scrollPane = new JScrollPane();
+
+ scrollPane.setAutoscrolls(true);
+ textArea.setEditable(false);
+ textArea.setRows(10);
+ textArea.setMargin(new java.awt.Insets(5, 5, 5, 5));
+ scrollPane.setViewportView(textArea);
+
+ getContentPane().add(scrollPane,BorderLayout.CENTER);
+ setVisible(true);
+ repaint();
+
+ }
+
+ public static HotelView getSingletonInstance()
+ {
+ if (hotelView == null)
+ {
+ synchronized(HotelView.class)
+ {
+ if (hotelView == null)
+ {
+ hotelView = new HotelView();
+ }
+ }
+ }
+ return hotelView;
+ }
+
+ public void addMessage(String message)
+ {
+ textArea.append(message + "\n");
+ }
+
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/UserDescription.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/UserDescription.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/UserDescription.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,34 @@
+package wstest.services.hotel;
+
+/**
+ * Author: Maciej Machulak
+ */
+public class UserDescription
+{
+ private String username;
+ private Integer roomNumber;
+ private Integer reservationNumber;
+
+
+ public UserDescription(String username, Integer roomNumber, Integer reservationNumber)
+ {
+ this.username = username;
+ this.roomNumber = roomNumber;
+ this.reservationNumber = reservationNumber;
+ }
+
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append("User:");
+ sb.append(username);
+ sb.append(",");
+ sb.append("Room:");
+ sb.append(roomNumber);
+ sb.append(",");
+ sb.append("Reservation:");
+ sb.append(reservationNumber);
+ return sb.toString();
+ }
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/at/HotelAT.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/at/HotelAT.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/at/HotelAT.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,21 @@
+package wstest.services.hotel.at;
+
+import javax.jws.WebService;
+
+/**
+ * Author: Maciej Machulak
+ * Date: May 16, 2007
+ */
+ at WebService
+public interface HotelAT {
+
+ void bookRooms(int how_many);
+
+ int getBookingCount();
+
+ String getHotelInfo();
+
+ String getHotelAddress();
+
+ String getHotelOwner();
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/at/HotelATImpl.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/at/HotelATImpl.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/at/HotelATImpl.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,83 @@
+package wstest.services.hotel.at;
+
+import org.apache.log4j.Logger;
+
+import javax.persistence.PersistenceContext;
+import javax.persistence.EntityManager;
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.jws.HandlerChain;
+import javax.jws.soap.SOAPBinding;
+import javax.ejb.*;
+
+import wstest.services.hotel.at.HotelAT;
+import wstest.services.hotel.HotelEntityImpl;
+
+ at Stateless
+ at Remote(HotelAT.class)
+
+// default is REQUIRED for all methods unless overriden.
+// the container gets first crack at this, so we have to
+// tell it not to create it's own tx as we will do that.
+// TODO: ordering of container vs. registered handlers?
+//@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
+
+ at WebService(name="HotelAT") // (name = "Bistro2", targetNamespace = "http://www.jboss.org/txbridgedemoejb", serviceName = "BistroService")
+ at SOAPBinding(style = SOAPBinding.Style.RPC)
+ at HandlerChain(file = "jaxws-hotel-handlers-server.xml") // relative path from the class file
+public class HotelATImpl implements HotelAT {
+
+ private static Logger log = Logger.getLogger(HotelATImpl.class);
+ private static final int HOTEL_ID = 1;
+
+ @PersistenceContext
+ protected EntityManager em;
+
+ @WebMethod
+ public void bookRooms(int how_many)
+ {
+ log.info("bookRooms(how_many="+how_many+")");
+ HotelEntityImpl entity = getHotelEntity();
+ entity.increaseBookingCount(how_many);
+ }
+
+ @WebMethod
+ @TransactionAttribute(TransactionAttributeType.MANDATORY)
+ public int getBookingCount()
+ {
+ log.info("getBookedSeatCount()");
+ return getHotelEntity().getBookingCount();
+ }
+
+ @WebMethod
+ @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
+ public String getHotelInfo()
+ {
+ log.info("getHotelInfo()");
+ return "HotelAT Hilton";
+ }
+
+ @WebMethod
+ @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
+ public String getHotelAddress()
+ {
+ log.info("getHotelAddress()");
+ return "HotelAT Address";
+ }
+
+ public String getHotelOwner()
+ {
+ log.info("getHotelOwner()");
+ return "HotelAT Owner";
+ }
+
+ private HotelEntityImpl getHotelEntity()
+ {
+ HotelEntityImpl entity = em.find(HotelEntityImpl.class, HOTEL_ID);
+ if(entity == null) {
+ entity = new HotelEntityImpl();
+ em.persist(entity);
+ }
+ return entity;
+ }
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/ba/HotelBA.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/ba/HotelBA.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/ba/HotelBA.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,27 @@
+package wstest.services.hotel.ba;
+
+import javax.jws.WebService;
+import javax.jws.WebMethod;
+
+/**
+ * Author: Maciej Machulak
+ */
+ at WebService
+public interface HotelBA
+{
+
+ void bookRooms(int how_many);
+
+ int getBookingCount();
+
+ String getHotelInfo(String username);
+
+ String getHotelAddress(String username);
+
+ String getHotelOwner();
+
+ Integer makeReservation(String userName, String password, Integer roomNumber);
+
+ void cancelReservation(String userName,String password, Integer reservationNumber);
+
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/ba/HotelBAImpl.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/ba/HotelBAImpl.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/hotel/ba/HotelBAImpl.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,233 @@
+package wstest.services.hotel.ba;
+
+import org.apache.log4j.Logger;
+import org.jboss.txbridge.annotations.*;
+import org.jboss.txbridge.helper.CompensationManager;
+
+import javax.persistence.PersistenceContext;
+import javax.persistence.EntityManager;
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.jws.HandlerChain;
+import javax.jws.soap.SOAPBinding;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.ejb.Stateless;
+import javax.ejb.Remote;
+
+import wstest.services.hotel.HotelEntityImpl;
+import wstest.services.hotel.HotelView;
+import wstest.services.hotel.UserDescription;
+
+import java.util.Random;
+import java.util.Map;
+import java.util.HashMap;
+
+ at Stateless
+ at Remote(HotelBA.class)
+/**
+ * Author: Maciej Machulak
+ */
+ at WebService(name="HotelBA") // (name = "Bistro2", targetNamespace = "http://www.jboss.org/txbridgedemoejb", serviceName = "BistroService")
+ at SOAPBinding(style = SOAPBinding.Style.RPC)
+ at HandlerChain(file = "../../jaxws-ba-handlers-server.xml")
+public class HotelBAImpl implements HotelBA
+{
+ // Logger
+ private static Logger log = Logger.getLogger(HotelBAImpl.class);
+
+ // Random Generator
+ Random randomGenerator = new Random();
+
+ // View
+ HotelView hotelView = HotelView.getSingletonInstance();
+
+ @PersistenceContext
+ protected EntityManager em;
+
+ @CompensationManagement
+ private CompensationManager cm = new CompensationManager();
+
+ @CompensationIdentifier
+ private String cid;
+
+ // Reservations (Reservation_Number,Hotel_Room_Number)
+ private static Map<Integer,Integer> reservations = new HashMap<Integer,Integer>();
+
+ // Service account
+ private static Integer serviceAccount = 0;
+
+ private static final int HOTEL_ID = 1;
+
+ @WebMethod
+ @BAService(BAServiceType.READONLY)
+ @BATransactionAttribute(BATransactionAttributeType.PARTICIPANT_COMPLETION)
+ public String getHotelInfo(String username)
+ {
+ hotelView.addMessage("getHotelInfo()");
+
+ String returnValue = "Hotel Information...";
+
+ log.info("getHotelInfo(" + username + ")");
+ log.info("Returning: " + returnValue);
+
+ return returnValue;
+ }
+
+ @WebMethod
+ @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
+ public String getHotelAddress(String username)
+ {
+ hotelView.addMessage("getHotelAddress()");
+
+ String returnValue = "Hotel Address...";
+
+ log.info("getHotelAddress(" + username + ")");
+ log.info("Returning:" + returnValue);
+
+ return returnValue;
+ }
+
+ @WebMethod
+ @BAService(BAServiceType.MODIFY)
+ @BATransactionAttribute(BATransactionAttributeType.PARTICIPANT_COMPLETION)
+ @BACompensatedBy("getHotelAddress")
+ public String getHotelOwner()
+ {
+ hotelView.addMessage("getHotelOwner()");
+
+ String returnValue = "Hotel Owner...";
+
+ log.info("getHotelOwner()");
+
+ return returnValue;
+ }
+
+ @WebMethod
+ @BAService(BAServiceType.MODIFY)
+ @BATransactionAttribute(BATransactionAttributeType.PARTICIPANT_COMPLETION)
+ @BACompensatedBy("cancelReservation")
+ public Integer makeReservation(String userName, String password, Integer roomNumber)
+ {
+ log.info("makeReservation()");
+
+ String reservationAnnotation = "User " + userName + " charge.";
+
+ hotelView.addMessage("makeReservation()");
+ hotelView.addMessage("Username: " + userName);
+ hotelView.addMessage("Password: " + password);
+ hotelView.addMessage("Room no: " + roomNumber);
+
+ Integer reservationNumber = randomGenerator.nextInt();
+ hotelView.addMessage("Obtained reservation number: " + reservationNumber);
+ reservations.put(reservationNumber,roomNumber);
+ hotelView.addMessage("Reservation has been stored...");
+ hotelView.addMessage("Original service balance: " + serviceAccount);
+ hotelView.addMessage("Username's length: " + userName.length());
+ hotelView.addMessage("Charging for the reservation: " + userName.length());
+ serviceAccount = serviceAccount + userName.length();
+ hotelView.addMessage("New service balance: " + serviceAccount);
+ log.info("Creating user object...");
+ UserDescription theUserDescription = new UserDescription(userName,roomNumber,reservationNumber);
+
+ // -- TRANSACTION RELATED CODE BEGIN
+ cm.store("makeReservation",userName);
+ cm.store("makeReservation",password);
+ cm.storeTemporary("makeReservation","charge",userName.length());
+ cm.storeTemporary("makeReservation","annotation",reservationAnnotation);
+ cm.storeTemporary("makeReservation","user",theUserDescription);
+ // -- TRANSACTION RELATED CODE END
+
+ hotelView.addMessage("-------------");
+ hotelView.addMessage("Reservations:");
+ for (Integer singleKey : reservations.keySet())
+ {
+ hotelView.addMessage("(" + singleKey + "," + reservations.get(singleKey)+")");
+ }
+
+ return reservationNumber;
+ }
+
+ @WebMethod
+ public void cancelReservation(String userName,String password, Integer reservationNumber)
+ {
+ log.info("cancelReservation()");
+
+ hotelView.addMessage("cancelReservation()");
+ hotelView.addMessage("Username: " + userName);
+ hotelView.addMessage("Password: " + password);
+ hotelView.addMessage("Reservation no: " + reservationNumber);
+
+ if (!reservations.containsKey(reservationNumber))
+ {
+ log.info("No such reservation.");
+ }
+ else
+ {
+ log.info("Reservation cancelled.");
+ reservations.remove(reservationNumber);
+ }
+ hotelView.addMessage("Current service balance: " + serviceAccount);
+ hotelView.addMessage("Checking if refund should be given...");
+
+ // - TRANSACTION RELATED CODE - BEGIN //
+ Integer reservationCharge = (Integer) cm.getTemporaryObject(cid,"cancelReservation","charge");
+ String reservationAnnotation = (String) cm.getTemporaryObject(cid,"cancelReservation","annotation");
+ UserDescription user = (UserDescription) cm.getTemporaryObject(cid,"cancelReservation","user");
+ // - TRANSACTION RELATED CODE - END //
+
+ if (user != null)
+ {
+ hotelView.addMessage(user.toString());
+ }
+ if (reservationCharge != null)
+ {
+ hotelView.addMessage("User paid: " + reservationCharge);
+ hotelView.addMessage("Refund: " + reservationCharge/2);
+ if (reservationAnnotation != null)
+ {
+ hotelView.addMessage("Refund given for: " + reservationAnnotation);
+ serviceAccount = serviceAccount - reservationCharge;
+ }
+ hotelView.addMessage("New service balance: " + serviceAccount);
+ }
+ else
+ {
+ hotelView.addMessage("No refund. This is a normal cancel");
+ }
+
+ hotelView.addMessage("-------------");
+ hotelView.addMessage("Reservations:");
+ for (Integer singleKey : reservations.keySet())
+ {
+ hotelView.addMessage("(" + singleKey + "," + reservations.get(singleKey)+")");
+ }
+ }
+
+ @WebMethod
+ public void bookRooms(int how_many)
+ {
+ log.info("bookRooms(how_many="+how_many+")");
+ HotelEntityImpl entity = getHotelEntity();
+ entity.increaseBookingCount(how_many);
+ }
+
+ @WebMethod
+ @TransactionAttribute(TransactionAttributeType.MANDATORY)
+ public int getBookingCount()
+ {
+ log.info("getBookedSeatCount()");
+ return getHotelEntity().getBookingCount();
+ }
+
+ private HotelEntityImpl getHotelEntity()
+ {
+ HotelEntityImpl entity = em.find(HotelEntityImpl.class, HOTEL_ID);
+ if(entity == null)
+ {
+ entity = new HotelEntityImpl();
+ em.persist(entity);
+ }
+ return entity;
+ }
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantAT.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantAT.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantAT.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,12 @@
+package wstest.services.restaurant;
+
+import javax.jws.WebService;
+
+/**
+ * Author: Maciej Machulak
+ */
+ at WebService
+public interface RestaurantAT
+{
+ public void bookTables(int noOfTables);
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantATImpl.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantATImpl.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantATImpl.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,70 @@
+package wstest.services.restaurant;
+
+import org.apache.log4j.Logger;
+
+import javax.ejb.Stateless;
+import javax.jws.WebService;
+import javax.jws.HandlerChain;
+import javax.jws.soap.SOAPBinding;
+
+import com.arjuna.mw.wst.UserTransactionFactory;
+import com.arjuna.mw.wst.TransactionManagerFactory;
+import com.arjuna.ats.arjuna.common.Uid;
+
+/**
+ * Author: Maciej Machulak
+ */
+
+ at Stateless
+ at WebService(endpointInterface = "wstest.services.restaurant.RestaurantAT")
+ at SOAPBinding(style=SOAPBinding.Style.RPC)
+ at HandlerChain(file="../jaxws-handlers-server.xml")
+public class RestaurantATImpl implements RestaurantAT {
+ // Logger
+ private static Logger log = Logger.getLogger(RestaurantATImpl.class);
+
+ // RestaurantAT manager - business logic + transactions
+ private static RestaurantManager restaurant = RestaurantManager.getSingletonInstance();
+
+ // Exposed business method
+ public void bookTables(int noOfTables)
+ {
+ // Debug information
+ log.info("bookTables()");
+
+ // Getting the transaction identifier
+ String txId = UserTransactionFactory.userTransaction().transactionIdentifier();
+ log.info("Transaction identifier: " + txId);
+
+ // Checking if this is a transaction we are aware of
+ if (restaurant.knowsAbout(txId))
+ {
+ log.info("Transaction known.");
+ }
+ else
+ {
+ // Creating a participant for a new transaction
+ try
+ {
+ log.info("New transaction.");
+
+ // Creating a participant
+ log.info("Creating participant.");
+ RestaurantParticipantAT participant = new RestaurantParticipantAT(txId);
+
+ // Enlisting the participant
+ log.info("Enlisting participant.");
+ TransactionManagerFactory.transactionManager().enlistForDurableTwoPhase(participant,new Uid().toString());
+ log.info("Participant successfully enlisted.");
+ }
+ catch (Exception e)
+ {
+ log.error("Participant could not be enlisted.");
+ }
+ }
+ // Calling a bookTables method on the restaurant manager
+ restaurant.bookTables(txId,noOfTables);
+
+ }
+
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantEntityImpl.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantEntityImpl.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantEntityImpl.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,80 @@
+package wstest.services.restaurant;
+
+import org.apache.log4j.Logger;
+
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import java.io.Serializable;
+
+/**
+ * Author: Maciej Machulak
+ */
+ at Entity
+ at Table(name="restaurant")
+public class RestaurantEntityImpl implements Serializable {
+
+ private final static int DEFAULT_NUMBER_OF_TABLES = 10;
+
+ private static Logger log = Logger.getLogger(RestaurantEntityImpl.class);
+
+ private int id;
+ private int noOfTables = DEFAULT_NUMBER_OF_TABLES;
+ private int noOfBookedTables = 0;
+
+ public RestaurantEntityImpl()
+ {
+ }
+
+ @Id
+ @GeneratedValue
+ public int getId()
+ {
+ log.info("getId: " + id);
+ return id;
+ }
+
+ public void setId(int id)
+ {
+ log.info("setId: " + id);
+ this.id = id;
+ }
+
+ public int getNoOfTables()
+ {
+ log.info("getNoOfTables: " + noOfTables);
+ return noOfTables;
+ }
+
+ public void setNoOfTables(int noOfTables)
+ {
+ log.info("setNoOfTables: " + noOfTables);
+ this.noOfTables = noOfTables;
+ }
+
+ public void increaseNoOfTables(int noOfTables)
+ {
+ setNoOfTables(getNoOfTables() + noOfTables);
+ }
+
+ public int getNoOfBookedTables() {
+ return noOfBookedTables;
+ }
+
+ private void setNoOfBookedTables(int noOfBookedTables)
+ {
+ this.noOfBookedTables = noOfBookedTables;
+ }
+
+ public boolean bookTables(int noOfTables)
+ {
+ log.info("bookTables: " + noOfTables);
+ if (getNoOfBookedTables() + noOfTables > this.noOfTables)
+ {
+ setNoOfBookedTables(getNoOfBookedTables() + noOfTables);
+ return true;
+ }
+ return false;
+ }
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantManager.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantManager.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantManager.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,288 @@
+package wstest.services.restaurant;
+
+import org.apache.log4j.Logger;
+
+import java.util.Hashtable;
+
+
+/**
+ * Author: Maciej Machulak
+ */
+public class RestaurantManager {
+
+ private static Logger log = Logger.getLogger(RestaurantParticipantAT.class);
+
+ // Default values
+ private final static int TABLE_CAPACITY = 15;
+
+ // It's a singleton pattern so we have only one restaurant manager
+ private static RestaurantManager restaurant = null;
+
+ // Those hashtables will store all the transactions - both prepared and unprepared
+ // A transaction will be stored as a pair:
+ // 1) key (transaction id = txId) - Integer
+ // 2) value (number of tables) - String
+ private Hashtable preparedTransactions;
+ private Hashtable unpreparedTransactions;
+
+ // I'm still not sure how I will represent resources in the annotation style
+ // programming
+ // Maybe I will have just 3 copies of resources
+ // - total number of tables
+ private Integer noOfTables;
+ // - number of free tables
+ private Integer noOfFreeTables;
+ // - number of provisionally booked tables (can be greater > noOfFreeTables/noOfTables)
+ private Integer noOfBookedTables;
+ // - number of prepared tables
+ private Integer noOfPreparedTables;
+ // - number of committed tables
+ private Integer noOfCommittedTables;
+
+ /**
+ * The auto commit mode.
+ * <p/>
+ * true = automatically commit, false = manually commit
+ */
+ private boolean autoCommitMode;
+
+ /**
+ * The object used for wait/notify in manual commit mode.
+ */
+ private Object preparation;
+
+ /**
+ * The waiting status, when in manual commit mode.
+ */
+ private boolean isPreparationWaiting;
+
+ /**
+ * The user specified outcome when in manual commit mode.
+ */
+ private boolean isCommit;
+
+ private RestaurantManager()
+ {
+ log.info("Creating manager.");
+ setToDefault();
+ }
+
+ // Initialise method
+ public void setToDefault()
+ {
+ log.info("setToDefault()");
+ preparedTransactions = new Hashtable();
+ unpreparedTransactions = new Hashtable();
+ noOfTables = TABLE_CAPACITY;
+ noOfFreeTables = noOfTables;
+ noOfBookedTables = 0;
+ noOfPreparedTables = 0;
+ noOfCommittedTables = 0;
+ }
+ // Pre-booking the tables
+ // This method does not have to return anything - basically if the pre-booking does
+ // not succeed then it will not be possible to prepare/commit - so the error will
+ // be detected then.
+ public void bookTables(String txId, int noOfTables)
+ {
+ log.info("bookTables()");
+
+ // Check if there is already something associated with this transaction
+ Integer request = (Integer) unpreparedTransactions.get(txId);
+
+ // If the transaction is new
+ if (request == null)
+ {
+ log.info("This is a new transaction.");
+ request = 0;
+ }
+ else
+ {
+ log.info("This is a known transaction.");
+ }
+ noOfBookedTables = noOfBookedTables + noOfTables;
+ unpreparedTransactions.put(txId, request + noOfTables);
+ log.info("Transaction added to unprepared transactions.");
+
+ }
+
+ // Reserving the tables - this method checks if we actually can reserve the table
+ // (btw. methods do not have to be synchronised because this is the singleton pattern
+ // and we only have 1 instance - although... hmm... I think those methods should be
+ // synchronised...)
+ public boolean prepare(String txId)
+ {
+ log.info("prepare()");
+
+ // Check if there is such transaction to be prepared
+ Integer request = (Integer) unpreparedTransactions.get(txId);
+ if (request == null)
+ {
+ log.info("No such transaction.");
+ return false;
+ }
+ else
+ {
+ log.info("Request for transaction found - proceeding.");
+ }
+
+ // Check if there are enough resources
+ if (request > noOfFreeTables)
+ {
+ log.info("Cannot prepare - no free resources.");
+ return false;
+ }
+ else
+ {
+ log.info("Resources are available - proceeding.");
+ }
+
+ // Calculate number of new resources
+ noOfFreeTables = noOfFreeTables - noOfTables;
+ noOfPreparedTables = noOfPreparedTables + noOfTables;
+
+ // Move transaction to the pool of prepared transactions
+ log.info("Marking transaction as PREPARED.");
+ preparedTransactions.put(txId,request);
+ unpreparedTransactions.remove(txId);
+
+ return true;
+ }
+
+ // Committing the tables - it produces the output (whether committing has been successful
+ // or not -> but the participant is still going to ignore the output of this method)
+ public boolean commit(String txId)
+ {
+
+ log.info("commit()");
+
+ // Initially the method is not successful
+ boolean success = false;
+
+ // There can be 3 situations:
+ // - 2 phase commit protocol
+ if (preparedTransactions.get(txId) != null)
+ {
+ log.info("- 2 phase commit");
+ Integer request = (Integer) preparedTransactions.get(txId);
+ preparedTransactions.remove(txId);
+ noOfPreparedTables -= request;
+ noOfCommittedTables += request;
+ success = true;
+ }
+ // - 1 phase commit protocol
+ else if (unpreparedTransactions.get(txId) != null)
+ {
+ log.info("- 1 phase commit");
+ Integer request = (Integer) unpreparedTransactions.get(txId);
+ unpreparedTransactions.remove(txId);
+ noOfPreparedTables -= request;
+ noOfCommittedTables += request;
+ success = true;
+ }
+ // - transaction invalid
+ else
+ {
+ log.info("- no such transaction");
+ }
+ return success;
+
+ }
+
+ public boolean knowsAbout(Object txID)
+ {
+ log.info("knowsAbout()");
+ return (unpreparedTransactions.containsKey(txID) || preparedTransactions.containsKey(txID));
+ }
+
+
+ public boolean rollback(String txId)
+ {
+ log.info("rollback()");
+ boolean success = false;
+
+ // If the transaction has already been told to prepare
+ if (preparedTransactions.containsKey(txId))
+ {
+ log.info("Rolling back prepared transaction.");
+ Integer request = (Integer) preparedTransactions.get(txId);
+ noOfPreparedTables -= request;
+ noOfFreeTables += request;
+ noOfBookedTables -= request;
+ success = true;
+ }
+ else if (unpreparedTransactions.containsKey(txId))
+ {
+ log.info("Rolling back unprepared transaction.");
+ noOfBookedTables += (Integer) unpreparedTransactions.get(txId);
+ success = true;
+ }
+ else
+ {
+ log.info("No such transaction.");
+ }
+ return success;
+
+ }
+
+ public static RestaurantManager getSingletonInstance()
+ {
+ log.info("getSingletonInstance()");
+ if (restaurant == null)
+ {
+ log.info("New instance.");
+ restaurant = new RestaurantManager();
+ }
+ else
+ {
+ log.info("Instance already exists.");
+ }
+ return restaurant;
+ }
+
+
+ public int getNBookedTables() {
+ return noOfBookedTables;
+ }
+
+ public int getNPreparedTables() {
+ return noOfPreparedTables;
+ }
+
+ public int getNCommittedTables() {
+ return noOfCommittedTables;
+ }
+
+ public int getNFreeTables() {
+ return noOfFreeTables;
+ }
+
+ public int getNTotalTables() {
+ return noOfTables;
+ }
+
+
+ public boolean isAutoCommitMode() {
+ return autoCommitMode;
+ }
+
+ public boolean getIsPreparationWaiting() {
+ return isPreparationWaiting;
+ }
+
+ public void setAutoCommitMode(boolean autoCommitMode) {
+ this.autoCommitMode = autoCommitMode;
+ }
+
+ public Object getPreparation() {
+ return preparation;
+ }
+
+ public void setCommit(boolean commit) {
+ this.isCommit = commit;
+ }
+
+ public void newCapacity(int newCapacity) {
+ this.noOfTables = newCapacity;
+ }
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantParticipantAT.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantParticipantAT.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantParticipantAT.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,90 @@
+package wstest.services.restaurant;
+
+import com.arjuna.wst.*;
+import org.apache.log4j.Logger;
+
+/**
+ * Author: Maciej Machulak
+ */
+public class RestaurantParticipantAT implements Durable2PCParticipant
+{
+ // Logger
+ private static Logger log = Logger.getLogger(RestaurantParticipantAT.class);
+
+ // Transaction identifier
+ private String txId;
+
+ // RestaurantAT manager (business logic + transactions)
+ private RestaurantManager restaurantManager;
+ private RestaurantView restaurantView;
+
+ public RestaurantParticipantAT(String txId)
+ {
+ log.info("Constructor.");
+ restaurantManager = RestaurantManager.getSingletonInstance();
+ restaurantView = RestaurantView.getSingletonInstance();
+ this.txId = txId;
+ restaurantView.addMessage("Transaction: txId");
+ }
+
+ public Vote prepare() throws WrongStateException, SystemException
+ {
+ log.info("prepare()");
+
+ // Executing perform logic
+ boolean success = restaurantManager.prepare(txId);
+
+ // Checking if the logic has been executed successfully
+ if ( success )
+ {
+ log.info("prepare() successful");
+ return new Prepared();
+ }
+ log.info("prepare() failed");
+ return new Aborted();
+ }
+
+ public void commit() throws WrongStateException, SystemException
+ {
+ log.info("commit()");
+
+ // Executing commit logic
+ boolean success = restaurantManager.commit(txId);
+
+ // Checking if the logic has been executed succesfully
+ if ( success )
+ {
+ log.info("commit() succesful");
+ }
+ else
+ {
+ log.info("commit() failed");
+ }
+ }
+
+ public void rollback() throws WrongStateException, SystemException
+ {
+ log.info("rollback()");
+
+ // Executing rollback
+ boolean success = restaurantManager.rollback(txId);
+ if ( success )
+ {
+ log.info("rollback() successful");
+ }
+ else
+ {
+ log.info("rollback() failed");
+ }
+ }
+
+ public void unknown() throws SystemException
+ {
+ log.info("unknown()");
+ }
+
+ public void error() throws SystemException
+ {
+ log.info("error()");
+ }
+}
Added: labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantView.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantView.java (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/demo/app/src/wstest/services/restaurant/RestaurantView.java 2007-06-19 01:44:17 UTC (rev 12674)
@@ -0,0 +1,469 @@
+package wstest.services.restaurant;
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a full listing
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License, v. 2.0.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License,
+ * v. 2.0 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+/*
+ * RestaurantView.java
+ *
+ * Copyright (c) 2003 Arjuna Technologies Ltd.
+ *
+ * $Id: RestaurantView.java,v 1.2 2004/04/21 13:09:18 jhalliday Exp $
+ *
+ */
+
+/**
+ * The visual interface (GUI) for the RestaurantAT Service.
+ *
+ * @author Jonathan Halliday (jonathan.halliday at arjuna.com)
+ * @version $Revision: 1.2 $
+ */
+public class RestaurantView extends javax.swing.JFrame
+{
+ // Note: Some parts of this file were auto-generated
+ // by NetBeans 3.3 FormEditor (http://www.netbeans.org)
+
+ /**
+ * Create a new RestaurantView instance.
+ *
+ * @param rManager The {@link RestaurantManager} instance to bind to
+ */
+ public RestaurantView(RestaurantManager rManager)
+ {
+ restManager = rManager;
+ initComponents();
+ updateFields();
+ backButtonColor = jButtonConfirm.getBackground();
+ }
+
+ /**
+ * Initialize the form.
+ * This is called by the constructor
+ * <p/>
+ * WARNING: Automatically generated code, may be overwritten
+ */
+ private void initComponents()
+ {//GEN-BEGIN:initComponents
+ jPanel2 = new javax.swing.JPanel();
+ jLabel5 = new javax.swing.JLabel();
+ jLabelNBookedTables = new javax.swing.JLabel();
+ jLabel9 = new javax.swing.JLabel();
+ jLabelNPreparedTables = new javax.swing.JLabel();
+ jLabel2 = new javax.swing.JLabel();
+ jLabelNConfirmedTables = new javax.swing.JLabel();
+ jLabel6 = new javax.swing.JLabel();
+ jLabelNFreeTables = new javax.swing.JLabel();
+ jLabel7 = new javax.swing.JLabel();
+ jButtonResetFields = new javax.swing.JButton();
+ jPanel1 = new javax.swing.JPanel();
+ jLabel8 = new javax.swing.JLabel();
+ jLabel1 = new javax.swing.JLabel();
+ jLabelNTotalTables = new javax.swing.JLabel();
+ jLabel4 = new javax.swing.JLabel();
+ jLabel3 = new javax.swing.JLabel();
+ jTextFieldNewNTotalTables = new javax.swing.JTextField();
+ jButtonSetNTotalTables = new javax.swing.JButton();
+ jPanelLeft = new javax.swing.JPanel();
+ jLabel10 = new javax.swing.JLabel();
+ jLabelDisplayMode = new javax.swing.JLabel();
+ jButtonChangeMode = new javax.swing.JButton();
+ jLabelResponse = new javax.swing.JLabel();
+ jButtonConfirm = new javax.swing.JButton();
+ jButtonCancel = new javax.swing.JButton();
+ jScrollPane1 = new javax.swing.JScrollPane();
+ jTextArea = new javax.swing.JTextArea();
+
+ setTitle("RestaurantAT Service");
+ setName("restaurantView");
+ addWindowListener(new java.awt.event.WindowAdapter()
+ {
+ public void windowClosing(java.awt.event.WindowEvent evt)
+ {
+ exitForm(evt);
+ }
+ });
+
+ jPanel2.setBorder(new javax.swing.border.LineBorder(java.awt.Color.black));
+ jLabel5.setText("Tables: ");
+ jLabel5.setFont(new java.awt.Font("Dialog", 1, 14));
+ jPanel2.add(jLabel5);
+
+ jLabelNBookedTables.setText(Integer.toString(restManager.getNBookedTables()));
+ jLabelNBookedTables.setForeground(java.awt.Color.gray);
+ jLabelNBookedTables.setFont(new java.awt.Font("Dialog", 1, 18));
+ jPanel2.add(jLabelNBookedTables);
+
+ jLabel9.setText("Booked, ");
+ jPanel2.add(jLabel9);
+
+ jLabelNPreparedTables.setText(Integer.toString(restManager.getNPreparedTables()));
+ jLabelNPreparedTables.setForeground(java.awt.Color.darkGray);
+ jLabelNPreparedTables.setFont(new java.awt.Font("Dialog", 1, 18));
+ jPanel2.add(jLabelNPreparedTables);
+
+ jLabel2.setText("Prepared, ");
+ jPanel2.add(jLabel2);
+
+ jLabelNConfirmedTables.setText(Integer.toString(restManager.getNCommittedTables()));
+ jLabelNConfirmedTables.setForeground(new java.awt.Color(0, 51, 204));
+ jLabelNConfirmedTables.setFont(new java.awt.Font("Dialog", 1, 18));
+ jPanel2.add(jLabelNConfirmedTables);
+
+ jLabel6.setText("Confirmed, ");
+ jPanel2.add(jLabel6);
+
+ jLabelNFreeTables.setText(Integer.toString(restManager.getNFreeTables()));
+ jLabelNFreeTables.setForeground(new java.awt.Color(0, 153, 0));
+ jLabelNFreeTables.setFont(new java.awt.Font("Dialog", 1, 18));
+ jPanel2.add(jLabelNFreeTables);
+
+ jLabel7.setText("Free ");
+ jPanel2.add(jLabel7);
+
+ jButtonResetFields.setText("Reset Fields");
+ jButtonResetFields.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ jButtonResetFieldsActionPerformed(evt);
+ }
+ });
+
+ jPanel2.add(jButtonResetFields);
+
+ getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
+
+ jPanel1.setBorder(new javax.swing.border.LineBorder(java.awt.Color.black));
+ jLabel8.setText("RestaurantAT ");
+ jLabel8.setForeground(java.awt.Color.red);
+ jLabel8.setFont(new java.awt.Font("Dialog", 1, 24));
+ jPanel1.add(jLabel8);
+
+ jLabel1.setText("Capacity:");
+ jLabel1.setFont(new java.awt.Font("Dialog", 1, 14));
+ jPanel1.add(jLabel1);
+
+ jLabelNTotalTables.setText(Integer.toString(restManager.getNTotalTables()));
+ jLabelNTotalTables.setForeground(java.awt.Color.darkGray);
+ jLabelNTotalTables.setFont(new java.awt.Font("Dialog", 1, 18));
+ jPanel1.add(jLabelNTotalTables);
+
+ jLabel4.setText("Tables");
+ jLabel4.setFont(new java.awt.Font("Dialog", 1, 14));
+ jPanel1.add(jLabel4);
+
+ jLabel3.setText(" New capacity:");
+ jLabel3.setFont(new java.awt.Font("Dialog", 1, 14));
+ jPanel1.add(jLabel3);
+
+ jTextFieldNewNTotalTables.setFont(new java.awt.Font("Dialog", 0, 18));
+ jTextFieldNewNTotalTables.setText(Integer.toString(restManager.getNTotalTables()));
+ jPanel1.add(jTextFieldNewNTotalTables);
+
+ jButtonSetNTotalTables.setFont(new java.awt.Font("Dialog", 1, 14));
+ jButtonSetNTotalTables.setText("Set");
+ jButtonSetNTotalTables.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ jButtonSetNTotalTablesActionPerformed(evt);
+ }
+ });
+
+ jPanel1.add(jButtonSetNTotalTables);
+
+ getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
+
+ jPanelLeft.setLayout(new javax.swing.BoxLayout(jPanelLeft, javax.swing.BoxLayout.Y_AXIS));
+
+ jLabel10.setText("Mode:");
+ jPanelLeft.add(jLabel10);
+
+ jLabelDisplayMode.setText("Automatic");
+ jLabelDisplayMode.setForeground(java.awt.Color.blue);
+ jLabelDisplayMode.setFont(new java.awt.Font("Dialog", 1, 18));
+ jPanelLeft.add(jLabelDisplayMode);
+
+ jButtonChangeMode.setText("Change mode");
+ jButtonChangeMode.setPreferredSize(new java.awt.Dimension(119, 27));
+ jButtonChangeMode.setMaximumSize(new java.awt.Dimension(119, 27));
+ jButtonChangeMode.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ jButtonChangeModeActionPerformed(evt);
+ }
+ });
+
+ jPanelLeft.add(jButtonChangeMode);
+
+ jLabelResponse.setText("Response:");
+ jPanelLeft.add(jLabelResponse);
+
+ jButtonConfirm.setText("Confirm");
+ jButtonConfirm.setPreferredSize(new java.awt.Dimension(119, 27));
+ jButtonConfirm.setMaximumSize(new java.awt.Dimension(119, 27));
+ jButtonConfirm.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ jButtonConfirmActionPerformed(evt);
+ }
+ });
+
+ jPanelLeft.add(jButtonConfirm);
+
+ jButtonCancel.setText("Cancel");
+ jButtonCancel.setPreferredSize(new java.awt.Dimension(119, 27));
+ jButtonCancel.setMaximumSize(new java.awt.Dimension(119, 27));
+ jButtonCancel.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ jButtonCancelActionPerformed(evt);
+ }
+ });
+
+ jPanelLeft.add(jButtonCancel);
+
+ getContentPane().add(jPanelLeft, java.awt.BorderLayout.WEST);
+
+ jScrollPane1.setAutoscrolls(true);
+ jTextArea.setEditable(false);
+ jTextArea.setRows(10);
+ jTextArea.setMargin(new java.awt.Insets(5, 5, 5, 5));
+ jScrollPane1.setViewportView(jTextArea);
+
+ getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
+
+ pack();
+ }//GEN-END:initComponents
+
+ /**
+ * Reset event handler.
+ */
+ private void jButtonResetFieldsActionPerformed(java.awt.event.ActionEvent evt)
+ {//GEN-FIRST:event_jButtonResetFieldsActionPerformed
+ restManager.setToDefault();
+ updateFields();
+ }//GEN-LAST:event_jButtonResetFieldsActionPerformed
+
+ /**
+ * Cancel event handler.
+ */
+ private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt)
+ {//GEN-FIRST:event_jButtonCancelActionPerformed
+ if (restManager.getIsPreparationWaiting())
+ {
+ Object preparation = restManager.getPreparation();
+ try
+ {
+ restManager.setCommit(false);
+ synchronized (preparation)
+ {
+ preparation.notify();
+ }
+ }
+ catch (Exception e)
+ {
+ System.err.println("RestaurantView.jButtonCancelActionPerformed(): Unable to notify preparation.");
+ }
+ }
+ }//GEN-LAST:event_jButtonCancelActionPerformed
+
+ /**
+ * Confirm event handler.
+ */
+ private void jButtonConfirmActionPerformed(java.awt.event.ActionEvent evt)
+ {//GEN-FIRST:event_jButtonConfirmActionPerformed
+ if (restManager.getIsPreparationWaiting())
+ {
+ Object preparation = restManager.getPreparation();
+ try
+ {
+ restManager.setCommit(true);
+ synchronized (preparation)
+ {
+ preparation.notify();
+ }
+ }
+ catch (Exception e)
+ {
+ System.err.println("RestaurantView.jButtonCancelActionPerformed(): Unable to notify preparation.");
+ }
+ }
+ }//GEN-LAST:event_jButtonConfirmActionPerformed
+
+ /**
+ * ChangeMode event handler.
+ */
+ private void jButtonChangeModeActionPerformed(java.awt.event.ActionEvent evt)
+ {//GEN-FIRST:event_jButtonChangeModeActionPerformed
+ if (restManager.isAutoCommitMode())
+ {
+ restManager.setAutoCommitMode(false);
+ }
+ else
+ {
+ restManager.setAutoCommitMode(true);
+ }
+ updateFields();
+ }//GEN-LAST:event_jButtonChangeModeActionPerformed
+
+ /**
+ * Capacity change event handler.
+ */
+ private void jButtonSetNTotalTablesActionPerformed(java.awt.event.ActionEvent evt)
+ {//GEN-FIRST:event_jButtonSetNTotalTablesActionPerformed
+ String strNTables = jTextFieldNewNTotalTables.getText();
+
+ restManager.newCapacity(Integer.parseInt(strNTables));
+ int nFreeTables = restManager.getNFreeTables();
+
+ jLabelNTotalTables.setText(strNTables);
+ jLabelNFreeTables.setText(Integer.toString(nFreeTables));
+ }//GEN-LAST:event_jButtonSetNTotalTablesActionPerformed
+
+ /**
+ * Exit the application.
+ */
+ private void exitForm(java.awt.event.WindowEvent evt)
+ {//GEN-FIRST:event_exitForm
+ //System.exit(0); // disabled for embedding in application servers.
+ }//GEN-LAST:event_exitForm
+
+ /**
+ * Add regular text to the central jTextArea.
+ *
+ * @param text The String to add
+ */
+ public void addMessage(java.lang.String text)
+ {
+ jButtonConfirm.setBackground(backButtonColor);
+ jButtonCancel.setBackground(backButtonColor);
+ jTextArea.append(text + "\n");
+ jScrollPane1.getVerticalScrollBar().setValue(jScrollPane1.getVerticalScrollBar().getMaximum());
+ }
+
+ /**
+ * Add status (highlighted) text to the central jTextArea.
+ *
+ * @param text The String to add
+ */
+ public void addPrepareMessage(java.lang.String text)
+ {
+ jButtonConfirm.setBackground(java.awt.Color.red);
+ jButtonCancel.setBackground(java.awt.Color.red);
+ jTextArea.append(text + "\n");
+ jScrollPane1.getVerticalScrollBar().setValue(jScrollPane1.getVerticalScrollBar().getMaximum());
+ }
+
+
+ /**
+ * Synchronise the GUI with the underlying state.
+ */
+ public void updateFields()
+ {
+ jLabelNTotalTables.setText(Integer.toString(restManager.getNTotalTables()));
+ jTextFieldNewNTotalTables.setText(Integer.toString(restManager.getNTotalTables()));
+ jLabelNPreparedTables.setText(Integer.toString(restManager.getNPreparedTables()));
+ jLabelNConfirmedTables.setText(Integer.toString(restManager.getNCommittedTables()));
+ jLabelNFreeTables.setText(Integer.toString(restManager.getNFreeTables()));
+ jLabelNBookedTables.setText(Integer.toString(restManager.getNBookedTables()));
+
+ //update fields related to interactive mode.
+ if (restManager.isAutoCommitMode())
+ {
+ jLabelResponse.setVisible(false);
+ jButtonConfirm.setVisible(false);
+ jButtonCancel.setVisible(false);
+ jLabelDisplayMode.setText("automatic");
+ }
+ else
+ {
+ jLabelResponse.setVisible(true);
+ jButtonConfirm.setVisible(true);
+ jButtonCancel.setVisible(true);
+ jLabelDisplayMode.setText("interactive");
+ }
+ }
+
+ /**
+ * Allow use of a singleton model for web services demo.
+ */
+ public static RestaurantView getSingletonInstance()
+ {
+ if (singletonInstance == null)
+ {
+ singletonInstance = new RestaurantView(RestaurantManager.getSingletonInstance());
+ }
+
+ singletonInstance.show();
+ return singletonInstance;
+ }
+
+ /**
+ * A singleton instance of this class.
+ */
+ private static RestaurantView singletonInstance;
+
+
+ // Variables declaration - automatically generated - do not modify
+
+ private javax.swing.JPanel jPanel2;
+ private javax.swing.JLabel jLabel5;
+ private javax.swing.JLabel jLabelNBookedTables;
+ private javax.swing.JLabel jLabel9;
+ private javax.swing.JLabel jLabelNPreparedTables;
+ private javax.swing.JLabel jLabel2;
+ private javax.swing.JLabel jLabelNConfirmedTables;
+ private javax.swing.JLabel jLabel6;
+ private javax.swing.JLabel jLabelNFreeTables;
+ private javax.swing.JLabel jLabel7;
+ private javax.swing.JButton jButtonResetFields;
+ private javax.swing.JPanel jPanel1;
+ private javax.swing.JLabel jLabel8;
+ private javax.swing.JLabel jLabel1;
+ private javax.swing.JLabel jLabelNTotalTables;
+ private javax.swing.JLabel jLabel4;
+ private javax.swing.JLabel jLabel3;
+ private javax.swing.JTextField jTextFieldNewNTotalTables;
+ private javax.swing.JButton jButtonSetNTotalTables;
+ private javax.swing.JPanel jPanelLeft;
+ private javax.swing.JLabel jLabel10;
+ private javax.swing.JLabel jLabelDisplayMode;
+ private javax.swing.JButton jButtonChangeMode;
+ private javax.swing.JLabel jLabelResponse;
+ private javax.swing.JButton jButtonConfirm;
+ private javax.swing.JButton jButtonCancel;
+ private javax.swing.JScrollPane jScrollPane1;
+ private javax.swing.JTextArea jTextArea;
+
+ // End of automatically generated variables declarations
+
+ /**
+ * The {@link RestaurantManager} instance this view is bound to.
+ */
+ private RestaurantManager restManager;
+
+ /**
+ * The current color of the back button.
+ */
+ private java.awt.Color backButtonColor;
+}
More information about the jboss-svn-commits
mailing list