KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > omg > CosActivity > ChildLifetime


1 /**
2  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3  -
4  - JASS: Java Advanced tranSaction Support
5  -
6  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7  -
8  - This module was originally developed by
9  -
10  - LSD (Distributed Systems Lab, http://lsd.ls.fi.upm.es/lsd/lsd.htm)
11  - at Universidad Politecnica de Madrid (UPM) as an ObjectWeb Consortium
12  - (http://www.objectweb.org) project.
13  -
14  - This project has been partially funded by the European Commission under
15  - the IST programme of V FP grant IST-2001-37126 and by the Spanish
16  - Ministry of Science & Technology (MCyT) grants TIC2002-10376-E and
17  - TIC2001-1586-C03-02
18  -
19  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20  - The original code and portions created by LSD are
21  - Copyright (c) 2004 LSD (UPM)
22  - All rights reserved.
23  -
24  - Redistribution and use in source and binary forms, with or without
25  - modification, are permitted provided that the following conditions are met:
26  -
27  - -Redistributions of source code must retain the above copyright notice, this
28  - list of conditions and the following disclaimer.
29  -
30  - -Redistributions in binary form must reproduce the above copyright notice,
31  - this list of conditions and the following disclaimer in the documentation
32  - and/or other materials provided with the distribution.
33  -
34  - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
35  - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36  - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37  - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
38  - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
39  - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
40  - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
41  - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
42  - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
43  - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44  - POSSIBILITY OF SUCH DAMAGE.
45  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
46  -
47  - Author: Francisco Perez Sorrosal (frperezs)
48  -
49  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50 */

51
52 package org.omg.CosActivity;
53
54 import javax.activity.ActivityCoordinator JavaDoc;
55 import javax.activity.CompletionStatus JavaDoc;
56 import javax.activity.CoordinationInformation JavaDoc;
57 import javax.activity.Outcome JavaDoc;
58 import javax.activity.Signal JavaDoc;
59 import javax.activity.SignalSetActiveException JavaDoc;
60 import javax.activity.SignalSetInactiveException JavaDoc;
61 import javax.activity.coordination.SignalSet;
62
63 public class ChildLifetime implements SignalSet {
64
65     public static final String JavaDoc SSNAME = "org.omg.CosActivity.ChildLifetime";
66     // The name of this SignalSet
67
private String JavaDoc signalSetName;
68
69     private ActivityCoordinator JavaDoc ac;
70
71     private int completionStatus;
72
73     private int status;
74
75     private Outcome JavaDoc outcome;
76
77     private boolean started;
78     
79     private boolean finished;
80
81     // Constructors --------------------------------------------------
82

83     public ChildLifetime() {
84         this.signalSetName = SSNAME;
85         this.outcome = null;
86         this.started = false;
87         this.finished = false;
88     }
89
90     // Public --------------------------------------------------------
91

92     // Signal implementation -------------------------------------
93

94     public java.lang.String JavaDoc getSignalSetName() {
95         return this.signalSetName;
96     }
97
98     public Signal JavaDoc getSignal() {
99
100         Signal JavaDoc signal = null;
101
102         if (!finished) {
103             if (started == false) {
104                 started = true;
105                 signal =
106                     new Signal JavaDoc(
107                         "childBegin",
108                         this.signalSetName,
109                         (java.io.Serializable JavaDoc) null);
110             }
111
112             if (signal == null)
113                 finished = true;
114         }
115         return signal;
116     }
117
118     public CoordinationInformation JavaDoc setResponse(Outcome JavaDoc response)
119         throws SignalSetInactiveException JavaDoc {
120
121         if (!started)
122             throw new SignalSetInactiveException JavaDoc();
123
124         CoordinationInformation JavaDoc info =
125             new CoordinationInformation JavaDoc(false, false);
126
127         if ((completionStatus != CompletionStatus.CompletionStatusFailOnly)
128             && (response.getName().equals("ActionError")
129                 || response.getName().equals("ActionError"))) {
130             completionStatus = CompletionStatus.CompletionStatusFailOnly;
131         }
132
133         return info;
134
135     }
136
137     public Outcome JavaDoc getOutcome() throws SignalSetActiveException JavaDoc {
138         return outcome;
139     }
140
141     public void setCompletionStatus(int completionStatus, int status) {
142         this.completionStatus = completionStatus;
143         this.status = status;
144     }
145
146     public int getCompletionStatus() throws SignalSetActiveException JavaDoc {
147         if (!finished)
148             throw new SignalSetActiveException JavaDoc();
149         return this.completionStatus;
150     }
151
152     public void setActivityCoordinator(ActivityCoordinator JavaDoc coord)
153         throws SignalSetActiveException JavaDoc {
154
155         if (started)
156             throw new SignalSetActiveException JavaDoc();
157         ac = coord;
158     }
159
160     public void destroy() {
161         ac = null;
162     }
163
164 }
165
Popular Tags