KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > ejb > cfg > EjbMethodPattern


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.ejb.cfg;
30
31 import com.caucho.config.ConfigException;
32 import com.caucho.util.L10N;
33
34 import java.util.ArrayList JavaDoc;
35
36 /**
37  * Configuration for a method.
38  */

39 public class EjbMethodPattern {
40   private static L10N L = new L10N(EjbMethodPattern.class);
41
42   public final static int RESIN_DATABASE = 0;
43   public final static int RESIN_READ_ONLY = 1;
44   public final static int RESIN_ROW_LOCK = 2;
45
46   private EjbBean _bean;
47
48   private String JavaDoc _location;
49
50   private MethodSignature _signature;
51   
52   private int _resinIsolation = -1;
53   private int _jdbcIsolation = -1;
54   
55   private boolean _queryLoadsBean = true;
56   private boolean _relationLoadsBean;
57   
58   private String JavaDoc _query;
59   private String JavaDoc _queryLocation;
60   
61   private int _transactionType = -1;
62   private ArrayList JavaDoc _roles;
63
64   /**
65    * Creates a new method.
66    */

67   public EjbMethodPattern()
68   {
69   }
70
71   /**
72    * Creates a new method.
73    *
74    * @param entity the owning entity bean.
75    * @param signature the method signature.
76    */

77   public EjbMethodPattern(EjbBean bean, MethodSignature signature)
78   {
79     _bean = bean;
80     _signature = signature;
81   }
82
83   /**
84    * Sets the bean.
85    */

86   public void setBean(EjbBean bean)
87   {
88     _bean = bean;
89   }
90
91   /**
92    * Sets the config location.
93    */

94   public void setLocation(String JavaDoc location)
95   {
96     _location = location;
97   }
98
99   /**
100    * Returns the config location.
101    */

102   public String JavaDoc getLocation()
103   {
104     return _location;
105   }
106
107   /**
108    * Sets the method signature.
109    */

110   public void setSignature(MethodSignature sig)
111   {
112     _signature = sig;
113   }
114
115   /**
116    * Returns the method signature.
117    */

118   public MethodSignature getSignature()
119   {
120     return _signature;
121   }
122
123   /**
124    * Returns the method name.
125    */

126   public String JavaDoc getName()
127   {
128     return _signature.getName();
129   }
130
131   /**
132    * Returns true if the method does not set any values.
133    */

134   public boolean isReadOnly()
135   {
136     return _resinIsolation == RESIN_READ_ONLY;
137   }
138
139   /**
140    * Returns the Resin isolation.
141    */

142   public int getResinIsolation()
143   {
144     return _resinIsolation;
145   }
146
147   /**
148    * Sets the Resin isolation.
149    */

150   public void setResinIsolation(String JavaDoc isolation)
151     throws ConfigException
152   {
153     if (isolation.equals("read-only"))
154       _resinIsolation = RESIN_READ_ONLY;
155     else if (isolation.equals("database"))
156       _resinIsolation = RESIN_DATABASE;
157     else if (isolation.equals("row-locking"))
158       _resinIsolation = RESIN_ROW_LOCK;
159     else
160       throw new ConfigException(L.l("`{0}' is an unknown value for resin-isolation. Only 'read-only', 'database', and 'row-locking' are allowed.",
161                                     isolation));
162   }
163
164   /**
165    * Returns the JDBC isolation.
166    */

167   public int getJDBCIsolation()
168   {
169     return _jdbcIsolation;
170   }
171
172   /**
173    * Sets the JDBC isolation.
174    */

175   public void setJDBCIsolation(int isolation)
176   {
177     _jdbcIsolation = isolation;
178   }
179
180   /**
181    * Returns the method's query.
182    */

183   public String JavaDoc getQuery()
184   {
185     return _query;
186   }
187
188   /**
189    * Sets the method's query.
190    */

191   public void setQuery(String JavaDoc query)
192   {
193     _query = query;
194   }
195
196   /**
197    * Returns the query config location.
198    */

199   public String JavaDoc getQueryLocation()
200   {
201     return _queryLocation;
202   }
203
204   /**
205    * Sets the query node.
206    */

207   public void setQueryLocation(String JavaDoc location)
208   {
209     _queryLocation = location;
210   }
211
212   /**
213    * Returns the method's transaction type, e.g. Required.
214    */

215   public int getTransactionType()
216   {
217     if (_transactionType >= 0)
218       return _transactionType;
219     else if (isReadOnly())
220       return EjbMethod.TRANS_SUPPORTS;
221     else
222       return EjbMethod.TRANS_REQUIRED;
223   }
224
225   public void setTransaction(int type)
226     throws ConfigException
227   {
228     _transactionType = type;
229   }
230   
231   /**
232    * Sets the method's transaction type, e.g. Required
233    */

234   public void setTransAttribute(String JavaDoc type)
235     throws ConfigException
236   {
237     if ("Required".equals(type))
238       _transactionType = EjbMethod.TRANS_REQUIRED;
239     else if ("RequiresNew".equals(type))
240       _transactionType = EjbMethod.TRANS_REQUIRES_NEW;
241     else if ("Mandatory".equals(type))
242       _transactionType = EjbMethod.TRANS_MANDATORY;
243     else if ("NotSupported".equals(type))
244       _transactionType = EjbMethod.TRANS_NOT_SUPPORTED;
245     else if ("Never".equals(type))
246       _transactionType = EjbMethod.TRANS_NEVER;
247     else if ("Supports".equals(type))
248       _transactionType = EjbMethod.TRANS_SUPPORTS;
249     else
250       throw new ConfigException(L.l("`{0}' is an unknown transaction type. The transaction types are:\n Required - creates a new transaction if none is active.\n RequiresNew - always creates a new transaction.\n Mandatory - requires an active transaction.\n NotSupported - suspends any active transaction.\n Never - forbids any active transaction.\n Supports - allows a transaction or no transaction.", type));
251   }
252
253   /**
254    * Returns true if the query method should load bean values.
255    */

256   public boolean getQueryLoadsBean()
257   {
258     return _queryLoadsBean;
259   }
260
261   /**
262    * Set true if the query method should load bean values.
263    */

264   public void setQueryLoadsBean(boolean loadBean)
265   {
266     _queryLoadsBean = loadBean;
267   }
268
269   /**
270    * Returns true if the relation method should load bean values.
271    */

272   public boolean getRelationLoadsBean()
273   {
274     return _relationLoadsBean;
275   }
276
277   /**
278    * Set true if the relation method should load bean values.
279    */

280   public void setRelationLoadsBean(boolean loadBean)
281   {
282     _relationLoadsBean = loadBean;
283   }
284
285   /**
286    * Returns the roles allowed for the method.
287    */

288   public ArrayList JavaDoc getRoles()
289   {
290     return _roles;
291   }
292
293   /**
294    * Set the roles allowed for the method.
295    */

296   public void setRoles(ArrayList JavaDoc roles)
297   {
298     _roles = roles;
299   }
300
301   /**
302    * Set the roles allowed for the method.
303    */

304   public void setRoles(String JavaDoc []roles)
305   {
306     if (roles != null) {
307       if (_roles == null)
308     _roles = new ArrayList JavaDoc();
309       
310       for (String JavaDoc role : roles) {
311     _roles.add(role);
312       }
313     }
314   }
315
316   /**
317    * Returns true if these are equivalent.
318    */

319   public boolean equals(Object JavaDoc o)
320   {
321     if (! (o instanceof EjbMethodPattern))
322       return false;
323
324     EjbMethodPattern method = (EjbMethodPattern) o;
325
326     return _signature.equals(method.getSignature());
327   }
328
329   public String JavaDoc toString()
330   {
331     return "EJBMethodPattern[" + _signature.getName() + "]";
332   }
333 }
334
Popular Tags