felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From don...@apache.org
Subject svn commit: r640411 - in /felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer: ./ 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/sandbox/ src/main/java...
Date Mon, 24 Mar 2008 13:28:30 GMT
Author: donsez
Date: Mon Mar 24 06:28:26 2008
New Revision: 640411

URL: http://svn.apache.org/viewvc?rev=640411&view=rev
Log:
creation of the fictivepositionproducer bundle : a example of a producer for the Wire Admin
service

Added:
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/pom.xml   (with props)
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/util/
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/util/config/
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java
  (with props)
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/util/position/
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/util/position/PositionFormat.java
  (with props)
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/util/position/PositionUtil.java
  (with props)
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/wireadmin/
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/fictivepositionproducer/
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/fictivepositionproducer/PositionProducer.java
  (with props)
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/resources/
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/resources/config.properties
  (with props)
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/site/
    felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/site/readme.html   (with
props)

Added: felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/pom.xml?rev=640411&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/pom.xml (added)
+++ felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/pom.xml Mon Mar 24 06:28:26
2008
@@ -0,0 +1,72 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you 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.
+-->
+<project>
+	<properties>
+		<repositoryLocation>http://people.apache.org/~donsez/dev/felix/sandbox/</repositoryLocation>
+		<description>a example of a producer for the Wire Admin service.</description>
+	</properties>  
+
+  <modelVersion>4.0.0</modelVersion>
+  <packaging>bundle</packaging>
+  <name>Fictive Position Producer</name>
+  <description>${description}</description>
+  <groupId>org.apache.felix.sandbox</groupId>
+  <version>0.1.0-SNAPSHOT</version>
+  <artifactId>wireadmin.sample.fictivepositionproducer</artifactId>
+
+  <dependencies>
+
+	<dependency>
+		<groupId>org.apache.felix</groupId>
+		<artifactId>org.osgi.core</artifactId>
+  		<version>1.1.0-SNAPSHOT</version>
+	</dependency>
+	
+	<dependency>
+		<groupId>org.apache.felix</groupId>
+		<artifactId>org.osgi.compendium</artifactId>
+  		<version>0.9.0-SNAPSHOT</version>
+	</dependency>
+        
+  </dependencies>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Import-Package>*</Import-Package>
+            <Private-Package>
+              ${pom.groupId}.${pom.artifactId},
+              ${pom.groupId}.util.*
+            </Private-Package>
+           	<Bundle-Activator>${pom.groupId}.${pom.artifactId}.PositionProducer</Bundle-Activator>
+            
+            <!-- docs in http://cwiki.apache.org/FELIX/bundle-plugin-for-maven-bnd.html
and http://cwiki.apache.org/FELIX/osgi-plugin-for-maven-2.html -->
+            <Export-Service>org.osgi.service.wireadmin.Producer</Export-Service>
+                        
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java?rev=640411&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java
(added)
+++ felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java
Mon Mar 24 06:28:26 2008
@@ -0,0 +1,217 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.sandbox.util.config;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+/**
+ * configuration utility
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Configuration {
+	static String DEFAULT_PROPERTIES_FILE = "config.properties";
+
+	/**
+	 * loads properties from a file
+	 * 
+	 * @param filename
+	 *            the properties file name
+	 * @return the properties
+	 */
+	public static Properties loadProperties(String filename) {
+		if (filename == null) {
+			filename = System.getProperty(
+					"org.apache.felix.sandbox.util.configuration.file",
+					DEFAULT_PROPERTIES_FILE);
+		}
+		try {
+			return loadProperties(new FileInputStream(filename));
+		} catch (Exception ex) {
+			ex.printStackTrace();
+			return null;
+		}
+	}
+
+	/**
+	 * loads properties from a input stream
+	 * 
+	 * @param in
+	 *            the imput stream
+	 * @return the properties
+	 */
+	public static Properties loadProperties(InputStream in) {
+		Properties prop = new Properties();
+		try {
+			prop.load(in);
+		} catch (Exception ex) {
+			ex.printStackTrace();
+			return null;
+		}
+		return prop;
+	}
+
+	/**
+	 * builds a map from properties. the key list is in the property
+	 * keyListPropertyName <br>
+	 * Example getMap(props,"keylist") returns a hashtable with 3 key-value
+	 * entry
+	 * 
+	 * <pre>
+	 *  keylist=bar;bubba;foo
+	 *  bar=BAR
+	 *  foo=1.5;float
+	 *  bubba=100;int
+	 * </pre>
+	 * 
+	 * @param props
+	 *            the properties
+	 * @param keyListPropertyName
+	 *            the property name of the key list (separed by ;)
+	 * @return The map
+	 */
+	public static Map getMap(Properties props, String keyListPropertyName) {
+		return getHashtable(props, keyListPropertyName);
+	}
+
+	/**
+	 * builds a hashtable from properties. the key list is in the property
+	 * keyListPropertyName <br>
+	 * Example getHashtable(props,"keylist") returns a hashtable with 3
+	 * key-value entry
+	 * 
+	 * <pre>
+	 *  keylist=bar;bubba;foo
+	 *  bar=BAR
+	 *  foo=1.5;float
+	 *  bubba=100;int
+	 * </pre>
+	 * 
+	 * @param props
+	 *            the properties
+	 * @param keyListPropertyName
+	 *            the property name of the key list (separed by ;)
+	 * @return The hashtable
+	 */
+	public static Hashtable getHashtable(Properties props,
+			String keyListPropertyName) {
+
+		StringTokenizer st = new StringTokenizer(props
+				.getProperty(keyListPropertyName), ";");
+		Hashtable map = new Hashtable();
+
+		while (st.hasMoreTokens()) {
+			String key = st.nextToken();
+			StringTokenizer stvaluetype = new StringTokenizer(props
+					.getProperty(key), ";");
+			Object obj = null;
+			if (stvaluetype.hasMoreTokens()) {
+				String value = stvaluetype.nextToken();
+				if (stvaluetype.hasMoreTokens()) {
+					String type = stvaluetype.nextToken();
+					if (type.equals("int")) {
+						obj = new Integer(value);
+					} else if (type.equals("long")) {
+						obj = new Long(value);
+					} else if (type.equals("float")) {
+						obj = new Float(value);
+					} else if (type.equals("double")) {
+						obj = new Double(value);
+					} else if (type.equals("string")) {
+						obj = value;
+					} else {
+						// default : string
+						obj = value;
+					}
+				} else {
+					// no type means String
+					obj = value;
+				}
+
+			}
+			map.put(key, obj);
+		}
+		return map;
+	}
+
+	/**
+	 * builds a (ordered) vector from properties. the index list is in the
+	 * property keyListPropertyName <br>
+	 * Example getVector(props,"tab") returns a 4 elements vector (tab.5 is
+	 * ignored since tab.4 does not exist)
+	 * 
+	 * <pre>
+	 *  tab.0=bar
+	 *  tab.1=foo
+	 *  tab.2=1.5;float
+	 *  tab.3=100;int
+	 *  tab.5=10000;long
+	 * </pre>
+	 * 
+	 * @param props
+	 *            the properties
+	 * @param vectorPropertyName
+	 *            the property name of the key list (separed by ;)
+	 * @return The vector
+	 */
+	public static Vector getVector(Properties props, String vectorPropertyName) {
+
+		Vector vect = new Vector();
+
+		for (int i = 0; true; i++) {
+			String valuetype = props.getProperty(vectorPropertyName) + "." + i;
+			if (valuetype == null)
+				break;
+			StringTokenizer stvaluetype = new StringTokenizer(valuetype, ";");
+			Object obj = null;
+			if (stvaluetype.hasMoreTokens()) {
+				String value = stvaluetype.nextToken();
+				if (stvaluetype.hasMoreTokens()) {
+					String type = stvaluetype.nextToken();
+					if (type.equals("int")) {
+						obj = new Integer(value);
+					} else if (type.equals("long")) {
+						obj = new Long(value);
+					} else if (type.equals("float")) {
+						obj = new Float(value);
+					} else if (type.equals("double")) {
+						obj = new Double(value);
+					} else if (type.equals("string")) {
+						obj = value;
+					} else {
+						// default : string
+						obj = value;
+					}
+				} else {
+					// no type means String
+					obj = value;
+				}
+
+			}
+			vect.addElement(obj);
+		}
+		return vect;
+	}
+}

Propchange: felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/util/position/PositionFormat.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/util/position/PositionFormat.java?rev=640411&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/util/position/PositionFormat.java
(added)
+++ felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/util/position/PositionFormat.java
Mon Mar 24 06:28:26 2008
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.sandbox.util.position;
+
+import java.text.FieldPosition;
+import java.text.Format;
+import java.text.ParsePosition;
+
+/**
+ * Position Utilities.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class PositionFormat extends Format {
+
+	/* (non-Javadoc)
+	 * @see java.text.Format#parseObject(java.lang.String, java.text.ParsePosition)
+	 */
+	public Object parseObject(String arg0, ParsePosition arg1) {
+		// TODO Raccord de méthode auto-généré
+		return null;
+	}
+
+	/* (non-Javadoc)
+	 * @see java.text.Format#format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)
+	 */
+	public StringBuffer format(
+		Object arg0,
+		StringBuffer arg1,
+		FieldPosition arg2) {
+		// TODO Raccord de méthode auto-généré
+		return null;
+	}
+
+}

Propchange: felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/util/position/PositionFormat.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/util/position/PositionUtil.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/util/position/PositionUtil.java?rev=640411&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/util/position/PositionUtil.java
(added)
+++ felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/util/position/PositionUtil.java
Mon Mar 24 06:28:26 2008
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.sandbox.util.position;
+
+import org.osgi.util.measurement.Measurement;
+import org.osgi.util.position.Position;
+
+
+/**
+ * This class provides formatting utilities for position
+ * However this class should be redesigned as a class
+ * extending java.text.Format such as java.text.NumberFormat
+ * or java.text.DateFormat
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class PositionUtil {
+
+	public static StringBuffer toText(StringBuffer sb, Position position) {
+		if (sb == null) {
+			sb = new StringBuffer();
+		}
+		sb.append("Position[");
+		if(position==null) {
+			sb.append((String)null);
+		} else {
+			Measurement lat=position.getLatitude();
+			sb.append("latitude:");
+			sb.append(lat);
+			if(lat!=null)
+				sb.append("(").append(convertWG84toLattitudeDDDMMSSH(convertRadtoWG84(lat.getValue()))).append(")");
+			sb.append(',');
+			Measurement lon=position.getLongitude();
+			sb.append("longitude:");
+			sb.append(lon);
+			if(lon!=null)
+				sb.append("(").append(convertWG84toLongitudeDDDMMSSH(convertRadtoWG84(lon.getValue()))).append(")");
+			sb.append(',');
+			sb.append("altitude:").append(position.getAltitude()).append(',');
+			sb.append("speed:").append(position.getSpeed()).append(',');
+			sb.append("track:").append(position.getTrack());
+		}
+		sb.append(']');
+		return sb;
+	}
+
+	// get degrees (DDD) of a WG84 angle
+	public static int convertWG84toDDD(double wg84) {
+		if(wg84<0.0d) wg84=-wg84;
+		return (int)Math.round(Math.floor(wg84));
+	}
+
+	// get minutes (MM) of a WG84 angle
+	public static int convertWG84toMM(double wg84) {
+		if(wg84<0.0d) wg84=-wg84;
+		return (int)(Math.round((Math.floor((wg84-Math.floor(wg84))*60))));
+	}
+
+	// get seconds (SS) of a WG84 angle
+	public static int convertWG84toSS(double wg84) {
+		if(wg84<0.0d) wg84=-wg84;
+		double deg=(wg84-Math.floor(wg84))*60;
+		return (int)(Math.round(Math.floor((deg-Math.floor(deg))*60)));
+	}
+
+	// get hemisphere (H) of a WG84 angle
+
+	public final static boolean LATTITUDE_N=true;
+	public final static boolean LATTITUDE_S=false;
+
+	public final static boolean LONGITUDE_E=true;
+	public final static boolean LONGITUDE_W=false;
+
+	// converts a WG84 angle in H
+	public static boolean convertWG84toH(double wg84) {
+		return (wg84>0)?LATTITUDE_N:LATTITUDE_S;
+		// or return (wg84>0)?LONGITUDE_E:LONGITUDE_W;
+	}
+
+	// converts a WG84 angle in an DDD MM SS string
+	public static String convertWG84toDDDMMSS(double angleInwg84) {
+		if(angleInwg84==Double.NaN) return Double.toString(Double.NaN);
+		return 		convertWG84toDDD(angleInwg84)+"° "
+		         +	convertWG84toMM(angleInwg84)+"' "
+		         +	convertWG84toSS(angleInwg84)+"''";
+	}
+
+	// converts a lattitude WG84 angle in an DDD MM SS H string
+	public static String convertWG84toLattitudeDDDMMSSH(double angleInwg84) {
+		if(angleInwg84==Double.NaN) return Double.toString(Double.NaN);
+		return 		convertWG84toDDDMMSS(angleInwg84)
+		         +	(convertWG84toH(angleInwg84)?" N":" S");
+	}
+
+	// converts a longitude WG84 angle in an DDD MM SS H string
+	public static String convertWG84toLongitudeDDDMMSSH(double angleInwg84) {
+		if(angleInwg84==Double.NaN) return Double.toString(Double.NaN);
+		return 		convertWG84toDDDMMSS(angleInwg84)
+		         +	(convertWG84toH(angleInwg84)?" E":" W");
+	}
+
+	// converts DDD MM SS H in a WG84 angle
+	public static double convertDDDMMSSHtoWG84(int degrees, int minutes,int seconds, boolean
h) {
+		return (degrees+(minutes/60.0d)+(seconds/3600.0d))*(h?1.0d:-1.0d);
+	}
+
+	// converts a WG84 angle in Rad
+	public static double convertWG84toRad(double angleInwg84) {
+		if(angleInwg84==Double.NaN) return Double.NaN;
+		return Math.toRadians(angleInwg84);
+	}
+
+	// converts a Rad angle in WG84
+	public static double convertRadtoWG84(double angleInRad) {
+		if(angleInRad==Double.NaN) return Double.NaN;
+		return Math.toDegrees(angleInRad);
+	}
+}
+
+

Propchange: felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/util/position/PositionUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/fictivepositionproducer/PositionProducer.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/fictivepositionproducer/PositionProducer.java?rev=640411&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/fictivepositionproducer/PositionProducer.java
(added)
+++ felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/fictivepositionproducer/PositionProducer.java
Mon Mar 24 06:28:26 2008
@@ -0,0 +1,322 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.sandbox.wireadmin.sample.fictivepositionproducer;
+
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Properties;
+
+import org.apache.felix.sandbox.util.config.Configuration;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.wireadmin.Producer;
+import org.osgi.service.wireadmin.Wire;
+import org.osgi.util.measurement.Measurement;
+import org.osgi.util.measurement.Unit;
+import org.osgi.util.position.Position;
+
+
+// import org.apache.felix.sandbox.util.position.LocationUtil;
+
+/**
+ * This class implements a producer of fictive (GPS) position
+ * It's a sample for the Wire Admin service
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ * TODO takes into account wireadmin.filter http://www2.osgi.org/javadoc/r4/org/osgi/service/wireadmin/WireConstants.html#WIREADMIN_FILTER
+ * TODO add pause when no wires are created, connected or valid
+ * TODO add ManagedService for CM
+ * TODO refactor to have a factory PositionProducerFactory with several configuration files
+ */
+public class PositionProducer implements Producer, Runnable, BundleActivator {
+
+	private Wire wires[];
+	private ServiceRegistration serviceRegistration;
+
+	private String applicationName;
+	private String positioningMethod;
+	
+	private double currentLatitude;
+	private double latitudeStart;
+	private double latitudeError;
+	private double latitudeIncr;
+
+	private double currentLongitude;
+	private double longitudeStart;
+	private double longitudeError;
+	private double longitudeIncr;
+
+	private double currentAltitude;
+	private double altitudeStart;
+	private double altitudeError;
+	private double altitudeIncr;
+	
+	private long lastTimestamp;
+	private int pollDelay;
+
+	private PrintStream traceout;
+
+	private boolean quit;
+
+	private static final String CONFIGFILE = "/config.properties";
+
+	protected BundleContext bundleContext = null;
+
+	/**
+	 * Load the configuration properties from the default location
+	 */
+	private void configure() throws Exception {
+
+		// Get the Config-Location value from the manifest
+
+		String configLocation = null;
+		Dictionary dict = bundleContext.getBundle().getHeaders();
+		Enumeration enumeration = dict.keys();
+		while (enumeration.hasMoreElements()) {
+			Object nextKey = enumeration.nextElement();
+			Object nextElem = dict.get(nextKey);
+			if (nextKey.equals("Config-Location")) {
+				configLocation = nextElem.toString();
+				break;
+			}
+		}
+		if (configLocation == null) {
+			configLocation = CONFIGFILE;
+		}
+		
+		configure(configLocation);
+	}
+
+	/**
+	 * Load the configuration properties
+	 */
+	private void configure(String configLocation) throws Exception {
+
+		// Load properties from configLocation file
+		InputStream is = getClass().getResourceAsStream(configLocation);
+		Properties configurationProperties = Configuration.loadProperties(is);
+		configure(configurationProperties);
+	}
+		
+	/**
+	 * Set the configuration properties
+	 */
+	private void configure(Dictionary configurationProperties) throws Exception {
+		
+		String ptraceout = (String)configurationProperties.get("traceout");
+		traceout = null;
+		if (ptraceout != null) {
+			if (ptraceout.equals("System.out")) {
+				traceout = System.out;
+			} else if (ptraceout.equals("System.err")) {
+				traceout = System.err;
+			} else {
+				// TODO instanciante the class with the name	
+				System.err.println("custom trace is not implemented !");
+			}
+		} else {
+			traceout = null;
+		}
+
+		
+		applicationName = (String)configurationProperties.get("application.name");
+
+		positioningMethod = (String)configurationProperties.get("positioning.method");
+		
+		String polldelayprops = (String)configurationProperties.get("poll.delay");
+		pollDelay = 10000; // default 10000 millisec
+		if (polldelayprops != null) {
+			pollDelay = Integer.parseInt(polldelayprops);
+		}
+		
+		String positionLatitudeStartStr = (String)configurationProperties.get("position.latitude.start");
+		latitudeStart=0.7887922290974462;
+		if (positionLatitudeStartStr != null) {
+			latitudeStart = Double.parseDouble(positionLatitudeStartStr);
+		}
+
+		String positionLongitudeStartStr = (String)configurationProperties.get("position.longitude.start");
+		longitudeStart=0.10071538443;
+		if (positionLongitudeStartStr != null) {
+			longitudeStart = Double.parseDouble(positionLongitudeStartStr);
+		}
+
+		String positionAltitudeStartStr = (String)configurationProperties.get("position.altitude.start");
+		altitudeStart=220.0;
+		if (positionAltitudeStartStr != null) {
+			altitudeStart = Double.parseDouble(positionAltitudeStartStr);
+		}
+
+		String positionLatitudeIncrStr = (String)configurationProperties.get("position.latitude.increment");
+		latitudeIncr=0.00001;
+		if (positionLatitudeIncrStr != null) {
+			latitudeIncr = Double.parseDouble(positionLatitudeIncrStr);
+		}
+
+		String positionLongitudeIncrStr = (String)configurationProperties.get("position.longitude.increment");
+		longitudeIncr=0.0001;
+		if (positionLongitudeIncrStr != null) {
+			longitudeIncr = Double.parseDouble(positionLongitudeIncrStr);
+		}
+
+		String positionAltitudeIncrStr = (String)configurationProperties.get("position.altitude.increment");
+		altitudeIncr=0.01;
+		if (positionAltitudeIncrStr != null) {
+			altitudeIncr = Double.parseDouble(positionAltitudeIncrStr);
+		}
+
+		String positionLatitudeErrorStr = (String)configurationProperties.get("position.latitude.error");
+		latitudeError=0.000001;
+		if (positionLatitudeErrorStr != null) {
+			latitudeError = Double.parseDouble(positionLatitudeErrorStr);
+		}
+
+		String positionLongitudeErrorStr = (String)configurationProperties.get("position.longitude.error");
+		longitudeError=0.000001;
+		if (positionLongitudeErrorStr != null) {
+			longitudeError = Double.parseDouble(positionLongitudeErrorStr);
+		}
+
+		String positionAltitudeErrorStr = (String)configurationProperties.get("position.altitude.error");
+		altitudeError=0.001;
+		if (positionAltitudeErrorStr != null) {
+			altitudeError = Double.parseDouble(positionAltitudeErrorStr);
+		}
+	}
+
+	/**
+	 * @see java.lang.Runnable#run()
+	 */
+	public void run() {
+		while (!quit){
+			try {
+				Position position = getPosition();
+				synchronized (this) {	
+					for (int i = 0; wires != null && i < wires.length; i++) {
+						Wire wire = wires[i];
+						// check if wire is valid and connected ?
+						if (!wire.isConnected() || !wire.isValid())
+							continue;
+						Object obj=adapt(wire,position);
+						// TODO : respect the control flow specified by the consumer
+						if(obj!=null) wire.update(obj);
+					}
+				}
+				Thread.sleep(pollDelay);
+			} catch (InterruptedException ie) {
+				/* will recheck quit */
+			}
+		}
+	}
+
+	/**
+	 * @see org.osgi.service.wireadmin.Producer#consumersConnected(org.osgi.service.wireadmin.Wire[])
+	 */
+	public synchronized void consumersConnected(Wire wires[]) {
+		this.wires = wires;
+	}
+
+	/**
+	 * @see org.osgi.service.wireadmin.Producer#polled(org.osgi.service.wireadmin.Wire)
+	 */
+	public Object polled(Wire wire) {
+		return adapt(wire,getPosition());
+	}
+
+	private Object adapt(Wire wire,Position position) {
+		Class clazzes[] = wire.getFlavors();
+		for (int i = 0; i < clazzes.length; i++) {
+			Class clazz = clazzes[i];
+			if (clazz.isAssignableFrom(Position.class))
+				return position;
+			if (clazz.isAssignableFrom(String.class))
+				return position.toString();
+		}
+		return null;
+	}
+
+	/**
+	 * computer a Position according to a heading
+	 * @return the new position
+	 */
+	private Position getPosition() {
+		long timestamp=System.currentTimeMillis();
+		long delta=timestamp-lastTimestamp;
+		lastTimestamp=timestamp;
+		currentLatitude+=(latitudeIncr*(delta/1000.0));
+		currentLongitude+=(longitudeIncr*(delta/1000.0));
+		currentAltitude+=(altitudeIncr*(delta/1000.0));
+		return new Position(
+			new Measurement(currentLatitude,latitudeError,Unit.rad,timestamp),
+			new Measurement(currentLongitude,longitudeError,Unit.rad,timestamp),
+			new Measurement(currentAltitude,altitudeError,Unit.m,timestamp),
+			null, // @TODO compute speed
+			null // @TODO compute heading
+		);
+	}
+
+	/**
+	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+	 */
+	public void start(BundleContext bundleContext) throws Exception {
+		this.bundleContext=bundleContext;
+		
+		configure();
+		
+		currentLatitude=latitudeStart;
+		currentLongitude=longitudeStart;
+		currentAltitude=altitudeStart;
+		lastTimestamp=System.currentTimeMillis();
+		
+		Hashtable registrationProperties = new Hashtable();
+		registrationProperties.put(
+			org.osgi.service.wireadmin.WireConstants.WIREADMIN_PRODUCER_FLAVORS,
+			new Class[] { Position.class, /*Location.class,*/ String.class });
+		registrationProperties.put(
+				org.osgi.framework.Constants.SERVICE_PID,
+				this.getClass().getPackage().getName());
+		registrationProperties.put(
+				"application.name",
+				applicationName);
+		registrationProperties.put(
+				"positioning.method",
+				positioningMethod); 
+		registrationProperties.put(
+				org.osgi.framework.Constants.SERVICE_DESCRIPTION,
+				"a simple Producer that poll Position objects");
+
+		serviceRegistration=bundleContext.registerService(Producer.class.getName(), this, registrationProperties);
+
+		quit = false;
+		Thread thread=new Thread(this);
+		thread.setName(getClass().getPackage().getName());
+		thread.start();
+	}
+
+	/**
+	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+	 */
+	public void stop(BundleContext bundleContext) throws Exception {
+		this.quit = true;
+		serviceRegistration.unregister();
+	}
+}
\ No newline at end of file

Propchange: felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/fictivepositionproducer/PositionProducer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/resources/config.properties
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/resources/config.properties?rev=640411&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/resources/config.properties
(added)
+++ felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/resources/config.properties
Mon Mar 24 06:28:26 2008
@@ -0,0 +1,29 @@
+
+traceout=System.err
+
+application.name=FictiveGPS
+
+# positioning methods could be @see javax.microedition.location.Location.MTA* constants in
http://jcp.org/en/jsr/detail?id=179
+positioning.method=fictive
+
+# poll delay
+poll.delay=10000
+
+# position parameter for generation
+
+# latitude in rad lat=45.19446564 degre=45°11'37"N
+position.latitude.start=0.78879222909744629
+# longitude in rad lon=5.77056646 degre=05°46'15"E
+position.longitude.start=0.1007153844321536
+# altitude in meter
+position.altitude.start=220.0
+
+# increment every 1000 ms
+position.latitude.increment=0.00001
+position.longitude.increment=0.000001
+position.altitude.increment=0.01
+
+position.latitude.error=0.0000001
+position.longitude.error=0.0000001
+position.altitude.error=0.001
+

Propchange: felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/main/resources/config.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/site/readme.html
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/site/readme.html?rev=640411&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/site/readme.html (added)
+++ felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/site/readme.html Mon
Mar 24 06:28:26 2008
@@ -0,0 +1,73 @@
+<html>
+<head>
+<title>Fictive Position Producer</title>
+</head>
+<body>
+
+<hr width="100%" size="2">
+<h1><i><a name="org.apache.felix.sandbox.wireadmin.sample.fictivepositionproducer"></a><font
color="#0000aa">Fictive Position Producer</font></i></h1>
+
+<p>
+<b>Description</b><br>
+This bundle provides a simple Producer service which poll fictive Position objects (according
a linear track)
+</p>
+
+<p>
+<b>Contributors</b><br>
+Apache Project Team
+</p>
+
+<p>
+<b>License</b><br>
+ASL2<br>
+</p>
+
+<p>
+<b>Services</b><br>
+<code>org.osgi.service.wireadmin.Producer</code>
+</p>
+
+<p>
+<b>Properties</b><br>
+service.pid=org.apache.felix.sandbox.wireadmin.sample.fictivepositionproducer<br>
+wireadmin.producer.flavors=class org.osgi.util.position.Position,class java.lang.String<br>
+<br>
+</p>
+
+<p><b>Requirements</b><br>
+<ul>
+<li>org.osgi.service.wireadmin; version=1.0</li>
+<li>org.osgi.util.position; version=1.0</li>
+</ul>
+</p>
+
+
+<hr width="100%" size="2">
+
+
+<p>
+<b>Build</b><br>
+<ol>
+<li>setup the properties in src/main/resources/config.properties</li>
+<li>then build with Maven 2: <code>mvn clean install</code></li>
+</ol>
+</p>
+
+
+<p>
+<b>Tested gateways</b><br>
+<ul>
+<li>Objectweb Oscar (done)</li>
+<li>Apache Felix (done)</li>
+<li>Equinox (to do)</li>
+</ul>
+</p>
+
+<p>
+<b>TODO (contributions are welcome)</b><br>
+<ul>
+</ul>
+</p>
+
+</body>
+</html>

Propchange: felix/sandbox/donsez/wireadmin.sample.fictivepositionproducer/src/site/readme.html
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message