Commit the new iPOJO version (0.7.6).

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@642265 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/white.board.pattern.handler/metadata.xml b/ipojo/white.board.pattern.handler/metadata.xml
new file mode 100644
index 0000000..75de2bb
--- /dev/null
+++ b/ipojo/white.board.pattern.handler/metadata.xml
@@ -0,0 +1,6 @@
+<ipojo>

+	<handler

+		classname="org.apache.felix.ipojo.handler.wbp.WhiteBoardPatternHandler"

+		name="wbp" namespace="org.apache.felix.ipojo.white-board-pattern">

+	</handler>

+</ipojo>
\ No newline at end of file
diff --git a/ipojo/white.board.pattern.handler/pom.xml b/ipojo/white.board.pattern.handler/pom.xml
new file mode 100644
index 0000000..ccbe8ac
--- /dev/null
+++ b/ipojo/white.board.pattern.handler/pom.xml
@@ -0,0 +1,91 @@
+<!--

+	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>

+	<parent>

+		<artifactId>iPOJO</artifactId>

+		<groupId>org.apache.felix</groupId>

+		<version>0.7.6-SNAPSHOT</version>

+		<relativePath>../pom.xml</relativePath>

+	</parent>

+	<modelVersion>4.0.0</modelVersion>

+	<packaging>bundle</packaging>

+	<name>Apache Felix iPOJO White Board Pattern Handler</name>

+	<artifactId>

+		org.apache.felix.ipojo.handler.white.board.pattern

+	</artifactId>

+

+	<dependencies>

+		<dependency>

+			<groupId>org.apache.felix</groupId>

+			<artifactId>org.apache.felix.ipojo</artifactId>

+			<version>${pom.version}</version>

+		</dependency>

+		<dependency>

+			<groupId>org.apache.felix</groupId>

+			<artifactId>org.apache.felix.ipojo.metadata</artifactId>

+			<version>${pom.version}</version>

+		</dependency>

+		<dependency>

+			<groupId>org.apache.felix</groupId>

+			<artifactId>org.osgi.core</artifactId>

+			<version>1.0.0</version>

+		</dependency>

+		<dependency>

+			<groupId>org.apache.felix</groupId>

+			<artifactId>org.osgi.compendium</artifactId>

+			<version>1.0.0</version>

+		</dependency>

+	</dependencies>

+

+	<build>

+		<plugins>

+			<plugin>

+				<groupId>org.apache.felix</groupId>

+				<artifactId>maven-bundle-plugin</artifactId>

+				<extensions>true</extensions>

+				<configuration>

+					<instructions>

+						<Private-Package>

+							org.apache.felix.ipojo.handler.wbp

+						</Private-Package>

+						<Bundle-Name>${pom.name}</Bundle-Name>

+						<Bundle-SymbolicName>

+							ipojo.event.admin.handler.wbp

+						</Bundle-SymbolicName>

+					</instructions>

+				</configuration>

+			</plugin>

+			<plugin>

+				<groupId>org.apache.felix</groupId>

+				<artifactId>maven-ipojo-plugin</artifactId>

+				<version>${pom.version}</version>

+				<executions>

+					<execution>

+						<goals>

+							<goal>ipojo-bundle</goal>

+						</goals>

+						<configuration>

+							<metadata>metadata.xml</metadata>

+						</configuration>

+					</execution>

+				</executions>

+			</plugin>

+		</plugins>

+	</build>

+</project>

diff --git a/ipojo/white.board.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardManager.java b/ipojo/white.board.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardManager.java
new file mode 100644
index 0000000..d0206b5
--- /dev/null
+++ b/ipojo/white.board.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardManager.java
@@ -0,0 +1,173 @@
+/* 

+ * 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.ipojo.handler.wbp;

+

+import java.lang.reflect.InvocationTargetException;

+

+import org.apache.felix.ipojo.PrimitiveHandler;

+import org.apache.felix.ipojo.util.Callback;

+import org.apache.felix.ipojo.util.Tracker;

+import org.apache.felix.ipojo.util.TrackerCustomizer;

+import org.osgi.framework.Filter;

+import org.osgi.framework.ServiceReference;

+

+/**

+ * Manage a white board pattern.

+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>

+ */

+public class WhiteBoardManager implements TrackerCustomizer {

+    

+    /**

+     * monitored filter. 

+     */

+    private Filter m_filter;

+    

+    /**

+     * onArrival method. 

+     */

+    private Callback m_onArrival;

+    

+    /**

+     * onDeparture method. 

+     */

+    private Callback m_onDeparture;

+    

+    /**

+     * onModify method. 

+     */

+    private Callback m_onModification;

+    

+    /**

+     * Service Tracker. 

+     */

+    private Tracker m_tracker;

+    

+    /**

+     * Attached handler. 

+     */

+    private PrimitiveHandler m_handler;

+    

+    /**

+     * Constructor.

+     * @param handler : attached handler

+     * @param filter : monitored filter

+     * @param bind : onArrival method

+     * @param unbind : onDeparture method

+     * @param modification : onModify method

+     */

+    public WhiteBoardManager(WhiteBoardPatternHandler handler, Filter filter, String bind, String unbind, String modification) {

+        m_handler = handler;

+        m_onArrival = new Callback(bind, new Class[] {ServiceReference.class}, false, m_handler.getInstanceManager());

+        m_onDeparture = new Callback(unbind, new Class[] {ServiceReference.class}, false, m_handler.getInstanceManager());

+        if (modification != null) {

+            m_onModification = new Callback(modification, new Class[] {ServiceReference.class}, false, m_handler.getInstanceManager());

+        }

+        m_filter = filter;

+        m_tracker = new Tracker(handler.getInstanceManager().getContext(), m_filter, this);

+    }

+    

+    /**

+     * Open the tracker.

+     */

+    public void start() {

+        m_tracker.open();

+    }

+    

+    /**

+     * Close the tracker.

+     */

+    public void stop() {

+        m_tracker.close();

+    }

+

+    /**

+     * A new service was added to the tracker.

+     * @param arg0 : service reference.

+     * @see org.apache.felix.ipojo.util.TrackerCustomizer#addedService(org.osgi.framework.ServiceReference)

+     */

+    public void addedService(ServiceReference arg0) {

+        try {

+            m_onArrival.call(new Object[] {arg0});

+        } catch (NoSuchMethodException e) {

+            m_handler.error("The onArrival method " + m_onArrival.getMethod() + " does not exist in the class", e);

+            m_handler.getInstanceManager().stop();

+        } catch (IllegalAccessException e) {

+            m_handler.error("The onArrival method " + m_onArrival.getMethod() + " cannot be invoked", e);

+            m_handler.getInstanceManager().stop();

+        } catch (InvocationTargetException e) {

+            m_handler.error("The onArrival method " + m_onArrival.getMethod() + " has thrown an exception", e.getTargetException());

+            m_handler.getInstanceManager().stop();

+        }

+    }

+

+    /**

+     * A new service is detected.

+     * @param arg0 : service reference

+     * @return true to add the service

+     * @see org.apache.felix.ipojo.util.TrackerCustomizer#addingService(org.osgi.framework.ServiceReference)

+     */

+    public boolean addingService(ServiceReference arg0) {

+        return true;

+    }

+

+    /**

+     * An existing service was modified.

+     * @param arg0 : service reference

+     * @param arg1 : service object (if already get)

+     * @see org.apache.felix.ipojo.util.TrackerCustomizer#modifiedService(org.osgi.framework.ServiceReference, java.lang.Object)

+     */

+    public void modifiedService(ServiceReference arg0, Object arg1) {

+        if (m_onModification != null) {

+            try {

+                m_onModification.call(new Object[] {arg0});

+            } catch (NoSuchMethodException e) {

+                m_handler.error("The onModification method " + m_onModification.getMethod() + " does not exist in the class", e);

+                m_handler.getInstanceManager().stop();

+            } catch (IllegalAccessException e) {

+                m_handler.error("The onModification method " + m_onModification.getMethod() + " cannot be invoked", e);

+                m_handler.getInstanceManager().stop();

+            } catch (InvocationTargetException e) {

+                m_handler.error("The onModification method " + m_onModification.getMethod() + " has thrown an exception", e.getTargetException());

+                m_handler.getInstanceManager().stop();

+            }

+        }

+    }

+

+    /**

+     * A service disappears.

+     * @param arg0 : service reference

+     * @param arg1 : service object (if already get)

+     * @see org.apache.felix.ipojo.util.TrackerCustomizer#removedService(org.osgi.framework.ServiceReference, java.lang.Object)

+     */

+    public void removedService(ServiceReference arg0, Object arg1) {

+        try {

+            m_onDeparture.call(new Object[] {arg0});

+        } catch (NoSuchMethodException e) {

+            m_handler.error("The onDeparture method " + m_onDeparture.getMethod() + " does not exist in the class", e);

+            m_handler.getInstanceManager().stop();

+        } catch (IllegalAccessException e) {

+            m_handler.error("The onDeparture method " + m_onDeparture.getMethod() + " cannot be invoked", e);

+            m_handler.getInstanceManager().stop();

+        } catch (InvocationTargetException e) {

+            m_handler.error("The onDeparture method " + m_onDeparture.getMethod() + " has thrown an exception", e.getTargetException());

+            m_handler.getInstanceManager().stop();

+        }

+    }

+

+}

diff --git a/ipojo/white.board.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardPatternHandler.java b/ipojo/white.board.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardPatternHandler.java
new file mode 100644
index 0000000..4fb735b
--- /dev/null
+++ b/ipojo/white.board.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardPatternHandler.java
@@ -0,0 +1,99 @@
+/* 

+ * 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.ipojo.handler.wbp;

+

+import java.util.ArrayList;

+import java.util.Dictionary;

+import java.util.List;

+

+import org.apache.felix.ipojo.ConfigurationException;

+import org.apache.felix.ipojo.PrimitiveHandler;

+import org.apache.felix.ipojo.metadata.Element;

+import org.osgi.framework.InvalidSyntaxException;

+

+/**

+ * White board pattern handler.

+ * This handler aims to automate white board patterns by invoking callback when needed.

+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>

+ */

+public class WhiteBoardPatternHandler extends PrimitiveHandler {

+    

+    /**

+     * Handler namespace.

+     */

+    public static final String NAMESPACE = "org.apache.felix.ipojo.white-board-pattern";

+    

+    /**

+     * White board pattern to manage. By default just one. 

+     */

+    private List m_managers = new ArrayList(1);

+

+    /**

+     * Configure method. It will parse metadata to analyze org.apache.felix.ipojo.white-board-pattern:wbp element. 

+     * @param elem : component type description

+     * @param dict : instance description

+     * @throws ConfigurationException : occurs when the description is not valid.

+     * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)

+     */

+    public void configure(Element elem, Dictionary dict) throws ConfigurationException {

+        Element[] elems = elem.getElements("wbp", NAMESPACE);

+        for (int i = 0; i < elems.length; i++) {

+            String filter = elems[i].getAttribute("filter");

+            String onArrival = elems[i].getAttribute("onArrival");

+            String onDeparture = elems[i].getAttribute("onDeparture");

+            String onModification = elems[i].getAttribute("onModification");

+            

+            if (filter == null) {

+                throw new ConfigurationException("The white board pattern element requires a filter attribute");

+            }

+            if (onArrival == null || onDeparture == null) {

+                throw new ConfigurationException("The white board pattern element requires the onArrival and onDeparture attributes");

+            }

+            

+            try {

+                WhiteBoardManager wbm = new WhiteBoardManager(this, getInstanceManager().getContext().createFilter(filter), onArrival, onDeparture, onModification);

+                m_managers.add(wbm);

+            } catch (InvalidSyntaxException e) {

+                throw new ConfigurationException("The filter " + filter + " is invalid : " + e);

+            }

+        }

+        

+    }

+

+    /**

+     * Start method : start managers.

+     * @see org.apache.felix.ipojo.Handler#start()

+     */

+    public void start() {

+        for (int i = 0; i < m_managers.size(); i++) {

+            ((WhiteBoardManager) m_managers.get(i)).start();

+        }

+    }

+

+    /**

+     * Stop method : stop managers.

+     * @see org.apache.felix.ipojo.Handler#stop()

+     */

+    public void stop() {

+        for (int i = 0; i < m_managers.size(); i++) {

+            ((WhiteBoardManager) m_managers.get(i)).stop();

+        } 

+    }

+

+}