KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > impl > MuleTransactionConfig


1 /*
2  * $Id: MuleTransactionConfig.java 4259 2006-12-14 03:12:07Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.impl;
12
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15 import org.mule.MuleManager;
16 import org.mule.transaction.constraints.ConstraintFilter;
17 import org.mule.umo.UMOTransactionConfig;
18 import org.mule.umo.UMOTransactionFactory;
19
20 /**
21  * <p/> <code>MuleTransactionConfig</code> defines transaction configuration for a
22  * transactional endpoint.
23  */

24 public class MuleTransactionConfig implements UMOTransactionConfig
25 {
26     /**
27      * logger used by this class
28      */

29     protected static final Log logger = LogFactory.getLog(MuleTransactionConfig.class);
30
31     public static final String JavaDoc ACTION_NONE_STRING = "NONE";
32     public static final String JavaDoc ACTION_ALWAYS_BEGIN_STRING = "ALWAYS_BEGIN";
33     public static final String JavaDoc ACTION_BEGIN_OR_JOIN_STRING = "BEGIN_OR_JOIN";
34     public static final String JavaDoc ACTION_ALWAYS_JOIN_STRING = "ALWAYS_JOIN";
35     public static final String JavaDoc ACTION_JOIN_IF_POSSIBLE_STRING = "JOIN_IF_POSSIBLE";
36
37     private UMOTransactionFactory factory;
38
39     private byte action = ACTION_NONE;
40
41     private ConstraintFilter constraint = null;
42
43     private int timeout;
44
45     public MuleTransactionConfig()
46     {
47         timeout = MuleManager.getConfiguration().getTransactionTimeout();
48     }
49
50     /*
51      * (non-Javadoc)
52      *
53      * @see org.mule.umo.UMOTransactionConfig#getFactory()
54      */

55     public UMOTransactionFactory getFactory()
56     {
57         return factory;
58     }
59
60     /*
61      * (non-Javadoc)
62      *
63      * @see org.mule.umo.UMOTransactionConfig#setFactory(org.mule.umo.UMOTransactionFactory)
64      */

65     public void setFactory(UMOTransactionFactory factory)
66     {
67         if (factory == null)
68         {
69             throw new IllegalArgumentException JavaDoc("Transaction Factory cannot be null");
70         }
71         this.factory = factory;
72     }
73
74     /*
75      * (non-Javadoc)
76      *
77      * @see org.mule.umo.UMOTransactionConfig#getAction()
78      */

79     public byte getAction()
80     {
81         return action;
82     }
83
84     /*
85      * (non-Javadoc)
86      *
87      * @see org.mule.umo.UMOTransactionConfig#setAction(byte)
88      */

89     public void setAction(byte action)
90     {
91         this.action = action;
92
93     }
94
95     public void setActionAsString(String JavaDoc action)
96     {
97         if (ACTION_ALWAYS_BEGIN_STRING.equals(action))
98         {
99             this.action = ACTION_ALWAYS_BEGIN;
100         }
101         else if (ACTION_BEGIN_OR_JOIN_STRING.equals(action))
102         {
103             this.action = ACTION_BEGIN_OR_JOIN;
104         }
105         else if (ACTION_ALWAYS_JOIN_STRING.equals(action))
106         {
107             this.action = ACTION_ALWAYS_JOIN;
108         }
109         else if (ACTION_JOIN_IF_POSSIBLE_STRING.equals(action))
110         {
111             this.action = ACTION_JOIN_IF_POSSIBLE;
112         }
113         else if (ACTION_NONE_STRING.equals(action))
114         {
115             this.action = ACTION_NONE;
116         }
117         else
118         {
119             throw new IllegalArgumentException JavaDoc("Action " + action + " is not recognised as a begin action.");
120         }
121     }
122
123     public String JavaDoc getActionAsString()
124     {
125         switch (action)
126         {
127             case ACTION_ALWAYS_BEGIN :
128                 return ACTION_ALWAYS_BEGIN_STRING;
129             case ACTION_ALWAYS_JOIN :
130                 return ACTION_ALWAYS_JOIN_STRING;
131             case ACTION_JOIN_IF_POSSIBLE :
132                 return ACTION_JOIN_IF_POSSIBLE_STRING;
133             default :
134                 return ACTION_NONE_STRING;
135         }
136     }
137
138     public boolean isTransacted()
139     {
140         if (factory != null)
141         {
142             if (!factory.isTransacted())
143             {
144                 return false;
145             }
146             return action != ACTION_NONE;
147         }
148         return false;
149     }
150
151     public ConstraintFilter getConstraint()
152     {
153         if (constraint == null)
154         {
155             return null;
156         }
157         try
158         {
159             return (ConstraintFilter)constraint.clone();
160         }
161         catch (CloneNotSupportedException JavaDoc e)
162         {
163             logger.fatal("Failed to clone ContraintFilter: " + e.getMessage(), e);
164             return constraint;
165         }
166     }
167
168     public void setConstraint(ConstraintFilter constraint)
169     {
170         this.constraint = constraint;
171     }
172
173     public int getTimeout()
174     {
175         return timeout;
176     }
177
178     public void setTimeout(int timeout)
179     {
180         this.timeout = timeout;
181     }
182
183     public String JavaDoc toString()
184     {
185         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
186         buf.append("Transaction{factory=")
187             .append(factory)
188             .append(", action=")
189             .append(getActionAsString())
190             .append(", timeout=")
191             .append(timeout)
192             .append("}");
193         return buf.toString();
194     }
195 }
196
Popular Tags