FileDocCategorySizeDatePackage
ResourceDownloaderBaseImpl.javaAPI DocAzureus 3.0.3.46906Thu Feb 15 17:15:10 GMT 2007org.gudy.azureus2.pluginsimpl.local.utils.resourcedownloader

ResourceDownloaderBaseImpl

public abstract class ResourceDownloaderBaseImpl extends Object implements ResourceDownloader
author
parg

Fields Summary
private List
listeners
private boolean
result_informed
private Object
result_informed_data
private ResourceDownloaderBaseImpl
parent
private List
children
private boolean
download_cancelled
private Map
properties
protected org.gudy.azureus2.core3.util.AEMonitor
this_mon
Constructors Summary
protected ResourceDownloaderBaseImpl(ResourceDownloaderBaseImpl _parent)


	
	
			 
	
		parent	= _parent;
		
		if ( parent != null ){
			
			parent.addChild(this);
		}
	
Methods Summary
protected voidaddChild(org.gudy.azureus2.pluginsimpl.local.utils.resourcedownloader.ResourceDownloaderBaseImpl kid)

		children.add( kid );
	
public voidaddListener(ResourceDownloaderListener l)

		listeners.add( l );
		
		if ( result_informed ){
			
			if (result_informed_data instanceof InputStream ){
				
				l.completed( this, (InputStream)result_informed_data);
			}else{
				
				l.failed( this, (ResourceDownloaderException)result_informed_data);
			}
		}
	
protected voidaddReportListener(ResourceDownloader rd)

		rd.addListener(
				new ResourceDownloaderAdapter()
				{
					public void
					reportActivity(
						ResourceDownloader	downloader,
						String				activity )
					{
						informActivity( activity );
					}
					
					public void
					failed(
						ResourceDownloader			downloader,
						ResourceDownloaderException e )
					{
						informActivity( downloader.getName() + ":" + e.getMessage());
					}
				});
	
protected java.util.ListgetChildren()

		return( children );
	
public abstract org.gudy.azureus2.pluginsimpl.local.utils.resourcedownloader.ResourceDownloaderBaseImplgetClone(org.gudy.azureus2.pluginsimpl.local.utils.resourcedownloader.ResourceDownloaderBaseImpl _parent)

protected java.lang.StringgetLogIndent()

		String	indent = "";
		
		ResourceDownloaderBaseImpl	pos = parent;
		
		while( pos != null ){
			
			indent += "  ";
			
			pos = pos.getParent();
		}
		
		return( indent );
	
protected org.gudy.azureus2.pluginsimpl.local.utils.resourcedownloader.ResourceDownloaderBaseImplgetParent()

		return( parent );
	
public java.lang.ObjectgetProperty(java.lang.String name)

			// hack this, properties are read during size acquisition - should treat size as a property
			// too....
		
		getSize();
		
		return( properties.get( name ));
	
protected voidinformActivity(java.lang.String activity)

		for (int i=0;i<listeners.size();i++){
			
			try{
				((ResourceDownloaderListener)listeners.get(i)).reportActivity(this,activity);
				
			}catch( Throwable e ){
				
				Debug.printStackTrace(e);
			}
		}
	
protected voidinformAmountComplete(long amount)

		for (int i=0;i<listeners.size();i++){
			
			try{
				((ResourceDownloaderListener)listeners.get(i)).reportAmountComplete(this,amount);
				
			}catch( NoSuchMethodError e ){
				
				// handle addition of this new method with old impls
			}catch( AbstractMethodError e ){
				
				// handle addition of this new method with old impls
			
			}catch( Throwable e ){
				
				Debug.printStackTrace(e);
			}
		}
	
protected booleaninformComplete(java.io.InputStream is)

		if ( !result_informed ){
			
			for (int i=0;i<listeners.size();i++){
				
				try{
					if ( !((ResourceDownloaderListener)listeners.get(i)).completed(this,is)){
						
						return( false );
					}
				}catch( Throwable e ){
					
					Debug.printStackTrace(e);
					
					return( false );
				}
			}
			
			result_informed	= true;
			
			result_informed_data	= is;
		}
		
		return( true );
	
protected voidinformFailed(ResourceDownloaderException e)

		if ( !result_informed ){
			
			result_informed	= true;
		
			result_informed_data = e;
			
			for (int i=0;i<listeners.size();i++){
				
				try{
					((ResourceDownloaderListener)listeners.get(i)).failed(this,e);
					
				}catch( Throwable f ){
					
					Debug.printStackTrace(f);
				}
			}
		}
	
protected voidinformPercentDone(int percentage)

		for (int i=0;i<listeners.size();i++){
			
			try{
				((ResourceDownloaderListener)listeners.get(i)).reportPercentComplete(this,percentage);
				
			}catch( Throwable e ){
				
				Debug.printStackTrace(e);
			}
		}
	
public booleanisCancelled()

		return( download_cancelled );
	
protected voidremoveChild(org.gudy.azureus2.pluginsimpl.local.utils.resourcedownloader.ResourceDownloaderBaseImpl kid)

		children.remove( kid );
	
public voidremoveListener(ResourceDownloaderListener l)

		listeners.remove(l);
	
public voidreportActivity(java.lang.String str)

		informActivity( str );
	
public voidreportActivity(ResourceDownloader downloader, java.lang.String activity)

		informActivity( activity );
	
public voidreportAmountComplete(ResourceDownloader downloader, long amount)

		informAmountComplete( amount );
	
public voidreportPercentComplete(ResourceDownloader downloader, int percentage)

		informPercentDone( percentage );
	
protected voidsetCancelled()

		download_cancelled	= true;
	
protected voidsetParent(ResourceDownloader _parent)

		ResourceDownloaderBaseImpl	old_parent	= parent;
		
		parent	= (ResourceDownloaderBaseImpl)_parent;
		
		if( old_parent != null ){
			
			old_parent.removeChild( this );
		}
		
		if ( parent != null ){
			
			parent.addChild( this );
		}
	
protected voidsetProperties(org.gudy.azureus2.pluginsimpl.local.utils.resourcedownloader.ResourceDownloaderBaseImpl other)

		Map p = other.properties;
		
		Iterator it = p.keySet().iterator();
		
		while( it.hasNext()){
			
			String	key = (String)it.next();
			
			setProperty( key, p.get(key));
		}
	
protected abstract voidsetProperty(java.lang.String name, java.lang.Object value)

protected voidsetPropertySupport(java.lang.String name, java.lang.Object value)

		properties.put( name, value );
	
protected abstract voidsetSize(long size)