📄 plugininterfaceimpl.java
字号:
if ( dir == null || dir.length() == 0 ){
return(getPlugin() instanceof UnloadablePlugin );
}
List pis = PluginInitializer.getPluginInterfaces();
for (int i=0;i<pis.size();i++){
PluginInterface pi = (PluginInterface)pis.get(i);
String other_dir = pi.getPluginDirectoryName();
if ( other_dir == null || other_dir.length() == 0 ){
continue;
}
if ( dir.equals( other_dir )){
if ( !(pi.getPlugin() instanceof UnloadablePlugin )){
return( false );
}
}
}
for (int i=0;i<children.size();i++){
if ( !((PluginInterface)children.get(i)).isUnloadable()){
return( false );
}
}
return( true );
}
public void
unload()
throws PluginException
{
if ( !isUnloadable()){
throw( new PluginException( "Plugin isn't unloadable" ));
}
String dir = getPluginDirectoryName();
// if not dir based then just test this one
if ( dir == null || dir.length() == 0 ){
((UnloadablePlugin)getPlugin()).unload();
initialiser.unloadPlugin( this );
}else{
// we must copy the list here as when we unload interfaces they will be
// removed from the original list
List pis = new ArrayList(PluginInitializer.getPluginInterfaces());
for (int i=0;i<pis.size();i++){
PluginInterfaceImpl pi = (PluginInterfaceImpl)pis.get(i);
String other_dir = pi.getPluginDirectoryName();
if ( other_dir == null || other_dir.length() == 0 ){
continue;
}
if ( dir.equals( other_dir )){
((UnloadablePlugin)pi.getPlugin()).unload();
initialiser.unloadPlugin( pi );
}
}
}
for (int i=0;i<children.size();i++){
((PluginInterface)children.get(i)).unload();
}
setOperational(false);
class_loader = null;
}
public void
reload()
throws PluginException
{
unload();
initialiser.reloadPlugin( this );
}
public void
uninstall()
throws PluginException
{
PluginInstallerImpl.getSingleton(getPluginManager()).uninstall( this );
}
public ClientIDManager
getClientIDManager()
{
return( ClientIDManagerImpl.getSingleton());
}
public ConnectionManager getConnectionManager() {
return ConnectionManagerImpl.getSingleton( initialiser.getAzureusCore());
}
public MessageManager getMessageManager() {
return MessageManagerImpl.getSingleton( initialiser.getAzureusCore() );
}
public DistributedDatabase
getDistributedDatabase()
{
return( DDBaseImpl.getSingleton(initialiser.getAzureusCore()));
}
public PlatformManager
getPlatformManager()
{
return( PlatformManagerFactory.getPlatformManager());
}
protected void
initialisationComplete()
{
for (int i=0;i<listeners.size();i++){
try{
((PluginListener)listeners.get(i)).initializationComplete();
}catch( Throwable e ){
Debug.printStackTrace( e );
}
}
for (int i=0;i<children.size();i++){
((PluginInterfaceImpl)children.get(i)).initialisationComplete();
}
}
protected void
closedownInitiated()
{
for (int i=0;i<listeners.size();i++){
try{
((PluginListener)listeners.get(i)).closedownInitiated();
}catch( Throwable e ){
Debug.printStackTrace( e );
}
}
for (int i=0;i<children.size();i++){
((PluginInterfaceImpl)children.get(i)).closedownInitiated();
}
}
protected void
closedownComplete()
{
for (int i=0;i<listeners.size();i++){
try{
((PluginListener)listeners.get(i)).closedownComplete();
}catch( Throwable e ){
Debug.printStackTrace( e );
}
}
for (int i=0;i<children.size();i++){
((PluginInterfaceImpl)children.get(i)).closedownComplete();
}
}
public void
firePluginEvent(
PluginEvent event )
{
for (int i=0;i<event_listeners.size();i++){
try{
((PluginEventListener)event_listeners.get(i)).handleEvent( event );
}catch( Throwable e ){
Debug.printStackTrace( e );
}
}
for (int i=0;i<children.size();i++){
((PluginInterfaceImpl)children.get(i)).firePluginEvent(event);
}
}
public ClassLoader
getPluginClassLoader()
{
return( class_loader );
}
public PluginInterface
getLocalPluginInterface(
Class plugin_class,
String id )
throws PluginException
{
try{
Plugin p = (Plugin)plugin_class.newInstance();
PluginInterfaceImpl pi =
new PluginInterfaceImpl(
p,
initialiser,
initialiser_key,
class_loader,
key + "." + id,
props,
pluginDir,
plugin_id + "." + id,
plugin_version );
p.initialize( pi );
children.add( pi );
return( pi );
}catch( Throwable e ){
if ( e instanceof PluginException ){
throw((PluginException)e);
}
throw( new PluginException( "Local initialisation fails", e ));
}
}
public IPCInterface
getIPC()
{
return( ipc_interface );
}
public void
addListener(
PluginListener l )
{
listeners.add(l);
if ( initialiser.isInitialisationComplete()){
l.initializationComplete();
}
}
public void
removeListener(
PluginListener l )
{
listeners.remove(l);
}
public void
addEventListener(
PluginEventListener l )
{
event_listeners.add(l);
}
public void
removeEventListener(
PluginEventListener l )
{
event_listeners.remove(l);
}
protected void
generateEvidence(
IndentWriter writer )
{
writer.println( getPluginName());
try{
writer.indent();
writer.println( "id:" + getPluginID() + ",version:" + getPluginVersion());
String user_dir = FileUtil.getUserFile( "plugins" ).toString();
String shared_dir = FileUtil.getApplicationFile( "plugins" ).toString();
String plugin_dir = getPluginDirectoryName();
String type;
if ( plugin_dir.startsWith( shared_dir )){
type = "shared";
}else if ( plugin_dir.startsWith( user_dir )){
type = "per-user";
}else{
type = "built-in";
}
writer.println( "type:" + type + ",enabled:" + !isDisabled() + ",operational:" + isOperational());
}finally{
writer.exdent();
}
}
// unfortunately we need to protect ourselves against the plugin itself trying to set
// plugin.version and plugin.id as this screws things up if they get it "wrong".
// They should be setting these things in the plugin.properties file
// currently the RSSImport plugin does this (version 1.1 sets version as 1.0)
protected class
propertyWrapper
extends Properties
{
protected boolean initialising = true;
protected
propertyWrapper(
Properties _props )
{
Iterator it = _props.keySet().iterator();
while( it.hasNext()){
Object key = it.next();
put( key, _props.get(key));
}
initialising = false;
}
public Object
setProperty(
String str,
String val )
{
// if its us then we probably know what we're doing :P
if ( ! ( plugin.getClass().getName().startsWith( "org.gudy") || plugin.getClass().getName().startsWith( "com.aelitis."))){
if ( str.equalsIgnoreCase( "plugin.id" ) || str.equalsIgnoreCase("plugin.version" )){
if (org.gudy.azureus2.core3.logging.Logger.isEnabled())
org.gudy.azureus2.core3.logging.Logger
.log(new LogEvent(LOGID, LogEvent.LT_WARNING, "Plugin '"
+ getPluginName() + "' tried to set property '" + str
+ "' - action ignored"));
return( null );
}
}
return( super.setProperty( str, val ));
}
public Object
put(
Object key,
Object value )
{
// if its us then we probably know what we're doing :P
if ( ! ( plugin.getClass().getName().startsWith( "org.gudy") || plugin.getClass().getName().startsWith( "com.aelitis."))){
if ((!initialising ) && key instanceof String ){
String k_str = (String)key;
if ( k_str.equalsIgnoreCase( "plugin.id" ) || k_str.equalsIgnoreCase("plugin.version" )){
if (org.gudy.azureus2.core3.logging.Logger.isEnabled())
org.gudy.azureus2.core3.logging.Logger.log(new LogEvent(LOGID,
LogEvent.LT_WARNING, "Plugin '" + getPluginName()
+ "' tried to set property '" + k_str
+ "' - action ignored"));
return( null );
}
}
}
return( super.put( key, value ));
}
public Object
get(
Object key )
{
return( super.get(key));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -