FileDocCategorySizeDatePackage
UPnPServiceImpl.javaAPI DocAzureus 3.0.3.46017Tue Sep 25 13:45:14 BST 2007com.aelitis.net.upnp.impl.services

UPnPServiceImpl

public class UPnPServiceImpl extends Object implements UPnPService
author
parg

Fields Summary
protected com.aelitis.net.upnp.impl.device.UPnPDeviceImpl
device
protected String
service_type
protected String
local_desc_url
protected String
local_control_url
protected List
actions
protected List
state_vars
protected boolean
direct_invoke
Constructors Summary
public UPnPServiceImpl(com.aelitis.net.upnp.impl.device.UPnPDeviceImpl _device, String indent, org.gudy.azureus2.plugins.utils.xml.simpleparser.SimpleXMLParserDocumentNode service_node)

		device		= _device;
		
		service_type 		= service_node.getChild("ServiceType").getValue().trim();
		
		local_desc_url		= service_node.getChild("SCPDURL").getValue();
		
		local_control_url	= service_node.getChild("controlURL").getValue();
		
		device.getUPnP().log( indent + service_type + ":desc=" + device.getAbsoluteURL(local_desc_url) + ", control=" + device.getAbsoluteURL(local_control_url));
	
Methods Summary
public UPnPActiongetAction(java.lang.String name)

		UPnPAction[]	my_actions = getActions();
		
		for (int i=0;i<my_actions.length;i++){
			
			if ( my_actions[i].getName().equalsIgnoreCase( name )){
				
				return( my_actions[i] );
			}
		}
		
		return( null );
	
public UPnPAction[]getActions()

		if ( actions == null ){
			
			loadDescription();
		}
		
		UPnPAction[]	res = new UPnPAction[actions.size()];
		
		actions.toArray( res );
		
		return( res );
	
public java.net.URLgetControlURL()

		return( getURL( device.getAbsoluteURL( local_control_url )));
	
public java.net.URLgetDescriptionURL()

		return( getURL( device.getAbsoluteURL( local_desc_url )));
	
public UPnPDevicegetDevice()

		return( device );
	
public booleangetDirectInvocations()

		return( direct_invoke );
	
public java.lang.StringgetServiceType()

		return( service_type );
	
public com.aelitis.net.upnp.services.UPnPSpecificServicegetSpecificService()

		if ( service_type.equalsIgnoreCase("urn:schemas-upnp-org:service:WANIPConnection:1")){
			
			return( new UPnPSSWANIPConnectionImpl( this ));
			
		}else if ( service_type.equalsIgnoreCase("urn:schemas-upnp-org:service:WANPPPConnection:1")){
			
			return( new UPnPSSWANPPPConnectionImpl( this ));
			
		}else if ( service_type.equalsIgnoreCase("urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1")){
			
			return( new UPnPSSWANCommonInterfaceConfigImpl( this ));
			
		}else{
			
			return( null );
		}
	
public UPnPStateVariablegetStateVariable(java.lang.String name)

		UPnPStateVariable[]	vars = getStateVariables();
		
		for (int i=0;i<vars.length;i++){
			
			if ( vars[i].getName().equalsIgnoreCase( name )){
				
				return( vars[i] );
			}
		}
		
		return( null );
	
public UPnPStateVariable[]getStateVariables()

		if ( state_vars == null ){
			
			loadDescription();
		}
		
		UPnPStateVariable[]	res = new UPnPStateVariable[state_vars.size()];
		
		state_vars.toArray( res );
		
		return( res );		
	
protected java.net.URLgetURL(java.lang.String basis)

		try{
			URL	target;
			
			String	lc_basis = basis.toLowerCase();
			
			if ( lc_basis.startsWith( "http" ) || lc_basis.startsWith( "https" )){
				
					// absolute
				
				target = new URL( basis );
				
			}else{
				
					// relative
				
				URL	root_location = device.getRootDevice().getLocation();
				
				target = new URL( root_location.getProtocol() + "://" +
									root_location.getHost() + 
									(root_location.getPort() == -1?"":":" + root_location.getPort()) + 
									(basis.startsWith( "/" )?"":"/") + basis );
				
			}
			
			return( target );
			
		}catch( MalformedURLException e ){
			
			throw( new UPnPException( "Malformed URL", e ));
		}
	
protected voidloadDescription()

		
		SimpleXMLParserDocument	doc = device.getUPnP().downloadXML( device, getDescriptionURL());

		parseActions( doc.getChild( "ActionList" ));
				
		parseStateVars( doc.getChild( "ServiceStateTable"));
	
protected voidparseActions(org.gudy.azureus2.plugins.utils.xml.simpleparser.SimpleXMLParserDocumentNode action_list)

		actions	= new ArrayList();
		
		SimpleXMLParserDocumentNode[]	kids = action_list.getChildren();
		
		for (int i=0;i<kids.length;i++){
			
			actions.add( new UPnPActionImpl( this, kids[i] ));
		}
	
protected voidparseStateVars(org.gudy.azureus2.plugins.utils.xml.simpleparser.SimpleXMLParserDocumentNode action_list)

		state_vars	= new ArrayList();
		
		SimpleXMLParserDocumentNode[]	kids = action_list.getChildren();
		
		for (int i=0;i<kids.length;i++){
			
			state_vars.add( new UPnPStateVariableImpl( this, kids[i] ));
		}
	
public voidsetDirectInvocations(boolean force)

		direct_invoke	= force;