File: Plugin.java

package info (click to toggle)
libjpf-java 1.5.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch, wheezy
  • size: 2,280 kB
  • ctags: 2,079
  • sloc: java: 13,449; xml: 337; sh: 48; makefile: 19
file content (130 lines) | stat: -rw-r--r-- 4,290 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*****************************************************************************
 * Java Plug-in Framework (JPF)
 * Copyright (C) 2004-2007 Dmitry Olshansky
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *****************************************************************************/
package org.java.plugin;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.java.plugin.registry.PluginDescriptor;

/**
 * This is base for "home" class of plug-in runtime. Using this class,
 * plug-in code can get access to plug-in framework
 * ({@link org.java.plugin.PluginManager manager},
 * {@link org.java.plugin.registry.PluginRegistry registry}) which was loaded it.
 * It is also used by manager during plug-in life cycle management (activation
 * and deactivation).
 * <br>
 * Plug-in vendor may provide it's own implementation of this class if some
 * actions should be performed during plug-in activation/deactivation. When no
 * class specified, framework provides default "empty" implementation that does
 * nothing when plug-in started and stopped.
 * @version $Id$
 */
public abstract class Plugin {
    /**
     * Makes logging service available for descending classes.
     */
    protected final Log log = LogFactory.getLog(getClass());

    private PluginManager manager;
    private PluginDescriptor descriptor;
    private boolean started;

    /**
     * @return descriptor of this plug-in
     */
    public final PluginDescriptor getDescriptor() {
        return descriptor;
    }
    
    /*
     * For internal use only!
     */
    final void setDescriptor(final PluginDescriptor descr) {
        this.descriptor = descr;
    }
    
    /**
     * @return manager which controls this plug-in
     */
    public final PluginManager getManager() {
        return manager;
    }
    
    /*
     * For internal use only!
     */
    final void setManager(final PluginManager aManager) {
        this.manager = aManager;
    }

    /*
     * For internal use only!
     */
    final void start() throws Exception {
        if (!started) {
            doStart();
            started = true;
        }
    }

    /*
     * For internal use only!
     */
    final void stop() throws Exception {
        if (started) {
            doStop();
            started = false;
        }
    }

    /**
     * @return <code>true</code> if this plug-in is in active state
     */
    public final boolean isActive() {
        return started;
    }

    /**
     * This method will be called once during plug-in activation before any
     * access to any code from this plug-in.
     * @throws Exception if an error has occurred during plug-in start-up
     */
    protected abstract void doStart() throws Exception;

    /**
     * This method will be called once during plug-in deactivation. After
     * this method call, no other code from this plug-in can be accessed,
     * unless {@link #doStart()} method will be called again (but for another
     * instance of this class).
     * @throws Exception if an error has occurred during plug-in shutdown
     */
    protected abstract void doStop() throws Exception;

    /**
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return "{" + getClass().getName() //$NON-NLS-1$
            + ": manager=" + manager //$NON-NLS-1$
            + ", descriptor=" + descriptor //$NON-NLS-1$
            + "}"; //$NON-NLS-1$
    }
}