KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > server > kernel > UpgradeMethod


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.server.kernel;
10
11 import java.util.Iterator JavaDoc;
12
13 import org.jboss.portal.server.kernel.state.State;
14
15 /**
16  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
17  * @version $Revision: 1.2 $
18  */

19 public abstract class UpgradeMethod extends LifeCycleMethod
20 {
21
22    protected UpgradeMethod(Kernel kernel)
23    {
24       super(kernel);
25    }
26
27    public State invoke(Entry entry) throws TransitionNotPossibleException, ServiceFailureException
28    {
29       // Ensure we can do it
30
checkState(entry);
31
32       // Check all the service it depends on
33
for (Iterator JavaDoc i = entry.depends.iterator();i.hasNext();)
34       {
35          ServiceID dependOnID = (ServiceID)i.next();
36          Entry dependOnEntry = kernel.getEntry(dependOnID);
37          if (doesDependantPreventsInvoke(dependOnEntry))
38          {
39             return entry.getState();
40          }
41       }
42
43       try
44       {
45          // Try to invoke the service
46
invokeMethod(entry);
47
48          // Dependants recursively if possible
49
invokeOnDependsOnMe(entry);
50
51          //
52
return entry.getState();
53       }
54       catch (Exception JavaDoc e)
55       {
56          // todo julien : on fail, should not we fail all the dependant services recursively ?
57
entry.machine.fail(false);
58          throw new ServiceFailureException(e);
59       }
60    }
61
62    /**
63     * Check that a service which the current service depends on is in the good state
64     *
65     * @return true if the service state it depends on prevent from invoking the method
66     */

67    protected abstract boolean doesDependantPreventsInvoke(Entry entry);
68 }
69
Popular Tags