felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From don...@apache.org
Subject svn commit: r611491 - in /felix/sandbox/donsez/wireadminbinder: ./ 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/org/apache/felix/sandbox...
Date Sat, 12 Jan 2008 21:51:54 GMT
Author: donsez
Date: Sat Jan 12 13:51:47 2008
New Revision: 611491

URL: http://svn.apache.org/viewvc?rev=611491&view=rev
Log:
creation of the WireAdminBinder(WAB) bundle. WAB automates the creation and deletion of wires between WireAdmin producers and consumers according to the contract-based approach.

Added:
    felix/sandbox/donsez/wireadminbinder/
    felix/sandbox/donsez/wireadminbinder/pom.xml   (with props)
    felix/sandbox/donsez/wireadminbinder/src/
    felix/sandbox/donsez/wireadminbinder/src/main/
    felix/sandbox/donsez/wireadminbinder/src/main/java/
    felix/sandbox/donsez/wireadminbinder/src/main/java/org/
    felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/
    felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/
    felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/
    felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/
    felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/BaseActivator.java   (with props)
    felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/DescriptorParser.java   (with props)
    felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/Property.java   (with props)
    felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/ServiceReferenceDelegate.java   (with props)
    felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/ServiceReferenceDelegateKeysEnumeration.java   (with props)
    felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/Util.java   (with props)
    felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireAdminBinderException.java   (with props)
    felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireAdminBinderService.java   (with props)
    felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireApp.java   (with props)
    felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireAppManager.java   (with props)
    felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireSet.java   (with props)
    felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireSetManager.java   (with props)
    felix/sandbox/donsez/wireadminbinder/src/main/resource/
    felix/sandbox/donsez/wireadminbinder/src/main/resource/org/
    felix/sandbox/donsez/wireadminbinder/src/main/resource/org/apache/
    felix/sandbox/donsez/wireadminbinder/src/main/resource/org/apache/felix/
    felix/sandbox/donsez/wireadminbinder/src/main/resource/org/apache/felix/sandbox/
    felix/sandbox/donsez/wireadminbinder/src/main/resource/org/apache/felix/sandbox/wireadminbinder/
    felix/sandbox/donsez/wireadminbinder/src/main/resource/org/apache/felix/sandbox/wireadminbinder/wireapp.dtd   (with props)
    felix/sandbox/donsez/wireadminbinder/src/site/
    felix/sandbox/donsez/wireadminbinder/src/site/readme.html   (with props)
    felix/sandbox/donsez/wireadminbinder/src/site/script.txt   (with props)

Added: felix/sandbox/donsez/wireadminbinder/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadminbinder/pom.xml?rev=611491&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadminbinder/pom.xml (added)
+++ felix/sandbox/donsez/wireadminbinder/pom.xml Sat Jan 12 13:51:47 2008
@@ -0,0 +1,88 @@
+<!--
+ 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://www-adele.imag.fr/users/Didier.Donsez/dev/felix/sandbox/</repositoryLocation>
+		<description>automates the creation and deletion of wires between WireAdmin producers and consumers.</description>
+	</properties>  
+
+
+  <modelVersion>4.0.0</modelVersion>
+  <packaging>bundle</packaging>
+  <name>Apache Felix Wire Admin Binder</name>
+  <artifactId>org.apache.felix.sandbox.wireadminbinder</artifactId>
+  <groupId>org.apache.felix.sandbox</groupId>
+  <version>0.1.0</version>
+  <description>${description}</description>
+
+  <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>
+        
+	<dependency>
+		<groupId>org.apache.felix</groupId>
+		<artifactId>org.apache.felix.bundlerepository</artifactId>
+  		<version>1.1.0-SNAPSHOT</version>
+	</dependency>
+
+  </dependencies>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <version>1.1.0-SNAPSHOT</version>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Export-Package>
+                ${artifactId}; version=1.0
+            </Export-Package>
+            
+            <Import-Package>
+            	org.osgi.framework,
+            	org.osgi.service.wireadmin,
+            	!javax.xml.parsers,!org.xml.sax,*
+            </Import-Package>
+
+            <Export-Package>${pom.artifactId}</Export-Package>
+
+            <Private-Package>
+            		${pom.artifactId}.*,
+            		org.apache.felix.sandbox.util.*,
+            		org.kxml2.io,org.xmlpull.*,org.apache.felix.bundlerepository.metadataparser.*             		
+            </Private-Package>
+                                    
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: felix/sandbox/donsez/wireadminbinder/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/BaseActivator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/BaseActivator.java?rev=611491&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/BaseActivator.java (added)
+++ felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/BaseActivator.java Sat Jan 12 13:51:47 2008
@@ -0,0 +1,368 @@
+/*
+ *   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.sandbox.wireadminbinder;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+import org.osgi.service.wireadmin.WireAdmin;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * This activator starts and stops WireAdminBinder applications.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ * @TODO add log service service for tracing event
+ * @TODO add event service for tracing event
+ */
+public class BaseActivator implements BundleActivator, ServiceListener {
+	
+	// this bundle's context
+	private BundleContext bundleContext;
+
+	private ServiceReference wireAdminServiceReference;
+	private WireAdmin wireAdmin;
+	// the wireadmin service
+	//private static ServiceTracker m_wireAdminServiceTracker;
+
+	private InputStream inputStream;
+
+	// name of the LogService class (this is a string to not create a reference
+	// to the class)
+	private static final String LOGSERVICE_CLASS = "org.osgi.service.log.LogService";
+
+	// Flag that sets tracing messages
+	private static boolean m_trace = true;
+
+	// Flag that sets error messages
+	private static boolean m_error = true;
+
+	// the log service to log messages to
+	private static ServiceTracker m_logService;
+
+	
+	protected List wireApps=new ArrayList();
+
+	public BaseActivator() {
+	}
+
+	public BaseActivator(InputStream inputStream) {
+		this.inputStream = inputStream;
+	}
+
+	public BaseActivator(InputStream[] inputStream) {
+		error("Not implemented",null);
+	}
+
+	/**
+	 * 
+	 */
+	public void start(BundleContext bundleContext) throws Exception {
+		init(bundleContext);
+
+		if (inputStream == null) {
+			loadWireApps();
+		} else {
+			loadWireApp(inputStream);
+		}
+	}
+
+	/**
+	 * init log service
+	 * 
+	 * @param bundleContext
+	 */
+	private void init(BundleContext bundleContext) {
+		this.bundleContext = bundleContext;
+
+		// require the log service
+		m_logService = new ServiceTracker(bundleContext, LOGSERVICE_CLASS, null);
+		m_logService.open();
+		
+		
+		// configure logging from context properties
+		if("true".equalsIgnoreCase(bundleContext
+				.getProperty("org.apache.felix.sandbox.wireadminbinder.showtrace"))){
+			m_trace = true;
+		}
+		if("true".equalsIgnoreCase(bundleContext
+				.getProperty("org.apache.felix.sandbox.wireadminbinder.showerrors"))){
+			m_error = true;
+		}
+		if ("true".equalsIgnoreCase(bundleContext
+				.getProperty("org.apache.felix.sandbox.wireadminbinder.showversion"))) {
+			trace(bundleContext.getBundle().getSymbolicName()
+					+ "[ Version = "
+					+ bundleContext.getBundle().getHeaders().get(
+							Constants.BUNDLE_VERSION) + " ]", null);
+		}
+		
+		// require the WireAdmin service
+		// TODO replace by a service tracker
+		ServiceReference wireAdminServiceReference = bundleContext
+				.getServiceReference(WireAdmin.class.getName());
+		if (wireAdminServiceReference == null) {
+			error("No WireAdmin service available",null);
+			return;
+		}
+		wireAdmin = (WireAdmin) bundleContext
+				.getService(wireAdminServiceReference);
+		if (wireAdmin == null) {
+			error("No WireAdmin service available",null);
+			return;
+		}
+		bundleContext.addServiceListener(this);
+		
+	}
+
+	/**
+	 * fini log service
+	 */
+	private void fini() {
+		disposeAllWireApps();
+		
+		bundleContext.removeServiceListener(this);
+		if (wireAdminServiceReference != null)
+			bundleContext.ungetService(wireAdminServiceReference);
+		wireAdmin = null;
+		
+		m_logService.close();
+	}
+
+	/**
+	 * load wire apps from the descriptors
+	 * 
+	 * @throws Exception
+	 */
+	private void loadWireApps() {
+		String descriptorLocations = (String) bundleContext.getBundle()
+				.getHeaders().get("WireAdminBinder-Metadata");
+
+		if (descriptorLocations != null) {
+			error("WireAdminBinder-Metadata entry not found in the manifest",
+					null);
+			return;
+		}
+
+		StringTokenizer st = new StringTokenizer(descriptorLocations, ", ");
+
+		while (st.hasMoreTokens()) {
+			String descriptorLocation = st.nextToken();
+
+			URL descriptorURL = bundleContext.getBundle().getResource(
+					descriptorLocation);
+			if (descriptorURL == null) {
+				error("WAB descriptor entry '" + descriptorLocation
+						+ "' not found", null);
+				continue;
+			}
+
+			InputStream inputStream = null;
+			try {
+				inputStream = descriptorURL.openStream();
+			} catch (IOException e) {
+				error("WAB descriptor entry '" + descriptorLocation
+						+ "' can not open", null);
+				return;
+			}
+			loadWireApp(inputStream);
+		}
+	}
+
+	/**
+	 * load one wire apps from the input stream
+	 * 
+	 * @param inputStream
+	 * @throws Exception
+	 */
+	private void loadWireApp(InputStream inputStream) {
+		// parse the metadata file
+		DescriptorParser descriptorParser = new DescriptorParser();
+		descriptorParser.setTrace(m_trace);
+		WireApp wireApp=null;
+		try {
+			wireApp = descriptorParser.getWireApp(this.getClass().getClassLoader(),inputStream);
+		} catch (Exception e) {
+			error(e.toString(),null);
+			return;
+		}
+		try {
+			inputStream.close();
+		} catch (IOException e) {
+			error(e.toString(),null);
+			return;
+		}
+
+		trace(wireApp.toString(), wireApp);
+
+		// create the wireadminbinder
+		try {
+			WireAppManager wireAppManager = new WireAppManager(bundleContext, wireAdmin, wireApp);
+			wireApps.add(wireAppManager);
+		} catch (Exception e) {
+			error(e.toString(),null);
+			return;
+		}
+	}
+
+    // Unloads all wire apps 
+	private void disposeAllWireApps() {
+	    {
+	        for (Iterator it = wireApps.iterator(); it.hasNext();)
+	        {
+	            WireAppManager wireAppManager = (WireAppManager) it.next();
+	            try
+	            {
+	                wireAppManager.dispose();
+	            }
+	            catch (Exception e)
+	            {
+	                exception(
+	                    "Error while disposing wire app "
+	                        + wireAppManager.getWireAppMetadata().getId(),null, e);
+	            }
+	            it.remove();
+	        }
+	    }
+		
+	}
+	
+	
+	
+	/**
+	 * ???
+	 */
+	public void serviceChanged(ServiceEvent e) {
+		ServiceReference serviceReference = e.getServiceReference();
+		if (e.getType() == ServiceEvent.UNREGISTERING
+				&& serviceReference.equals(wireAdminServiceReference)) {
+			try {
+				bundleContext.getBundle().stop();
+			} catch (BundleException be) {
+				// never throw in principle
+				be.printStackTrace();
+			}
+		}
+	}
+
+	public void stop(BundleContext bundleContext) {
+		fini();
+	}
+
+	/**
+	 * Method to display traces
+	 * 
+	 * @param message
+	 *            a string to be displayed
+	 * @param metadata
+	 *            WABMetadata associated to the message (can be null)
+	 */
+	static void trace(String message, WireApp metadata) {
+		if (m_trace) {
+			StringBuffer msg = new StringBuffer("--- ");
+			if (metadata != null) {
+				msg.append("[").append(metadata.getDescription()).append("] ");
+			}
+			msg.append(message);
+
+			log(LogService.LOG_DEBUG, msg.toString(), null);
+		}
+	}
+
+	/**	 * Method to display errors
+	 * 
+	 * @param message
+	 *            a string to be displayed
+	 * @param metadata
+	 *            optional metadata providing more information to log
+	 */
+	static void error(String message, WireApp metadata) {
+		if (m_error) {
+			StringBuffer msg = new StringBuffer("### ");
+			if (metadata != null) {
+				msg.append("[").append(metadata.getDescription()).append("] ");
+			}
+			msg.append(message);
+
+			log(LogService.LOG_ERROR, msg.toString(), null);
+		}
+	}
+
+	/**
+	 * Method to display exceptions
+	 * 
+	 * @param ex
+	 *            an exception
+	 */
+	static void exception(String message, WireApp metadata,
+			Throwable ex) {
+		if (m_error) {
+			StringBuffer msg = new StringBuffer("--- ");
+			if (metadata != null) {
+				msg.append("[").append(metadata.getDescription()).append("] ");
+			}
+			msg.append("Exception with component : ");
+			msg.append(message).append(" ---");
+
+			log(LogService.LOG_ERROR, msg.toString(), ex);
+		}
+	}
+
+	/**
+	 * Method to actually emit the log message. If the LogService is available,
+	 * the message will be logged through the LogService. Otherwise the message
+	 * is logged to stdout (or stderr in case of LOG_ERROR level messages),
+	 * 
+	 * @param level
+	 *            The log level to log the message at
+	 * @param message
+	 *            The message to log
+	 * @param ex
+	 *            An optional <code>Throwable</code> whose stack trace is
+	 *            written, or <code>null</code> to not log a stack trace.
+	 */
+	static void log(int level, String message, Throwable ex) {
+
+		Object logger = m_logService.getService();
+		if (logger == null) {
+			PrintStream out = (level == LogService.LOG_ERROR) ? System.err
+					: System.out;
+			out.println(message);
+			if (ex != null) {
+				ex.printStackTrace(out);
+			}
+		} else {
+			((LogService) logger).log(level, message, ex);
+		}
+	}
+
+}

Propchange: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/BaseActivator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/DescriptorParser.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/DescriptorParser.java?rev=611491&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/DescriptorParser.java (added)
+++ felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/DescriptorParser.java Sat Jan 12 13:51:47 2008
@@ -0,0 +1,96 @@
+/*
+ * 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.wireadminbinder;
+
+import java.io.InputStream;
+
+import org.apache.felix.bundlerepository.metadataparser.KXml2MetadataHandler;
+import org.apache.felix.bundlerepository.metadataparser.MetadataHandler;
+
+/**
+ * parse the WAB descriptor
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class DescriptorParser
+{
+	public static final String DESCRIPTORS_ENTRY="WAB-Component";
+	private boolean flag=false;
+	
+	public WireApp getWireApp(ClassLoader classLoader, String entry) throws WireAdminBinderException {
+		// metadata file can be a path in the bundle classpath or a remote document over the Web
+		// 1) get the input stream
+	
+		InputStream is;
+		
+		// metadata may be in the bundle classpath
+		is=classLoader.getResourceAsStream(entry);
+
+		if(is==null)
+			throw new WireAdminBinderException("Cannot open entry " +entry);			
+
+		return getWireApp(classLoader,is);
+	}
+
+	
+	public WireApp getWireApp(ClassLoader classLoader, InputStream is) throws WireAdminBinderException {
+		// 2) create a metadata handler
+		// * KXml2MetadataHandler for kXML parser (light XML parser)
+		// * XmlMetadataHandler for SAX compliant parser
+		MetadataHandler handler=new KXml2MetadataHandler();
+		// MetadataHandler handler=new XmlMetadataHandler();
+
+		// 3) set the corresponding type for each PI
+		handler.setMissingPIExceptionFlag(false);
+		//handler.addPI("mapping", MappingProcessingInstructionHandler.class);
+
+		try {
+		// 4) set the corresponding type for each element
+		    handler.addType("wireapp", WireApp.class,null,null);
+		    handler.addType("wireset", WireSet.class,null,null);
+		    handler.addType("consumersFilter", String.class,null,null);
+		    handler.addType("producersFilter", String.class,null,null);
+		    handler.addType("property", Property.class,null,null);
+		
+		// 5) set a default type (String, HashMap, ...) for the other elements 
+		// if the default type is not set, then the parsing of other elements fails 
+		// handler.setDefaultType(String.class);
+		// String is for terminal element (EMPTY with a value attribute or PCDATA)
+		} catch (Exception e) {
+			e.printStackTrace();
+			throw new WireAdminBinderException("Error occur during metadata parsing:"+e.getMessage(),e);			
+		}
+
+		// 6) parse the stream
+		handler.setTrace(flag);
+		try {
+			handler.parse(is);
+		} catch (Exception e) {
+			e.printStackTrace();
+			throw new WireAdminBinderException("Error occur during metadata parsing:"+e.getMessage(),e);			
+		}
+		
+		// 7) use the metadata	
+		return (WireApp)handler.getMetadata();
+    }
+
+	public void setTrace(boolean flag){
+		this.flag=flag;
+	}
+}
\ No newline at end of file

Propchange: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/DescriptorParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/Property.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/Property.java?rev=611491&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/Property.java (added)
+++ felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/Property.java Sat Jan 12 13:51:47 2008
@@ -0,0 +1,103 @@
+/*
+ *   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.sandbox.wireadminbinder;
+
+import java.io.Serializable;
+
+/**
+ * represents the property element
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Property implements Serializable {
+
+	private String name;
+	private String value;
+
+	/**
+	 * the CDATA text of the SOSOC script
+	 */
+	private String text;
+	
+	private String type;
+	
+	/**
+	 * @return
+	 */
+	public String getName() {
+		return name;
+	}
+
+	/**
+	 * @return
+	 */
+	public String getType() {
+		return type;
+	}
+
+	/**
+	 * @return
+	 */
+	public String getValue() {
+		return value;
+	}
+
+	/**
+	 * @param string
+	 */
+	public void setName(String string) {
+		name = string;
+	}
+
+	/**
+	 * @param string
+	 */
+	public void setType(String string) {
+		type = string;
+	}
+
+	/**
+	 * @param string
+	 */
+	public void setValue(String string) {
+		value = string;
+	}
+
+	public void addText(String text) {
+		this.text = text;
+	}
+
+	public void process() throws Throwable {	
+		if(name==null) throw new IllegalArgumentException("attribute name is missing");
+		if(value==null && text==null) throw new IllegalArgumentException("CDATA or attributes entry and url are missing");
+		if(value!=null && text!=null) throw new IllegalArgumentException("could not have both attributes value and CDATA");
+		value=text;
+		text=null;
+	}
+	
+	public String toString() {
+		StringBuffer sb=new StringBuffer();
+		sb.append('[');
+		sb.append("name=").append(name);
+		if(value!=null) sb.append("value=").append(value);
+		if(text!=null) sb.append("text=").append(value);
+		sb.append("type=").append(type);
+		sb.append(']');
+		return sb.toString();
+	}
+
+}

Propchange: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/Property.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/ServiceReferenceDelegate.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/ServiceReferenceDelegate.java?rev=611491&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/ServiceReferenceDelegate.java (added)
+++ felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/ServiceReferenceDelegate.java Sat Jan 12 13:51:47 2008
@@ -0,0 +1,108 @@
+/*
+ *   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.sandbox.wireadminbinder;
+
+import java.util.Dictionary;
+import java.util.Enumeration;
+
+import org.osgi.framework.ServiceReference;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ServiceReferenceDelegate extends Dictionary {
+
+    private ServiceReference serviceReference = null;
+
+    public ServiceReferenceDelegate(ServiceReference serviceReference) {
+        this.serviceReference = serviceReference;
+    }
+
+    /**
+     * This method is unused by the filter checker
+     * 
+     * @see java.util.Dictionary#size()
+     */
+    public int size() {
+        return 0;
+    }
+
+    /**
+     * This method is unused by the filter checker
+     * 
+     * @see java.util.Dictionary#isEmpty()
+     */
+    public boolean isEmpty() {
+        return false;
+    }
+
+    /**
+     * This method is unused by the filter checker
+     * 
+     * @see java.util.Dictionary#elements()
+     */
+    public Enumeration elements() {
+        return null;
+    }
+
+    /**
+     * This method is unused by the filter checker
+     * 
+     * @see java.util.Dictionary#keys()
+     */
+    public Enumeration keys() {
+        return new ServiceReferenceDelegateKeysEnumeration(
+                	serviceReference.getPropertyKeys()
+                );
+    }
+
+    /**
+     * This method is the only one used by the filter checker
+     * 
+     * @see java.util.Dictionary#get(java.lang.Object)
+     */
+
+    public Object get(Object key) {
+        Object property = serviceReference.getProperty((String) key);
+        if (property instanceof Class[]) {
+            Class[] clazzes = (Class[]) property;
+            String[] strs = new String[clazzes.length];
+            for (int i = 0; i < clazzes.length; i++)
+                strs[i] = clazzes[i].toString();
+            return strs;
+        } else
+            return property;
+    }
+
+    /**
+     * This method is unused by the filter checker
+     * 
+     * @see java.util.Dictionary#remove(java.lang.Object)
+     */
+    public Object remove(Object arg0) {
+        return null;
+    }
+
+    /**
+     * This method is unused by the filter checker
+     * 
+     * @see java.util.Dictionary#put(java.lang.Object, java.lang.Object)
+     */
+    public Object put(Object arg0, Object arg1) {
+        return null;
+    }
+}

Propchange: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/ServiceReferenceDelegate.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/ServiceReferenceDelegateKeysEnumeration.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/ServiceReferenceDelegateKeysEnumeration.java?rev=611491&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/ServiceReferenceDelegateKeysEnumeration.java (added)
+++ felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/ServiceReferenceDelegateKeysEnumeration.java Sat Jan 12 13:51:47 2008
@@ -0,0 +1,54 @@
+/*
+ *   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.sandbox.wireadminbinder;
+
+import java.util.Enumeration;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+class ServiceReferenceDelegateKeysEnumeration implements Enumeration {
+
+    private String[] keys;
+
+    private int index = 0;
+
+    ServiceReferenceDelegateKeysEnumeration(String[] keys) {
+        this.keys = keys;
+    }
+
+    /**
+     * @see java.util.Enumeration#hasMoreElements()
+     */
+    public boolean hasMoreElements() {
+        if (keys == null || index >= keys.length)
+            return false;
+        else
+            return true;
+    }
+
+    /**
+     * @see java.util.Enumeration#nextElement()
+     */
+    public Object nextElement() {
+        if (hasMoreElements())
+            return keys[index++];
+        else
+            return null;
+    }
+
+}
\ No newline at end of file

Propchange: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/ServiceReferenceDelegateKeysEnumeration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/Util.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/Util.java?rev=611491&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/Util.java (added)
+++ felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/Util.java Sat Jan 12 13:51:47 2008
@@ -0,0 +1,90 @@
+/*
+ *   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.sandbox.wireadminbinder;
+
+import java.io.PrintStream;
+import java.util.Dictionary;
+import java.util.Enumeration;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * utility to list services
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Util {
+	/**
+	 * list a subset of services and their properties
+	 */
+	public static void listServices(PrintStream out,BundleContext bundleContext, String interfaceName, String filter)
+		throws Exception {
+		ServiceReference[] srefs = null;
+		srefs = bundleContext.getServiceReferences(interfaceName, filter);
+
+		if (srefs != null) {
+			for (int i = 0; i < srefs.length; i++) {
+				ServiceReference sr = srefs[i];
+
+				out.print("Bundle#" + sr.getBundle().getBundleId());
+				out.print(",Service#" + sr.getProperty(Constants.SERVICE_ID));
+				//out.print("," + sr.getClass().getName());
+				out.println(":");
+
+				String[] keys = sr.getPropertyKeys();
+				for (int j = 0; j < keys.length; j++) {
+					out.print("\t" + keys[j] + "=");
+					Object value = sr.getProperty(keys[j]);
+					if (value.getClass().isArray()) {
+						Object[] array = (Object[]) value;
+						int k = 0;
+						while (k < array.length) {
+							out.print(array[k++]);
+							if (k < array.length)
+								out.print(',');
+						}
+						out.println();
+					} else {
+						out.println(value);
+					}
+				}
+				sr = null;
+			}
+			srefs = null;
+		} else {
+			out.println("No "+(interfaceName==null?"Service":interfaceName)+" with the filter:" + filter);
+		}
+	}
+
+	/**
+	 * list a dictionary
+	 * @param dictionary
+	 * @return
+	 */
+	public static StringBuffer listDictionary(Dictionary dictionary, String prefix) {
+		StringBuffer sb=new StringBuffer();
+		Enumeration enumeration=dictionary.keys();
+		while(enumeration.hasMoreElements()){
+			if(prefix!=null) sb.append(prefix);
+			String name=(String) enumeration.nextElement();
+			String value=(String) dictionary.get(name);
+			sb.append(name).append('=').append(value).append('\n');			
+		}
+		return sb;
+	}
+}
\ No newline at end of file

Propchange: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/Util.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireAdminBinderException.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireAdminBinderException.java?rev=611491&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireAdminBinderException.java (added)
+++ felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireAdminBinderException.java Sat Jan 12 13:51:47 2008
@@ -0,0 +1,16 @@
+package org.apache.felix.sandbox.wireadminbinder;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class WireAdminBinderException extends Exception {
+
+	public WireAdminBinderException(String msg) {
+		super(msg);
+	}
+
+	public WireAdminBinderException(String msg, Throwable t) {
+		super(msg,t);
+	}
+
+}

Propchange: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireAdminBinderException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireAdminBinderService.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireAdminBinderService.java?rev=611491&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireAdminBinderService.java (added)
+++ felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireAdminBinderService.java Sat Jan 12 13:51:47 2008
@@ -0,0 +1,29 @@
+/*
+ *   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.sandbox.wireadminbinder;
+
+import org.osgi.service.wireadmin.Wire;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public interface WireAdminBinderService {
+	public WireAppManager[] getWireApps();
+	public Wire[] getManagedWires();
+	public Wire[] getManagedWires(String wireAppId);
+	public Wire[] getManagedWires(String wireAppId,String WireSetId);
+}

Propchange: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireAdminBinderService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireApp.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireApp.java?rev=611491&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireApp.java (added)
+++ felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireApp.java Sat Jan 12 13:51:47 2008
@@ -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.sandbox.wireadminbinder;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * represents the wireapp element
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class WireApp implements Serializable {
+	
+	private String id;
+	private String description;
+	private List wiresets;
+
+	
+	
+	/**
+	 * @return
+	 */
+	public String getId() {
+		return id;
+	}
+
+	/**
+	 * @return
+	 */
+	public List getWiresets() {
+		return wiresets;
+	}
+
+	/**
+	 * @return
+	 */
+	public String getDescription() {
+		return description;
+	}
+
+	/**
+	 * @param string
+	 */
+    public void setId(String id) {
+		this.id = id;
+	}
+
+	/**
+	 * @param wireset
+	 */
+    public void addWireset(WireSet wireset) {
+		if(wiresets==null) wiresets=new LinkedList();
+		wiresets.add(wireset);
+	}
+
+	/**
+	 * @param string
+	 */
+    public void setDescription(String string) {
+		description = string;
+	}
+
+	public String toString() {
+		StringBuffer sb=new StringBuffer();
+		sb.append('[');
+		sb.append("id=").append(id);
+		sb.append(";description=").append(description);
+		sb.append(";wiresets=").append(wiresets);
+		sb.append(']');
+		return sb.toString();
+	}	
+	
+	
+	public void process() throws Throwable {
+		if (id == null)
+			throw new IllegalArgumentException("attribute id is missing");
+	}
+
+}

Propchange: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireApp.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireAppManager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireAppManager.java?rev=611491&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireAppManager.java (added)
+++ felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireAppManager.java Sat Jan 12 13:51:47 2008
@@ -0,0 +1,79 @@
+/*
+ *   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.sandbox.wireadminbinder;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.wireadmin.WireAdmin;
+
+/**
+ * manages a wireapp
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class WireAppManager {
+	private BundleContext bundleContext;
+	private WireAdmin wireAdmin;
+    private WireApp wireApp;
+    private List wireSets;
+    
+    public WireAppManager(BundleContext bundleContext, WireAdmin wireAdmin, WireApp wireApp) throws SecurityException, IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, BundleException, InvalidSyntaxException
+    {
+        this.bundleContext=bundleContext;
+        this.wireAdmin=wireAdmin;
+        this.wireApp=wireApp;
+        this.wireSets=new ArrayList();
+        Collection wireSetMetadatas = wireApp.getWiresets();
+        if(wireSetMetadatas!=null){                
+            Iterator iter = wireSetMetadatas.iterator();
+            while (iter.hasNext()) {
+                WireSetManager wireSetManager = new WireSetManager(bundleContext,wireAdmin,(WireSet) iter.next());
+                wireSets.add(wireSetManager);
+            }
+        }
+    }
+    
+    public void dispose(){
+        Iterator iter=wireSets.iterator();
+        while(iter.hasNext()){
+            ((WireSetManager)iter.next()).stop();
+        }        
+        wireSets=null;
+        
+        wireAdmin=null;
+        bundleContext=null;
+    }
+    
+	public String toString() {
+		StringBuffer sb=new StringBuffer();
+		sb.append('[');
+		sb.append("metadata=").append(wireApp);
+		sb.append(";wiresets=").append(wireSets);
+		sb.append(']');
+		return sb.toString();
+	}
+
+	public WireApp getWireAppMetadata() {
+		return wireApp;
+	}
+}

Propchange: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireAppManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireSet.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireSet.java?rev=611491&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireSet.java (added)
+++ felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireSet.java Sat Jan 12 13:51:47 2008
@@ -0,0 +1,205 @@
+/*
+ *   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.sandbox.wireadminbinder;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * the wireset element
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class WireSet implements Serializable {
+
+	/**
+	 * indicates to keep alive the wire 
+	 * when the producer or the consumer are unregistered
+	 */
+	public final static String REMOVE_POLICY_KEEPALIVE="keepAlive";
+	/**
+	 * indicates to delete the wire 
+	 * until the producer is unregistered
+	 */
+	public final static String REMOVE_POLICY_WHILEPRODUCER="whileProducer";
+	/**
+	 * indicates to delete the wire 
+	 * until the consumer is unregistered
+	 */
+	public final static String REMOVE_POLICY_WHILECONSUMER="whileConsumer";
+	/**
+	 * indicates to delete the wire 
+	 * when the producer or the consumer are unregistered
+	 */
+	public final static String REMOVE_POLICY_IFDISCONNECTED="ifDisconnected";
+
+	
+	private String producersFilter;
+	private String consumersFilter;
+	private String producerPID;
+	private String consumerPID;
+	private String removepolicy=REMOVE_POLICY_IFDISCONNECTED;
+	private String id;
+	private String description;
+	private List properties;
+
+	// private boolean mandatory; for lifecycle management
+	
+	/**
+	 * @return
+	 */
+	public String getConsumersFilter() {
+		return consumersFilter;
+	}
+
+	/**
+	 * @return
+	 */
+	public String getDescription() {
+		return description;
+	}
+
+	/**
+	 * @return
+	 */
+	public String getId() {
+		return id;
+	}
+
+	/**
+	 * @return
+	 */
+	public String getRemovepolicy() {
+		return removepolicy;
+	}
+
+	/**
+	 * @return
+	 */
+	public String getProducersFilter() {
+		return producersFilter;
+	}
+
+	/**
+	 * @return
+	 */
+	public List getProperties() {
+		return properties;
+	}
+
+	
+	/**
+	 * @return the producerPID
+	 */
+	public String getProducerPID() {
+		return producerPID;
+	}
+
+
+	/**
+	 * @return the consumerPID
+	 */
+	public String getConsumerPID() {
+		return consumerPID;
+	}
+
+	
+	/**
+	 * @param string
+	 */
+    public void setConsumersFilter(String string) {
+		consumersFilter = string;
+	}
+
+	/**
+	 * @param string
+	 */
+    public void setDescription(String string) {
+		description = string;
+	}
+
+	/**
+	 * @param string
+	 */
+    public void setId(String string) {
+		id = string;
+	}
+
+	/**
+	 * @param string
+	 */
+    public void setRemovepolicy(String string) {
+		removepolicy = string;
+	}
+
+	/**
+	 * @param string
+	 */
+    public void setProducersFilter(String string) {
+		producersFilter = string;
+	}
+
+	/**
+	 * @param list
+	 */
+	public void addProperty(Property prop) {
+		if(properties==null) properties=new LinkedList();
+		properties.add(prop);
+	}
+
+	/**
+	 * @param producerPID the producerPID to set
+	 */
+	public void setProducerPID(String producerPID) {
+		this.producerPID = producerPID;
+	}
+
+	/**
+	 * @param consumerPID the consumerPID to set
+	 */
+	public void setConsumerPID(String consumerPID) {
+		this.consumerPID = consumerPID;
+	}
+	
+	public void process() throws Throwable {
+		if (id == null)
+			throw new IllegalArgumentException("attribute id is missing");
+		if (consumerPID!=null & consumersFilter!=null)
+			throw new IllegalArgumentException("could not have both consumerPID and consumersFilter");
+		if (consumerPID==null & consumersFilter==null)
+			throw new IllegalArgumentException("consumerPID or consumersFilter are missing");
+		if (producerPID!=null & producersFilter!=null)
+			throw new IllegalArgumentException("could not have both producerPID and producersFilter");
+		if (producerPID==null & producersFilter==null)
+			throw new IllegalArgumentException("producerPID or producersFilter are missing");
+	}
+	
+	public String toString() {
+		StringBuffer sb=new StringBuffer();
+		sb.append('[');
+		sb.append("id=").append(id);
+		if(producersFilter!=null) sb.append(";producersFilter=").append(producersFilter);
+		if(producerPID!=null) sb.append(";producerPID=").append(producerPID);
+		if(consumersFilter!=null) sb.append(";consumersFilter=").append(consumersFilter);
+		if(consumerPID!=null) sb.append(";consumerPID=").append(consumerPID);
+		if(description!=null) sb.append(";description=").append(description);
+		if(properties!=null) sb.append(";properties=").append(properties);
+		sb.append(']');
+		return sb.toString();
+	}
+}

Propchange: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireSet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireSetManager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireSetManager.java?rev=611491&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireSetManager.java (added)
+++ felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireSetManager.java Sat Jan 12 13:51:47 2008
@@ -0,0 +1,525 @@
+/*
+ *   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.sandbox.wireadminbinder;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collection;
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.wireadmin.Consumer;
+import org.osgi.service.wireadmin.Producer;
+import org.osgi.service.wireadmin.Wire;
+import org.osgi.service.wireadmin.WireAdmin;
+import org.osgi.service.wireadmin.WireAdminEvent;
+import org.osgi.service.wireadmin.WireAdminListener;
+import org.osgi.service.wireadmin.WireConstants;
+
+/**
+ * manages a wireset
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class WireSetManager {
+    	private BundleContext bundleContext;
+    	private WireAdmin wireAdmin;
+        private WireSet wireSet;
+        private Set consumersSet;
+        private ConsumerListener consumerListener;
+        private Set producersSet;
+        private ProducerListener producerListener;
+        private Set wires;
+        private Dictionary wiresCreationProperties;
+        private ServiceRegistration walistenerReg;
+        private WAListener walistener;
+        private boolean traceFlag=false;
+        
+        public WireSetManager(BundleContext bundleContext, WireAdmin wireAdmin, WireSet wireSet) throws ClassNotFoundException,
+                SecurityException, NoSuchMethodException,
+                IllegalArgumentException, InstantiationException,
+                IllegalAccessException, InvocationTargetException, BundleException, InvalidSyntaxException {
+            this.bundleContext=bundleContext;
+            this.wireAdmin=wireAdmin;
+            this.consumersSet = new HashSet();
+            this.producersSet = new HashSet();
+            this.wires = new HashSet();
+            this.wireSet = wireSet;
+            if (this.wireSet != null) {
+                wiresCreationProperties = new Hashtable();
+                Collection properties=wireSet.getProperties();
+                if(properties!=null){                    
+	                Iterator iter =properties.iterator();
+	                while (iter.hasNext()) {
+	                    Property property = (Property) iter
+	                            .next();
+	                    String type = property.getType();
+	                    Class clazz = WireSetManager.class.getClassLoader()
+	                            .loadClass(type);
+	                    Constructor constructor = clazz
+	                            .getConstructor(new Class[] { String.class });
+	                    wiresCreationProperties
+	                            .put(
+	                                    property.getName(),
+	                                    constructor
+	                                            .newInstance(new Object[] { property
+	                                                    .getValue() }));
+	                }
+                }
+            }
+            // register the listeners
+            try {
+                consumerListener = new ConsumerListener(this);
+                consumerListener.fillServices();
+            } catch (InvalidSyntaxException e) {
+                throw new BundleException("Invalid LDAP filter:"+this.wireSet.getConsumersFilter(), e);
+            }
+
+            try {
+                producerListener = new ProducerListener(this);
+                producerListener.fillServices();
+            } catch (InvalidSyntaxException e) {
+                throw new BundleException("Invalid LDAP filter:"+this.wireSet.getProducersFilter(), e);
+            }
+
+            // register the listeners
+            bundleContext.addServiceListener(consumerListener,filterConsumerStr);
+            bundleContext.addServiceListener(producerListener,filterProducerStr);
+/*            walistener= new WAListener();
+            Dictionary properties=new Hashtable();
+            properties.put(WireConstants.WIREADMIN_EVENTS,new Integer(WireAdminEvent.WIRE_DELETED));
+            walistenerReg=bundleContext.registerService(WireAdminListener.class.getName(),walistener,properties);
+*/        }
+
+        public void stop(){
+            wireSet=null;
+            
+            consumersSet=null;
+            producersSet=null;
+
+/*            walistenerReg.unregister();
+            walistener=null;
+*/            
+            bundleContext.removeServiceListener(consumerListener);
+            consumerListener=null;
+
+            bundleContext.removeServiceListener(producerListener);
+            producerListener=null;
+            
+            Iterator iter=wires.iterator();
+            while(iter.hasNext()){
+                wireAdmin.deleteWire((Wire)iter.next());
+            }
+            wires=null;
+            
+            wiresCreationProperties=null;
+            
+            wireAdmin=null;
+            bundleContext=null;
+        }
+        
+    	public String toString() {
+    		StringBuffer sb=new StringBuffer();
+    		sb.append('[');
+    		sb.append("metadata=").append(wireSet);
+    		sb.append(";producersSet=").append(producersSet);
+    		sb.append(";consumersSet=").append(consumersSet);
+    		sb.append(";wires=").append(wires);
+    		sb.append(']');
+    		return sb.toString();
+    	}
+
+    	/**
+    	 * this listener listens wire deletion. The deletion can be initiated by the wireset or from another bundle/tool (eg wa deleteall, wa delete wire.pid, ...)
+    	 * <p>it could be use to handle wire connection and disconnection
+    	 **/
+    	class WAListener implements WireAdminListener {
+
+            /**
+             * @see org.osgi.service.wireadmin.WireAdminListener#wireAdminEvent(org.osgi.service.wireadmin.WireAdminEvent)
+             */
+            public void wireAdminEvent(WireAdminEvent wireAdminEvent) {
+                if(wireAdminEvent.getType()==WireAdminEvent.WIRE_DELETED) {
+                    Wire wire=wireAdminEvent.getWire();
+                    if(wires.remove(wire)){
+                        trace(	getClass().getName()
+                                + ".wireAdminEvent():wirepid="+wire.getProperties().get(WireConstants.WIREADMIN_PID)
+                        		+ '\n' + (wire.isValid() ? "valid, ": "not valid, ")
+                            	+ '\n' + (wire.isConnected() ? "connected": "disconnected")	
+                				+ '\n' + Util.listDictionary(wire.getProperties(), "\t").toString()
+                                );
+                    }
+                }
+            }
+    	}
+
+        private final String filterConsumerStr="("+Constants.OBJECTCLASS+"="+Consumer.class.getName()+")";
+
+        class ConsumerListener implements ServiceListener {
+
+	    private WireSetManager wireSetManager;
+            private String filterStr;        
+            private Filter filter;
+            private boolean traceFlag=false;
+        
+            public ConsumerListener(WireSetManager wireSetManager)
+                    throws InvalidSyntaxException {
+                this.wireSetManager = wireSetManager;
+                this.filterStr = "(&"+filterConsumerStr
+                        + wireSetManager.wireSet.getConsumersFilter() + ")";
+                this.filter = bundleContext.createFilter(filterStr);
+                trace(this.getClass().getName()+":filterStr="+filterStr);
+            }
+        
+            public void fillServices() throws InvalidSyntaxException {
+                trace(getClass().getName()+".fillServices()");
+                // get references on service
+                ServiceReference[] refs = bundleContext.getServiceReferences(null,
+                        filterConsumerStr);
+                //ServiceReference[]
+                // refs=context.getServiceReferences(Consumer.class.getName(),null);
+                if (refs == null)
+                    return;
+                for (int i = 0; i < refs.length; i++) {
+                    ServiceReference serviceReference=refs[i];
+                    if(filter.match(new ServiceReferenceDelegate(serviceReference))){
+                        wireSetManager.consumersSet.add(serviceReference);
+                        // create wires with consumers in customersSet
+                        createWires(serviceReference);
+                    }
+                }
+            }
+        
+            public void serviceChanged(ServiceEvent e) {
+                trace(getClass().getName()+".serviceChanged()");
+                ServiceReference servref = e.getServiceReference();
+                switch (e.getType()) {
+                case ServiceEvent.REGISTERED:
+                    trace(getClass().getName()+".serviceChanged():REGISTERED");
+                    if(filter.match(new ServiceReferenceDelegate(servref))){
+                    trace(servref + " (from "
+                            + servref.getBundle().getLocation() + ") is added");
+                    wireSetManager.consumersSet.add(servref);
+                    // create wires with producers in producersSet
+                    //synchronized(wireSetManager) {
+                    	createWires(servref);
+                    //}
+                    };
+                    break;
+                case ServiceEvent.UNREGISTERING:
+                    trace(getClass().getName()+".serviceChanged():UNREGISTERING");
+                	//if(filter.match(new ServiceReferenceDelegate(servref))){
+                	// test filter is not useful since if the ref is in the consumer set, it matchs the filter
+                		if (wireSetManager.consumersSet.remove(servref)) {
+                	        trace(servref + " is removed");
+                	        // delete wires with consumers in customersMap
+                	        //synchronized(wireSetManager) {
+                	        deleteWires(servref);
+                	        //}
+                	    }
+                    //}
+                    break;
+                case ServiceEvent.MODIFIED:
+                    trace(getClass().getName()+".serviceChanged(): MODIFIED");
+                    if (wireSetManager.consumersSet.contains(servref) && !filter.match(new ServiceReferenceDelegate(servref))) {
+                        trace(servref
+                                + " is removed since properties has changed");
+                        wireSetManager.consumersSet.remove(servref);
+                        // delete wires with producers in producersSet
+                        //synchronized(wireSetManager) {
+                        deleteWires(servref);
+                        //}
+                    }
+                    break;
+                }
+            }
+        
+            /**
+             * create wires with producers in producersSet 
+             */
+            private void createWires(ServiceReference consservref) {
+                	
+                String consumerPid= (String) consservref.getProperty(Constants.SERVICE_PID);
+                // test if the wire is already created with this consumer
+                Iterator wireiter = wireSetManager.wires.iterator();
+		        while (wireiter.hasNext()) {
+                    Wire wire = (Wire) wireiter.next();
+                    Dictionary properties=wire.getProperties();
+                    if(properties.get(WireConstants.WIREADMIN_CONSUMER_PID).equals(consumerPid)){
+                        return;
+                    }
+                }
+                
+                // create wire with each producer
+                Iterator iter = wireSetManager.producersSet.iterator();
+                while (iter.hasNext()) {
+                    ServiceReference prodservref = (ServiceReference) iter.next();
+                    Wire wire = wireAdmin.createWire(
+                            (String) prodservref
+                                    .getProperty(Constants.SERVICE_PID),
+                            consumerPid,
+                            wireSetManager.wiresCreationProperties);
+                    traceWire(wire, wireSetManager.toString()+" wire created:");
+                    wireSetManager.wires.add(wire);
+                }                
+            }
+        
+            /**
+             * delete wires with this consumer
+             * */
+            private void deleteWires(ServiceReference consservref) {
+
+                String policy = wireSetManager.wireSet.getRemovepolicy();
+                if (policy.equals(WireSet.REMOVE_POLICY_IFDISCONNECTED)
+                        || policy.equals(WireSet.REMOVE_POLICY_WHILECONSUMER)) {
+        
+                    Object consumerPid = consservref
+                            .getProperty(Constants.SERVICE_PID);
+                    Iterator iter = wireSetManager.wires.iterator();
+        
+                    while (iter.hasNext()) {
+                        Wire wire = (Wire) iter.next();
+                        Dictionary properties = wire.getProperties();
+        
+                        if (consumerPid.equals(properties
+                                .get(WireConstants.WIREADMIN_CONSUMER_PID))) {
+                            wireAdmin.deleteWire(wire);
+                            traceWire(wire,	wireSetManager.toString() + " wire deleted:");
+                            // delete the wire                  
+                            iter.remove();
+                            // break; // TODO since only one consumer have this pid
+                        }
+                    }
+                }
+            }
+
+//            public void setTrace(boolean traceFlag){
+//                this.traceFlag=traceFlag;
+//            }
+//            /**
+//             * 
+//             * @param tracemsg
+//             */
+//            void trace(String tracemsg) {
+//                if(traceFlag) System.err.println(tracemsg);
+//            }
+        }
+
+	private final String filterProducerStr="("+Constants.OBJECTCLASS+"="+Producer.class.getName()+")";
+	
+        class ProducerListener implements ServiceListener {
+        
+            private WireSetManager wireSetManager;
+            private String filterStr;
+            private Filter filter;
+            private boolean traceFlag=false;
+        
+            public ProducerListener(WireSetManager wireSetManager) throws InvalidSyntaxException {
+                this.wireSetManager = wireSetManager;
+                this.filterStr = "(&"+filterProducerStr
+                        + wireSetManager.wireSet.getProducersFilter() + ")";
+                this.filter = bundleContext.createFilter(filterStr);
+                trace(this.getClass().getName()+":filterStr="+filterStr);
+            }
+        
+            public void fillServices() throws InvalidSyntaxException {
+                trace(getClass().getName()+".fillServices()");
+                // get references on service
+                ServiceReference[] refs = bundleContext.getServiceReferences(null,
+                        filterProducerStr);
+                //ServiceReference[]
+                // refs=context.getServiceReferences(Producer.class.getName(),null);
+                if (refs == null)
+                    return;
+                for (int i = 0; i < refs.length; i++) {
+                    ServiceReference serviceReference=refs[i];
+                    if(filter.match(new ServiceReferenceDelegate(serviceReference))){
+                    Object svc = bundleContext.getService(serviceReference);
+                    if (svc != null) {
+                        wireSetManager.producersSet.add(serviceReference);
+                        // create wires with consumers in customersSet
+                        createWires(serviceReference);
+                    }
+                    }
+                }
+            }
+        
+            public void serviceChanged(ServiceEvent e) {
+                trace(getClass().getName()+".serviceChanged()");
+                ServiceReference servref = e.getServiceReference();
+                Object ref;
+                switch (e.getType()) {
+                case ServiceEvent.REGISTERED:
+                    trace(getClass().getName()+".serviceChanged():REGISTERED");
+                if(filter.match(new ServiceReferenceDelegate(servref))){
+                    trace(servref + " (from " + servref.getBundle().getLocation()
+                            + ") is added");
+                    wireSetManager.producersSet.add(servref);
+                    // create wires with consumers in customersSet
+                    //synchronized(wireSetManager) {
+                    createWires(servref);
+                    //}
+                    };
+                    break;
+                case ServiceEvent.UNREGISTERING:
+                    trace(getClass().getName()+".serviceChanged():UNREGISTERING");
+                //if(filter.match(new ServiceReferenceDelegate(servref))){
+               	// test filter is not useful since if the ref is in the consumer set, it matchs the filter
+                                    if(wireSetManager.producersSet.remove(servref)) {
+                        trace(servref + " is removed");
+                        // delete wires with consumers in customersSet
+                        //synchronized(wireSetManager) {
+                        	deleteWires(servref);
+                        //}
+                    }
+                //}
+                break;
+                case ServiceEvent.MODIFIED:
+                    trace(getClass().getName()+".serviceChanged():MODIFIED");
+                    if (wireSetManager.producersSet.contains(servref) && !filter.match(new ServiceReferenceDelegate(servref))) {
+                        trace(servref + " is removed since properties has changed");
+                        wireSetManager.producersSet.remove(servref);
+                        // delete wires with consumers in customersSet
+                        // synchronized(wireSetManager) { 
+                            deleteWires(servref);
+                        //}
+                    }
+                    break;
+                }
+            }
+        
+            /**
+             * create wires with consumers in customersSet
+             */
+            private void createWires(ServiceReference prodservref) {
+                // test if the wire is already created with this producer
+                String producerPid= (String) prodservref.getProperty(Constants.SERVICE_PID);
+                Iterator wireiter = wireSetManager.wires.iterator();
+                while (wireiter.hasNext()) {
+                    Wire wire = (Wire) wireiter.next();
+                    Dictionary properties=wire.getProperties();
+                    if(properties.get(WireConstants.WIREADMIN_PRODUCER_PID).equals(producerPid)){
+                        return;
+                    }
+                }
+
+                // create wire with each consumer
+                Iterator iter = wireSetManager.consumersSet.iterator();
+                while (iter.hasNext()) {
+                    ServiceReference conservref = (ServiceReference) iter.next();
+                    Wire wire = wireAdmin
+                            .createWire(
+                                    producerPid,
+                                    (String) conservref
+                                            .getProperty(Constants.SERVICE_PID),
+                                    wireSetManager.wiresCreationProperties);
+                    wireSetManager.wires.add(wire);
+                    traceWire(	wire, wireSetManager.toString()+" wire created:");
+                }
+            }
+        
+            /**
+             * delete wires with this producer
+             * */
+            private void deleteWires(ServiceReference prodservref) {        
+                String policy = wireSetManager.wireSet.getRemovepolicy();
+                if (policy.equals(WireSet.REMOVE_POLICY_IFDISCONNECTED)
+                        || policy.equals(WireSet.REMOVE_POLICY_WHILEPRODUCER)) {
+        
+                    Object producerPid = prodservref
+                            .getProperty(Constants.SERVICE_PID);
+                    Iterator iter = wireSetManager.wires.iterator();
+        
+                    while (iter.hasNext()) {
+                        Wire wire = (Wire) iter.next();
+                        Dictionary properties = wire.getProperties();
+        
+                        if (producerPid.equals(properties
+                                .get(WireConstants.WIREADMIN_PRODUCER_PID))) {
+                            wireAdmin.deleteWire(wire);
+                            traceWire(wire,	wireSetManager.toString() + " wire deleted:");
+                            // delete the wire
+                            iter.remove();
+                            // break; // TODO since only one producer have this pid
+                        }
+                    }
+                }
+            }
+
+//            public void setTrace(boolean traceFlag){
+//                this.traceFlag=traceFlag;
+//            }
+//            /**
+//             * 
+//             * @param tracemsg
+//             */
+//            void trace(String tracemsg) {
+//                if(traceFlag) System.err.println(tracemsg);
+//            }
+        }
+
+        public void setTrace(boolean traceFlag){
+            this.traceFlag=traceFlag;
+//            if(consumerListener!=null) consumerListener.setTrace(traceFlag);
+//            if(producerListener!=null) producerListener.setTrace(traceFlag);
+        }
+        /**
+         * 
+         * @param tracemsg
+         */
+        void trace(String tracemsg) {
+            if(traceFlag) System.err.println(tracemsg);
+        }
+        
+        void traceWire(Wire wire, String header){
+            trace(header+wire.getProperties().get(WireConstants.WIREADMIN_PID)
+        		+ '\n' + (wire.isValid() ? "valid, ": "not valid, ")
+            	+ '\n' + (wire.isConnected() ? "connected": "disconnected")	
+				+ '\n' + Util.listDictionary(wire.getProperties(), "\t").toString()
+                );
+        }
+        
+        void traceWires(Collection wires, String header){
+            trace(header);
+            if (wires != null) {
+                Iterator iter=wires.iterator();
+                if(!iter.hasNext()) {
+                    trace("No wire");
+                    return;
+                }
+                for (int i = 0; iter.hasNext(); i++) {
+                    Wire wire=(Wire)iter.next();
+                    traceWire(wire,"Wire #" + i + ":\n");
+                }
+            } else {
+                trace("No wire");
+            }
+
+        }
+    }

Propchange: felix/sandbox/donsez/wireadminbinder/src/main/java/org/apache/felix/sandbox/wireadminbinder/WireSetManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadminbinder/src/main/resource/org/apache/felix/sandbox/wireadminbinder/wireapp.dtd
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadminbinder/src/main/resource/org/apache/felix/sandbox/wireadminbinder/wireapp.dtd?rev=611491&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadminbinder/src/main/resource/org/apache/felix/sandbox/wireadminbinder/wireapp.dtd (added)
+++ felix/sandbox/donsez/wireadminbinder/src/main/resource/org/apache/felix/sandbox/wireadminbinder/wireapp.dtd Sat Jan 12 13:51:47 2008
@@ -0,0 +1,124 @@
+<!--
+ 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.
+-->
+<!--
+  DTD for org.apache.felix.sandbox.wireadminbinder descriptor DTD
+
+  Author : Felix Project Team
+  Date : March 2, 2004
+  Last Update: January 12, 2008
+-->
+
+<!--
+<!ENTITY %descriptionatt "description CDATA #IMPLIED">
+<!ENTITY %idatt "id CDATA #IMPLIED">
+<!ENTITY %filteratt "filter CDATA #REQUIRED">
+-->
+
+
+<!--
+WireApp describes a list of related wiresets
+
+wireadmin-servicepid is the service.pid properties of the wire admin that manages this application
+-->
+<!ELEMENT wireapp (wireset+)>
+<!ATTLIST  wireapp
+	id CDATA #REQUIRED
+	description CDATA #IMPLIED
+>
+
+<!--
+WireSet describes a set of wires created between producers and consumers
+
+producers-filter: the LDAP filter to select a subset of registered producers
+	service.pid could be use to select only one producer
+	Examples of one producer:
+			producers-filter="(service.pid=org.apache.felix.sample.clock)"
+			producerPID="org.apache.felix.sample.clock"
+	Examples of many producers:
+			producers-filter="(service.pid=org.apache.felix.sample.*)"
+			producers-filter="(wireadmin.producer.flavors=org.osgi.position.Position)"
+	
+consumers-filter: the LDAP filter to select a subset of registered consumers
+	service.pid could be use to select only one consumer
+	Examples of many consumer:
+			consumers-filter="(service.pid=org.apache.felix.sample.consumerservlet)"
+			consumerPID="org.apache.felix.sample.consumerservlet"
+	Examples of many consumers:
+			consumers-filter="(service.pid=org.apache.felix.sample.*)"
+			consumers-filter="(wireadmin.consumer.flavors=org.osgi.position.Position)"	
+	
+removepolicy indicates what to do with the wire when the producer or the consumer is unregistered
+	removepolicy="keepAlive" : the wire is keep alive when the producer or the consumer are unregistered. 	
+	removepolicy="whileProducer" : the wire is deleted when the producer is unregistered.
+	removepolicy="whileConsumer" : the wire is deleted when the consumer is unregistered.
+	removepolicy="ifDisconnected" : the wire is deleted when the producer or the consumer are unregistered (ie the wire is "disconnected")
+
+TODO : in fact, this could be not relevant
+manage="own" : manages (remove) only the wires created by the wireadminbinder
+manage="other" : manages (remove) all wires
+-->
+<!ELEMENT wireset (producersFilter?,consumersFilter?,property*)>
+<!ATTLIST  wireset
+	id CDATA #REQUIRED
+	description CDATA #IMPLIED
+	producers-filter CDATA #IMPLIED
+	consumers-filter CDATA #IMPLIED
+	producerPID CDATA #IMPLIED
+	consumerPID CDATA #IMPLIED
+	removepolicy (keepAlive|whileProducer|whileConsumer|ifDisconnected) 'keepAlive'
+>
+
+<!ELEMENT producersFilter (#PCDATA)>
+<!ELEMENT consumersFilter (#PCDATA)>
+
+<!--
+property describes a wire-creation property
+	Example for OSGi Spec R3, 16.7 Wire Flow Control
+
+	Filtering by Time (16.7.1)
+	<property
+		name="wireadmin.filter"
+		type="java.lang.String"
+	><![CDATA[(wirevalue.elapsed>=2000)]]></property>
+	Filtering by Change (16.7.2) Absolute value delta
+	<property
+		name="wireadmin.filter"
+		type="java.lang.String"
+	><![CDATA[(wirevalue.delta.relative>=0.1)]]></property>
+	
+	Filtering by Change (16.7.2) Relative value delta
+	<property
+		name="wireadmin.filter"
+		type="java.lang.String"
+	><![CDATA[(wirevalue.delta.absolute>=1)]]></property>
+	Hysteresis (16.7.3)
+	<property
+		name="wireadmin.filter"
+		type="java.lang.String"
+	><![CDATA[(|(&(wirevalue.previous<=250)(wirevalue.current>250))(&(wirevalue.previous>=249)(wirevalue.current<249)))]]></property>
+
+	Other properties could be setted
+-->
+
+<!ELEMENT property (#PCDATA)>
+<!ATTLIST  property
+	name CDATA #REQUIRED
+	value CDATA #IMPLIED
+	type CDATA #REQUIRED
+>

Propchange: felix/sandbox/donsez/wireadminbinder/src/main/resource/org/apache/felix/sandbox/wireadminbinder/wireapp.dtd
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadminbinder/src/site/readme.html
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadminbinder/src/site/readme.html?rev=611491&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadminbinder/src/site/readme.html (added)
+++ felix/sandbox/donsez/wireadminbinder/src/site/readme.html Sat Jan 12 13:51:47 2008
@@ -0,0 +1,133 @@
+<html>
+<head>
+<title>WireAdmin Binder</title>
+</head>
+<body>
+
+<!-- Start of Bundle Documentation -->
+<hr width="100%" size="2">
+<h1><i><a name="org.osgi.felix.sandbox.wireadminbinder"></a><font color="#0000aa">WireAdmin Binder</font></i></h1>
+
+<p>
+<b>Description</b><br>
+automates the creation and deletion of wires between producers and consumers
+<br>For more details on how to use this bundle, refer to the /doc/readme.html file embedded in the bundle jarfile.<br>
+</p>
+
+<p>
+<b>Contributors</b><br>
+<ul>
+<li>Author: Apache Felix Team</li>
+</ul>
+</p>
+
+<p>
+<b>License</b><br>
+ASL2.0
+</p>
+
+<p>
+<b>Services</b><br>
+<ul>
+<li>None</li>
+</ul>
+</p>
+
+<p>
+<b>Properties</b><br>
+<ul>
+<li>org.apache.felix.sandbox.wireadminbinder.trace=true|false</li>
+</ul>
+</p>
+
+<p><b>Requirements</b><br>
+<li>org.osgi.service.wireadmin; specification-version=1.0.0<li>
+</p>
+
+<!-- End of OSCAR Bundle Documentation -->
+
+<hr width="100%" size="2">
+
+<!-- Start of extra information  -->
+
+
+<p id="build">
+<b>Build</b><br>
+<ol>
+<li>build with Maven (<code>mvn clean install</code>)</li>
+</ol>
+</p>
+
+<p id="settings">
+<b>Metadata Settings</b><br>
+
+<br> The bundle' manifest should contains this entry. 
+<pre>
+WireAdminBinder-Metadata: /WAB-INF/wireadminbinder.xml
+</pre>
+</p>
+
+<script language="JavaScript">
+function openOnTheFly() {
+  myWin= open("wireadminbinder.dtd", "DTD for WireAdminBinder", "status=yes,toolbar=yes,menubar=yes");
+  myWin.document.open("text/plain");
+  myWin.document.close();  
+}
+</script>
+
+<p id="metadata">
+<b>Metadata Settings</b><br>
+<!--have a look on the <a href="javascript:openOnTheFly()">wireadminbinder.dtd</a> file -->
+have a look on the <a href="wireadminbinder.dtd">wireadminbinder.dtd</a> file
+</p>
+
+<p id="rundemo">
+<b>Run the demo</b><br>
+To run the demo of this bundle, enter in the Felix shell the <a href="script.txt">commands</a><br>
+</p>
+
+<p id="typicalusage">
+<b>Typical Usages</b><br>
+WireAdminBinder' BaseActivator could be embedded inside others bundles
+(that provide consumer services, producer services or none)<br>
+<a href='dev/osgi/wireadminbinderdemo/readme.html'>A simple demonstrator of WireAdminBinder</a> gives an example of the usage.
+</p>
+
+<p id="platforms">
+<b>Tested platforms</b><br>
+<ul>
+<li>Felix (done)</li>
+<li><a href="http://oscar.objectweb.org/">Oscar</a> (done)</li>
+<li>Apache Felix (done)</li>
+<li>Equinox (to do)</li>
+</ul>
+</p>
+
+
+<p id="versions">
+<b>Versions history</b><br>
+<ul>
+</ul>
+</p>
+
+
+<p id="todo">
+<b>TODO (contributions are welcome)</b><br>
+<ul>
+<li>2007-12-19: add consumersFilter and producersFilter elements to set LDAP filters in CDATA section</li>
+<li>2007-12-19: add consumerPid and producerPid attributes in wireset elements to simplify PID setting</li>
+<li>2007-12-19: add wireapp lifecycle control in wiresets</li>
+<li>2007-12-19: provides a XML schema definition of the metadata</li>
+</ul>
+</p>
+
+<p id="links">
+<b>Links</b><br>
+<ul>
+<li>WireAdminBinder was presented at CCNC08:
+Humberto Cervantes, Didier Donsez, Lionel Touseau, "An Architecture Description Language for Dynamic Sensor-Based Applications", 5th IEEE Consumer Communications and Networking Conference (CCNC) 2008, http://www.ieee-ccnc.org/</li> 
+</ul>
+</p>
+
+</body>
+</html>

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

Added: felix/sandbox/donsez/wireadminbinder/src/site/script.txt
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadminbinder/src/site/script.txt?rev=611491&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadminbinder/src/site/script.txt (added)
+++ felix/sandbox/donsez/wireadminbinder/src/site/script.txt Sat Jan 12 13:51:47 2008
@@ -0,0 +1,14 @@
+
+obr remove-url file:C:\Docume~1\donsez\.m2\repository\repository.xml
+obr add-url file:C:\Docume~1\donsez\.m2\repository\repository.xml
+
+obr start "WireAdmin"
+obr start "Apache Felix Wire Admin Binder";0.1.0
+obr start "Apache Felix Wire Admin Binder Command";0.1.0
+wab list
+
+wab base file:F:\osgi\felix\sandbox\donsez\wireadminbinder.cmd\src\site\
+wab base
+
+wab start wab1.xml
+wab start wab10.xml

Propchange: felix/sandbox/donsez/wireadminbinder/src/site/script.txt
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message