KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > julia > control > lifecycle > ContainerLifeCycleMixin


1 /***
2  * Julia: France Telecom's implementation of the Fractal API
3  * Copyright (C) 2001-2002 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: Eric.Bruneton@rd.francetelecom.com
20  *
21  * Author: Eric Bruneton
22  */

23
24 package org.objectweb.fractal.julia.control.lifecycle;
25
26 import org.objectweb.fractal.api.Component;
27 import org.objectweb.fractal.api.NoSuchInterfaceException;
28 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
29 import org.objectweb.fractal.api.control.LifeCycleController;
30
31 /**
32  * Provides container related functions to a {@link LifeCycleController}.
33  * <br>
34  * <br>
35  * <b>Requirements</b>
36  * <ul>
37  * <li>none.</li>
38  * </ul>
39  */

40
41 public abstract class ContainerLifeCycleMixin
42   implements LifeCycleCoordinator
43 {
44
45   // -------------------------------------------------------------------------
46
// Private constructor
47
// -------------------------------------------------------------------------
48

49   private ContainerLifeCycleMixin () {
50   }
51
52   // -------------------------------------------------------------------------
53
// Fields and methods added and overriden by the mixin class
54
// -------------------------------------------------------------------------
55

56   /**
57    * Calls the overriden method and then calls the {@link #setFcContentState
58    * setFcContentState} method.
59    *
60    * @return <tt>true</tt> if the execution state has changed, or <tt>false</tt>
61    * if it had already the {@link #STARTED STARTED} value.
62    * @throws IllegalLifeCycleException if a problem occurs.
63    */

64
65   public boolean setFcStarted () throws IllegalLifeCycleException {
66     synchronized (this) {
67       if (_super_setFcStarted()) {
68         setFcContentState(true);
69         return true;
70       }
71       return false;
72     }
73   }
74
75   /**
76    * Calls the overriden method and then calls the {@link #setFcContentState
77    * setFcContentState} method.
78    *
79    * @return <tt>true</tt> if the execution state has changed, or <tt>false</tt>
80    * if it had already the {@link #STOPPED STOPPED} value.
81    * @throws IllegalLifeCycleException if a problem occurs.
82    */

83
84   public boolean setFcStopped () throws IllegalLifeCycleException {
85     synchronized (this) {
86       if (_super_setFcStopped()) {
87         setFcContentState(false);
88         return true;
89       }
90       return false;
91     }
92   }
93
94   /**
95    * Calls the {@link LifeCycleController#startFc startFc} or {@link
96    * LifeCycleController#stopFc stopFc} method on the encapsulated component.
97    * This method does nothing if there is no encapsulated component, or if it
98    * does not implement the {@link LifeCycleController} interface.
99    *
100    * @param started <tt>true</tt> to call the {@link LifeCycleController#startFc
101    * startFc}, or <tt>false</tt> to call the {@link
102    * LifeCycleController#stopFc stopFc} method.
103    * @throws IllegalLifeCycleException if a problem occurs.
104    */

105
106   public void setFcContentState (final boolean started)
107     throws IllegalLifeCycleException
108   {
109     Object JavaDoc content;
110     try {
111       content = _this_weaveableOptC.getFcInterface("/content");
112     } catch (NullPointerException JavaDoc e) {
113       return;
114     } catch (NoSuchInterfaceException e) {
115       return;
116     }
117     if (content == this) {
118       // case of merge...AndContent options
119
if (this instanceof ContentLifeCycleController) {
120         if (started) {
121           ((ContentLifeCycleController)this).startFcContent();
122         } else {
123           ((ContentLifeCycleController)this).stopFcContent();
124         }
125       }
126     } else if (content instanceof LifeCycleController) {
127       if (started) {
128         ((LifeCycleController)content).startFc();
129       } else {
130         ((LifeCycleController)content).stopFc();
131       }
132     }
133   }
134
135   // -------------------------------------------------------------------------
136
// Fields and methods required by the mixin class in the base class
137
// -------------------------------------------------------------------------
138

139   /**
140    * The <tt>weaveableOptC</tt> field required by this mixin. This field is
141    * supposed to reference the {@link Component} interface of the component to
142    * which this controller object belongs.
143    */

144
145   public Component _this_weaveableOptC;
146
147   /**
148    * The {@link LifeCycleCoordinator#setFcStarted setFcStarted} method overriden
149    * by this mixin.
150    *
151    * @return <tt>true</tt> if the execution state has changed, or <tt>false</tt>
152    * if it had already the {@link #STARTED STARTED} value.
153    * @throws IllegalLifeCycleException if a problem occurs.
154    */

155
156   public abstract boolean _super_setFcStarted ()
157     throws IllegalLifeCycleException;
158
159   /**
160    * The {@link LifeCycleCoordinator#setFcStopped setFcStopped} method overriden
161    * by this mixin.
162    *
163    * @return <tt>true</tt> if the execution state has changed, or <tt>false</tt>
164    * if it had already the {@link #STOPPED STOPPED} value.
165    * @throws IllegalLifeCycleException if a problem occurs.
166    */

167
168   public abstract boolean _super_setFcStopped ()
169     throws IllegalLifeCycleException;
170 }
171
Popular Tags