1 19 package org.java.plugin; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 23 import org.java.plugin.registry.PluginDescriptor; 24 25 39 public abstract class Plugin { 40 43 protected final Log log = LogFactory.getLog(getClass()); 44 45 private PluginManager manager; 46 private PluginDescriptor descriptor; 47 private boolean started; 48 49 53 protected Plugin() { 54 } 56 57 70 public Plugin(final PluginManager aManager, final PluginDescriptor descr) { 71 this.manager = aManager; 72 this.descriptor = descr; 73 if (descr == null) { 74 throw new IllegalArgumentException ("descriptor cannot be NULL"); } 76 } 77 78 81 public final PluginDescriptor getDescriptor() { 82 return descriptor; 83 } 84 85 88 final void setDescriptor(final PluginDescriptor descr) { 89 this.descriptor = descr; 90 } 91 92 95 public final PluginManager getManager() { 96 return manager; 97 } 98 99 102 final void setManager(final PluginManager aManager) { 103 this.manager = aManager; 104 } 105 106 109 final void start() throws Exception { 110 if (!started) { 111 doStart(); 112 started = true; 113 } 114 } 115 116 119 final void stop() throws Exception { 120 if (started) { 121 doStop(); 122 started = false; 123 } 124 } 125 126 129 public final boolean isActive() { 130 return started; 131 } 132 133 138 protected abstract void doStart() throws Exception ; 139 140 147 protected abstract void doStop() throws Exception ; 148 149 152 public String toString() { 153 return "{" + getClass().getName() + ": manager=" + manager + ", descriptor=" + descriptor + "}"; } 158 } 159 | Popular Tags |