felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From furf...@apache.org
Subject svn commit: r391447 [3/3] - in /incubator/felix/trunk/org.apache.felix.upnp.basedriver: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/felix/ src/main/java/org/apache/felix/upnp/ src/main/java/org...
Date Tue, 04 Apr 2006 23:33:44 GMT
Added: incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/upnp/UPnPActionImpl.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/upnp/UPnPActionImpl.java?rev=391447&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/upnp/UPnPActionImpl.java (added)
+++ incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/upnp/UPnPActionImpl.java Tue Apr  4 16:33:40 2006
@@ -0,0 +1,188 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.felix.upnp.basedriver.importer.core.upnp;
+
+
+import java.util.Dictionary;
+import java.util.Properties;
+
+import org.cybergarage.upnp.Action;
+import org.cybergarage.upnp.Argument;
+import org.cybergarage.upnp.ArgumentList;
+import org.cybergarage.upnp.UPnPStatus;
+
+import org.osgi.service.upnp.UPnPAction;
+import org.osgi.service.upnp.UPnPStateVariable;
+
+import org.apache.felix.upnp.extra.util.Converter;
+import org.apache.felix.upnp.extra.util.UPnPException;
+
+/**
+ * @author Matteo "matted" Demuru
+ * @author Stefanoi "kismet-sl" Lenzi
+ * 
+ */
+public class UPnPActionImpl implements UPnPAction {
+
+	private Action act;	
+	private UPnPServiceImpl actsFather;
+	/**
+	 * @param act
+	 */
+	public UPnPActionImpl(Action act,UPnPServiceImpl ser) {
+		// TODO to check
+		this.act=act;
+		actsFather=ser;	
+	}
+
+	/* (non-Javadoc)
+	 * @see org.osgi.service.upnp.UPnPAction#getName()
+	 */
+	public String getName() {
+		// TODO to check
+		return act.getName();
+	}
+
+	/* (non-Javadoc)
+	 * @see org.osgi.service.upnp.UPnPAction#getReturnArgumentName()
+	 */
+	public String getReturnArgumentName() {
+	/*	 TODO da discutere .. perche' mi dovrei riparsare l'xml 
+		 */
+		
+		return null;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.osgi.service.upnp.UPnPAction#getInputArgumentNames()
+	 */
+	public String[] getInputArgumentNames() {
+		// TODO to check
+		ArgumentList argsList=act.getInputArgumentList();
+		if(argsList.size()==0){
+			return null;
+		}
+		String [] inputArgs=new String[argsList.size()]; 
+		for(int i=0;i<argsList.size();i++){
+			inputArgs[i]=argsList.getArgument(i).getName();
+		}
+		return inputArgs;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.osgi.service.upnp.UPnPAction#getOutputArgumentNames()
+	 */
+	public String[] getOutputArgumentNames() {
+		// TODO to check
+		ArgumentList argsList=act.getOutputArgumentList();
+		if(argsList.size()==0){
+			return null;
+		}
+		String [] outArgs=new String[argsList.size()]; 
+		for(int i=0;i<argsList.size();i++){
+			outArgs[i]=argsList.getArgument(i).getName();
+		}
+		return outArgs;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.osgi.service.upnp.UPnPAction#getStateVariable(java.lang.String)
+	 */
+	public UPnPStateVariable getStateVariable(String argumentName) {
+		/*TODO  controllare se non e' 
+		troppo brutto il modo di ottenere 
+		la UPnPStateVariable
+		
+		check if the way to obtain the UPnPStateVariabile is not too bad
+		
+		*/
+		Argument arg=act.getArgument(argumentName);
+		if(arg==null){
+			return null;
+		}
+		String varName=arg.getRelatedStateVariableName();
+		return actsFather.getStateVariable(varName);
+	}
+
+	/* (non-Javadoc)
+	 * @see org.osgi.service.upnp.UPnPAction#invoke(java.util.Dictionary)
+	 */
+	public Dictionary invoke(Dictionary args) throws Exception {
+		/*TODO da controllare se ho capito bene quello che 
+		richiedeva il metodo
+		
+		check if I have understood wath this method should do
+		*/
+		/*
+		 * mi ricavo gli argomenti e i valori
+		 * e gli inserisco in un ArgumentList
+		 * 
+		 * I look for argument and value and then I add them to ArgumentList
+		 */
+		ArgumentList argsList=new ArgumentList();
+		argsList= act.getInputArgumentList();
+	
+		for(int i=0;i<argsList.size();i++){
+			/*
+			TODO assumo che .getArgument(i) mi dia un Argument con solo il nome e non il valore 
+			che sara' cio che ci mettero' io 
+			e assumo anche che siano ordinati
+			
+			 * I assert that .getArgument(i) will return to me an Argument with only the name of the
+			 * Argument and not it's value. I'll set the associated value by myself and
+			 * Also I assert that the Argument are ordered
+			 */
+			Argument argument=argsList.getArgument(i);
+			String argumentName=argument.getName();
+			//String relateVar=argument.getRelatedStateVariableName();
+			UPnPStateVariable stateVar=this.getStateVariable(argumentName);
+			String upnpType=stateVar.getUPnPDataType();
+			/*Class javaClass=stateVar.getJavaDataType();*/
+			//setto il valore dell'argomento di input
+			//setting the value related to the input argument
+			argument.setValue(Converter.toString(args.get(argumentName),upnpType));
+		}
+		act.setArgumentValues(argsList);
+		if(act.postControlAction()==true){
+			//TODO controllare cosa succede se non ho argomenti di out 
+			//TODO check what happen if I don't have any output argument
+			Properties outDic=new Properties();
+			ArgumentList outArgs=act.getOutputArgumentList();
+			if(outArgs.size()==0){
+				return null;
+			}
+			for(int i=0;i<outArgs.size();i++){
+				Argument argument=outArgs.getArgument(i);
+				String argumentName=outArgs.getArgument(i).getName();
+				//String relateVar=argument.getRelatedStateVariableName();
+				UPnPStateVariable stateVar=getStateVariable(argumentName);
+				//String javaType=stateVar.getJavaDataType().getName(); 
+				//TODO ricordarsi di catchare nunber exception
+				//TODO rember to catch number exception
+				String upnpType=stateVar.getUPnPDataType();
+				outDic.put(argumentName,Converter.parseString(argument.getValue(),upnpType));
+			}
+			return outDic;
+		}else{
+            UPnPStatus controlStatus = act.getControlStatus();
+            throw new UPnPException(controlStatus.getCode(),controlStatus.getDescription());
+		}
+
+	}
+
+}

Added: incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/upnp/UPnPDeviceImpl.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/upnp/UPnPDeviceImpl.java?rev=391447&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/upnp/UPnPDeviceImpl.java (added)
+++ incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/upnp/UPnPDeviceImpl.java Tue Apr  4 16:33:40 2006
@@ -0,0 +1,146 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.felix.upnp.basedriver.importer.core.upnp;
+
+
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import org.cybergarage.upnp.Device;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.service.upnp.UPnPDevice;
+import org.osgi.service.upnp.UPnPIcon;
+import org.osgi.service.upnp.UPnPService;
+
+import org.apache.felix.upnp.basedriver.importer.util.DeviceSetup;
+import org.apache.felix.upnp.basedriver.importer.util.DictionaryProp;
+
+/**
+ * @author Matteo "matted" Demuru
+ * @author Stefanoi "kismet-sl" Lenzi
+ * 
+ */
+public class UPnPDeviceImpl implements UPnPDevice {
+
+	/**
+	 * <code>properties</code> Dictionary that contains Device properties
+	 */
+	private DictionaryProp properties;
+	private Vector icons;
+	private Hashtable services;
+	/**
+	 * @param dev
+	 *            Device the cyberLink Device used to rappresent the real UPnP
+	 *            Device
+	 */
+	public UPnPDeviceImpl(Device dev, BundleContext context) {
+		properties = new DictionaryProp();
+		this.services=new Hashtable();
+		this.icons=new Vector();
+		DeviceSetup.deviceSetup(properties,dev,icons,services);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.osgi.service.upnp.UPnPDevice#getService(java.lang.String)
+	 */
+	public UPnPService getService(String serviceId) {
+		return (UPnPServiceImpl) services.get(serviceId);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.osgi.service.upnp.UPnPDevice#getServices()
+	 */
+	public UPnPService[] getServices() {
+		Enumeration e = services.elements();
+		if (e == null) {
+			//TODO restituisco null o un array vuoto null l'ho letto nella specifica
+			//TODO should I return null or an empty array? The specification seems to said to return null
+			return null;
+		}
+		UPnPService[] uPnPser = new UPnPService[services.size()];
+		int i = 0;
+		while (e.hasMoreElements()) {
+			uPnPser[i] = (UPnPServiceImpl) e.nextElement();
+			i++;
+		}
+		return uPnPser;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.osgi.service.upnp.UPnPDevice#getIcons(java.lang.String)
+	 */
+	public UPnPIcon[] getIcons(String locale) {
+		if (locale != null) {
+			return null;
+		}
+		if(icons.size()==0){
+			return null;
+		}
+		return (UPnPIcon[]) icons.toArray(new UPnPIcon[]{});
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.osgi.service.upnp.UPnPDevice#getDescriptions(java.lang.String)
+	 */
+
+	public Dictionary getDescriptions(String locale) {
+		//TODO Sent the right localized version of Description if are available
+		if (locale != null) {
+			return null;
+		}
+		return properties;
+	}
+
+	/**
+	 * @param serviceType
+	 * @return true if device contains the serviceType
+	 */
+	public boolean existServiceType(String serviceType) {
+		String[] services = (String[]) properties.get(UPnPService.TYPE);
+		if (services != null) {
+			for (int i = 0; i < services.length; i++) {
+				if (services[i].equals(serviceType)) {
+					return true;
+				}
+			}
+		}
+		return false;
+	}
+
+	/**
+	 * @param property
+	 * @param obj
+	 */
+	public void setProperty(String property, Object obj) {
+		properties.remove(property);
+		properties.put(property, obj);
+
+	}
+
+}
\ No newline at end of file

Added: incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/upnp/UPnPIconImpl.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/upnp/UPnPIconImpl.java?rev=391447&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/upnp/UPnPIconImpl.java (added)
+++ incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/upnp/UPnPIconImpl.java Tue Apr  4 16:33:40 2006
@@ -0,0 +1,111 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.felix.upnp.basedriver.importer.core.upnp;
+
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.cybergarage.upnp.Icon;
+
+import org.osgi.service.upnp.UPnPIcon;
+
+import org.apache.felix.upnp.basedriver.importer.util.HTTPRequestForIcon;
+import org.apache.felix.upnp.basedriver.importer.util.ParseLocation;
+
+/**
+ * @author Matteo "matted" Demuru
+ * @author Stefanoi "kismet-sl" Lenzi
+ * 
+ */
+public class UPnPIconImpl implements UPnPIcon {
+
+	/* (non-Javadoc)
+	 * @see org.osgi.service.upnp.UPnPIcon#getMimeType()
+	 */
+	private Icon icon;
+	private org.cybergarage.upnp.Device cyberdev;
+	public UPnPIconImpl(Icon cybericon,org.cybergarage.upnp.Device cyberdev){
+		this.icon=cybericon;
+		this.cyberdev=cyberdev;
+	}
+	public String getMimeType() {
+		// TODO to check
+		return icon.getMimeType();
+	}
+
+	/* (non-Javadoc)
+	 * @see org.osgi.service.upnp.UPnPIcon#getWidth()
+	 */
+	public int getWidth() {
+		// TODO se parso una stringa vuota che succede ? da eccezione?penso di si 
+		//TODO what happen if the String is empty? do I get an Exception? I think so
+		String width=icon.getWidth();
+		if(width.length()==0){
+			return -1;
+		}
+		return Integer.parseInt(width);
+	}
+
+	/* (non-Javadoc)
+	 * @see org.osgi.service.upnp.UPnPIcon#getHeight()
+	 */
+	public int getHeight() {
+		// TODO Auto-generated method stub
+		String higth=icon.getHeight();
+		if(higth.length()==0){
+			return -1;
+		}
+		return Integer.parseInt(higth);
+	}
+
+	/* (non-Javadoc)
+	 * @see org.osgi.service.upnp.UPnPIcon#getSize()
+	 */
+	public int getSize() {
+		// TODO Auto-generated method stub
+		return -1;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.osgi.service.upnp.UPnPIcon#getDepth()
+	 */
+	public int getDepth() {
+		// TODO Auto-generated method stub
+		String depth=icon.getDepth();
+		if(depth.length()==0){
+			return -1;
+		}
+		return Integer.parseInt(depth);
+	}
+
+	/* (non-Javadoc)
+	 * @see org.osgi.service.upnp.UPnPIcon#getInputStream()
+	 */
+	public InputStream getInputStream() throws IOException {
+		// TODO Auto-generated method stub
+		
+		String urlString=ParseLocation.getUrlBase(cyberdev.getLocation())+icon.getURL();
+		URL url=new URL(urlString);
+		HTTPRequestForIcon requestor=new HTTPRequestForIcon(url);
+		
+		return requestor.getInputStream();
+	}
+
+}

Added: incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/upnp/UPnPServiceImpl.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/upnp/UPnPServiceImpl.java?rev=391447&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/upnp/UPnPServiceImpl.java (added)
+++ incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/upnp/UPnPServiceImpl.java Tue Apr  4 16:33:40 2006
@@ -0,0 +1,164 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.felix.upnp.basedriver.importer.core.upnp;
+
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import org.cybergarage.upnp.Action;
+import org.cybergarage.upnp.ActionList;
+import org.cybergarage.upnp.Service;
+import org.cybergarage.upnp.ServiceStateTable;
+import org.cybergarage.upnp.StateVariable;
+
+import org.osgi.service.upnp.UPnPAction;
+import org.osgi.service.upnp.UPnPService;
+import org.osgi.service.upnp.UPnPStateVariable;
+
+/**
+ * @author Matteo "matted" Demuru
+ * @author Stefanoi "kismet-sl" Lenzi
+ * 
+ */
+public class UPnPServiceImpl implements UPnPService {
+	private Service service;
+	private Hashtable actions;
+	private Hashtable stateVariables;
+	
+	public UPnPServiceImpl(Service service) {
+		this.service = service;
+		actions = new Hashtable();
+		stateVariables=new Hashtable();
+		/*
+		 * azioni
+		 * action
+		 */
+		ActionList actionlist = service.getActionList();
+		for (int i = 0; i < actionlist.size(); i++) {
+			Action act = actionlist.getAction(i);
+			actions.put(act.getName(), new UPnPActionImpl(act,this));
+		}
+		/*StateVariable*/
+		ServiceStateTable stateTable=service.getServiceStateTable();
+		for(int i=0;i<stateTable.size();i++){
+			StateVariable var= stateTable.getStateVariable(i);
+			stateVariables.put(var.getName(),new UPnPStateVariableImpl(var));
+		}
+	
+	
+	} /*
+	   * (non-Javadoc)
+	   * 
+	   * @see org.osgi.service.upnp.UPnPService#getId()
+	   */
+	public String getId() {
+		// TODO Auto-generated method stub
+		return service.getServiceID();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.osgi.service.upnp.UPnPService#getType()
+	 */
+	public String getType() {
+		// TODO Auto-generated method stub
+		return service.getServiceType();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.osgi.service.upnp.UPnPService#getVersion()
+	 */
+	public String getVersion() {
+		// TODO da  controllare si puo' migliorare lastindexof
+		//TODO to check can I speed up this? May be using lastIndexOf
+		String [] splited=service.getServiceType().split(":"); 
+		return splited[splited.length-1];
+	} 
+	/*
+	   * (non-Javadoc)
+	   * 
+	   * @see org.osgi.service.upnp.UPnPService#getAction(java.lang.String)
+	   */
+	public UPnPAction getAction(String name) {
+		// TODO da controllare
+		//TODO to check
+		return (UPnPAction) actions.get(name);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.osgi.service.upnp.UPnPService#getActions()
+	 */
+	public UPnPAction[] getActions() {
+		// TODO ricontrollare
+		//TODO check again
+		Enumeration e=actions.elements();
+		if(e==null){
+			return null;
+		}
+		UPnPAction [] uPnPacts=new UPnPAction[actions.size()];
+		int i=0;
+		while(e.hasMoreElements()){
+			uPnPacts[i]=(UPnPActionImpl)e.nextElement();
+			i++;
+		}
+		return uPnPacts;
+	}
+	
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.osgi.service.upnp.UPnPService#getStateVariables()
+	 */
+	public UPnPStateVariable[] getStateVariables() {
+		// TODO ricontrollare
+		//TODO check again
+		UPnPStateVariableImpl [] vars =new UPnPStateVariableImpl[stateVariables.size()];
+		Enumeration e=stateVariables.elements();
+		if(e==null){
+			return null;
+		}
+		int i=0;
+		while(e.hasMoreElements()){
+			vars[i]=(UPnPStateVariableImpl)e.nextElement();
+			i++;
+		}
+		return vars;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.osgi.service.upnp.UPnPService#getStateVariable(java.lang.String)
+	 */
+	public UPnPStateVariable getStateVariable(String name) {
+		// TODO ricontrollare	
+		//TODO chack again
+		return (UPnPStateVariableImpl) stateVariables.get(name);
+	}
+
+	public Service getCyberService(){
+		return service;
+	}
+
+}
\ No newline at end of file

Added: incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/upnp/UPnPStateVariableImpl.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/upnp/UPnPStateVariableImpl.java?rev=391447&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/upnp/UPnPStateVariableImpl.java (added)
+++ incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/upnp/UPnPStateVariableImpl.java Tue Apr  4 16:33:40 2006
@@ -0,0 +1,242 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.felix.upnp.basedriver.importer.core.upnp;
+
+
+import java.util.Date;
+import java.util.Hashtable;
+
+import org.cybergarage.upnp.AllowedValueList;
+import org.cybergarage.upnp.AllowedValueRange;
+import org.cybergarage.upnp.StateVariable;
+
+import org.osgi.service.upnp.UPnPStateVariable;
+
+import org.apache.felix.upnp.extra.util.Converter;
+
+/**
+ * @author Matteo "matted" Demuru
+ * @author Stefanoi "kismet-sl" Lenzi
+ * 
+ */
+public class UPnPStateVariableImpl implements UPnPStateVariable {
+
+	private StateVariable variable;
+	private static Hashtable upnp2javaTable = null;
+	
+	static{
+		upnp2javaTable = new Hashtable(30);
+		String[] upnpType = null;
+		upnpType = new String[]{"ui1","ui2","i1","i2","i4","int"};
+		for (int i = 0; i < upnpType.length; i++) {
+			upnp2javaTable.put(upnpType[i],Integer.class);
+		}
+
+		upnpType = new String[]{"ui4","time","time.tz"};
+		for (int i = 0; i < upnpType.length; i++) {
+			upnp2javaTable.put(upnpType[i],Long.class);
+		}		
+
+		upnpType = new String[]{"r4","float"};
+		for (int i = 0; i < upnpType.length; i++) {
+			upnp2javaTable.put(upnpType[i],Float.class);
+		}		
+
+		upnpType = new String[]{"r8","number","fixed.14.4"};
+		for (int i = 0; i < upnpType.length; i++) {
+			upnp2javaTable.put(upnpType[i],Double.class);
+		}		
+
+		upnpType = new String[]{"char"};
+		for (int i = 0; i < upnpType.length; i++) {
+			upnp2javaTable.put(upnpType[i],Character.class);
+		}		
+
+		upnpType = new String[]{"string","uri","uuid"};
+		for (int i = 0; i < upnpType.length; i++) {
+			upnp2javaTable.put(upnpType[i],String.class);
+		}		
+
+		upnpType = new String[]{"date","dateTime","dateTime.tz"};
+		for (int i = 0; i < upnpType.length; i++) {
+			upnp2javaTable.put(upnpType[i],Date.class);
+		}		
+
+		upnpType = new String[]{"boolean"};
+		for (int i = 0; i < upnpType.length; i++) {
+			upnp2javaTable.put(upnpType[i],Boolean.class);
+		}		
+
+		upnpType = new String[]{"bin.base64","bin.hex"};
+		for (int i = 0; i < upnpType.length; i++) {
+			upnp2javaTable.put(upnpType[i],byte[].class);
+		}		
+		
+		
+	}
+	
+	/**
+	 * @param variable
+	 */
+	public UPnPStateVariableImpl(StateVariable variable) {
+
+		this.variable = variable;
+	} /*
+	   * (non-Javadoc)
+	   * 
+	   * @see org.osgi.service.upnp.UPnPStateVariable#getName()
+	   */
+
+	public String getName() {
+		return variable.getName();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.osgi.service.upnp.UPnPStateVariable#getJavaDataType()
+	 */
+	public Class getJavaDataType() {
+		return (Class) upnp2javaTable.get(variable.getDataType());
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.osgi.service.upnp.UPnPStateVariable#getUPnPDataType()
+	 */
+	public String getUPnPDataType() {
+		return variable.getDataType();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.osgi.service.upnp.UPnPStateVariable#getDefaultValue()
+	 */
+	public Object getDefaultValue() {
+		//TODO da implementare da zero.. e' raccommended ..
+		//TODO must be implemented from scretch, it's just raccommend
+		return null;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.osgi.service.upnp.UPnPStateVariable#getAllowedValues()
+	 */
+	public String[] getAllowedValues() {
+		if (variable.getDataType().equals("string")) {
+			AllowedValueList allowedvalue = variable.getAllowedValueList();
+            if (allowedvalue == null) return null;
+			if(allowedvalue.size()==0){
+				return null;
+			} 
+			String[] values = new String[allowedvalue.size()];
+			for (int i = 0; i < allowedvalue.size(); i++) {
+				values[i] = allowedvalue.getAllowedValue(i).getValue();
+			}
+			return values;
+		}
+
+		return null;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.osgi.service.upnp.UPnPStateVariable#getMinimum()
+	 */
+	public Number getMinimum() {
+		// TODO stessa cosa get maximum
+		//TODO the same thing for getMaximum
+		AllowedValueRange allowedValueRange = variable.getAllowedValueRange();
+		if(allowedValueRange==null){
+			return null;
+		}
+		String min=allowedValueRange.getMinimum();
+        //francesco 22/10/2005
+        if (min.equals("")) return null;
+		try {
+			return (Number)Converter.parseString(min,getUPnPDataType());
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			return null;
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.osgi.service.upnp.UPnPStateVariable#getMaximum()
+	 */
+	public Number getMaximum() {
+		// TODO suppongo che le invochino con cognizione di causa ??
+		//TODO I think that this method will be invoked from people that know what is doing
+		AllowedValueRange allowedValueRange = variable.getAllowedValueRange();
+		if(allowedValueRange==null){
+			return null;
+		}
+		String max = allowedValueRange.getMaximum();
+        //francesco 22/10/2005
+        if (max.equals("")) return null;
+		try {
+			return (Number)Converter.parseString(max,getUPnPDataType());
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			return null;
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.osgi.service.upnp.UPnPStateVariable#getStep()
+	 */
+	public Number getStep() {
+		// TODO stssa cosa di getmaximum
+		//TODO same things of getMaxium
+		AllowedValueRange allowedValueRange = variable.getAllowedValueRange();
+		if(allowedValueRange==null){
+			return null;
+		}
+		String step = allowedValueRange.getStep();
+        //francesco 22/10/2005
+        if (step.equals("")) return null;
+		try {
+			return (Number)Converter.parseString(step,getUPnPDataType());
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			return null;
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.osgi.service.upnp.UPnPStateVariable#sendsEvents()
+	 */
+	public boolean sendsEvents() {
+		return variable.isSendEvents();
+	}
+
+
+}

Added: incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/util/DeviceSetup.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/util/DeviceSetup.java?rev=391447&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/util/DeviceSetup.java (added)
+++ incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/util/DeviceSetup.java Tue Apr  4 16:33:40 2006
@@ -0,0 +1,146 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.felix.upnp.basedriver.importer.util;
+
+
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Vector;
+
+import org.cybergarage.upnp.Device;
+import org.cybergarage.upnp.DeviceList;
+import org.cybergarage.upnp.IconList;
+import org.cybergarage.upnp.Service;
+import org.cybergarage.upnp.ServiceList;
+
+import org.osgi.service.upnp.UPnPDevice;
+import org.osgi.service.upnp.UPnPIcon;
+import org.osgi.service.upnp.UPnPService;
+
+import org.apache.felix.upnp.basedriver.importer.core.upnp.UPnPIconImpl;
+import org.apache.felix.upnp.basedriver.importer.core.upnp.UPnPServiceImpl;
+import org.apache.felix.upnp.extra.util.Constants;
+
+/**
+ * @author Matteo "matted" Demuru 
+ * @author Stefano "Kismet" Lenzi
+ *  
+ */
+public class DeviceSetup {
+
+	public static void deviceSetup(DictionaryProp properties, Device dev,Vector icons,Hashtable services) {
+		//TODO se non ho device ho una devlist con zero elementi
+		//TODO if I don't have any device, the size of devlist is 0 
+		DeviceList devList = dev.getDeviceList();
+		/* childrenUDN property */
+		if (devList.size() > 0) {
+			String[] childrenUDN = new String[devList.size()];
+			for (int i = 0; i < devList.size(); i++) {
+				childrenUDN[i] = devList.getDevice(i).getUDN();
+			}
+			properties.put(UPnPDevice.CHILDREN_UDN, childrenUDN);
+		}
+		/* DEVICE CATEGORY */
+		properties.put(
+		        org.osgi.service
+		        	.device.Constants.DEVICE_CATEGORY,
+	        	new String[]{UPnPDevice.DEVICE_CATEGORY}
+	        );
+
+		/*UPNP_IMPORT*/
+		properties.put(Constants.UPNP_IMPORT, "http://domoware.isti.cnr.it");
+		
+		/* FRIENDLY_NAME */
+		//TODO controllato in metodo getFriendlyName se non esiste il frinedly mi restituisce una stringa vuota
+		//check the implementation fo getFriendlyName made by CyberLink
+		properties.put(UPnPDevice.FRIENDLY_NAME, dev.getFriendlyName());
+		/* MANUFACTURER */
+		properties.put(UPnPDevice.MANUFACTURER, dev.getManufacture());
+		/* MANUFACTURER_URL */
+		properties.put(UPnPDevice.MANUFACTURER_URL, dev.getManufactureURL());
+		/* MODEL_DESCRIPTION */
+		properties.put(UPnPDevice.MODEL_DESCRIPTION, dev.getModelDescription());
+		/* MODEL_NAME */
+		properties.put(UPnPDevice.MODEL_NAME, dev.getModelName());
+		/* MODEL_NUMBER */
+		properties.put(UPnPDevice.MODEL_NUMBER, dev.getModelNumber());
+		/* MODEL_URL */
+		properties.put(UPnPDevice.MODEL_URL, dev.getModelURL());
+		/* PARENT_UDN */
+		if (!dev.isRootDevice()) {
+			Device parent = dev.getParentDevice();
+			/*Device root = dev.getRootDevice();
+			if (root == null) {
+				System.out.println("il device " + dev.getFriendlyName()
+						+ "non ha root !!!");
+			}*/
+			properties.put(UPnPDevice.PARENT_UDN, parent.getUDN());
+		}
+		/* PRESENTATION_URL */
+		properties.put(UPnPDevice.PRESENTATION_URL, dev.getPresentationURL());
+		/* SERIAL_NUMBER */
+		properties.put(UPnPDevice.SERIAL_NUMBER, dev.getSerialNumber());
+		/* TYPE */
+		properties.put(UPnPDevice.TYPE, dev.getDeviceType());
+		/* UDN */
+		properties.put(UPnPDevice.UDN, dev.getUDN());
+		/* UPC */
+		properties.put(UPnPDevice.UPC, dev.getUPC());
+
+		IconList iconsList = dev.getIconList();
+		if (iconsList.size() != 0) {
+			for (int i = 0; i < iconsList.size(); i++) {
+				UPnPIcon icon = new UPnPIconImpl(iconsList.getIcon(i),dev);
+				icons.add(icon);
+			}
+		}
+		/* 
+		 * servizi del device
+		 * service of this device
+		 */ 
+		ServiceList serviceList = dev.getServiceList();//ok mi restituisce una
+													   // service list con zero
+													   // elementi
+		/*
+		 * if dev contain no service I'll get an empty SserviceList object
+		 */
+		String[] servicesIDProperty = new String[serviceList.size()];
+		String[] servicesTypeProperty;
+		HashSet serTypeSet = new HashSet();
+		for (int i = 0; i < serviceList.size(); i++) {
+			Service service = serviceList.getService(i);
+			UPnPServiceImpl serviceImpl = new UPnPServiceImpl(service);
+			services.put(service.getServiceID(), serviceImpl);
+			servicesIDProperty[i] = serviceImpl.getId();
+			serTypeSet.add(serviceImpl.getType());
+		}
+		servicesTypeProperty = new String[serTypeSet.size()];
+		Iterator iter = serTypeSet.iterator();
+		int i = 0;
+		while (iter.hasNext()) {
+			servicesTypeProperty[i] = (String) iter.next();
+			i++;
+		}
+		properties.put(UPnPService.ID, servicesIDProperty);
+		properties.put(UPnPService.TYPE, servicesTypeProperty);
+
+	
+	}
+
+}
\ No newline at end of file

Added: incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/util/DictionaryProp.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/util/DictionaryProp.java?rev=391447&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/util/DictionaryProp.java (added)
+++ incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/util/DictionaryProp.java Tue Apr  4 16:33:40 2006
@@ -0,0 +1,123 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.felix.upnp.basedriver.importer.util;
+
+import java.util.*;
+
+/**
+ * @author Matteo "matted" Demuru
+ *
+ */
+public class DictionaryProp extends Dictionary {
+	private Hashtable hash=null;
+	/* (non-Javadoc)
+	 * @see java.util.Dictionary#size()
+	 */
+
+	public DictionaryProp(){
+		hash=new Hashtable();
+	}
+	
+	public int size() {
+		// TODO Auto-generated method stub
+		return hash.size();
+	}
+
+	/* (non-Javadoc)
+	 * @see java.util.Dictionary#isEmpty()
+	 */
+	public boolean isEmpty() {
+		// TODO Auto-generated method stub
+		return hash.isEmpty();
+	}
+
+	/* (non-Javadoc)
+	 * @see java.util.Dictionary#elements()
+	 */
+	public Enumeration elements() {
+		// TODO Auto-generated method stub
+		return hash.elements();
+	}
+
+	/* (non-Javadoc)
+	 * @see java.util.Dictionary#keys()
+	 */
+	public Enumeration keys() {
+		// TODO Auto-generated method stub
+		return hash.keys();
+	}
+
+	/* (non-Javadoc)
+	 * @see java.util.Dictionary#get(java.lang.Object)
+	 */
+	public Object get(Object key) {
+		// TODO Auto-generated method stub
+		String s=((String)key).toLowerCase();
+		return hash.get(s);
+	}
+
+	/* (non-Javadoc)
+	 * @see java.util.Dictionary#remove(java.lang.Object)
+	 */
+	public Object remove(Object arg0) {
+		// TODO Auto-generated method stub
+		String s=((String)arg0).toLowerCase();
+		return hash.remove(s);
+	}
+
+	/* (non-Javadoc)
+	 * @see java.util.Dictionary#put(java.lang.Object, java.lang.Object)
+	 */
+	public Object put(Object arg0, Object arg1) {
+		// TODO Auto-generated method stub
+		String s=((String)arg0).toLowerCase();
+		return hash.put(s,arg1);
+	}
+
+	/**
+	 * @param key
+	 * @return
+	 */
+	public boolean containsKey(Object key) {
+		//String s=((String)key).toLowerCase();
+		return hash.containsKey(key);
+	}
+
+	public String toString() {
+		StringBuffer sb = new StringBuffer("");
+		Enumeration e = keys();
+		while (e.hasMoreElements()) {
+			String key = (String) e.nextElement();
+			sb.append(key).append(" = ");
+			if(get(key) instanceof String[]){
+				String[] aux = (String[]) get(key);
+				sb.append("[");
+				for (int i = 0; i < aux.length-1; i++) {
+					sb.append(aux[i]).append(",");
+				}
+				if(aux.length>0)
+					sb.append(aux[aux.length-1]);
+				sb.append("]");
+			}else{
+				sb.append(get(key).toString());
+			}
+			sb.append("\n");
+		}
+		return sb.toString();
+	}
+}

Added: incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/util/HTTPRequestForIcon.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/util/HTTPRequestForIcon.java?rev=391447&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/util/HTTPRequestForIcon.java (added)
+++ incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/util/HTTPRequestForIcon.java Tue Apr  4 16:33:40 2006
@@ -0,0 +1,98 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.felix.upnp.basedriver.importer.util;
+
+import java.io.*;
+import java.net.*;
+
+/**
+ * @author Matteo "matted" Demuru
+ * @author Stefanoi "kismet-sl" Lenzi
+ *
+ * 
+ * TODO To change the template for this generated type comment go to Window -
+ * Preferences - Java - Code Style - Code Templates
+ */
+public class HTTPRequestForIcon {
+	private URL url;
+
+	public HTTPRequestForIcon(URL url) {
+		this.url = url;
+	}
+	public InputStream getInputStream() throws IOException {
+		//TODO da discutere
+		//TODO we should speak about that
+		InetAddress inet = InetAddress.getByName(url.getHost());
+		int port = url.getPort();
+		Socket socket = null;
+		socket = new Socket(inet, port);
+		OutputStream out = null;
+		out = socket.getOutputStream();
+		String CRLF = "\r\n";
+		url.getFile();
+		String request = "GET " + url.getPath() + " " + "HTTP/1.1" + CRLF
+				+ "Host: " + url.getHost() + CRLF + "Connection: " + "close"
+				+ CRLF + CRLF;
+		//System.out.println(request);
+		byte[] get = request.getBytes();
+		out.write(get, 0, get.length);
+		InputStream in = socket.getInputStream();
+		boolean exit = true;
+		while (exit) {
+			byte[] b = new byte[1];
+			in.read(b, 0, b.length);
+
+			if (b[0] == '\r') {
+				in.read(b, 0, b.length);
+				while (b[0] == '\r') {
+					in.read(b, 0, b.length);
+				}
+				if (b[0] != '\n') {
+					continue;
+				}
+				in.read(b, 0, b.length);
+				if (b[0] != '\r') {
+					continue;
+				}
+				in.read(b, 0, b.length);
+				if (b[0] != '\n') {
+					continue;
+				}
+				exit = false;
+			}
+		}
+
+		return in;
+
+		/*
+		 * utilizzando la classe di satoshi HTTPResponse response=new
+		 * HTTPResponse(in); InputStream
+		 * iconInStream=response.getContentInputStream(); return iconInStream;
+		 * 
+		 */
+		/*
+		 * 
+		 * byte[] buff = new byte[maxLength]; int initial = 0; while (initial <
+		 * maxLength - 1) { int read = 0; read = in.read(buff, initial, 1024);
+		 * if (read == -1) break; initial += read; } System.out.println(new
+		 * String(buff));
+		 */
+
+	}
+
+}
\ No newline at end of file

Added: incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/util/ParseLocation.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/util/ParseLocation.java?rev=391447&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/util/ParseLocation.java (added)
+++ incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/util/ParseLocation.java Tue Apr  4 16:33:40 2006
@@ -0,0 +1,30 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.felix.upnp.basedriver.importer.util;
+
+/**
+ * @author Matteo "matted" Demuru
+ *
+ */
+public class ParseLocation {
+	public static String getUrlBase(String location){
+		//http://148.12.14.144:65888/
+		String [] splited=location.split("/");
+		return splited[0]+"/"+"/"+splited[2];
+	}
+}

Added: incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/util/ParseUSN.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/util/ParseUSN.java?rev=391447&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/util/ParseUSN.java (added)
+++ incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/util/ParseUSN.java Tue Apr  4 16:33:40 2006
@@ -0,0 +1,62 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.felix.upnp.basedriver.importer.util;
+
+/**
+ * @author Matteo "matted" Demuru
+ *
+ */
+public class ParseUSN {
+	boolean service;
+	boolean device;
+	String udn;
+	String serviceType;
+	
+	public ParseUSN(String usn) {
+		String [] splited=usn.split(":"); 	
+		if(splited.length==5||splited.length==2){
+			udn="uuid:"+splited[1];
+			device=true;
+			service=false;
+		}else if(splited.length==8){
+			udn="uuid:"+splited[1];
+			if(splited[5].equals("device")){
+				device=true;
+				service=false;
+			}else{
+				serviceType=splited[3]+":"+splited[4]+":"+splited[5]+":"+splited[6]+":"+splited[7];
+				device=false;
+				service=true;
+			}
+		}
+	}	
+
+	public boolean isService() {
+		return service;
+	}
+	public boolean isDevice() {
+		return device;
+	}
+	public String getUDN() {
+		return udn;
+	}
+	public String getServiceType() {
+		return serviceType;
+	}
+	
+}
\ No newline at end of file

Added: incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/tool/Logger.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/tool/Logger.java?rev=391447&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/tool/Logger.java (added)
+++ incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/tool/Logger.java Tue Apr  4 16:33:40 2006
@@ -0,0 +1,255 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.felix.upnp.basedriver.tool;
+
+import java.io.PrintStream;
+
+import org.cybergarage.util.Debug;
+
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+
+import org.apache.felix.upnp.basedriver.Activator;
+
+/**
+ * @author Stefano "Kismet" Lenzi
+ * @author Francesco Furfari
+ *         
+ */
+public class Logger implements ServiceListener {
+	
+	private ServiceReference rls;
+	private LogService osgiLogService;
+    private int level;
+	private PrintStream out;
+	public  final static String NEWLINE = System.getProperty("line.separator");
+    public static final String ROW ="\n================REQUEST=====================\n";
+    public static final String END_ROW ="--------------------------------------------";
+    
+	private final static String LEVEL_TO_STRING[] = new String[]{
+		"",
+		"ERROR [ " + Activator.bc.getBundle().getBundleId() + " ] ",
+		"WARNING [ " + Activator.bc.getBundle().getBundleId() + " ] ",
+		"INFO [ " + Activator.bc.getBundle().getBundleId() + " ] ",
+		"DEBUG [ " + Activator.bc.getBundle().getBundleId() + " ] ",
+	};
+	
+	
+	/**
+	 * Create a Logger with <code>System.out</code> as <tt>PrintStream</tt> and without 
+	 * 		reporting message on both <tt>PrintStream</tt> and <tt>LogService</tt>
+	 * 
+	 * @param log <tt>ServiceReference</tt> to the <tt>LogService</tt> to use, 
+	 * 		or null to avoid the use of this service
+	 * 
+	 * @see #Logger(LogService, PrintStream, boolean)
+	 */
+	public Logger(String levelStr){
+	    this.out = System.out;
+		try {
+	        this.level = Integer.parseInt(levelStr);
+	    } catch (Exception ex){
+	    	out.println("WARNING [UPnPBaseDriver Log]: " + levelStr+" is not a valid value!");
+	    	this.level=2;
+	    }
+ 	    findService();
+	}
+
+    public void setCyberDebug(String value){
+        try {
+            if (Boolean.valueOf(value).booleanValue()){
+                Debug.on();
+                out.println("INFO [UPnPBaseDriver] Started CyberLink Debug");
+            }
+       } catch (Exception ex){
+            out.println("WARNING [UPnPBaseDriver CyberLog]: " + value +" is not a valid value!");
+        }
+    }
+    
+    ////////////////////////////////////////////////////////////////////////////////////
+    //////////////////////////// programmatic interface ////////////////////////////////
+    ////////////////////////////////////////////////////////////////////////////////////
+    
+    public void setLogLevel(int level){
+        if (level < 0 || level >4 ) throw new IllegalArgumentException("Log Level must be [0-4]");
+        this.level = level;
+    }
+    
+    public int getLogLevel(){
+        return this.level;
+    }
+    
+    
+    public void setCyberDebug(boolean value){
+        if (value) Debug.on();
+        else Debug.off();
+    }
+    
+    public boolean getCyberDebug(){
+        return Debug.isOn();
+    }
+    //////////////////////////// end programmatic interface ////////////////////////////
+   
+    
+	public final void ERROR(String message) {
+	    log(1,message);
+	}
+	
+	public final void WARNING(String message) {
+	    log(2,message);
+	}
+	
+	public final void INFO(String message) {
+	    log(3,message);
+	}
+	
+    public final void DEBUG(String message) {
+        log(4,message);
+    }
+    
+    public final void PACKET(String message) {
+        log(4, new StringBuffer(ROW).append(message).append(END_ROW).toString());
+    }
+
+    /**
+     * Logs a message.
+     *
+     * <p>The <tt>ServiceReference</tt> field and the <tt>Throwable</tt>
+     * field of the <tt>LogEntry</tt> object will be set to <tt>null</tt>.
+     * @param msglevel The severity of the message.
+     * This should be one of the defined log levels
+     * but may be any integer that is interpreted in a user defined way.
+     * @param message Human readable string describing the condition or <tt>null</tt>.
+     * @see #LOG_ERROR
+     * @see #LOG_WARNING
+     * @see #LOG_INFO
+     * @see #LOG_DEBUG
+     */
+	public void log(int msglevel, String message) {
+		synchronized (this) {
+            if (msglevel <= this.level){
+    			if (this.osgiLogService != null ){
+    				    osgiLogService.log(msglevel, message);
+    			}
+    			else {
+    				StringBuffer sb = new StringBuffer(Logger.LEVEL_TO_STRING[msglevel]);
+    			    this.out.println(sb.append(message));
+    			}
+            }
+		}
+		
+	}
+
+	 /**
+     * Logs a message with an exception.
+     *
+     * <p>The <tt>ServiceReference</tt> field of the <tt>LogEntry</tt> object will be set to <tt>null</tt>.
+     * @param msglevel The severity of the message.
+     * This should be one of the defined log levels
+     * but may be any integer that is interpreted in a user defined way.
+     * @param message The human readable string describing the condition or <tt>null</tt>.
+     * @param exception The exception that reflects the condition or <tt>null</tt>.
+     * @see #LOG_ERROR
+     * @see #LOG_WARNING
+     * @see #LOG_INFO
+     * @see #LOG_DEBUG
+     */
+	public void log(int msglevel, String message, Throwable exception) {
+		synchronized (this) {
+            if (msglevel <= this.level){ 
+    			if(this.osgiLogService != null){
+    				    osgiLogService.log(msglevel, message, exception);
+    			}
+    			else {
+    				StringBuffer sb = new StringBuffer(Logger.LEVEL_TO_STRING[msglevel]);
+    			    this.out.println(sb.append(message).append(NEWLINE).append(exception));
+    				exception.printStackTrace(this.out);
+    			}
+            }
+		}
+	}
+
+	private synchronized void setLogService(ServiceReference reference){
+		this.rls = reference;
+		this.osgiLogService = (LogService) Activator.bc.getService(rls);
+	}	
+	/**
+	 * This look for a <tt>LogService</tt> if it founds no <tt>LogService</tt> will register a new
+	 * Listener of LogService 
+	 *
+	 */
+	private synchronized void findService() {
+		//PRE:Actually no LogService are setted and we are registered as ServiceListener 
+		//		for LogService (unregisterin event)
+		this.rls = Activator.bc.getServiceReference(LogService.class.getName());
+		if (this.rls != null){
+			this.osgiLogService = (LogService) Activator.bc.getService(rls);
+		}
+		try {
+			Activator.bc.addServiceListener(this, 
+					"(" + Constants.OBJECTCLASS	+ "=" + LogService.class.getName() + ")"
+			);
+		} catch (InvalidSyntaxException ignore) {}				
+		//POST: We are connected to a LogService or we are registered as ServiceListener 
+		//		for LogService(registering event)
+	}
+	
+	private synchronized void releaseLogService() {
+        if( osgiLogService != null)
+            Activator.bc.ungetService(this.rls);
+		this.rls = null;
+		this.osgiLogService = null;
+	}
+	
+	/**
+	 * Used to keep track the existence of a <tt>LogService</tt>
+	 * 
+	 * @see ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
+	 */
+	public void serviceChanged(ServiceEvent e) {
+		switch (e.getType()) {
+			case ServiceEvent.REGISTERED: {
+			    // put here code check for serviceid
+				setLogService(e.getServiceReference());
+			}break;
+	
+			case ServiceEvent.MODIFIED: 
+			break;
+	
+			case ServiceEvent.UNREGISTERING: {				
+			    // put here code check for serviceid
+				releaseLogService();
+			}break;
+		}		
+	}
+
+	/**
+	 * Stop using the <tt>LogService</tt> and listening for those service event
+	 * 
+	 * NOTE: All the message will be reported to <tt>PrintStream</tt>
+	 *
+	 */
+	public void close(){	
+		Activator.bc.removeServiceListener(this);
+		releaseLogService();
+	}
+}

Added: incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/tool/Util.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/tool/Util.java?rev=391447&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/tool/Util.java (added)
+++ incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/java/org/apache/felix/upnp/basedriver/tool/Util.java Tue Apr  4 16:33:40 2006
@@ -0,0 +1,94 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.felix.upnp.basedriver.tool;
+
+import java.io.File;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.upnp.UPnPDevice;
+
+/**
+ * @author Stefano "Kismet" Lenzi 
+ * 
+ */
+public class Util {
+	
+	public static boolean isUPnPDevice(ServiceReference sr){
+		String[] aux = (String[]) sr.getProperty(Constants.OBJECTCLASS);
+		String val=UPnPDevice.class.getName();
+		int i;
+		for (i = 0; i < aux.length; i++) {
+			if(aux[i].equals(val)) break;
+		}
+		if(i==aux.length) return false;
+		aux = (String[]) sr.getProperty(org.osgi.service.device.Constants.DEVICE_CATEGORY);
+		val=UPnPDevice.DEVICE_CATEGORY;
+		for (i = 0; i < aux.length; i++) {
+			if(aux[i].equals(val)) 
+					return true;
+		}		
+		return false;
+	}
+	
+	public static final boolean isRootDevice(ServiceReference sr){
+		return (sr.getProperty(UPnPDevice.PARENT_UDN)==null)
+				&& isUPnPDevice(sr);
+	}
+	
+	public static final String getPropertyDefault(BundleContext bc, String propertyName, String defaultValue ){
+		String value = bc.getProperty(propertyName);
+		if(value == null)
+			return defaultValue;
+		return value;
+	}
+
+	public static String sanitizeFilename(String name){
+		return name.replaceAll("[:;\\,/*?<>\"|]","_");
+	}
+
+	public static boolean makeParentPath(String filePath){
+		int l=filePath.lastIndexOf(File.separator);
+		filePath=filePath.substring(0,l);
+		File p=new File(filePath);
+		if(p.exists())
+			return true;
+		return p.mkdirs();
+	}
+
+	/**
+	 * @param d
+	 */
+	public static boolean deleteRecursive(File d) {
+		if(!d.delete()){
+			if(d.isDirectory()){
+				File[] subs = d.listFiles();
+				for (int i = 0; i < subs.length; i++) {
+					if(!deleteRecursive(subs[i]))
+						return false;
+				}
+				return d.delete();
+			}else{
+				return false;
+			}			
+		}
+		return true;
+	}	
+	
+}

Added: incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/resources/META-INF/Manifest.mf
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/resources/META-INF/Manifest.mf?rev=391447&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/resources/META-INF/Manifest.mf (added)
+++ incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/resources/META-INF/Manifest.mf Tue Apr  4 16:33:40 2006
@@ -0,0 +1,6 @@
+Manifest-Version: 1.0
+Bundle-ClassPath: .,lib/cyberlink-1.7-patched-release.jar
+Bundle-Author: Matteo Demuru <matte-d@users.sourceforge.net>,Stefano "
+ Kismet" Lenzi <kismet-sl@users.sourceforge.net>,Francesco Furfari <fr
+ ancesco.furfari@isti.cnr.it>,Satoshi Konno
+

Added: incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/resources/lib/cyberlink-1.7-patched-debug.jar
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/resources/lib/cyberlink-1.7-patched-debug.jar?rev=391447&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/resources/lib/cyberlink-1.7-patched-debug.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/resources/lib/cyberlink-1.7-patched-release.jar
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/resources/lib/cyberlink-1.7-patched-release.jar?rev=391447&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/resources/lib/cyberlink-1.7-patched-release.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/resources/lib/install CyberLink.txt
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/resources/lib/install%20CyberLink.txt?rev=391447&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/resources/lib/install CyberLink.txt (added)
+++ incubator/felix/trunk/org.apache.felix.upnp.basedriver/src/main/resources/lib/install CyberLink.txt Tue Apr  4 16:33:40 2006
@@ -0,0 +1,2 @@
+mvn install:install-file -DgroupId=org.cybergarage -DartifactId=cyberlink-patched-release 
+-Dversion=1.7 -Dpackaging=jar -Dfile=<basedir>trunk\org.apache.felix.upnp.basedriver\src\main\resources\lib\cyberlink-1.7-patched-release.jar
\ No newline at end of file



Mime
View raw message