KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > java > plugin > standard > PluginLifecycleHandler


1 /*****************************************************************************
2  * Java Plug-in Framework (JPF)
3  * Copyright (C) 2004-2005 Dmitry Olshansky
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.1 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 package org.java.plugin.standard;
20
21 import org.java.plugin.ObjectFactory;
22 import org.java.plugin.Plugin;
23 import org.java.plugin.PluginClassLoader;
24 import org.java.plugin.PluginLifecycleException;
25 import org.java.plugin.PluginManager;
26 import org.java.plugin.registry.PluginDescriptor;
27 import org.java.plugin.util.ExtendedProperties;
28
29
30 /**
31  * Manager class that handles plug-in life cycle related logic. This class is
32  * part of standard implementation of plug-in manager, other implementations may
33  * not use it at all. The main purpose of this class is to simplify
34  * customization of plug-in manager behavior.
35  * @version $Id: PluginLifecycleHandler.java,v 1.2 2005/12/03 16:06:20 ddimon Exp $
36  */

37 public abstract class PluginLifecycleHandler {
38     private PluginManager manager;
39
40     /**
41      * Initializes this handler instance. This method called once during this
42      * handler instance life cycle.
43      * @param aManager a plug-in manager, this handler is "connected" to
44      */

45     protected void init(PluginManager aManager) {
46         manager = aManager;
47     }
48     
49     /**
50      * @return instance of plug-in manager, this handler is "connected" to
51      */

52     protected PluginManager getPluginManager() {
53         return manager;
54     }
55     
56     /**
57      * Configures this handler instance. Note that this method should be called
58      * once before {@link #init(PluginManager)}, usually this is done in
59      * {@link ObjectFactory object factory} implementation.
60      * @param config handler configuration data
61      */

62     protected abstract void configure(ExtendedProperties config);
63     
64     /**
65      * This method should create new instance of class loader for given plug-in.
66      * @param descr plug-in descriptor
67      * @return class loader instance for given plug-in
68      */

69     protected abstract PluginClassLoader createPluginClassLoader(
70             PluginDescriptor descr);
71
72     /**
73      * This method should create new instance of plug-in class. No initializing
74      * logic should be executed in new class instance during this method call.
75      * <br>
76      * Note that this method will NOT be called for those plug-ins that have NO
77      * class declared in plug-in descriptor i.e., method
78      * {@link PluginDescriptor#getPluginClassName()} returns blank string or
79      * <code>null</code>.
80      * @param descr plug-in descriptor
81      * @return new not initialized instance of plug-in class
82      * @throws PluginLifecycleException if plug-in class can't be instantiated
83      * for some reason
84      */

85     protected abstract Plugin createPluginInstance(PluginDescriptor descr)
86         throws PluginLifecycleException;
87     
88     /**
89      * This method will be called by {@link PluginManager} just before starting
90      * plug-in. Put here any "initializing" logic that should be executed before
91      * plug-in start.
92      * @param plugin plug-in being starting
93      * @throws PluginLifecycleException if plug-in can't be "initialized"
94      */

95     protected abstract void beforePluginStart(final Plugin plugin)
96         throws PluginLifecycleException;
97     
98     /**
99      * This method will be called by {@link PluginManager} just after stopping
100      * plug-in. Put here any "un-initializing" logic that should be executed
101      * after plug-in stop.
102      * @param plugin plug-in being stopping
103      * @throws PluginLifecycleException if plug-in can't be "un-initialized"
104      */

105     protected abstract void afterPluginStop(final Plugin plugin)
106         throws PluginLifecycleException;
107     
108     /**
109      * Should dispose all resources allocated by this handler instance. No
110      * methods will be called for this class instance after executing this
111      * method.
112      */

113     protected abstract void dispose();
114 }
115
Popular Tags