FileDocCategorySizeDatePackage
PluginInterfaceImpl.javaAPI DocAzureus 3.0.3.420643Wed Sep 26 18:24:42 BST 2007org.gudy.azureus2.pluginsimpl.local

PluginInterfaceImpl

public class PluginInterfaceImpl extends Object implements PluginInterface
author
Olivier

Fields Summary
private static final LogIDs
LOGID
private Plugin
plugin
private PluginInitializer
initialiser
private Object
initialiser_key
private ClassLoader
class_loader
private List
listeners
private List
event_listeners
private String
key
private String
pluginConfigKey
private Properties
props
private String
pluginDir
private PluginConfig
config
private String
plugin_id
private String
plugin_version
private boolean
operational
private boolean
disabled
private org.gudy.azureus2.plugins.logging.Logger
logger
private org.gudy.azureus2.pluginsimpl.local.ipc.IPCInterfaceImpl
ipc_interface
private List
children
private List
configSections
Constructors Summary
public PluginInterfaceImpl(Plugin _plugin, PluginInitializer _initialiser, Object _initialiser_key, ClassLoader _class_loader, String _key, Properties _props, String _pluginDir, String _plugin_id, String _plugin_version)

  
   
  
  						
  			
						
					
		 				
		 			
		 				
						
						  
  
  	plugin				= _plugin;
  	initialiser			= _initialiser;
  	initialiser_key		= _initialiser_key;
  	class_loader		= _class_loader;
  	key					= _key;
  	pluginConfigKey 	= "Plugin." + _key;
    props 				= new propertyWrapper(_props );
    pluginDir 			= _pluginDir;
    config 				= new PluginConfigImpl(this,pluginConfigKey);
    plugin_id			= _plugin_id;
    plugin_version		= _plugin_version;
    ipc_interface		= new IPCInterfaceImpl( initialiser, plugin );
  
Methods Summary
public voidaddColumnToMyTorrentsTable(java.lang.String columnName, org.gudy.azureus2.plugins.ui.tables.mytorrents.PluginMyTorrentsItemFactory item)

deprecated
Use getUIManager().getTableManager().createColumn

	   Debug.out( "Method PluginInterface::addColumnToMyTorrentsTable deprecated. Use getUIManager().getTableManager().createColumn" );
 
public voidaddColumnToPeersTable(java.lang.String columnName, org.gudy.azureus2.plugins.ui.tables.peers.PluginPeerItemFactory item)

deprecated
Use getUIManager().getTableManager().createColumn

    Debug.out( "Method PluginInterface::addColumnToPeersTable deprecated. Use getUIManager().getTableManager().createColumn" );
  
public voidaddConfigSection(org.gudy.azureus2.plugins.ui.config.ConfigSection section)

  	ConfigSectionRepository.getInstance().addConfigSection(section);
  	configSections.add(section);
  
public voidaddConfigUIParameters(org.gudy.azureus2.plugins.ui.config.Parameter[] parameters, java.lang.String displayName)

  	ParameterRepository.getInstance().addPlugin(parameters, displayName);
  
public voidaddEventListener(PluginEventListener l)

  	event_listeners.add(l);
  
public voidaddListener(PluginListener l)

  	listeners.add(l);
  	
  	if ( initialiser.isInitialisationComplete()){
  		
  		l.initializationComplete();
  	}
  
public voidaddView(PluginView view)

deprecated

    getUIManager().getSWTManager().addView(view);
  
protected voidclosedownComplete()

  	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();
  	}
  
protected voidclosedownInitiated()

  	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();
  	}
  
public voidfirePluginEvent(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);
  	}
  
protected voidgenerateEvidence(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();
		}
	
public java.lang.StringgetAzureusName()

		return( Constants.AZUREUS_NAME );
	
public java.lang.StringgetAzureusVersion()

		return( Constants.AZUREUS_VERSION );
	
public org.gudy.azureus2.plugins.clientid.ClientIDManagergetClientIDManager()

	 	return( ClientIDManagerImpl.getSingleton());
	 
public org.gudy.azureus2.plugins.ui.config.ConfigSection[]getConfigSections()

  	return (ConfigSection[]) configSections.toArray(new ConfigSection[0]);
  
public org.gudy.azureus2.plugins.network.ConnectionManagergetConnectionManager()

     return ConnectionManagerImpl.getSingleton( initialiser.getAzureusCore());
   
public org.gudy.azureus2.plugins.ddb.DistributedDatabasegetDistributedDatabase()

   	return( DDBaseImpl.getSingleton(initialiser.getAzureusCore()));
   
public DownloadManagergetDownloadManager()

  	return( DownloadManagerImpl.getSingleton(initialiser.getAzureusCore()));
  
public org.gudy.azureus2.plugins.ipc.IPCInterfacegetIPC()

		 return( ipc_interface );
	 
public org.gudy.azureus2.plugins.ipfilter.IPFiltergetIPFilter()

  	return( new IPFilterImpl());
  
public java.lang.ObjectgetInitializerKey()

  		return( initialiser_key );
  	
public PluginInterfacegetLocalPluginInterface(java.lang.Class plugin_class, java.lang.String id)

		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 org.gudy.azureus2.plugins.logging.LoggergetLogger()

  	if ( logger == null ){
  		
  		logger = new LoggerImpl( this );
  	}
  	
  	return( logger );
  
public org.gudy.azureus2.plugins.messaging.MessageManagergetMessageManager()

     return MessageManagerImpl.getSingleton( initialiser.getAzureusCore() );
   
public PeerProtocolManagergetPeerProtocolManager()

  	return( PeerProtocolManagerImpl.getSingleton());
  
public org.gudy.azureus2.plugins.platform.PlatformManagergetPlatformManager()

	   return( PlatformManagerFactory.getPlatformManager());
   
public PlugingetPlugin()

  		return( plugin );
	
public java.lang.ClassLoadergetPluginClassLoader()

  	return( class_loader );
  
public java.lang.StringgetPluginConfigKey()

  	return( pluginConfigKey );
  
public org.gudy.azureus2.plugins.ui.config.PluginConfigUIFactorygetPluginConfigUIFactory()

    return new PluginConfigUIFactoryImpl(config,pluginConfigKey);
  
public java.lang.StringgetPluginDirectoryName()

    return pluginDir;
  
public java.lang.StringgetPluginID()

  	String	id = (String)props.get("plugin.id");
  	
  	if ( id == null ){
  		
  		id = plugin_id;
  	}
  	
  	return( id==null?"<none>":id );
  
public PluginManagergetPluginManager()

  		return( initialiser.getPluginManager());
  	
public java.lang.StringgetPluginName()

  	String	name = null;
  	
  	if ( props != null ){
  		
  		name = (String)props.get( "plugin.name");
  	}
  	
  	if ( name == null ){
  		
  		try{
  			
  			name = new File(pluginDir).getName();
  			
  		}catch( Throwable e ){
  			
  		}
  	}
  	
  	if ( name == null || name.length() == 0 ){
  		
  		name = plugin.getClass().getName();
  	}
  	
  	return( name );
  
public java.util.PropertiesgetPluginProperties()

    return(props);
  
public java.lang.StringgetPluginVersion()

	String	version = (String)props.get("plugin.version");
  	
  	if ( version == null ){
  		
  		version = plugin_version;
  	}
  	
  	return( version );
  
public PluginConfiggetPluginconfig()

    return config;
  
public ShareManagergetShareManager()

  	return( ShareManagerImpl.getSingleton());
  
public ShortCutsgetShortCuts()

  	return( new ShortCutsImpl(this));
  
public TorrentManagergetTorrentManager()

  	return( TorrentManagerImpl.getSingleton().specialise( this ));
  
public org.gudy.azureus2.plugins.tracker.TrackergetTracker()

  	return( TrackerImpl.getSingleton());
  
public UIManagergetUIManager()

  	return( new UIManagerImpl( this ));
  
public UpdateManagergetUpdateManager()

  	return( UpdateManagerImpl.getSingleton( initialiser.getAzureusCore()));
  
public UtilitiesgetUtilities()

  	return( new UtilitiesImpl( initialiser.getAzureusCore(), this ));
  
protected voidinitialisationComplete()

  	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();
  	}
  
public booleanisBuiltIn()

	  String	dir = getPluginDirectoryName();
	  
	  if ( dir == null ){
		  
		  return( PluginInitializer.isLoadingBuiltin());
	  }
	  
  		return( dir.length() == 0 || getPluginID().equals( "azupdater" ));
  
public booleanisDisabled()

		return( disabled );
	
public booleanisInitialisationThread()

		return( initialiser.isInitialisationThread());
	
public booleanisMandatory()

	String	mand = getPluginProperties().getProperty( "plugin.mandatory");
	
	return( mand != null && mand.trim().toLowerCase().equals("true"));
  
public booleanisOperational()

    	return( operational );
    
public booleanisShared()

		String shared_dir 	= FileUtil.getApplicationFile( "plugins" ).toString(); 
		   
		String	plugin_dir = getPluginDirectoryName();
				
		return( plugin_dir.startsWith( shared_dir ));
	
public booleanisUnloadable()

  	String dir = getPluginDirectoryName();
  	
  		// mechanism to override unloadability 
  	
   	boolean	disable_unload = getPluginProperties().getProperty( "plugin.unload.disabled", "" ).equalsIgnoreCase( "true" );
  	
  	if ( disable_unload ){
  		
  		return( false );
  	}
  	
		// if not dir based then just test this one
  	
  	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 voidopenTorrentFile(java.lang.String fileName)

deprecated

	  try{
		  getDownloadManager().addDownload( new File(fileName));
	  }catch( DownloadException e ){
		  throw( new RuntimeException(e));
	  }
  
public voidopenTorrentURL(java.lang.String url)

deprecated

	  try{
		  getDownloadManager().addDownload( new URL( url ));
	  }catch( Throwable e ){
		  throw( new RuntimeException(e));
	  } 
  
public voidreload()

	  	// we use the "reload" method to load disabled plugins regardless of whether they are
	  	// unloadable. If currently disabled then no unloading to do anyway
	  
	if ( isUnloadable() || isOperational()){
		
	  unload();
	}
	  
  	initialiser.reloadPlugin( this );
  
public voidremoveConfigSection(org.gudy.azureus2.plugins.ui.config.ConfigSection section)

  	ConfigSectionRepository.getInstance().removeConfigSection(section);
  	configSections.remove(section);
  
public voidremoveEventListener(PluginEventListener l)

  	event_listeners.remove(l);
  
public voidremoveListener(PluginListener l)

  	listeners.remove(l);
  
public voidsetDisabled(boolean _disabled)

		disabled	= _disabled;
	
protected voidsetOperational(boolean b)

  		operational	= b;
  	
public voidsetPluginDirectoryName(java.lang.String name)

  	initialiser_key	= new File(name);
  	
  	pluginDir	= name;
  
public voidsetPluginName(java.lang.String name)

  	props.put( "plugin.name", name );
  
public voidsetPluginVersion(java.lang.String version)

	props.put( "plugin.version", version );
  
public voiduninstall()

		PluginInstallerImpl.getSingleton(getPluginManager()).uninstall( this );
	
public voidunload()

  	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;
  
protected voidunloadSupport()

	  ipc_interface.unload();