Added a projects building the different distribution (tutorials) used on the iPOJO web site.
- added quickstart
- add handler tutorial
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1470277 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/distributions/handler-tutorial/FooService-And-Impl/pom.xml b/ipojo/distributions/handler-tutorial/FooService-And-Impl/pom.xml
new file mode 100755
index 0000000..6e80bd8
--- /dev/null
+++ b/ipojo/distributions/handler-tutorial/FooService-And-Impl/pom.xml
@@ -0,0 +1,65 @@
+<!--
+ ~ 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>
+
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>ipojo-handler-tutorial</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
+ </parent>
+
+ <packaging>bundle</packaging>
+
+ <name>iPOJO Foo Service</name>
+
+ <artifactId>org.apache.felix.ipojo.log.foo</artifactId>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.felix.ipojo.foo
+ </Export-Package>
+ <Private-Package>
+ org.apache.felix.ipojo.foo.impl
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-ipojo-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>ipojo-bundle</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/ipojo/distributions/handler-tutorial/FooService-And-Impl/src/main/java/org/apache/felix/ipojo/foo/FooService.java b/ipojo/distributions/handler-tutorial/FooService-And-Impl/src/main/java/org/apache/felix/ipojo/foo/FooService.java
new file mode 100755
index 0000000..1bd0b9f
--- /dev/null
+++ b/ipojo/distributions/handler-tutorial/FooService-And-Impl/src/main/java/org/apache/felix/ipojo/foo/FooService.java
@@ -0,0 +1,29 @@
+/*
+ * 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.foo;
+
+/**
+ * A service interface doing mostly nothing.
+ */
+public interface FooService {
+
+ public void foo();
+
+}
diff --git a/ipojo/distributions/handler-tutorial/FooService-And-Impl/src/main/java/org/apache/felix/ipojo/foo/impl/FooServiceImpl.java b/ipojo/distributions/handler-tutorial/FooService-And-Impl/src/main/java/org/apache/felix/ipojo/foo/impl/FooServiceImpl.java
new file mode 100755
index 0000000..2817fe4
--- /dev/null
+++ b/ipojo/distributions/handler-tutorial/FooService-And-Impl/src/main/java/org/apache/felix/ipojo/foo/impl/FooServiceImpl.java
@@ -0,0 +1,41 @@
+/*
+ * 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.foo.impl;
+
+import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.annotations.Instantiate;
+import org.apache.felix.ipojo.annotations.Provides;
+import org.apache.felix.ipojo.foo.FooService;
+
+
+@Component
+@Provides
+@Instantiate(name = "ipojo.foo.provider")
+/**
+ * A very simple implementation of the FooService.
+ */
+public class FooServiceImpl implements FooService {
+
+ public void foo() {
+ System.out.println("Foo");
+ }
+
+
+}
diff --git a/ipojo/distributions/handler-tutorial/Log-Handler-Consumer/pom.xml b/ipojo/distributions/handler-tutorial/Log-Handler-Consumer/pom.xml
new file mode 100755
index 0000000..ac19fda
--- /dev/null
+++ b/ipojo/distributions/handler-tutorial/Log-Handler-Consumer/pom.xml
@@ -0,0 +1,57 @@
+<project>
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>ipojo-handler-tutorial</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
+ </parent>
+
+ <packaging>bundle</packaging>
+ <name>iPOJO Log Handler Consumer</name>
+ <artifactId>org.apache.felix.ipojo.log.consumer</artifactId>
+ <description>A bundle using the log handler</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>org.apache.felix.ipojo.log.foo</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>org.apache.felix.ipojo.log.handler</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </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.log.handler.example
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-ipojo-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>ipojo-bundle</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/ipojo/distributions/handler-tutorial/Log-Handler-Consumer/src/main/java/org/apache/felix/ipojo/log/handler/example/SimpleComponent.java b/ipojo/distributions/handler-tutorial/Log-Handler-Consumer/src/main/java/org/apache/felix/ipojo/log/handler/example/SimpleComponent.java
new file mode 100755
index 0000000..e6c1e3e
--- /dev/null
+++ b/ipojo/distributions/handler-tutorial/Log-Handler-Consumer/src/main/java/org/apache/felix/ipojo/log/handler/example/SimpleComponent.java
@@ -0,0 +1,26 @@
+package org.apache.felix.ipojo.log.handler.example;
+
+
+import org.apache.felix.ipojo.annotations.*;
+import org.apache.felix.ipojo.foo.FooService;
+import org.apache.felix.ipojo.log.handler.Log;
+
+@Component(immediate = true)
+@Log(level = Log.Level.INFO) // We configure the handler.
+@Instantiate(name = "my.simple.consumer")
+public class SimpleComponent {
+
+ @Requires
+ FooService fs;
+
+ @Validate
+ public void starting() {
+ System.out.println("Starting...");
+ fs.foo();
+ }
+
+ @Invalidate
+ public void stopping() {
+ System.out.println("Stopping...");
+ }
+}
diff --git a/ipojo/distributions/handler-tutorial/Log-Handler-In-Felix/pom.xml b/ipojo/distributions/handler-tutorial/Log-Handler-In-Felix/pom.xml
new file mode 100644
index 0000000..2c94c8d
--- /dev/null
+++ b/ipojo/distributions/handler-tutorial/Log-Handler-In-Felix/pom.xml
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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 xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>ipojo-handler-tutorial</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>loghandler-tutorial-felix</artifactId>
+ <name>Log-Handler-In-Felix</name>
+
+ <packaging>pom</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.main.distribution</artifactId>
+ <type>zip</type>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.arch.gogo</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.log</artifactId>
+ <version>1.0.1</version>
+ </dependency>
+
+ <!-- our project -->
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>org.apache.felix.ipojo.log.foo</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>org.apache.felix.ipojo.log.handler</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>org.apache.felix.ipojo.log.consumer</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>2.7</version>
+ <executions>
+
+ <execution>
+ <id>unpack-felix</id>
+ <phase>package</phase>
+ <goals>
+ <goal>unpack-dependencies</goal>
+ </goals>
+ <configuration>
+ <includeArtifactIds>org.apache.felix.main.distribution</includeArtifactIds>
+ <outputDirectory>${project.build.directory}</outputDirectory>
+ </configuration>
+ </execution>
+
+ <execution>
+ <id>copy-bundles</id>
+ <phase>package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <includeArtifactIds>
+ org.apache.felix.ipojo.log.foo,
+ org.apache.felix.ipojo.log.handler,
+ org.apache.felix.ipojo.log.consumer,
+ org.apache.felix.log,org.apache.felix.ipojo,
+ org.apache.felix.ipojo.arch.gogo
+ </includeArtifactIds>
+ <outputDirectory>${project.build.directory}/felix-framework-${felix.version}/bundle</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+ </build>
+
+
+</project>
\ No newline at end of file
diff --git a/ipojo/distributions/handler-tutorial/Log-Handler/pom.xml b/ipojo/distributions/handler-tutorial/Log-Handler/pom.xml
new file mode 100755
index 0000000..f797d3c
--- /dev/null
+++ b/ipojo/distributions/handler-tutorial/Log-Handler/pom.xml
@@ -0,0 +1,76 @@
+<!--
+ ~ 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>
+
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>ipojo-handler-tutorial</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
+ </parent>
+
+ <packaging>bundle</packaging>
+ <name>iPOJO Log Handler</name>
+ <artifactId>org.apache.felix.ipojo.log.handler</artifactId>
+ <description>A handler logging messages in an OSGi Log Service</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>4.2.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>4.2.0</version>
+ <scope>provided</scope>
+ </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.log.handler
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-ipojo-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>ipojo-bundle</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/ipojo/distributions/handler-tutorial/Log-Handler/src/main/java/org/apache/felix/ipojo/log/handler/Log.java b/ipojo/distributions/handler-tutorial/Log-Handler/src/main/java/org/apache/felix/ipojo/log/handler/Log.java
new file mode 100644
index 0000000..f9aa1db
--- /dev/null
+++ b/ipojo/distributions/handler-tutorial/Log-Handler/src/main/java/org/apache/felix/ipojo/log/handler/Log.java
@@ -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.log.handler;
+
+/**
+ * The annotation used to configure the LogHandler.
+ */
+public @interface Log {
+
+ public enum Level {
+ INFO, ERROR, WARNING
+ }
+
+ /**
+ * @return the log level
+ */
+ Level level();
+}
diff --git a/ipojo/distributions/handler-tutorial/Log-Handler/src/main/java/org/apache/felix/ipojo/log/handler/LogHandler.java b/ipojo/distributions/handler-tutorial/Log-Handler/src/main/java/org/apache/felix/ipojo/log/handler/LogHandler.java
new file mode 100755
index 0000000..9b5609b
--- /dev/null
+++ b/ipojo/distributions/handler-tutorial/Log-Handler/src/main/java/org/apache/felix/ipojo/log/handler/LogHandler.java
@@ -0,0 +1,109 @@
+/*
+ * 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.log.handler;
+
+
+import org.apache.felix.ipojo.ConfigurationException;
+import org.apache.felix.ipojo.InstanceManager;
+import org.apache.felix.ipojo.PrimitiveHandler;
+import org.apache.felix.ipojo.annotations.Handler;
+import org.apache.felix.ipojo.annotations.Requires;
+import org.apache.felix.ipojo.metadata.Element;
+import org.osgi.service.log.LogService;
+
+import java.util.Dictionary;
+
+// Declare a handler.
+@Handler(name = "Log", namespace = LogHandler.NAMESPACE)
+public class LogHandler extends PrimitiveHandler {
+
+ public static final String NAMESPACE = "org.apache.felix.ipojo.log.handler";
+
+ // Handlers are iPOJO components, so can use service dependencies
+ @Requires(optional = true, nullable = false)
+ LogService log;
+ private InstanceManager instanceManager;
+ private int logLevel;
+
+ /**
+ * Parses the component's metadata to retrieve the log level in which we log messages.
+ *
+ * @param metadata component's metadata
+ * @param configuration instance configuration (unused in this example)
+ * @throws ConfigurationException the configuration is inconsistent
+ */
+ @Override
+ public void configure(Element metadata, Dictionary configuration) throws ConfigurationException {
+ // First parse the metadata to check if the log handler logLevel
+
+ // Get all Namespace:log element from the metadata
+ Element[] log_elements = metadata.getElements("log", NAMESPACE);
+
+ // If an element match, parse the logLevel attribute of the first found element
+ if (log_elements[0].containsAttribute("level")) {
+ String l = log_elements[0].getAttribute("level");
+ if (l.equalsIgnoreCase("info")) {
+ logLevel = LogService.LOG_INFO;
+ } else if (l.equalsIgnoreCase("error")) {
+ logLevel = LogService.LOG_ERROR;
+ } else if (l.equalsIgnoreCase("warning")) {
+ logLevel = LogService.LOG_WARNING;
+ }
+ }
+
+ instanceManager = getInstanceManager();
+ }
+
+ /**
+ * The instance is starting.
+ */
+ public void start() {
+ if (log != null) {
+ log.log(logLevel, "The component instance " + instanceManager.getInstanceName() + " is starting");
+ }
+ }
+
+ /**
+ * The instance is stopping.
+ */
+ public void stop() {
+ if (log != null) {
+ log.log(logLevel, "The component instance " + instanceManager.getInstanceName() + " is stopping");
+ }
+ }
+
+ /**
+ * Logging messages when the instance state is changing
+ *
+ * @param state the new state
+ */
+ public void stateChanged(int state) {
+ if (log != null) {
+ if (state == InstanceManager.VALID) {
+ System.out.println("The component instance " + instanceManager.getInstanceName() + " becomes valid");
+ log.log(logLevel, "The component instance " + instanceManager.getInstanceName() + " becomes valid");
+ }
+ if (state == InstanceManager.INVALID) {
+ System.out.println("The component instance " + instanceManager.getInstanceName() + " becomes invalid");
+ log.log(logLevel, "The component instance " + instanceManager.getInstanceName() + " becomes invalid");
+ }
+ }
+ }
+}
diff --git a/ipojo/distributions/handler-tutorial/Property-Handler-Consumer/pom.xml b/ipojo/distributions/handler-tutorial/Property-Handler-Consumer/pom.xml
new file mode 100755
index 0000000..ceeaf25
--- /dev/null
+++ b/ipojo/distributions/handler-tutorial/Property-Handler-Consumer/pom.xml
@@ -0,0 +1,68 @@
+<!--
+ 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>
+
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>ipojo-handler-tutorial</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
+ </parent>
+
+ <packaging>bundle</packaging>
+ <name>iPOJO Property Handler Consumer</name>
+ <artifactId>org.apache.felix.ipojo.properties.consumer</artifactId>
+ <description>A bundle using the properties handler</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>org.apache.felix.ipojo.properties.handler</artifactId>
+ <version>${project.version}</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.props.example
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-ipojo-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>ipojo-bundle</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/ipojo/distributions/handler-tutorial/Property-Handler-Consumer/src/main/ipojo/metadata.xml b/ipojo/distributions/handler-tutorial/Property-Handler-Consumer/src/main/ipojo/metadata.xml
new file mode 100755
index 0000000..29f7aa1
--- /dev/null
+++ b/ipojo/distributions/handler-tutorial/Property-Handler-Consumer/src/main/ipojo/metadata.xml
@@ -0,0 +1,9 @@
+<ipojo>
+ <!-- Declare an instance illustrating instance configuration -->
+ <instance component="PropertiesTester"
+ name="instance-using-properties-i1">
+ <property name="props.file"
+ value="props\properties-i1.properties" />
+ </instance>
+
+</ipojo>
diff --git a/ipojo/distributions/handler-tutorial/Property-Handler-Consumer/src/main/java/org/apache/felix/ipojo/handler/properties/example/PropertiesTester.java b/ipojo/distributions/handler-tutorial/Property-Handler-Consumer/src/main/java/org/apache/felix/ipojo/handler/properties/example/PropertiesTester.java
new file mode 100755
index 0000000..e75aa2d
--- /dev/null
+++ b/ipojo/distributions/handler-tutorial/Property-Handler-Consumer/src/main/java/org/apache/felix/ipojo/handler/properties/example/PropertiesTester.java
@@ -0,0 +1,78 @@
+/*
+ * 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.properties.example;
+
+import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.annotations.Instantiate;
+import org.apache.felix.ipojo.annotations.Invalidate;
+import org.apache.felix.ipojo.annotations.Validate;
+import org.apache.felix.ipojo.handler.properties.Properties;
+
+import java.text.DateFormat;
+import java.util.Date;
+
+@Component(immediate = true, name = "PropertiesTester")
+@Properties(file = "props/my-properties.properties")
+@Instantiate
+public class PropertiesTester {
+
+ // These two fields will be injected.
+ private String property1;
+ private String property2;
+
+ /**
+ * Starting method.
+ * This method will be called when the instance starts.
+ */
+ @Validate
+ public void start() {
+ System.out.println("PropertiesTester is starting ...");
+ // Read the injected properties.
+ System.out.println("Property 1 : " + property1);
+ System.out.println("Property 2 : " + property2);
+
+ // Update the properties.
+ updateProperties();
+ }
+
+ /**
+ * Stopping method.
+ * This method will be called when the instance stops.
+ */
+ @Invalidate
+ public void stop() {
+ System.out.println("PropertiesTester is stopping ...");
+ System.out.println("Property 1 : " + property1);
+ System.out.println("Property 2 : " + property2);
+ }
+
+ /**
+ * This method just updates managed properties.
+ * It appends the current date to the actual property value.
+ */
+ private void updateProperties() {
+ System.out.println("Update properties");
+ Date date = new Date();
+ DateFormat df = DateFormat.getDateTimeInstance();
+ // The properties will be updated in the property file
+ property1 = property1 + " - " + df.format(date);
+ property2 = property2 + " - " + df.format(date);
+ }
+
+}
diff --git a/ipojo/distributions/handler-tutorial/Property-Handler-In-Felix/pom.xml b/ipojo/distributions/handler-tutorial/Property-Handler-In-Felix/pom.xml
new file mode 100644
index 0000000..dac5110
--- /dev/null
+++ b/ipojo/distributions/handler-tutorial/Property-Handler-In-Felix/pom.xml
@@ -0,0 +1,141 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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 xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>ipojo-handler-tutorial</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.felix</groupId>
+ <artifactId>Property-Handler-In-Felix</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
+
+ <packaging>pom</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.main.distribution</artifactId>
+ <type>zip</type>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.arch.gogo</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.log</artifactId>
+ <version>1.0.1</version>
+ </dependency>
+
+ <!-- our project -->
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>org.apache.felix.ipojo.properties.handler</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>org.apache.felix.ipojo.properties.consumer</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>2.7</version>
+ <executions>
+
+ <execution>
+ <id>unpack-felix</id>
+ <phase>package</phase>
+ <goals>
+ <goal>unpack-dependencies</goal>
+ </goals>
+ <configuration>
+ <includeArtifactIds>org.apache.felix.main.distribution</includeArtifactIds>
+ <outputDirectory>${project.build.directory}</outputDirectory>
+ </configuration>
+ </execution>
+
+ <execution>
+ <id>copy-bundles</id>
+ <phase>package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <includeArtifactIds>
+ org.apache.felix.ipojo.properties.handler,
+ org.apache.felix.ipojo.properties.consumer,
+ org.apache.felix.ipojo,
+ org.apache.felix.ipojo.arch.gogo
+ </includeArtifactIds>
+ <outputDirectory>${project.build.directory}/felix-framework-${felix.version}/bundle
+ </outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!--
+ we also copy properties file to the distribution folder,
+ the properties are stored in src/main/resources/props
+ -->
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>2.6</version>
+ <executions>
+ <execution>
+ <id>copy-resources</id>
+ <phase>package</phase>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>
+ ${project.build.directory}/felix-framework-${felix.version}/props
+ </outputDirectory>
+ <resources>
+ <resource>
+ <directory>src/main/resources/props</directory>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
diff --git a/ipojo/distributions/handler-tutorial/Property-Handler-In-Felix/src/main/resources/props/my-properties.properties b/ipojo/distributions/handler-tutorial/Property-Handler-In-Felix/src/main/resources/props/my-properties.properties
new file mode 100644
index 0000000..8ebd943
--- /dev/null
+++ b/ipojo/distributions/handler-tutorial/Property-Handler-In-Felix/src/main/resources/props/my-properties.properties
@@ -0,0 +1,21 @@
+#
+# 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.
+#
+
+property1:"aaa"
+property2:"bbb"
\ No newline at end of file
diff --git a/ipojo/distributions/handler-tutorial/Property-Handler-In-Felix/src/main/resources/props/properties-i1.properties b/ipojo/distributions/handler-tutorial/Property-Handler-In-Felix/src/main/resources/props/properties-i1.properties
new file mode 100644
index 0000000..195278e
--- /dev/null
+++ b/ipojo/distributions/handler-tutorial/Property-Handler-In-Felix/src/main/resources/props/properties-i1.properties
@@ -0,0 +1,21 @@
+#
+# 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.
+#
+
+property1:"ccc"
+property2:"ddd"
\ No newline at end of file
diff --git a/ipojo/distributions/handler-tutorial/Property-Handler/pom.xml b/ipojo/distributions/handler-tutorial/Property-Handler/pom.xml
new file mode 100755
index 0000000..11e1678
--- /dev/null
+++ b/ipojo/distributions/handler-tutorial/Property-Handler/pom.xml
@@ -0,0 +1,61 @@
+<!--
+ ~ 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>
+
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>ipojo-handler-tutorial</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
+ </parent>
+
+ <packaging>bundle</packaging>
+ <name>iPOJO Properties Handler</name>
+ <artifactId>org.apache.felix.ipojo.properties.handler</artifactId>
+ <description>A handler loading a property file</description>
+
+ <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.properties
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-ipojo-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>ipojo-bundle</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/ipojo/distributions/handler-tutorial/Property-Handler/src/main/java/org/apache/felix/ipojo/handler/properties/Properties.java b/ipojo/distributions/handler-tutorial/Property-Handler/src/main/java/org/apache/felix/ipojo/handler/properties/Properties.java
new file mode 100755
index 0000000..8a0f49b
--- /dev/null
+++ b/ipojo/distributions/handler-tutorial/Property-Handler/src/main/java/org/apache/felix/ipojo/handler/properties/Properties.java
@@ -0,0 +1,33 @@
+/*
+ * 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.properties;
+
+/**
+ * The Properties annotation.
+ * This annotation may be used in POJO class to used the Property handler.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public @interface Properties {
+
+ /**
+ * Returns the property file used by the handler.
+ */
+ String file();
+
+}
diff --git a/ipojo/distributions/handler-tutorial/Property-Handler/src/main/java/org/apache/felix/ipojo/handler/properties/PropertiesHandler.java b/ipojo/distributions/handler-tutorial/Property-Handler/src/main/java/org/apache/felix/ipojo/handler/properties/PropertiesHandler.java
new file mode 100755
index 0000000..08efa3c
--- /dev/null
+++ b/ipojo/distributions/handler-tutorial/Property-Handler/src/main/java/org/apache/felix/ipojo/handler/properties/PropertiesHandler.java
@@ -0,0 +1,295 @@
+/*
+ * 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.properties;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.ConfigurationException;
+import org.apache.felix.ipojo.PrimitiveHandler;
+import org.apache.felix.ipojo.annotations.Handler;
+import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.parser.FieldMetadata;
+import org.apache.felix.ipojo.parser.PojoMetadata;
+
+/**
+ * This handler load a properties file containing property value.
+ * The handler injects this values inside fields. When stopped the handler stores updated value inside the file. The
+ * properties file contains <pre>field-name : field-value</pre> (field-value are strings)
+ *
+ * Instances can override file locations by setting the {@literal properties.file} property.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@Handler(name="properties", namespace = PropertiesHandler.NAMESPACE)
+public class PropertiesHandler extends PrimitiveHandler {
+
+ /**
+ * The Handler namespace.
+ */
+ public static final String NAMESPACE = "org.apache.felix.ipojo.handler.properties";
+
+ /**
+ * The loaded properties.
+ */
+ private Properties m_properties = new Properties();
+
+ /**
+ * The properties file location, configured in the component's metadata.
+ */
+ private String m_file;
+
+ /**
+ * This method is the first to be invoked.
+ * This method aims to configure the handler. It receives the component type metadata and the instance
+ * configuration. The method parses given metadata and registers fields to inject.
+ *
+ * Step 3 : when the instance configuration contains the properties.file property, it overrides the properties file location.
+ *
+ * @param metadata : component type metadata
+ * @param configuration : instance description
+ * @throws ConfigurationException : the configuration of the handler has failed.
+ */
+ @SuppressWarnings("unchecked")
+ public void configure(Element metadata, Dictionary configuration) throws ConfigurationException {
+ // Parse metadata to get <properties file="$file"/>
+
+ // Get all elements to configure the handler
+ Element[] elem = metadata.getElements("properties", NAMESPACE);
+
+ switch (elem.length) {
+ case 0:
+ // No matching element in metadata, throw a configuration error.
+ // It actually happen only if you force the handler to be plugged.
+ throw new ConfigurationException("No properties found");
+ case 1:
+ // One 'properties' found, get attributes.
+ m_file = elem[0].getAttribute("file");
+ if (m_file == null) {
+ // if file is null, throw a configuration error.
+ throw new ConfigurationException("Malformed properties element : file attribute must be set");
+ }
+ break;
+ default:
+ // To simplify we handle only one properties element.
+ throw new ConfigurationException("Only one properties element is supported");
+ }
+
+ // Look if the instance overrides file location :
+ String instanceFile = (String) configuration.get("properties.file");
+ if (instanceFile != null) {
+ m_file = instanceFile;
+ }
+
+ // Load properties
+ try {
+ loadProperties();
+ } catch (IOException e) {
+ throw new ConfigurationException("Error when reading the " + m_file + " file : " + e.getMessage());
+ }
+
+ // Register fields
+ // By convention, properties file entry are field name, so look for each property to get field list.
+
+ //First get Pojo Metadata metadata :
+ PojoMetadata pojoMeta = getPojoMetadata();
+ Enumeration e = m_properties.keys();
+ while (e.hasMoreElements()) {
+ String field = (String) e.nextElement();
+ FieldMetadata fm = pojoMeta.getField(field);
+
+ if (fm == null) { // The field does not exist
+ throw new ConfigurationException("The field " + field + " is declared in the properties file but does not exist in the pojo");
+ }
+
+ // Then check that the field is a String field
+ if (!fm.getFieldType().equals(String.class.getName())) {
+ throw new ConfigurationException("The field " + field + " exists in the pojo, but is not a String");
+ }
+
+ // All checks are ok, register the interceptor.
+ getInstanceManager().register(fm, this);
+ }
+
+ // Finally register the field to listen
+ }
+
+ /**
+ * This method is called when the instance start (after the configure method). We just print stored properties.
+ * @see org.apache.felix.ipojo.Handler#start()
+ */
+ public void start() {
+ // The properties are already loaded (in the configure method), just print values.
+ m_properties.list(System.out);
+ }
+
+ /**
+ * This method is called when the instance stops. We save the properties to not lost the instance state and clear the stored properties.
+ * @see org.apache.felix.ipojo.Handler#stop()
+ */
+ public void stop() {
+ try {
+ saveProperties();
+ } catch (IOException e) {
+ error("Cannot read the file : " + m_file, e); // Log an error message by using the iPOJO logger
+ }
+ m_properties = null;
+ }
+
+ /**
+ * This method is called at each time the pojo 'get' a listened field. The method return the stored value.
+ * @param pojo : pojo object getting the field
+ * @param field : field name.
+ * @param o : previous value.
+ * @return the stored value.
+ */
+ public Object onGet(Object pojo, String field, Object o) {
+ // When the pojo requires a value for a managed field, this method is invoked.
+ // So, we have just to return the stored value.
+ return m_properties.get(field);
+ }
+
+ /**
+ * This method is called at each time the pojo 'set' a listened field. This method updates the local properties.
+ * @param pojo : pojo object setting the field
+ * @param field : field name
+ * @param newvalue : new value
+ */
+ public void onSet(Object pojo, String field, Object newvalue) {
+ // When the pojo set a value to a managed field, this method is invoked.
+ // So, we update the stored value.
+ m_properties.put(field, newvalue);
+ }
+
+ /**
+ * Step 2 : state properties when the instance becomes invalid.
+ * @param newState : the instance state
+ * @see org.apache.felix.ipojo.Handler#stateChanged(int)
+ */
+ public void stateChanged(int newState) {
+ // This method is invoked each times that the instance state changed.
+
+ // If the new state is invalid, save the properties.
+ if (newState == ComponentInstance.INVALID) {
+ // Reload properties
+ try {
+ saveProperties();
+ } catch (IOException e) {
+ error("Cannot read the file : " + m_file, e); // Log an error message by using the iPOJO logger
+ }
+ }
+ }
+
+ /**
+ * Step 5 : dynamic reconfiguration. This method is call when the instance is reconfigured externally. The given property contains property value.
+ * @param dict : new properties
+ * @see org.apache.felix.ipojo.Handler#reconfigure(java.util.Dictionary)
+ */
+ @SuppressWarnings("unchecked")
+ public synchronized void reconfigure(Dictionary dict) {
+ // For each property, look if a new value is contained in the new configuration.
+ Enumeration e = m_properties.keys();
+ while (e.hasMoreElements()) {
+ String field = (String) e.nextElement();
+ String value = (String) dict.get(field);
+ // If the dictionary contains a value, update the stored value.
+ if (value != null) {
+ m_properties.put(field, value);
+ }
+ }
+ }
+
+ /**
+ * Returns handler description.
+ * @return the handler description.
+ * @see org.apache.felix.ipojo.Handler#getDescription()
+ */
+ public HandlerDescription getDescription() {
+ return new Description(this);
+ }
+
+ /**
+ * Helper method just loading the properties.
+ * @throws IOException : the file cannot be read.
+ */
+ private void loadProperties() throws IOException {
+ // Load the properties file from file system
+ File file = new File(m_file);
+ InputStream is = new FileInputStream(file);
+ m_properties.load(is);
+ }
+
+ /**
+ * Helper method writing properties.
+ * @throws IOException : the file cannot be written.
+ */
+ private void saveProperties() throws IOException {
+ // Store the file, modified the last modification date.
+ File file = new File(m_file);
+ OutputStream os = new FileOutputStream(file);
+ m_properties.store(os, "");
+ }
+
+ /**
+ * Step 3 : The handler will participate to the instance architecture.
+ * This class describing the handler.
+ */
+ private class Description extends HandlerDescription {
+
+ /**
+ * Instantiates a new description.
+ * @param h the h
+ */
+ public Description(PrimitiveHandler h) {
+ super(h);
+ }
+
+ /**
+ * This method must return the Element describing the handler. The description of this handler contains the list of properties with attached
+ * value.
+ * @return the description of the handler.
+ * @see org.apache.felix.ipojo.architecture.HandlerDescription#getHandlerInfo()
+ */
+ @SuppressWarnings("unchecked")
+ public Element getHandlerInfo() {
+ Element elem = super.getHandlerInfo(); // This method must be called to get the root description element.
+ Enumeration e = m_properties.keys();
+ while (e.hasMoreElements()) {
+ String field = (String) e.nextElement();
+ Element prop = new Element("property", ""); // Create an element for the actual property.
+ // Add two attribute (the field and the value).
+ prop.addAttribute(new Attribute("field", field));
+ prop.addAttribute(new Attribute("value", (String) m_properties.get(field)));
+ elem.addElement(prop); // Attach the current element to the root element.
+ }
+ return elem;
+ }
+
+ }
+}
diff --git a/ipojo/distributions/handler-tutorial/pom.xml b/ipojo/distributions/handler-tutorial/pom.xml
new file mode 100644
index 0000000..af9c88a
--- /dev/null
+++ b/ipojo/distributions/handler-tutorial/pom.xml
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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 xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.distributions</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>ipojo-handler-tutorial</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
+
+ <packaging>pom</packaging>
+
+ <description>
+ Build the handlers form the tutorial and distributions to test them
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.main.distribution</artifactId>
+ <type>zip</type>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.arch.gogo</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.annotations</artifactId>
+ </dependency>
+ </dependencies>
+
+ <modules>
+ <!-- Log Handler tutorial -->
+ <module>FooService-And-Impl</module>
+ <module>Log-Handler</module>
+ <module>Log-Handler-Consumer</module>
+ <module>Log-Handler-In-Felix</module>
+
+ <!-- Property handler tutorial -->
+ <module>Property-Handler</module>
+ <module>Property-Handler-Consumer</module>
+ <module>Property-Handler-In-Felix</module>
+ </modules>
+
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <descriptorRefs>
+ <ref>project</ref>
+ </descriptorRefs>
+
+ <!--<descriptors>-->
+ <!--<descriptor>src/main/assembly/distribution.xml</descriptor>-->
+ <!--</descriptors>-->
+ <attach>true</attach>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <phase>package</phase>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file