KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dream > control > lifecycle > FullLifeCycleMixin


1 /**
2  * Dream Copyright (C) 2003-2004 INRIA Rhone-Alpes
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License as published by the Free
6  * Software Foundation; either version 2 of the License, or (at your option) any
7  * later version.
8  *
9  * This library is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Contact: dream@objectweb.org
19  *
20  * Initial developer(s): Matthieu Leclercq
21  * Contributor(s):
22  */

23
24 package org.objectweb.dream.control.lifecycle;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.objectweb.fractal.api.Component;
31 import org.objectweb.fractal.api.NoSuchInterfaceException;
32 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
33 import org.objectweb.fractal.julia.control.content.Util;
34 import org.objectweb.fractal.julia.control.lifecycle.ChainedIllegalLifeCycleException;
35 import org.objectweb.fractal.julia.control.lifecycle.LifeCycleCoordinator;
36 import org.objectweb.util.monolog.api.BasicLevel;
37 import org.objectweb.util.monolog.api.Logger;
38
39 /**
40  * This mixin provides a useable implementation of the
41  * {@link org.objectweb.fractal.api.control.LifeCycleController#stopFc() }
42  * method. This method stop every sub components providing a lifecycle
43  * controller at once.
44  * <p>
45  * <p>
46  * <b>Requirements </b>
47  * <ul>
48  * <li>This mixin must be used with the
49  * {@link org.objectweb.fractal.julia.UseComponentMixin }mixin.</li>
50  * <li>This mixin must be used with the {@link SimpleLifeCycleControllerMixin}
51  * lifecycle controller implementation.</li>
52  * <li>This mixin must be used with the {@link ThreadCounterMixin }lifecycle
53  * controller extension.</li>
54  * </ul>
55  */

56 public abstract class FullLifeCycleMixin
57 {
58
59   // ---------------------------------------------------------------------------
60
// Fields and methods added and overriden by the mixin class
61
// ---------------------------------------------------------------------------
62

63   /**
64    * @see org.objectweb.fractal.api.control.LifeCycleController#stopFc()
65    */

66   public void stopFc() throws IllegalLifeCycleException
67   {
68     if (_this_weaveableFcState == 2)
69     {
70       _this_weaveableLCCLogger.log(BasicLevel.DEBUG, "Stop component");
71       _this_stopFc(getFcLifeCycleControllers());
72       _this_setFcState(false);
73     }
74   }
75
76   // ---------------------------------------------------------------------------
77
// Utility methods
78
// ---------------------------------------------------------------------------
79

80   /**
81    * Returns the lifecycle control interface of sub components.
82    *
83    * @return array of {@link LifeCycleCoordinator}of sub components.
84    * @throws IllegalLifeCycleException if a problem occurs.
85    */

86   public LifeCycleCoordinator[] getFcLifeCycleControllers()
87       throws IllegalLifeCycleException
88   {
89     Component thisComponent;
90     try
91     {
92       thisComponent = (Component) _this_weaveableC.getFcInterface("component");
93     }
94     catch (NoSuchInterfaceException e)
95     {
96       throw new ChainedIllegalLifeCycleException(e, _this_weaveableC,
97           "The DreamLifeCycleCoordinatorMixin requires components to provide "
98               + "the Component interface");
99     }
100     List JavaDoc allSubComponents = Util.getAllSubComponents(thisComponent);
101     List JavaDoc result = new ArrayList JavaDoc();
102     Iterator JavaDoc iterator = allSubComponents.iterator();
103     while (iterator.hasNext())
104     {
105       Component c = (Component) iterator.next();
106       try
107       {
108         result.add((LifeCycleCoordinator) c
109             .getFcInterface("lifecycle-controller"));
110       }
111       catch (Exception JavaDoc ignored)
112       {
113         // ignore
114
}
115     }
116     return (LifeCycleCoordinator[]) result
117         .toArray(new LifeCycleCoordinator[result.size()]);
118   }
119
120   // ---------------------------------------------------------------------------
121
// Fields and methods required by the mixin class in the base class
122
// ---------------------------------------------------------------------------
123

124   /**
125    * The <code>weaveableC</code> field required by this mixin. This field is
126    * supposed to reference the {@link Component}interface of the component to
127    * which this controller object belongs.
128    */

129   public Component _this_weaveableC;
130
131   /**
132    * the <code>weaveableFcState</code> field reqired by this mixin. This field
133    * is supposed to reference the current state of the component lifecycle.
134    *
135    * @see SimpleLifeCycleControllerMixin#weaveableFcState
136    */

137   public int _this_weaveableFcState;
138
139   /**
140    * The <tt>weaveableLCCLogger</tt> field required by this mixin. This field
141    * is supposed to reference the {@link Logger }of this controller.
142    */

143   public Logger _this_weaveableLCCLogger;
144
145   /**
146    * The <tt>setFcState</tt> method required by this mixin. This method is
147    * supposed to work as this
148    * {@link org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleCoordinatorMixin#setFcState
149    * setFcState} method.
150    *
151    * @param started <tt>true</tt> to set the lifecycle state of the components
152    * to
153    * {@link org.objectweb.fractal.api.control.LifeCycleController#STARTED STARTED},
154    * or <tt>false</tt> to set this state to
155    * {@link org.objectweb.fractal.api.control.LifeCycleController#STOPPED STOPPED}.
156    * @throws IllegalLifeCycleException if a problem occurs.
157    */

158   public abstract void _this_setFcState(boolean started)
159       throws IllegalLifeCycleException;
160
161   /**
162    * the <code>stopFc</code> method required by this mixin. This method is
163    * supposed to work a this
164    * {@link org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleCoordinatorMixin#stopFc(LifeCycleCoordinator[])}
165    * method.
166    *
167    * @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleCoordinatorMixin#stopFc(LifeCycleCoordinator[])
168    */

169   public abstract void _this_stopFc(LifeCycleCoordinator[] components)
170       throws IllegalLifeCycleException;
171 }
Popular Tags