KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > om > TransitionPeer


1 package org.tigris.scarab.om;
2
3 /* ================================================================
4  * Copyright (c) 2000-2003 CollabNet. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowlegement: "This product includes
19  * software developed by Collab.Net <http://www.Collab.Net/>."
20  * Alternately, this acknowlegement may appear in the software itself, if
21  * and wherever such third-party acknowlegements normally appear.
22  *
23  * 4. The hosted project names must not be used to endorse or promote
24  * products derived from this software without prior written
25  * permission. For written permission, please contact info@collab.net.
26  *
27  * 5. Products derived from this software may not use the "Tigris" or
28  * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
29  * prior written permission of Collab.Net.
30  *
31  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
32  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34  * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
35  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
37  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
39  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  * ====================================================================
44  *
45  * This software consists of voluntary contributions made by many
46  * individuals on behalf of Collab.Net.
47  */

48
49 import org.apache.torque.util.Criteria;
50 import org.apache.torque.TorqueException;
51 import org.tigris.scarab.util.Log;
52
53 import java.util.List JavaDoc;
54
55 /**
56  * Exposes additional methods to manage torque-generated Transition objects.
57  */

58 public class TransitionPeer extends org.tigris.scarab.om.BaseTransitionPeer
59 {
60     public static List JavaDoc getAllTransitions(Attribute attribute)
61     {
62
63         Integer JavaDoc attribId = attribute.getAttributeId();
64         List JavaDoc transitions = null;
65         try
66         {
67             Criteria crit = new Criteria();
68             crit.add(ATTRIBUTE_ID, attribId);
69             transitions = doSelect(crit);
70         }
71         catch (TorqueException te)
72         {
73             te.printStackTrace();
74         }
75         return transitions;
76     }
77     /**
78      * Obtains every allowed transition from fromOption to toOption, including
79      * those implicited by a null value in fromOption and/or toOption.
80      *
81      * @param fromOption
82      * @param toOption
83      * @return
84      */

85     public static List JavaDoc getTransitions(AttributeOption fromOption,
86             AttributeOption toOption)
87     {
88
89         Integer JavaDoc attribId = toOption.getAttributeId();
90         Integer JavaDoc fromOptionId = fromOption.getOptionId();
91         Integer JavaDoc toOptionId = toOption.getOptionId();
92         List JavaDoc transitions = null;
93         try
94         { // "Open" transitions (null->null) must always be added if existing
95
Criteria crit = new Criteria();
96             crit.add(ATTRIBUTE_ID, attribId);
97             crit.add(FROM_OPTION_ID, (Object JavaDoc) "FROM_OPTION_ID IS NULL",
98                     Criteria.CUSTOM);
99             crit.add(TO_OPTION_ID, (Object JavaDoc) "TO_OPTION_ID IS NULL",
100                     Criteria.CUSTOM);
101             transitions = doSelect(crit);
102         }
103         catch (TorqueException te)
104         {
105             Log.get(TransitionPeer.class.getName()).error(
106                     "getTransitions(): " + te);
107         }
108         try
109         { // Asked transition
110
Criteria crit = new Criteria();
111             crit.add(ATTRIBUTE_ID, attribId);
112             crit.add(FROM_OPTION_ID, fromOptionId);
113             crit.add(TO_OPTION_ID, toOptionId);
114             transitions.addAll(doSelect(crit));
115         }
116         catch (TorqueException te)
117         {
118             Log.get(TransitionPeer.class.getName()).error(
119                     "getTransitions(): " + te);
120         }
121         try
122         { // Open-beginning
123
Criteria crit = new Criteria();
124             crit.add(ATTRIBUTE_ID, attribId);
125             crit.add(TO_OPTION_ID, toOptionId);
126             crit.add(FROM_OPTION_ID, (Object JavaDoc) "FROM_OPTION_ID IS NULL",
127                     Criteria.CUSTOM);
128             transitions.addAll(doSelect(crit));
129         }
130         catch (TorqueException te)
131         {
132             Log.get(TransitionPeer.class.getName()).error(
133                     "getTransitions(): Looking for nulls fromOption: " + te);
134         }
135         try
136         { // Open-ending
137
Criteria crit = new Criteria();
138             crit.add(ATTRIBUTE_ID, attribId);
139             crit.add(FROM_OPTION_ID, fromOptionId);
140             crit.add(TO_OPTION_ID, (Object JavaDoc) "TO_OPTION_ID IS NULL",
141                     Criteria.CUSTOM);
142             transitions.addAll(doSelect(crit));
143         }
144         catch (TorqueException te)
145         {
146             Log.get(TransitionPeer.class.getName()).error(
147                     "getTransitions(): Looking for nulls toOption: " + te);
148         }
149         return transitions;
150     }
151     /**
152      * If there is any defined transitions for the given attribute, it will
153      * return true. It's needed because the CheapWorkflow system will not try to
154      * restrict the transitions if there is none defined.
155      *
156      * @param attribute
157      * @return
158      */

159     public static boolean hasDefinedTransitions(Attribute attribute)
160     {
161         boolean result = false;
162         try
163         {
164             Criteria crit = new Criteria();
165             crit.add(ATTRIBUTE_ID, attribute.getAttributeId());
166             List JavaDoc attributeTransitions = doSelect(crit);
167             result = (attributeTransitions.size() > 0);
168         }
169         catch (TorqueException te)
170         {
171             Log.get(TransitionPeer.class.getName()).error(
172                     "hasDefinedTransitions(): " + te);
173         }
174         return result;
175     }
176
177     public static void doDelete(Transition tran) throws TorqueException
178     {
179         Criteria crit = new Criteria();
180         crit.add(ConditionPeer.TRANSITION_ID, tran.getTransitionId());
181         ConditionPeer.doDelete(crit);
182         BaseTransitionPeer.doDelete(tran);
183     }
184 }
185
186
Popular Tags