You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2008/04/25 18:50:22 UTC

svn commit: r651646 [6/22] - in /felix/trunk/ipojo/tests: ./ tests.composite/ tests.composite/src/ tests.composite/src/main/ tests.composite/src/main/java/ tests.composite/src/main/java/org/ tests.composite/src/main/java/org/apache/ tests.composite/src...

Added: felix/trunk/ipojo/tests/tests.core.configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java (added)
+++ felix/trunk/ipojo/tests/tests.core.configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java Fri Apr 25 09:49:43 2008
@@ -0,0 +1,326 @@
+/* 
+ * 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.test.scenarios.util;
+
+import java.util.Dictionary;
+import java.util.Properties;
+
+import junit.framework.Assert;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.Handler;
+import org.apache.felix.ipojo.HandlerFactory;
+import org.apache.felix.ipojo.ServiceContext;
+//import org.apache.felix.ipojo.composite.CompositeManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+public class Utils {
+
+    public static Factory getFactoryByName(BundleContext bc, String factoryName) {
+        ServiceReference[] refs;
+        try {
+            refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");
+            if (refs == null) {
+                System.err.println("Cannot get the factory " + factoryName);
+                return null;
+            }
+            return ((Factory) bc.getService(refs[0]));
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
+            return null;
+        }
+    }
+
+    public static HandlerFactory getHandlerFactoryByName(BundleContext bc, String factoryName) {
+        ServiceReference[] refs;
+        try {
+            refs = bc.getServiceReferences(Factory.class.getName(), "(" + Handler.HANDLER_NAME_PROPERTY + "=" + factoryName + ")");
+            if (refs == null) {
+                System.err.println("Cannot get the factory " + factoryName);
+                return null;
+            }
+            return (HandlerFactory) bc.getService(refs[0]);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
+            return null;
+        }
+    }
+
+    public static ComponentInstance getComponentInstance(BundleContext bc, String factoryName, Dictionary configuration) {
+        Factory fact = getFactoryByName(bc, factoryName);
+
+        if (fact == null) {
+            System.err.println("Factory " + factoryName + " not found");
+            return null;
+        }
+
+        // if(fact.isAcceptable(configuration)) {
+        try {
+            return fact.createComponentInstance(configuration);
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail("Cannot create the instance from " + factoryName + " : " + e.getMessage());
+            return null;
+        }
+        // }
+        // else {
+        // System.err.println("Configuration not accepted by : " + factoryName);
+        // return null;
+        // }
+    }
+
+    public static ComponentInstance getComponentInstanceByName(BundleContext bc, String factoryName, String name) {
+        Factory fact = getFactoryByName(bc, factoryName);
+
+        if (fact == null) {
+            System.err.println("Factory " + factoryName + " not found");
+            return null;
+        }
+
+        try {
+            Properties props = new Properties();
+            props.put("name", name);
+            return fact.createComponentInstance(props);
+        } catch (Exception e) {
+            System.err.println("Cannot create the instance from " + factoryName + " : " + e.getMessage());
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    public static ServiceReference[] getServiceReferences(BundleContext bc, String itf, String filter) {
+        ServiceReference[] refs = null;
+        try {
+            refs = bc.getServiceReferences(itf, filter);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Invalid Filter : " + filter);
+        }
+        if (refs == null) {
+            return new ServiceReference[0];
+        } else {
+            return refs;
+        }
+    }
+
+    public static ServiceReference getServiceReference(BundleContext bc, String itf, String filter) {
+        ServiceReference[] refs = null;
+        try {
+            refs = bc.getServiceReferences(itf, filter);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Invalid Filter : " + filter);
+        }
+        if (refs == null) {
+            return null;
+        } else {
+            return refs[0];
+        }
+    }
+
+    public static ServiceReference getServiceReferenceByName(BundleContext bc, String itf, String name) {
+        ServiceReference[] refs = null;
+        String filter = null;
+        if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {
+            filter = "(" + "factory.name" + "=" + name + ")";
+        } else {
+            filter = "(" + "instance.name" + "=" + name + ")";
+        }
+        try {
+            refs = bc.getServiceReferences(itf, filter);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Invalid Filter : " + filter);
+        }
+        if (refs == null) {
+            return null;
+        } else {
+            return refs[0];
+        }
+    }
+    
+    public static ServiceReference getServiceReferenceByPID(BundleContext bc, String itf, String pid) {
+        ServiceReference[] refs = null;
+        String filter = "(" + "service.pid" + "=" + pid + ")";
+        try {
+            refs = bc.getServiceReferences(itf, filter);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Invalid Filter : " + filter);
+        }
+        if (refs == null) {
+            return null;
+        } else if (refs.length == 1) {
+            return refs[0];
+        } else {
+            Assert.fail("A service lookup by PID returned several providers (" + refs.length + ")" + " for " + itf + " with " + pid);
+            return null;
+        }
+    }
+
+    public static Object getServiceObject(BundleContext bc, String itf, String filter) {
+        ServiceReference ref = getServiceReference(bc, itf, filter);
+        if (ref != null) {
+            return bc.getService(ref);
+        } else {
+            return null;
+        }
+    }
+
+    public static Object[] getServiceObjects(BundleContext bc, String itf, String filter) {
+        ServiceReference[] refs = getServiceReferences(bc, itf, filter);
+        if (refs != null) {
+            Object[] list = new Object[refs.length];
+            for (int i = 0; i < refs.length; i++) {
+                list[i] = bc.getService(refs[i]);
+            }
+            return list;
+        } else {
+            return new Object[0];
+        }
+    }
+
+//    public static ServiceContext getServiceContext(ComponentInstance ci) {
+//        if (ci instanceof CompositeManager) {
+//            return ((CompositeManager) ci).getServiceContext();
+//        } else {
+//            throw new RuntimeException("Cannot get the service context form an non composite instance");
+//        }
+//    }
+
+    public static Factory getFactoryByName(ServiceContext bc, String factoryName) {
+        ServiceReference[] refs;
+        try {
+            refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");
+            if (refs == null) { return null; }
+            return ((Factory) bc.getService(refs[0]));
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
+            return null;
+        }
+    }
+
+    public static ComponentInstance getComponentInstance(ServiceContext bc, String factoryName, Dictionary configuration) {
+        Factory fact = getFactoryByName(bc, factoryName);
+
+        if (fact == null) { return null; }
+
+        if (fact.isAcceptable(configuration)) {
+            try {
+                return fact.createComponentInstance(configuration);
+            } catch (Exception e) {
+                System.err.println(e.getMessage());
+                e.printStackTrace();
+                return null;
+            }
+        } else {
+            System.err.println("Configuration not accepted by : " + factoryName);
+            return null;
+        }
+    }
+
+    public static ServiceReference[] getServiceReferences(ServiceContext bc, String itf, String filter) {
+        ServiceReference[] refs = null;
+        try {
+            refs = bc.getServiceReferences(itf, filter);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Invalid Filter : " + filter);
+        }
+        if (refs == null) {
+            return new ServiceReference[0];
+        } else {
+            return refs;
+        }
+    }
+
+    public static ServiceReference getServiceReference(ServiceContext bc, String itf, String filter) {
+        ServiceReference[] refs = null;
+        try {
+            refs = bc.getServiceReferences(itf, filter);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Invalid Filter : " + filter);
+        }
+        if (refs == null) {
+            return null;
+        } else {
+            return refs[0];
+        }
+    }
+
+    public static ServiceReference getServiceReferenceByName(ServiceContext bc, String itf, String name) {
+        ServiceReference[] refs = null;
+        String filter = null;
+        if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {
+            filter = "(" + "factory.name" + "=" + name + ")";
+        } else {
+            filter = "(" + "instance.name" + "=" + name + ")";
+        }
+        try {
+            refs = bc.getServiceReferences(itf, filter);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Invalid Filter : " + filter);
+        }
+        if (refs == null) {
+            return null;
+        } else {
+            return refs[0];
+        }
+    }
+
+    public static Object getServiceObject(ServiceContext bc, String itf, String filter) {
+        ServiceReference ref = getServiceReference(bc, itf, filter);
+        if (ref != null) {
+            return bc.getService(ref);
+        } else {
+            return null;
+        }
+    }
+
+    public static Object[] getServiceObjects(ServiceContext bc, String itf, String filter) {
+        ServiceReference[] refs = getServiceReferences(bc, itf, filter);
+        if (refs != null) {
+            Object[] list = new Object[refs.length];
+            for (int i = 0; i < refs.length; i++) {
+                list[i] = bc.getService(refs[i]);
+            }
+            return list;
+        } else {
+            return new Object[0];
+        }
+    }
+    
+    public static boolean contains(String string, String[] array) {
+        for (int i = 0; array != null && i < array.length; i++) {
+            if (array[i] != null  && array[i].equals(string)) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    public static boolean contains(int value, int[] array) {
+        for (int i = 0; array != null && i < array.length; i++) {
+            if (array[i] == value) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+}

Added: felix/trunk/ipojo/tests/tests.core.configuration/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.configuration/src/main/resources/metadata.xml?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.configuration/src/main/resources/metadata.xml (added)
+++ felix/trunk/ipojo/tests/tests.core.configuration/src/main/resources/metadata.xml Fri Apr 25 09:49:43 2008
@@ -0,0 +1,148 @@
+<ipojo>
+	<component
+		className="org.apache.felix.ipojo.test.scenarios.component.FooProviderTypeDyn"
+		factory="CONFIG-FooProviderType-Conf" architecture="true">
+		<provides />
+		<properties propagation="false">
+			<property name="int" field="intProp" value="2" />
+			<property name="boolean" field="boolProp" value="false" />
+			<property name="string" field="strProp" value="foo" />
+			<property name="strAProp" field="strAProp"
+				value="{foo, bar}" />
+			<property name="intAProp" field="intAProp" value="{1,2, 3}" />
+		</properties>
+	</component>
+	<component
+		className="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
+		factory="CONFIG-FooProviderType-3" architecture="true">
+		<provides>
+			<property name="foo" field="m_foo" />
+			<property name="bar" field="m_bar" />
+			<property name="baz" type="java.lang.String" />
+		</provides>
+		<properties propagation="true">
+			<property name="foo" field="m_foo" />
+			<property name="bar" field="m_bar" />
+		</properties>
+	</component>
+	<!-- Configuration Management Test -->
+	<component factory="CONFIG-FieldConfigurableCheckService"
+		className="org.apache.felix.ipojo.test.scenarios.component.ConfigurableCheckServiceProvider"
+		architecture="true">
+		<provides />
+		<properties propagation="true">
+			<property field="b" />
+			<property field="s" />
+			<property field="i" />
+			<property field="l" />
+			<property field="d" />
+			<property field="f" />
+			<property field="c" />
+			<property field="bool" />
+			<property field="bs" />
+			<property field="ss" />
+			<property field="is" />
+			<property field="ls" />
+			<property field="ds" />
+			<property field="fs" />
+			<property field="cs" />
+			<property field="bools" />
+			<property field="string" />
+			<property field="strings" />
+		</properties>
+	</component>
+
+	<component factory="CONFIG-BothConfigurableCheckService"
+		className="org.apache.felix.ipojo.test.scenarios.component.ConfigurableCheckServiceProvider"
+		architecture="true">
+		<provides />
+		<properties propagation="true">
+			<property field="b" method="updateB" />
+			<property field="s" method="updateS" />
+			<property field="i" method="updateI" />
+			<property field="l" method="updateL" />
+			<property field="d" method="updateD" />
+			<property field="f" method="updateF" />
+			<property field="c" method="updateC" />
+			<property field="bool" method="updateBool" />
+			<property field="bs" method="updateBs" />
+			<property field="ss" method="updateSs" />
+			<property field="is" method="updateIs" />
+			<property field="ls" method="updateLs" />
+			<property field="ds" method="updateDs" />
+			<property field="fs" method="updateFs" />
+			<property field="cs" method="updateCs" />
+			<property field="bools" method="updateBools" />
+			<property field="string" method="updateString" />
+			<property field="strings" method="updateStrings" />
+		</properties>
+	</component>
+
+	<component factory="CONFIG-MethodConfigurableCheckService"
+		className="org.apache.felix.ipojo.test.scenarios.component.ConfigurableCheckServiceProvider"
+		architecture="true">
+		<provides />
+		<properties propagation="true">
+			<property method="updateB" name="b" />
+			<property method="updateS" name="s" />
+			<property method="updateI" name="i" />
+			<property method="updateL" name="l" />
+			<property method="updateD" name="d" />
+			<property method="updateF" name="f" />
+			<property method="updateC" name="c" />
+			<property method="updateBool" name="bool" />
+			<property method="updateBs" name="bs" />
+			<property method="updateSs" name="ss" />
+			<property method="updateIs" name="is" />
+			<property method="updateLs" name="ls" />
+			<property method="updateDs" name="ds" />
+			<property method="updateFs" name="fs" />
+			<property method="updateCs" name="cs" />
+			<property method="updateBools" name="bools" />
+			<property method="updateString" name="string" />
+			<property method="updateStrings" name="strings" />
+		</properties>
+	</component>
+
+	<component factory="CONFIG-ParentMethodConfigurableCheckService"
+		className="org.apache.felix.ipojo.test.scenarios.component.ParentConfigurableCheckServiceProvider"
+		architecture="true">
+		<provides />
+		<properties propagation="true">
+			<property method="updateB" name="b" />
+			<property method="updateS" name="s" />
+			<property method="updateI" name="i" />
+			<property method="updateL" name="l" />
+			<property method="updateD" name="d" />
+			<property method="updateF" name="f" />
+			<property method="updateC" name="c" />
+			<property method="updateBool" name="bool" />
+			<property method="updateBs" name="bs" />
+			<property method="updateSs" name="ss" />
+			<property method="updateIs" name="is" />
+			<property method="updateLs" name="ls" />
+			<property method="updateDs" name="ds" />
+			<property method="updateFs" name="fs" />
+			<property method="updateCs" name="cs" />
+			<property method="updateBools" name="bools" />
+			<property method="updateString" name="string" type="string" />
+			<property method="updateStrings" name="strings"
+				type="java.lang.String[]" />
+		</properties>
+	</component>
+	
+	<component
+		className="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
+		factory="CONFIG-FooProviderType-4" architecture="true">
+		<provides>
+			<property name="foo" field="m_foo" />
+			<property name="bar" field="m_bar" />
+			<property name="baz" type="java.lang.String" />
+		</provides>
+		<properties propagation="true" pid="FooProvider-3">
+			<property name="foo" field="m_foo" />
+			<property name="bar" field="m_bar" />
+		</properties>
+	</component>
+	
+</ipojo>

Propchange: felix/trunk/ipojo/tests/tests.core.external.handlers/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Apr 25 09:49:43 2008
@@ -0,0 +1,9 @@
+target*
+bin*
+.settings*
+.classpath
+.project
+.checkstyle
+maven-eclipse.xml
+.externalToolBuilders
+

Added: felix/trunk/ipojo/tests/tests.core.external.handlers/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.external.handlers/pom.xml?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.external.handlers/pom.xml (added)
+++ felix/trunk/ipojo/tests/tests.core.external.handlers/pom.xml Fri Apr 25 09:49:43 2008
@@ -0,0 +1,102 @@
+<!--
+	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>
+	<modelVersion>4.0.0</modelVersion>
+	<packaging>bundle</packaging>
+	<name>iPOJO External Handler Mechanism Test Suite</name>
+	<artifactId>tests.core.external.handlers</artifactId>
+	<groupId>ipojo.tests</groupId>
+	<version>0.7.6-SNAPSHOT</version>
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.apache.felix.ipojo</artifactId>
+			<version>0.7.6-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.apache.felix.ipojo.metadata</artifactId>
+			<version>0.7.6-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.osgi.core</artifactId>
+			<version>1.0.0</version>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>3.8.1</version>
+		</dependency>
+		<dependency>
+			<groupId>ipojo.examples</groupId>
+			<artifactId>org.apache.felix.ipojo.junit4osgi</artifactId>
+			<version>0.7.6-SNAPSHOT</version>
+		</dependency>
+	</dependencies>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-bundle-plugin</artifactId>
+				<version>1.4.0</version>
+				<extensions>true</extensions>
+				<configuration>
+					<instructions>
+						<Export-Package>
+							org.apache.felix.ipojo.test.scenarios.eh.service
+						</Export-Package>
+						<Bundle-SymbolicName>
+							${pom.artifactId}
+						</Bundle-SymbolicName>
+						<Private-Package>
+							org.apache.felix.ipojo.test*
+						</Private-Package>
+						<Test-Suite>
+							org.apache.felix.ipojo.test.scenarios.eh.ExternalHandlerTestSuite
+						</Test-Suite>
+					</instructions>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-ipojo-plugin</artifactId>
+				<version>0.7.6-SNAPSHOT</version>
+				<executions>
+					<execution>
+						<goals>
+							<goal>ipojo-bundle</goal>
+						</goals>
+						<configuration>
+							<ignoreAnnotations>true</ignoreAnnotations>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.4</source>
+					<target>1.4</target>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+</project>

Added: felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceHandler.java?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceHandler.java (added)
+++ felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceHandler.java Fri Apr 25 09:49:43 2008
@@ -0,0 +1,100 @@
+/* 
+ * 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.test.scenarios.component;
+
+import java.util.Dictionary;
+import java.util.Properties;
+
+import org.apache.felix.ipojo.PrimitiveHandler;
+import org.apache.felix.ipojo.architecture.ComponentTypeDescription;
+import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.architecture.PropertyDescription;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.test.scenarios.eh.service.CheckService;
+import org.osgi.framework.ServiceRegistration;
+
+public class CheckServiceHandler extends PrimitiveHandler implements CheckService {
+	
+	ServiceRegistration sr;
+	boolean isValid;
+	int changes = 0;
+	static final String NAMESPACE = "org.apache.felix.ipojo.test.handler.checkservice";
+	
+	Properties props = new Properties();
+
+	public void configure(Element metadata, Dictionary configuration) {
+		Element[] meta = metadata.getElements("check", NAMESPACE);
+		if(meta == null) { return;	}		
+		// Get handler props 
+		props.put("instance.name", configuration.get("name"));
+		if(configuration.get("csh.simple") != null) { props.put("Simple", configuration.get("csh.simple")); }
+		if(configuration.get("csh.map") != null) { 
+			Dictionary m = (Dictionary) configuration.get("csh.map");
+			props.put("Map1", m.get("a"));
+			props.put("Map2", m.get("b"));
+			props.put("Map3", m.get("c"));
+		}
+		props.put("changes", new Integer(changes));
+		
+	}
+	
+	public void initializeComponentFactory(ComponentTypeDescription cd, Element metadata) {
+	    cd.addProperty(new PropertyDescription("csh.simple", "java.lang.String", null));
+        cd.addProperty(new PropertyDescription("csh.map", "java.util.Dictionary", null));
+	}
+	
+	public void start() {
+		if(sr == null) {
+			sr = getInstanceManager().getContext().registerService(CheckService.class.getName(), this, props);
+		}
+		isValid = true;
+	}
+	
+	public void stop() {
+		isValid = false;
+		synchronized(this) {
+			if(sr != null) { sr.unregister(); }
+		}
+	}
+	
+	public boolean check() {
+		if(isValid) { isValid = false;}
+		else { isValid = true; }
+		return isValid;
+	}
+
+	public Properties getProps() {
+		return props;
+	}
+	
+	public void stateChanged(int state) {
+		changes++;
+		props.put("changes", new Integer(changes));
+		sr.setProperties(props);
+	}
+
+	public String getName() {
+		return NAMESPACE;
+	}
+	
+	public HandlerDescription getDescription() {
+		return new CheckServiceHandlerDescription(this);
+	}
+
+}

Added: felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceHandlerDescription.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceHandlerDescription.java?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceHandlerDescription.java (added)
+++ felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceHandlerDescription.java Fri Apr 25 09:49:43 2008
@@ -0,0 +1,38 @@
+/* 
+ * 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.test.scenarios.component;
+
+import org.apache.felix.ipojo.Handler;
+import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+
+public class CheckServiceHandlerDescription extends HandlerDescription {
+
+	public CheckServiceHandlerDescription(Handler h) {
+		super(h);
+	}
+	
+	public Element getHandlerInfo() {
+		Element elem = super.getHandlerInfo();
+		elem.addAttribute(new Attribute("isValid", isValid()+""));
+		return elem;
+	}
+
+}

Added: felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderType1.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderType1.java?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderType1.java (added)
+++ felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderType1.java Fri Apr 25 09:49:43 2008
@@ -0,0 +1,117 @@
+/* 
+ * 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.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.eh.service.FooService;
+import org.osgi.framework.BundleContext;
+
+public class FooProviderType1 implements FooService {
+	
+	private int m_bar;
+	private String m_foo;
+    
+    private BundleContext m_context;
+    
+    private static FooProviderType1 singleton;
+    private static int count = 0;
+    
+    private static FooProviderType1 singleton(BundleContext bc) {
+        if (singleton == null) {
+            count++;
+            singleton = new FooProviderType1(bc);
+        }
+        return singleton;
+    }
+    
+    public static FooProviderType1 several(BundleContext bc) {
+        count++;
+        return new FooProviderType1(bc);
+    }
+        
+    public FooProviderType1(BundleContext bc) {
+        if (bc ==null) {
+            throw new RuntimeException("Injected bundle context null");
+        }
+            m_context = bc;
+    }
+
+	public boolean foo() {
+		return true;
+	}
+
+	public Properties fooProps() {
+		Properties p = new Properties();
+		p.put("bar", new Integer(m_bar));
+        if(m_foo != null) {
+            p.put("foo", m_foo);
+        }
+        p.put("context", m_context);
+        
+        p.put("count", new Integer(count));
+		return p;
+	}
+    
+	public void testException() throws Exception {
+        String a = "foobarbaz";
+	    throw new Exception("foo"+a);
+    }
+    
+    public void testTry() {
+            String a = "foo";
+            a.charAt(0);
+    }
+    
+    public void testTry2(String s) {
+            String a = "foo";
+            a.charAt(0);
+    }
+    
+    private void nexttry(String  s) {
+        try {
+            s += "foo";
+        } catch(RuntimeException e) {
+            
+        }
+    }
+    
+	public boolean getBoolean() { return true; }
+
+	public double getDouble() { return 1.0; }
+
+	public int getInt() { return 1; }
+
+	public long getLong() { return 1; }
+
+	public Boolean getObject() { return new Boolean(true); }
+	
+	/**
+	 * Custom constructor.
+	 * @param bar
+	 * @param foo
+	 * @param bc
+	 */
+	public FooProviderType1(int bar, String foo, BundleContext bc) {
+	    m_bar = bar;
+	    m_foo = foo;
+	    m_context = bc;
+	}
+
+}

Added: felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/eh/ExternalHandlerTestSuite.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/eh/ExternalHandlerTestSuite.java?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/eh/ExternalHandlerTestSuite.java (added)
+++ felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/eh/ExternalHandlerTestSuite.java Fri Apr 25 09:49:43 2008
@@ -0,0 +1,35 @@
+/* 
+ * 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.test.scenarios.eh;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.osgi.framework.BundleContext;
+
+public class ExternalHandlerTestSuite extends TestSuite {
+
+	public static Test suite(BundleContext bc) {
+		OSGiTestSuite ots = new OSGiTestSuite("External Handler Test Suite", bc);
+		ots.addTestSuite(HandlerTest.class);
+		return ots;
+	}
+
+}

Added: felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/eh/HandlerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/eh/HandlerTest.java?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/eh/HandlerTest.java (added)
+++ felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/eh/HandlerTest.java Fri Apr 25 09:49:43 2008
@@ -0,0 +1,191 @@
+/* 
+ * 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.test.scenarios.eh;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.HandlerFactory;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.eh.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+public class HandlerTest extends OSGiTestCase {
+
+	ComponentInstance instance;
+
+	public void setUp() {
+		Properties props = new Properties();
+		props.put("name", "HandlerTest-1");
+		props.put("csh.simple", "simple");
+		Properties p = new Properties();
+		p.put("a", "a");
+		p.put("b", "b");
+		p.put("c", "c");
+		props.put("csh.map", p);
+		instance = Utils.getComponentInstance(context, "HANDLER-HandlerTester", props);
+	}
+	
+	public void tearDown() {
+		instance.dispose();
+		instance = null;
+	}
+	
+	public void testConfiguration1() {
+		// Check the availability of CheckService
+	    String name = "HandlerTest-1";
+		ServiceReference sr = null;
+		ServiceReference[] refs = null;
+        String filter = "("+"instance.name"+"="+name+")";
+        try {
+            refs = context.getServiceReferences(CheckService.class.getName(), filter);
+        } catch (InvalidSyntaxException e) { System.err.println("Invalid Filter : " + filter);}
+        if(refs != null) { sr = refs[0]; }
+        
+		assertNotNull("Check the check service availability", sr);
+		
+		CheckService cs = (CheckService) context.getService(sr);
+		Properties p = cs.getProps();
+		assertEquals("Assert 'simple' equality", p.get("Simple"), "simple");
+		assertEquals("Assert 'a' equality", p.get("Map1"), "a");
+		assertEquals("Assert 'b' equality", p.get("Map2"), "b");
+		assertEquals("Assert 'c' equality", p.get("Map3"), "c");
+		
+		cs = null;
+		context.ungetService(sr);
+	}
+	
+	public void testConfiguration2() {
+		// Check the availability of CheckService
+	    String name = "HandlerTest-2";
+        ServiceReference sr = null;
+        ServiceReference[] refs = null;
+        String filter = "("+"instance.name"+"="+name+")";
+        try {
+            refs = context.getServiceReferences(CheckService.class.getName(), filter);
+        } catch (InvalidSyntaxException e) { System.err.println("Invalid Filter : " + filter);}
+        if(refs != null) { sr = refs[0]; }
+		assertNotNull("Check the check service availability", sr);
+		
+		CheckService cs = (CheckService) context.getService(sr);
+		Properties p = cs.getProps();
+		assertEquals("Assert 'simple' equality", p.get("Simple"), "Simple");
+		assertEquals("Assert 'a' equality", p.get("Map1"), "a");
+		assertEquals("Assert 'b' equality", p.get("Map2"), "b");
+		assertEquals("Assert 'c' equality", p.get("Map3"), "c");
+		
+		cs = null;
+		context.ungetService(sr);
+	}
+	
+	public void testLifecycle() {
+		// Check the availability of CheckService
+	    String name = "HandlerTest-1";
+        ServiceReference sr = null;
+        ServiceReference[] refs = null;
+        String filter = "("+"instance.name"+"="+name+")";
+        try {
+            refs = context.getServiceReferences(CheckService.class.getName(), filter);
+        } catch (InvalidSyntaxException e) { System.err.println("Invalid Filter : " + filter);}
+        if(refs != null) { sr = refs[0]; }
+		assertNotNull("Check the check service availability", sr);
+		
+		ServiceReference sr_arch = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "HandlerTest-1");
+		Architecture arch = (Architecture) context.getService(sr_arch);
+		
+		assertEquals("Check instance validity - 0", arch.getInstanceDescription().getState(), ComponentInstance.VALID);
+		
+		CheckService cs = (CheckService) context.getService(sr);
+		Properties p = cs.getProps();
+		Integer changes = (Integer) p.get("changes");
+		assertNotNull("Check changes no null", changes);
+		assertEquals("Changes changes 1 ("+changes+")", changes.intValue(), 1);
+		assertEquals("Check instance validity - 1", arch.getInstanceDescription().getState(), ComponentInstance.VALID);
+		cs.check();
+		p = cs.getProps();
+		changes = (Integer) p.get("changes");
+		assertEquals("Changes changes 2 ("+changes+")", changes.intValue(), 2);
+		assertEquals("Check instance validity - 2", arch.getInstanceDescription().getState(), ComponentInstance.INVALID);
+		cs.check();
+		p = cs.getProps();
+		changes = (Integer) p.get("changes");
+		assertEquals("Changes changes 3 ("+changes+")", changes.intValue(), 3);
+		assertEquals("Check instance validity - 3", arch.getInstanceDescription().getState(), ComponentInstance.VALID);
+		cs.check();
+		p = cs.getProps();
+		changes = (Integer) p.get("changes");
+		assertEquals("Changes changes 4 ("+changes+")", changes.intValue(), 4);
+		assertEquals("Check instance validity - 4", arch.getInstanceDescription().getState(), ComponentInstance.INVALID);
+		
+		cs = null;
+		arch = null;
+		context.ungetService(sr_arch);
+		context.ungetService(sr);
+	}
+	
+	public void testAvailability() {
+	    String name = "HandlerTest-1";
+        ServiceReference sr = null;
+        ServiceReference[] refs = null;
+        String filter = "("+"instance.name"+"="+name+")";
+        try {
+            refs = context.getServiceReferences(CheckService.class.getName(), filter);
+        } catch (InvalidSyntaxException e) { System.err.println("Invalid Filter : " + filter);}
+        if(refs != null) { sr = refs[0]; }
+        assertNotNull("Check the check service availability", sr);
+        
+        ServiceReference sr_arch = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "HandlerTest-1");
+        Architecture arch = (Architecture) context.getService(sr_arch);
+        assertEquals("Check validity", arch.getInstanceDescription().getState(), ComponentInstance.VALID);
+        
+        // Kill the handler factory
+        HandlerFactory f = (HandlerFactory) Utils.getHandlerFactoryByName(context, "check");
+        f.stop();
+        
+        sr = Utils.getServiceReferenceByName(context, CheckService.class.getName(), "HandlerTest-1");
+        assertNull("Check the check service unavailability", sr);
+        
+        sr_arch = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "HandlerTest-1");
+        assertNull("Check the architecture unavailability", sr_arch);
+        
+        // The instance is disposed, restart the handler
+        f.start();
+        
+        Properties props = new Properties();
+        props.put("name", "HandlerTest-1");
+        props.put("csh.simple", "simple");
+        Properties p = new Properties();
+        p.put("a", "a");
+        p.put("b", "b");
+        p.put("c", "c");
+        props.put("csh.map", p);
+        instance = Utils.getComponentInstance(context, "HANDLER-HandlerTester", props);
+        
+        sr = Utils.getServiceReferenceByName(context, CheckService.class.getName(), "HandlerTest-1");
+        assertNotNull("Check the check service availability - 2", sr);
+        
+        sr_arch = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "HandlerTest-1");
+        arch = (Architecture) context.getService(sr_arch);
+        assertEquals("Check validity - 2", arch.getInstanceDescription().getState(), ComponentInstance.VALID);
+	}
+
+}

Added: felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/eh/service/CheckService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/eh/service/CheckService.java?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/eh/service/CheckService.java (added)
+++ felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/eh/service/CheckService.java Fri Apr 25 09:49:43 2008
@@ -0,0 +1,31 @@
+/* 
+ * 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.test.scenarios.eh.service;
+
+import java.util.Properties;
+
+public interface CheckService {
+    
+    public static final String foo = "foo";
+	
+	public boolean check();
+	
+	public Properties getProps();
+
+}

Added: felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/eh/service/FooService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/eh/service/FooService.java?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/eh/service/FooService.java (added)
+++ felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/eh/service/FooService.java Fri Apr 25 09:49:43 2008
@@ -0,0 +1,39 @@
+/* 
+ * 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.test.scenarios.eh.service;
+
+import java.util.Properties;
+
+public interface FooService {
+
+	boolean foo();
+	
+	Properties fooProps();
+	
+	Boolean getObject();
+	
+	boolean getBoolean();
+	
+	int getInt();
+	
+	long getLong();
+	
+	double getDouble();
+	
+}

Added: felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java (added)
+++ felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java Fri Apr 25 09:49:43 2008
@@ -0,0 +1,326 @@
+/* 
+ * 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.test.scenarios.util;
+
+import java.util.Dictionary;
+import java.util.Properties;
+
+import junit.framework.Assert;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.Handler;
+import org.apache.felix.ipojo.HandlerFactory;
+import org.apache.felix.ipojo.ServiceContext;
+//import org.apache.felix.ipojo.composite.CompositeManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+public class Utils {
+
+    public static Factory getFactoryByName(BundleContext bc, String factoryName) {
+        ServiceReference[] refs;
+        try {
+            refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");
+            if (refs == null) {
+                System.err.println("Cannot get the factory " + factoryName);
+                return null;
+            }
+            return ((Factory) bc.getService(refs[0]));
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
+            return null;
+        }
+    }
+
+    public static HandlerFactory getHandlerFactoryByName(BundleContext bc, String factoryName) {
+        ServiceReference[] refs;
+        try {
+            refs = bc.getServiceReferences(Factory.class.getName(), "(" + Handler.HANDLER_NAME_PROPERTY + "=" + factoryName + ")");
+            if (refs == null) {
+                System.err.println("Cannot get the factory " + factoryName);
+                return null;
+            }
+            return (HandlerFactory) bc.getService(refs[0]);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
+            return null;
+        }
+    }
+
+    public static ComponentInstance getComponentInstance(BundleContext bc, String factoryName, Dictionary configuration) {
+        Factory fact = getFactoryByName(bc, factoryName);
+
+        if (fact == null) {
+            System.err.println("Factory " + factoryName + " not found");
+            return null;
+        }
+
+        // if(fact.isAcceptable(configuration)) {
+        try {
+            return fact.createComponentInstance(configuration);
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail("Cannot create the instance from " + factoryName + " : " + e.getMessage());
+            return null;
+        }
+        // }
+        // else {
+        // System.err.println("Configuration not accepted by : " + factoryName);
+        // return null;
+        // }
+    }
+
+    public static ComponentInstance getComponentInstanceByName(BundleContext bc, String factoryName, String name) {
+        Factory fact = getFactoryByName(bc, factoryName);
+
+        if (fact == null) {
+            System.err.println("Factory " + factoryName + " not found");
+            return null;
+        }
+
+        try {
+            Properties props = new Properties();
+            props.put("name", name);
+            return fact.createComponentInstance(props);
+        } catch (Exception e) {
+            System.err.println("Cannot create the instance from " + factoryName + " : " + e.getMessage());
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    public static ServiceReference[] getServiceReferences(BundleContext bc, String itf, String filter) {
+        ServiceReference[] refs = null;
+        try {
+            refs = bc.getServiceReferences(itf, filter);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Invalid Filter : " + filter);
+        }
+        if (refs == null) {
+            return new ServiceReference[0];
+        } else {
+            return refs;
+        }
+    }
+
+    public static ServiceReference getServiceReference(BundleContext bc, String itf, String filter) {
+        ServiceReference[] refs = null;
+        try {
+            refs = bc.getServiceReferences(itf, filter);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Invalid Filter : " + filter);
+        }
+        if (refs == null) {
+            return null;
+        } else {
+            return refs[0];
+        }
+    }
+
+    public static ServiceReference getServiceReferenceByName(BundleContext bc, String itf, String name) {
+        ServiceReference[] refs = null;
+        String filter = null;
+        if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {
+            filter = "(" + "factory.name" + "=" + name + ")";
+        } else {
+            filter = "(" + "instance.name" + "=" + name + ")";
+        }
+        try {
+            refs = bc.getServiceReferences(itf, filter);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Invalid Filter : " + filter);
+        }
+        if (refs == null) {
+            return null;
+        } else {
+            return refs[0];
+        }
+    }
+    
+    public static ServiceReference getServiceReferenceByPID(BundleContext bc, String itf, String pid) {
+        ServiceReference[] refs = null;
+        String filter = "(" + "service.pid" + "=" + pid + ")";
+        try {
+            refs = bc.getServiceReferences(itf, filter);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Invalid Filter : " + filter);
+        }
+        if (refs == null) {
+            return null;
+        } else if (refs.length == 1) {
+            return refs[0];
+        } else {
+            Assert.fail("A service lookup by PID returned several providers (" + refs.length + ")" + " for " + itf + " with " + pid);
+            return null;
+        }
+    }
+
+    public static Object getServiceObject(BundleContext bc, String itf, String filter) {
+        ServiceReference ref = getServiceReference(bc, itf, filter);
+        if (ref != null) {
+            return bc.getService(ref);
+        } else {
+            return null;
+        }
+    }
+
+    public static Object[] getServiceObjects(BundleContext bc, String itf, String filter) {
+        ServiceReference[] refs = getServiceReferences(bc, itf, filter);
+        if (refs != null) {
+            Object[] list = new Object[refs.length];
+            for (int i = 0; i < refs.length; i++) {
+                list[i] = bc.getService(refs[i]);
+            }
+            return list;
+        } else {
+            return new Object[0];
+        }
+    }
+
+//    public static ServiceContext getServiceContext(ComponentInstance ci) {
+//        if (ci instanceof CompositeManager) {
+//            return ((CompositeManager) ci).getServiceContext();
+//        } else {
+//            throw new RuntimeException("Cannot get the service context form an non composite instance");
+//        }
+//    }
+
+    public static Factory getFactoryByName(ServiceContext bc, String factoryName) {
+        ServiceReference[] refs;
+        try {
+            refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");
+            if (refs == null) { return null; }
+            return ((Factory) bc.getService(refs[0]));
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
+            return null;
+        }
+    }
+
+    public static ComponentInstance getComponentInstance(ServiceContext bc, String factoryName, Dictionary configuration) {
+        Factory fact = getFactoryByName(bc, factoryName);
+
+        if (fact == null) { return null; }
+
+        if (fact.isAcceptable(configuration)) {
+            try {
+                return fact.createComponentInstance(configuration);
+            } catch (Exception e) {
+                System.err.println(e.getMessage());
+                e.printStackTrace();
+                return null;
+            }
+        } else {
+            System.err.println("Configuration not accepted by : " + factoryName);
+            return null;
+        }
+    }
+
+    public static ServiceReference[] getServiceReferences(ServiceContext bc, String itf, String filter) {
+        ServiceReference[] refs = null;
+        try {
+            refs = bc.getServiceReferences(itf, filter);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Invalid Filter : " + filter);
+        }
+        if (refs == null) {
+            return new ServiceReference[0];
+        } else {
+            return refs;
+        }
+    }
+
+    public static ServiceReference getServiceReference(ServiceContext bc, String itf, String filter) {
+        ServiceReference[] refs = null;
+        try {
+            refs = bc.getServiceReferences(itf, filter);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Invalid Filter : " + filter);
+        }
+        if (refs == null) {
+            return null;
+        } else {
+            return refs[0];
+        }
+    }
+
+    public static ServiceReference getServiceReferenceByName(ServiceContext bc, String itf, String name) {
+        ServiceReference[] refs = null;
+        String filter = null;
+        if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {
+            filter = "(" + "factory.name" + "=" + name + ")";
+        } else {
+            filter = "(" + "instance.name" + "=" + name + ")";
+        }
+        try {
+            refs = bc.getServiceReferences(itf, filter);
+        } catch (InvalidSyntaxException e) {
+            System.err.println("Invalid Filter : " + filter);
+        }
+        if (refs == null) {
+            return null;
+        } else {
+            return refs[0];
+        }
+    }
+
+    public static Object getServiceObject(ServiceContext bc, String itf, String filter) {
+        ServiceReference ref = getServiceReference(bc, itf, filter);
+        if (ref != null) {
+            return bc.getService(ref);
+        } else {
+            return null;
+        }
+    }
+
+    public static Object[] getServiceObjects(ServiceContext bc, String itf, String filter) {
+        ServiceReference[] refs = getServiceReferences(bc, itf, filter);
+        if (refs != null) {
+            Object[] list = new Object[refs.length];
+            for (int i = 0; i < refs.length; i++) {
+                list[i] = bc.getService(refs[i]);
+            }
+            return list;
+        } else {
+            return new Object[0];
+        }
+    }
+    
+    public static boolean contains(String string, String[] array) {
+        for (int i = 0; array != null && i < array.length; i++) {
+            if (array[i] != null  && array[i].equals(string)) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    public static boolean contains(int value, int[] array) {
+        for (int i = 0; array != null && i < array.length; i++) {
+            if (array[i] == value) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+}

Added: felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/resources/metadata.xml?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/resources/metadata.xml (added)
+++ felix/trunk/ipojo/tests/tests.core.external.handlers/src/main/resources/metadata.xml Fri Apr 25 09:49:43 2008
@@ -0,0 +1,24 @@
+<ipojo
+	xmlns:cs="org.apache.felix.ipojo.test.handler.checkservice">
+	<handler
+		classname="org.apache.felix.ipojo.test.scenarios.component.CheckServiceHandler"
+		name="check"
+		namespace="org.apache.felix.ipojo.test.handler.checkservice"
+		architecture="false">
+		<controller field="isValid" />
+	</handler>
+	<component
+		className="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
+		factory="HANDLER-HandlerTester" architecture="true">
+		<cs:check />
+	</component>
+	<instance name="HandlerTest-2" component="HANDLER-HandlerTester">
+		<property name="csh.simple" value="Simple" />
+		<property name="csh.map">
+			<property name="a" value="a" />
+			<property name="b" value="b" />
+			<property name="c" value="c" />
+		</property>
+	</instance>
+	
+</ipojo>

Propchange: felix/trunk/ipojo/tests/tests.core.factories/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Apr 25 09:49:43 2008
@@ -0,0 +1,9 @@
+target*
+bin*
+.settings*
+.classpath
+.project
+.checkstyle
+maven-eclipse.xml
+.externalToolBuilders
+

Added: felix/trunk/ipojo/tests/tests.core.factories/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.factories/pom.xml?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.factories/pom.xml (added)
+++ felix/trunk/ipojo/tests/tests.core.factories/pom.xml Fri Apr 25 09:49:43 2008
@@ -0,0 +1,102 @@
+<!--
+	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>
+	<modelVersion>4.0.0</modelVersion>
+	<packaging>bundle</packaging>
+	<name>iPOJO Factories Test Suite</name>
+	<artifactId>tests.core.factories</artifactId>
+	<groupId>ipojo.tests</groupId>
+	<version>0.7.6-SNAPSHOT</version>
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.apache.felix.ipojo</artifactId>
+			<version>0.7.6-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.apache.felix.ipojo.metadata</artifactId>
+			<version>0.7.6-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.osgi.core</artifactId>
+			<version>1.0.0</version>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>3.8.1</version>
+		</dependency>
+		<dependency>
+			<groupId>ipojo.examples</groupId>
+			<artifactId>org.apache.felix.ipojo.junit4osgi</artifactId>
+			<version>0.7.6-SNAPSHOT</version>
+		</dependency>
+	</dependencies>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-bundle-plugin</artifactId>
+				<version>1.4.0</version>
+				<extensions>true</extensions>
+				<configuration>
+					<instructions>
+						<Export-Package>
+							org.apache.felix.ipojo.test.scenarios.factories.service
+						</Export-Package>
+						<Bundle-SymbolicName>
+							${pom.artifactId}
+						</Bundle-SymbolicName>
+						<Private-Package>
+							org.apache.felix.ipojo.test*
+						</Private-Package>
+						<Test-Suite>
+							org.apache.felix.ipojo.test.scenarios.factories.FactoryTestSuite
+						</Test-Suite>
+					</instructions>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-ipojo-plugin</artifactId>
+				<version>0.7.6-SNAPSHOT</version>
+				<executions>
+					<execution>
+						<goals>
+							<goal>ipojo-bundle</goal>
+						</goals>
+						<configuration>
+							<ignoreAnnotations>true</ignoreAnnotations>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.4</source>
+					<target>1.4</target>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+</project>

Added: felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckProviderParentClass.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckProviderParentClass.java?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckProviderParentClass.java (added)
+++ felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckProviderParentClass.java Fri Apr 25 09:49:43 2008
@@ -0,0 +1,51 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import org.apache.felix.ipojo.test.scenarios.factories.service.FooService;
+import org.osgi.framework.ServiceReference;
+
+public abstract class CheckProviderParentClass {
+    
+    int simpleU = 0;
+    int objectU = 0;
+    int refU = 0;
+    int bothU = 0;
+    
+    
+    public void bothUnbind(FooService o, ServiceReference sr) {
+        if(sr != null && o != null && o instanceof FooService) { bothU++; }
+    }
+    
+    public void refUnbind(ServiceReference sr) {
+        if(sr != null) { refU++; }
+    }
+    
+    public void objectUnbind(FooService o) {
+        if(o != null && o instanceof FooService) { objectU++; }
+        else {
+            System.err.println("Unbind null : " + o);
+        }
+    }
+    
+    public void voidUnbind() {
+        simpleU++;
+    }
+
+}

Added: felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceProvider.java?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceProvider.java (added)
+++ felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceProvider.java Fri Apr 25 09:49:43 2008
@@ -0,0 +1,83 @@
+/* 
+ * 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.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.factories.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.factories.service.FooService;
+import org.osgi.framework.ServiceReference;
+
+public class CheckServiceProvider extends CheckProviderParentClass implements CheckService {
+    
+	FooService fs;
+	
+	int simpleB = 0;
+	int objectB = 0;
+	int refB = 0;
+	int bothB = 0;
+
+	public boolean check() {
+		return fs.foo();
+	}
+
+	public Properties getProps() {
+		Properties props = new Properties();
+		props.put("voidB", new Integer(simpleB));
+		props.put("objectB", new Integer(objectB));
+		props.put("refB", new Integer(refB));
+		props.put("bothB", new Integer(bothB));
+		props.put("voidU", new Integer(simpleU));
+		props.put("objectU", new Integer(objectU));
+		props.put("refU", new Integer(refU));
+		props.put("bothU", new Integer(bothU));
+		if (fs != null) {
+		    props.put("result", new Boolean(fs.foo()));
+		    props.put("boolean", new Boolean(fs.getBoolean()));
+		    props.put("int", new Integer(fs.getInt()));
+		    props.put("long", new Long(fs.getLong()));
+		    props.put("double", new Double(fs.getDouble()));
+		    if(fs.getObject() != null) { props.put("object", fs.getObject()); }
+		}
+        props.put("static", CheckService.foo);
+        props.put("class", CheckService.class.getName());
+		return props;
+	}
+	
+	private void voidBind() {
+		simpleB++;
+	}
+	
+	protected void objectBind(FooService o) {
+	    if (o == null) {
+	        System.err.println("Bind receive null !!! ");
+	        return;
+	    }
+		if(o != null && o instanceof FooService) { objectB++; }
+	}
+	
+	public void refBind(ServiceReference sr) {
+		if(sr != null) { refB++; }
+	}
+	
+    public void bothBind(FooService o, ServiceReference sr) {
+	    if(sr != null && o != null && o instanceof FooService) { bothB++; }
+	}
+
+}

Added: felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooBarProviderType1.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooBarProviderType1.java?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooBarProviderType1.java (added)
+++ felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooBarProviderType1.java Fri Apr 25 09:49:43 2008
@@ -0,0 +1,54 @@
+/* 
+ * 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.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.factories.service.BarService;
+import org.apache.felix.ipojo.test.scenarios.factories.service.FooService;
+
+public class FooBarProviderType1 implements FooService, BarService {
+
+	public boolean foo() {
+		return true;
+	}
+
+	public Properties fooProps() {
+		return new Properties();
+	}
+
+	public boolean bar() {
+		return true;
+	}
+
+	public Properties getProps() {
+		return new Properties();
+	}
+
+	public boolean getBoolean() { return true; }
+
+	public double getDouble() { return 1.0; }
+
+	public int getInt() { return 1; }
+
+	public long getLong() { return 1; }
+
+	public Boolean getObject() { return new Boolean(true); }
+
+}

Added: felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderType1.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderType1.java?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderType1.java (added)
+++ felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderType1.java Fri Apr 25 09:49:43 2008
@@ -0,0 +1,117 @@
+/* 
+ * 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.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.factories.service.FooService;
+import org.osgi.framework.BundleContext;
+
+public class FooProviderType1 implements FooService {
+	
+	private int m_bar;
+	private String m_foo;
+    
+    private BundleContext m_context;
+    
+    private static FooProviderType1 singleton;
+    private static int count = 0;
+    
+    private static FooProviderType1 singleton(BundleContext bc) {
+        if (singleton == null) {
+            count++;
+            singleton = new FooProviderType1(bc);
+        }
+        return singleton;
+    }
+    
+    public static FooProviderType1 several(BundleContext bc) {
+        count++;
+        return new FooProviderType1(bc);
+    }
+        
+    public FooProviderType1(BundleContext bc) {
+        if (bc ==null) {
+            throw new RuntimeException("Injected bundle context null");
+        }
+            m_context = bc;
+    }
+
+	public boolean foo() {
+		return true;
+	}
+
+	public Properties fooProps() {
+		Properties p = new Properties();
+		p.put("bar", new Integer(m_bar));
+        if(m_foo != null) {
+            p.put("foo", m_foo);
+        }
+        p.put("context", m_context);
+        
+        p.put("count", new Integer(count));
+		return p;
+	}
+    
+	public void testException() throws Exception {
+        String a = "foobarbaz";
+	    throw new Exception("foo"+a);
+    }
+    
+    public void testTry() {
+            String a = "foo";
+            a.charAt(0);
+    }
+    
+    public void testTry2(String s) {
+            String a = "foo";
+            a.charAt(0);
+    }
+    
+    private void nexttry(String  s) {
+        try {
+            s += "foo";
+        } catch(RuntimeException e) {
+            
+        }
+    }
+    
+	public boolean getBoolean() { return true; }
+
+	public double getDouble() { return 1.0; }
+
+	public int getInt() { return 1; }
+
+	public long getLong() { return 1; }
+
+	public Boolean getObject() { return new Boolean(true); }
+	
+	/**
+	 * Custom constructor.
+	 * @param bar
+	 * @param foo
+	 * @param bc
+	 */
+	public FooProviderType1(int bar, String foo, BundleContext bc) {
+	    m_bar = bar;
+	    m_foo = foo;
+	    m_context = bc;
+	}
+
+}

Added: felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderTypeDyn.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderTypeDyn.java?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderTypeDyn.java (added)
+++ felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderTypeDyn.java Fri Apr 25 09:49:43 2008
@@ -0,0 +1,64 @@
+/* 
+ * 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.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.factories.service.FooService;
+
+
+public class FooProviderTypeDyn implements FooService {
+	
+	private int intProp;	
+	private String strProp;
+	private String[] strAProp;
+	private int[] intAProp;
+	private boolean boolProp;
+
+	public boolean foo() {
+		intProp = 3;
+		boolProp = true;
+		if(strProp.equals("foo")) { strProp = "bar"; }
+		else { strProp = "foo"; }
+		strAProp = new String[] {"foo", "bar", "baz"};
+		intAProp = new int[] {3, 2, 1};
+		return true;
+	}
+
+	public Properties fooProps() {
+		Properties p = new Properties();
+		p.put("intProp", new Integer(intProp));
+		p.put("boolProp", new Boolean(boolProp));
+		p.put("strProp", strProp);
+		p.put("strAProp", strAProp);
+		p.put("intAProp", intAProp);
+		return p;
+	}
+	
+	public boolean getBoolean() { return true; }
+
+	public double getDouble() { return 1.0; }
+
+	public int getInt() { return 1; }
+
+	public long getLong() { return 1; }
+
+	public Boolean getObject() { return new Boolean(true); }
+
+}

Added: felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderTypeDyn2.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderTypeDyn2.java?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderTypeDyn2.java (added)
+++ felix/trunk/ipojo/tests/tests.core.factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderTypeDyn2.java Fri Apr 25 09:49:43 2008
@@ -0,0 +1,58 @@
+/* 
+ * 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.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.factories.service.FooService;
+
+public class FooProviderTypeDyn2 implements FooService {
+	
+	private int intProp = 2;
+	private boolean boolProp = true;
+	private String strProp = "foo";
+	private String[] strAProp = new String[] {"foo", "bar"};
+	private int[] intAProp = new int[] {1, 2, 3};
+
+	public boolean foo() {
+		intAProp = null;
+		return true;
+	}
+
+	public Properties fooProps() {
+		Properties p = new Properties();
+		p.put("intProp", new Integer(intProp));
+		p.put("boolProp", new Boolean(boolProp));
+		p.put("strProp", strProp);
+		p.put("strAProp", strAProp);
+		p.put("intAProp", intAProp);
+		return p;
+	}
+	
+	public boolean getBoolean() { return true; }
+
+	public double getDouble() { return 1.0; }
+
+	public int getInt() { return 1; }
+
+	public long getLong() { return 1; }
+
+	public Boolean getObject() { return new Boolean(true); }
+
+}