FileDocCategorySizeDatePackage
IPCInterfaceImpl.javaAPI DocAzureus 3.0.3.44386Wed Sep 26 18:24:40 BST 2007org.gudy.azureus2.pluginsimpl.local.ipc

IPCInterfaceImpl

public class IPCInterfaceImpl extends Object implements org.gudy.azureus2.plugins.ipc.IPCInterface
author
Damokles

Fields Summary
private org.gudy.azureus2.plugins.Plugin
target_use_accessor
private String
plugin_class
private org.gudy.azureus2.pluginsimpl.local.PluginInitializer
plugin_initializer
Constructors Summary
public IPCInterfaceImpl(org.gudy.azureus2.pluginsimpl.local.PluginInitializer _plugin_initializer, org.gudy.azureus2.plugins.Plugin _target)

		plugin_initializer	= _plugin_initializer;
		target_use_accessor = _target;
		plugin_class		= _target.getClass().getName();
	
Methods Summary
protected org.gudy.azureus2.plugins.PlugingetTarget()

		
		synchronized( this ){

			if ( target_use_accessor == null ){
				
				PluginInterface[] pis = plugin_initializer.getPlugins();
				
				for (int i=0;i<pis.length;i++){
					
					PluginInterface pi = pis[i];
					
					if ( pi.getPlugin().getClass().getName().equals( plugin_class )){
						
						target_use_accessor = pi.getPlugin();
						
						break;
					}
				}
			}
			
			if ( target_use_accessor == null ){
				
				throw( new IPCException( "Plugin has been unloaded" ));
			}
			
			return( target_use_accessor );
		}
	
public java.lang.Objectinvoke(java.lang.String methodName, java.lang.Object[] params)


		Plugin	target = getTarget();
		
		try {
			if (params == null) {
				params = new Object[0];
			}

			Class[] paramTypes = new Class[params.length];
			for (int i=0;i<params.length;i++) {
				if (params[i] instanceof Boolean) {
					paramTypes[i] = boolean.class;
				} else if (params[i] instanceof Integer) {
					paramTypes[i] = int.class;
				} else if (params[i] instanceof Long) {
					paramTypes[i] = long.class;
				} else if (params[i] instanceof Float) {
					paramTypes[i] = float.class;
				} else if (params[i] instanceof Double) {
					paramTypes[i] = double.class;
				} else if (params[i] instanceof Byte) {
					paramTypes[i] = byte.class;
				} else if (params[i] instanceof Character) {
					paramTypes[i] = char.class;
				} else if (params[i] instanceof Short) {
					paramTypes[i] = short.class;
				} else
					paramTypes[i] = params[i].getClass();
			}
			
			Method mtd	= null;
			
			try{
				mtd = target.getClass().getMethod(methodName,paramTypes);
				
			}catch( NoSuchMethodException e ){
				
				Method[]	methods = target.getClass().getMethods();
				
				for (int i=0;i<methods.length;i++){
					
					Method	method = methods[i];
					
					Class[] method_params = method.getParameterTypes();
					
					if ( method.getName().equals( methodName ) && method_params.length == paramTypes.length ){
						
						boolean	ok = true;
						
						for (int j=0;j<method_params.length;j++){
							
							Class	declared 	= method_params[j];
							Class	supplied	= paramTypes[j];
							
							if ( !declared.isAssignableFrom( supplied )){
						
								ok	= false;
								
								break;
							}
						}
						
						if ( ok ){
							
							mtd = method;
							
							break;
						}
					}
				}
				
				if ( mtd == null ){
					
					throw( e );
				}
			}
			
			return mtd.invoke(target, params);
		} catch (Exception e) {
			throw new IPCException(e);
		}
	
public voidunload()

		synchronized( this ){
		
			target_use_accessor	= null;
		}