Author: jbonofre
Date: Thu Apr 11 09:46:12 2013
New Revision: 1466815

URL: http://svn.apache.org/r1466815
Log:
[KARAF-2257] Refactore SCR examples

Added:
    karaf/trunk/scr/examples/component-factory/
    karaf/trunk/scr/examples/component-factory/NOTICE
      - copied, changed from r1466551, karaf/trunk/scr/examples/NOTICE
    karaf/trunk/scr/examples/component-factory/pom.xml
      - copied, changed from r1466551, karaf/trunk/scr/examples/pom.xml
    karaf/trunk/scr/examples/component-factory/src/
    karaf/trunk/scr/examples/component-factory/src/main/
    karaf/trunk/scr/examples/component-factory/src/main/java/
    karaf/trunk/scr/examples/component-factory/src/main/java/org/
    karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/
    karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/
    
karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/scr/
    
karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/scr/examples/
    
karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/scr/examples/component/
    
karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/scr/examples/component/factories/
    
karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/scr/examples/component/factories/GreeterServiceComponentFactory.java
      - copied, changed from r1466551, 
karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/component/MetaTypeManagedComponentConfig.java
    
karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/scr/examples/component/factories/component/
    
karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/scr/examples/component/factories/component/GreeterServiceFactoryManager.java
    
karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/scr/examples/component/factories/impl/
    
karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/scr/examples/component/factories/impl/GreeterServiceComponentFactoryImpl.java
    karaf/trunk/scr/examples/component-factory/src/main/resources/
    karaf/trunk/scr/examples/component-factory/src/main/resources/OSGI-INF/
    
karaf/trunk/scr/examples/component-factory/src/main/resources/OSGI-INF/bundle.info
    karaf/trunk/scr/examples/managed-service/
    karaf/trunk/scr/examples/managed-service/NOTICE
      - copied, changed from r1466551, karaf/trunk/scr/examples/NOTICE
    karaf/trunk/scr/examples/managed-service/pom.xml
      - copied, changed from r1466551, karaf/trunk/scr/examples/pom.xml
    karaf/trunk/scr/examples/managed-service/src/
    karaf/trunk/scr/examples/managed-service/src/main/
    karaf/trunk/scr/examples/managed-service/src/main/java/
    karaf/trunk/scr/examples/managed-service/src/main/java/org/
    karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/
    karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/
    karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/scr/
    
karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/scr/examples/
    
karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/scr/examples/managed/
    
karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/scr/examples/managed/service/
    
karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/scr/examples/managed/service/ManagedGreeterService.java
      - copied, changed from r1466551, 
karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/component/MetaTypeManagedComponentConfig.java
    
karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/scr/examples/managed/service/component/
    
karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/scr/examples/managed/service/component/ManagedGreeterComponent.java
    
karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/scr/examples/managed/service/impl/
    
karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/scr/examples/managed/service/impl/ManagedGreeterServiceImpl.java
    karaf/trunk/scr/examples/managed-service/src/main/resources/
    karaf/trunk/scr/examples/managed-service/src/main/resources/OSGI-INF/
    
karaf/trunk/scr/examples/managed-service/src/main/resources/OSGI-INF/bundle.info
    karaf/trunk/scr/examples/service/
    karaf/trunk/scr/examples/service/NOTICE
      - copied, changed from r1466551, karaf/trunk/scr/examples/NOTICE
    karaf/trunk/scr/examples/service/pom.xml
      - copied, changed from r1466551, karaf/trunk/scr/examples/pom.xml
    karaf/trunk/scr/examples/service/src/
    karaf/trunk/scr/examples/service/src/main/
    karaf/trunk/scr/examples/service/src/main/java/
    karaf/trunk/scr/examples/service/src/main/java/org/
    karaf/trunk/scr/examples/service/src/main/java/org/apache/
    karaf/trunk/scr/examples/service/src/main/java/org/apache/karaf/
    karaf/trunk/scr/examples/service/src/main/java/org/apache/karaf/scr/
    
karaf/trunk/scr/examples/service/src/main/java/org/apache/karaf/scr/examples/
    
karaf/trunk/scr/examples/service/src/main/java/org/apache/karaf/scr/examples/service/
    
karaf/trunk/scr/examples/service/src/main/java/org/apache/karaf/scr/examples/service/GreeterService.java
      - copied, changed from r1466551, 
karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/component/MetaTypeManagedComponentConfig.java
    
karaf/trunk/scr/examples/service/src/main/java/org/apache/karaf/scr/examples/service/component/
    
karaf/trunk/scr/examples/service/src/main/java/org/apache/karaf/scr/examples/service/component/GreeterComponent.java
      - copied, changed from r1466551, 
karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/component/SimpleComponent.java
    
karaf/trunk/scr/examples/service/src/main/java/org/apache/karaf/scr/examples/service/impl/
    
karaf/trunk/scr/examples/service/src/main/java/org/apache/karaf/scr/examples/service/impl/GreeterServiceImpl.java
    karaf/trunk/scr/examples/service/src/main/resources/
    karaf/trunk/scr/examples/service/src/main/resources/OSGI-INF/
    karaf/trunk/scr/examples/service/src/main/resources/OSGI-INF/bundle.info
Removed:
    karaf/trunk/scr/examples/NOTICE
    
karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/component/ManagedComponent.java
    
karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/component/MetaTypeManagedComponent.java
    
karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/component/MetaTypeManagedComponentConfig.java
    
karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/component/SimpleComponent.java
    
karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/service/ExampleService.java
    
karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/service/provider/ExampleServiceProvider.java
Modified:
    karaf/trunk/scr/examples/README
    karaf/trunk/scr/examples/pom.xml

Modified: karaf/trunk/scr/examples/README
URL: 
http://svn.apache.org/viewvc/karaf/trunk/scr/examples/README?rev=1466815&r1=1466814&r2=1466815&view=diff
==============================================================================
--- karaf/trunk/scr/examples/README (original)
+++ karaf/trunk/scr/examples/README Thu Apr 11 09:46:12 2013
@@ -1,3 +1,6 @@
+Karaf SCR Examples
+---------------------------
+
 features:addurl 
mvn:org.apache.karaf.scr/org.apache.karaf.scr.feature/2.2.6-SNAPSHOT/xml/features
 features:install scr-webconsole
 install -s 
mvn:org.apache.karaf.scr/org.apache.karaf.scr.examples/2.2.6-SNAPSHOT

Copied: karaf/trunk/scr/examples/component-factory/NOTICE (from r1466551, 
karaf/trunk/scr/examples/NOTICE)
URL: 
http://svn.apache.org/viewvc/karaf/trunk/scr/examples/component-factory/NOTICE?p2=karaf/trunk/scr/examples/component-factory/NOTICE&p1=karaf/trunk/scr/examples/NOTICE&r1=1466551&r2=1466815&rev=1466815&view=diff
==============================================================================
    (empty)

Copied: karaf/trunk/scr/examples/component-factory/pom.xml (from r1466551, 
karaf/trunk/scr/examples/pom.xml)
URL: 
http://svn.apache.org/viewvc/karaf/trunk/scr/examples/component-factory/pom.xml?p2=karaf/trunk/scr/examples/component-factory/pom.xml&p1=karaf/trunk/scr/examples/pom.xml&r1=1466551&r2=1466815&rev=1466815&view=diff
==============================================================================
--- karaf/trunk/scr/examples/pom.xml (original)
+++ karaf/trunk/scr/examples/component-factory/pom.xml Thu Apr 11 09:46:12 2013
@@ -23,20 +23,17 @@
 
     <parent>
         <groupId>org.apache.karaf.scr</groupId>
-        <artifactId>scr</artifactId>
+        <artifactId>org.apache.karaf.scr.examples</artifactId>
         <version>3.0.0-SNAPSHOT</version>
         <relativePath>../pom.xml</relativePath>
     </parent>
 
-    <artifactId>org.apache.karaf.scr.examples</artifactId>
+    <groupId>org.apache.karaf.scr.examples</groupId>
+    <artifactId>org.apache.karaf.scr.examples.component.factories</artifactId>
     <packaging>bundle</packaging>
-    <name>Apache Karaf :: SCR :: Examples</name>
+    <name>Apache Karaf :: SCR :: Examples :: Component Factories</name>
     <description>Building SCR Components using the BND Annotation 
Libraries</description>
 
-    <properties>
-        
<appendedResourcesDirectory>${basedir}/../../etc/appended-resources</appendedResourcesDirectory>
-    </properties>
-
     <dependencies>
         <dependency>
             <groupId>org.apache.felix</groupId>
@@ -48,11 +45,15 @@
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.compendium</artifactId>
+            <artifactId>org.osgi.core</artifactId>
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
         </dependency>
     </dependencies>
 
@@ -61,20 +62,20 @@
             <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
                 <inherited>true</inherited>
                 <configuration>
                     <instructions>
                         <Export-Package>
-                            ${project.artifactId}.service
+                            ${project.artifactId}
                         </Export-Package>
                         <Import-Package>
-                            !${project.artifactId}.service,
+                            !${project.artifactId},
                             *
                         </Import-Package>
                         <Private-Package>
-                            aQute.bnd.annotation.metatype,
                             ${project.artifactId}.component,
-                            ${project.artifactId}.service.provider
+                            ${project.artifactId}.impl
                         </Private-Package>
                         <Service-Component>*</Service-Component>
                     </instructions>
@@ -83,4 +84,4 @@
         </plugins>
     </build>
 
-</project>
+</project>
\ No newline at end of file

Copied: 
karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/scr/examples/component/factories/GreeterServiceComponentFactory.java
 (from r1466551, 
karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/component/MetaTypeManagedComponentConfig.java)
URL: 
http://svn.apache.org/viewvc/karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/scr/examples/component/factories/GreeterServiceComponentFactory.java?p2=karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/scr/examples/component/factories/GreeterServiceComponentFactory.java&p1=karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/component/MetaTypeManagedComponentConfig.java&r1=1466551&r2=1466815&rev=1466815&view=diff
==============================================================================
--- 
karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/component/MetaTypeManagedComponentConfig.java
 (original)
+++ 
karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/scr/examples/component/factories/GreeterServiceComponentFactory.java
 Thu Apr 11 09:46:12 2013
@@ -14,14 +14,15 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.karaf.scr.examples.component;
+package org.apache.karaf.scr.examples.component.factories;
 
-public interface MetaTypeManagedComponentConfig {
+/**
+ * The SCR Service interface we are going to publish
+ */
+public interface GreeterServiceComponentFactory {
+
+    void startGreeter();
 
-       String name();
-       
-       String salutation();
-       
-       Integer numberOfGreetings();
+    void stopGreeter();
 
 }

Added: 
karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/scr/examples/component/factories/component/GreeterServiceFactoryManager.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/scr/examples/component/factories/component/GreeterServiceFactoryManager.java?rev=1466815&view=auto
==============================================================================
--- 
karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/scr/examples/component/factories/component/GreeterServiceFactoryManager.java
 (added)
+++ 
karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/scr/examples/component/factories/component/GreeterServiceFactoryManager.java
 Thu Apr 11 09:46:12 2013
@@ -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.
+ */
+package org.apache.karaf.scr.examples.component.factories.component;
+
+import aQute.bnd.annotation.component.Activate;
+import aQute.bnd.annotation.component.Component;
+import aQute.bnd.annotation.component.Deactivate;
+import aQute.bnd.annotation.component.Reference;
+import 
org.apache.karaf.scr.examples.component.factories.GreeterServiceComponentFactory;
+import org.osgi.service.component.ComponentFactory;
+import org.osgi.service.component.ComponentInstance;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Properties;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+@Component(name = GreeterServiceFactoryManager.COMPONENT_NAME)
+public class GreeterServiceFactoryManager {
+
+    public static final String COMPONENT_NAME = "GreeterServiceFactoryManager";
+
+    public static final String COMPONENT_LABEL = "Greeter Service Factory 
Manager";
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(GreeterServiceFactoryManager.class);
+
+    private ComponentFactory factory;
+    private ComponentInstance instance;
+    private GreeterServiceComponentFactory greeterService;
+    private ReadWriteLock lock = new ReentrantReadWriteLock();
+
+    /**
+     * Called when all of the SCR Components required dependencies have been 
satisfied.
+     */
+    @Activate
+    public void activate() {
+        LOG.info("Activating the {}", COMPONENT_LABEL);
+        try {
+            lock.readLock().lock();
+            if (factory != null) {
+                final Properties props = new Properties();
+                props.setProperty("salutation", "Hello");
+                props.setProperty("name", "User");
+                instance = factory.newInstance(props);
+                greeterService = (GreeterServiceComponentFactory) 
instance.getInstance();
+                greeterService.startGreeter();
+            }
+        } finally {
+            lock.readLock().unlock();
+        }
+    }
+
+    /**
+     * Callend when any of the SCR Components required dependencies become 
unsatisfied.
+     */
+    @Deactivate
+    public void deactivate() {
+        LOG.info("Deactivating the {}", COMPONENT_LABEL);
+        try {
+            lock.readLock().lock();
+            greeterService.stopGreeter();
+            instance.dispose();
+        } finally {
+            lock.readLock().unlock();
+        }
+    }
+
+    @Reference(target = "(component.factory=greeter.factory.provider)")
+    public void setFactory(final ComponentFactory factory) {
+        try {
+            lock.writeLock().lock();
+            this.factory = factory;
+        } finally {
+            lock.writeLock().unlock();
+        }
+    }
+
+    public void unsetFactory() {
+        try {
+            lock.writeLock().lock();
+            this.factory = null;
+        } finally {
+            lock.writeLock().unlock();
+        }
+    }
+
+}

Added: 
karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/scr/examples/component/factories/impl/GreeterServiceComponentFactoryImpl.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/scr/examples/component/factories/impl/GreeterServiceComponentFactoryImpl.java?rev=1466815&view=auto
==============================================================================
--- 
karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/scr/examples/component/factories/impl/GreeterServiceComponentFactoryImpl.java
 (added)
+++ 
karaf/trunk/scr/examples/component-factory/src/main/java/org/apache/karaf/scr/examples/component/factories/impl/GreeterServiceComponentFactoryImpl.java
 Thu Apr 11 09:46:12 2013
@@ -0,0 +1,148 @@
+/*
+ * 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.karaf.scr.examples.component.factories.impl;
+
+import aQute.bnd.annotation.component.Activate;
+import aQute.bnd.annotation.component.Component;
+import aQute.bnd.annotation.component.Deactivate;
+import 
org.apache.karaf.scr.examples.component.factories.GreeterServiceComponentFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ * An implementation of the GreeterServiceComponentFactory interface. Component
+ * configuration includes setting the name attribute and setting the
+ * configuration policy to required. The default is optional and when the
+ * component attempts to activate it will throw a RuntimeException.
+ *
+ * @author sully6768
+ */
+// the ConfigAdmin PID of our component
+@Component(name = GreeterServiceComponentFactoryImpl.COMPONENT_NAME,
+    // the Factory ID of the Component Factory
+    factory = "greeter.factory.provider")
+public class GreeterServiceComponentFactoryImpl implements 
GreeterServiceComponentFactory {
+
+    public static final String COMPONENT_NAME = 
"GreeterServiceComponentFactory";
+    public static final String COMPONENT_LABEL = "Greeter Service Component 
Factory";
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(GreeterServiceComponentFactoryImpl.class);
+
+    private ExecutorService executor = Executors.newCachedThreadPool();
+    private Worker worker = new Worker();
+    private ReadWriteLock lock = new ReentrantReadWriteLock();
+
+    /**
+     * Called when all of the SCR Components required dependencies have been 
satisfied.
+     */
+    @Activate
+    public void activate(final Map<String, ?> properties) {
+        LOG.info("Activating the {}", COMPONENT_LABEL);
+
+        // just because the component has a policy of required doesn't help to 
ensure our
+        // properties are set.
+        // first check that salutation is set
+        if (properties.containsKey("salutation")) {
+            try {
+                lock.writeLock().lock();
+                worker.setSalutation((String) properties.get("salutation"));
+            } finally {
+                lock.writeLock().unlock();
+            }
+        } else {
+            throw new IllegalArgumentException("The salutation property may 
not be null or empty: " + properties.get("salutation"));
+        }
+
+        // now verify that name is set
+        if (properties.containsKey("name")) {
+            try {
+                lock.writeLock().lock();
+                worker.setName((String) properties.get("name"));
+            } finally {
+                lock.writeLock().unlock();
+            }
+        } else {
+            throw new IllegalArgumentException("The name property may not be 
null or empty: " + properties.get("name"));
+        }
+    }
+
+    /**
+     * Called when any of the SCR Components required dependencies become 
unsatisfied.
+     */
+    @Deactivate
+    public void deactivate() {
+        LOG.info("Deactivating the {}", COMPONENT_LABEL);
+    }
+
+    public void startGreeter() {
+        try {
+            lock.writeLock().lock();
+            executor.execute(worker);
+        } finally {
+            lock.writeLock().unlock();
+        }
+    }
+
+    public void stopGreeter() {
+        try {
+            lock.writeLock().lock();
+            if (!executor.isTerminated()) {
+                executor.shutdownNow();
+            }
+        } finally {
+            lock.writeLock().unlock();
+        }
+    }
+
+    /**
+     * Thread worker that continuously prints a message.
+     */
+    private class Worker implements Runnable {
+
+        private String name;
+        private String salutation;
+
+        public void run() {
+            boolean running = true;
+            int messageCount = 0;
+            while (running) {
+                try {
+                    LOG.info("Message {}: salutation {}", (++messageCount), 
name);
+                    Thread.sleep(1000);
+                } catch (InterruptedException e) {
+                    running = false;
+                    LOG.info("Thread shutting down");
+                }
+            }
+        }
+
+        public void setName(String userName) {
+            this.name = userName;
+        }
+
+        public void setSalutation(String salutation) {
+            this.salutation = salutation;
+        }
+    }
+
+}

Added: 
karaf/trunk/scr/examples/component-factory/src/main/resources/OSGI-INF/bundle.info
URL: 
http://svn.apache.org/viewvc/karaf/trunk/scr/examples/component-factory/src/main/resources/OSGI-INF/bundle.info?rev=1466815&view=auto
==============================================================================
--- 
karaf/trunk/scr/examples/component-factory/src/main/resources/OSGI-INF/bundle.info
 (added)
+++ 
karaf/trunk/scr/examples/component-factory/src/main/resources/OSGI-INF/bundle.info
 Thu Apr 11 09:46:12 2013
@@ -0,0 +1,10 @@
+\u001B[1mSYNOPSIS\u001B[0m
+    ${project.name}
+
+    ${project.description}
+
+    Maven URL:
+        
\u001B[33mmvn:${project.groupId}/${project.artifactId}/${project.version}\u001B[0m
+
+\u001B[1mDESCRIPTION\u001B[0m
+    An SCR example project for Component Factories.
\ No newline at end of file

Copied: karaf/trunk/scr/examples/managed-service/NOTICE (from r1466551, 
karaf/trunk/scr/examples/NOTICE)
URL: 
http://svn.apache.org/viewvc/karaf/trunk/scr/examples/managed-service/NOTICE?p2=karaf/trunk/scr/examples/managed-service/NOTICE&p1=karaf/trunk/scr/examples/NOTICE&r1=1466551&r2=1466815&rev=1466815&view=diff
==============================================================================
    (empty)

Copied: karaf/trunk/scr/examples/managed-service/pom.xml (from r1466551, 
karaf/trunk/scr/examples/pom.xml)
URL: 
http://svn.apache.org/viewvc/karaf/trunk/scr/examples/managed-service/pom.xml?p2=karaf/trunk/scr/examples/managed-service/pom.xml&p1=karaf/trunk/scr/examples/pom.xml&r1=1466551&r2=1466815&rev=1466815&view=diff
==============================================================================
--- karaf/trunk/scr/examples/pom.xml (original)
+++ karaf/trunk/scr/examples/managed-service/pom.xml Thu Apr 11 09:46:12 2013
@@ -23,36 +23,33 @@
 
     <parent>
         <groupId>org.apache.karaf.scr</groupId>
-        <artifactId>scr</artifactId>
+        <artifactId>org.apache.karaf.scr.examples</artifactId>
         <version>3.0.0-SNAPSHOT</version>
         <relativePath>../pom.xml</relativePath>
     </parent>
 
-    <artifactId>org.apache.karaf.scr.examples</artifactId>
+    <groupId>org.apache.karaf.scr.examples</groupId>
+    <artifactId>org.apache.karaf.scr.examples.managed.service</artifactId>
     <packaging>bundle</packaging>
-    <name>Apache Karaf :: SCR :: Examples</name>
+    <name>Apache Karaf :: SCR :: Examples :: Managed Services</name>
     <description>Building SCR Components using the BND Annotation 
Libraries</description>
 
-    <properties>
-        
<appendedResourcesDirectory>${basedir}/../../etc/appended-resources</appendedResourcesDirectory>
-    </properties>
-
     <dependencies>
         <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.scr</artifactId>
-        </dependency>
-        <dependency>
             <groupId>biz.aQute</groupId>
             <artifactId>bndlib</artifactId>
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.compendium</artifactId>
+            <artifactId>org.osgi.core</artifactId>
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
         </dependency>
     </dependencies>
 
@@ -61,20 +58,20 @@
             <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
                 <inherited>true</inherited>
                 <configuration>
                     <instructions>
                         <Export-Package>
-                            ${project.artifactId}.service
+                            ${project.artifactId}
                         </Export-Package>
                         <Import-Package>
-                            !${project.artifactId}.service,
+                            !${project.artifactId},
                             *
                         </Import-Package>
                         <Private-Package>
-                            aQute.bnd.annotation.metatype,
                             ${project.artifactId}.component,
-                            ${project.artifactId}.service.provider
+                            ${project.artifactId}.impl
                         </Private-Package>
                         <Service-Component>*</Service-Component>
                     </instructions>
@@ -83,4 +80,4 @@
         </plugins>
     </build>
 
-</project>
+</project>
\ No newline at end of file

Copied: 
karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/scr/examples/managed/service/ManagedGreeterService.java
 (from r1466551, 
karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/component/MetaTypeManagedComponentConfig.java)
URL: 
http://svn.apache.org/viewvc/karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/scr/examples/managed/service/ManagedGreeterService.java?p2=karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/scr/examples/managed/service/ManagedGreeterService.java&p1=karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/component/MetaTypeManagedComponentConfig.java&r1=1466551&r2=1466815&rev=1466815&view=diff
==============================================================================
--- 
karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/component/MetaTypeManagedComponentConfig.java
 (original)
+++ 
karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/scr/examples/managed/service/ManagedGreeterService.java
 Thu Apr 11 09:46:12 2013
@@ -14,14 +14,15 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.karaf.scr.examples.component;
+package org.apache.karaf.scr.examples.managed.service;
 
-public interface MetaTypeManagedComponentConfig {
+/**
+ * The SCR Service interface we are going to publish
+ */
+public interface ManagedGreeterService {
+
+    void startGreeter();
 
-       String name();
-       
-       String salutation();
-       
-       Integer numberOfGreetings();
+    void stopGreeter();
 
 }

Added: 
karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/scr/examples/managed/service/component/ManagedGreeterComponent.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/scr/examples/managed/service/component/ManagedGreeterComponent.java?rev=1466815&view=auto
==============================================================================
--- 
karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/scr/examples/managed/service/component/ManagedGreeterComponent.java
 (added)
+++ 
karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/scr/examples/managed/service/component/ManagedGreeterComponent.java
 Thu Apr 11 09:46:12 2013
@@ -0,0 +1,93 @@
+/*
+ * 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.karaf.scr.examples.managed.service.component;
+
+import aQute.bnd.annotation.component.Activate;
+import aQute.bnd.annotation.component.Component;
+import aQute.bnd.annotation.component.Deactivate;
+import aQute.bnd.annotation.component.Reference;
+import org.apache.karaf.scr.examples.managed.service.ManagedGreeterService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+@Component(name = ManagedGreeterComponent.COMPONENT_NAME)
+public class ManagedGreeterComponent {
+
+    public static final String COMPONENT_NAME = "ManagedGreeterComponent";
+
+    public static final String COMPONENT_LABEL = "Managed Greeter Component";
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(ManagedGreeterComponent.class);
+
+    private ManagedGreeterService greeterService;
+    private ReadWriteLock lock = new ReentrantReadWriteLock();
+
+    /**
+     * Called when all of the SCR Components required dependencies have been 
satisfied
+     */
+    @Activate
+    public void activate() {
+        LOG.info("Activating the {}", COMPONENT_LABEL);
+        try {
+            lock.readLock().lock();
+            if (greeterService != null) {
+                greeterService.startGreeter();
+            }
+        } finally {
+            lock.readLock().unlock();
+        }
+    }
+
+    /**
+     * Called when any of the SCR Components required dependencies become 
unsatisfied.
+     */
+    @Deactivate
+    public void deactivate() {
+        LOG.info("Deactivating the {}", COMPONENT_LABEL);
+        try {
+            lock.readLock().lock();
+            if (greeterService != null) {
+                greeterService.stopGreeter();
+            }
+        } finally {
+            lock.readLock().unlock();
+        }
+    }
+
+    @Reference
+    public void setGreeterService(final ManagedGreeterService greeterService) {
+        try {
+            lock.writeLock().lock();
+            this.greeterService = greeterService;
+        } finally {
+            lock.writeLock().unlock();
+        }
+    }
+
+    public void unsetGreeterService() {
+        try {
+            lock.writeLock().lock();
+            this.greeterService = null;
+        } finally {
+            lock.writeLock().unlock();
+        }
+    }
+
+}

Added: 
karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/scr/examples/managed/service/impl/ManagedGreeterServiceImpl.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/scr/examples/managed/service/impl/ManagedGreeterServiceImpl.java?rev=1466815&view=auto
==============================================================================
--- 
karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/scr/examples/managed/service/impl/ManagedGreeterServiceImpl.java
 (added)
+++ 
karaf/trunk/scr/examples/managed-service/src/main/java/org/apache/karaf/scr/examples/managed/service/impl/ManagedGreeterServiceImpl.java
 Thu Apr 11 09:46:12 2013
@@ -0,0 +1,167 @@
+/*
+ * 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.karaf.scr.examples.managed.service.impl;
+
+import aQute.bnd.annotation.component.*;
+import org.apache.karaf.scr.examples.managed.service.ManagedGreeterService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ * An implementation of the ManagedGreeterService interface. Component 
configuration includes setting
+ * the name attribute and setting the configuration policy to required. The 
default is optional and when the
+ * component attempts to activate it will throw a RuntimeException.
+ */
+@Component(name = ManagedGreeterServiceImpl.COMPONENT_NAME, 
configurationPolicy = ConfigurationPolicy.require)
+public class ManagedGreeterServiceImpl implements ManagedGreeterService {
+
+    public static final String COMPONENT_NAME = "ManagedGreeterService";
+    public static final String COMPONENT_LABEL = "Managed Greeter Service";
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(ManagedGreeterServiceImpl.class);
+
+    private ExecutorService executor = Executors.newCachedThreadPool();
+    private Worker worker = new Worker();
+    private ReadWriteLock lock = new ReentrantReadWriteLock();
+
+    /**
+     * Called when all of the SCR Components required dependencies have been 
satisfied.
+     */
+    @Activate
+    public void activate(final Map<String, ?> properties) {
+        LOG.info("Activating the {}", COMPONENT_LABEL);
+
+        // just because our component has a policy of required doesn't help to 
ensure our properties are set
+        // first check that salutation is set
+        if (properties.containsKey("salutation")) {
+            try {
+                lock.writeLock().lock();
+                worker.setSalutation((String) properties.get("salutation"));
+            } finally {
+                lock.writeLock().unlock();
+            }
+        } else {
+            throw new IllegalArgumentException("The salutation property may 
not be null or empty: " + properties.get("salutation"));
+        }
+
+        // now verify that name is set
+        if (properties.containsKey("name")) {
+            try {
+                lock.writeLock().lock();
+                worker.setName((String) properties.get("name"));
+            } finally {
+                lock.writeLock().unlock();
+            }
+        } else {
+            throw new IllegalArgumentException("The name property may not be 
null or empty: " + properties.get("name"));
+        }
+    }
+
+    /**
+     * Called when any of the SCR Components required dependencies become 
unsatisfied.
+     */
+    @Deactivate
+    public void deactivate() {
+        LOG.info("Deactivating the {}", COMPONENT_LABEL);
+    }
+
+    /**
+     * Called when the configuration associated with this component has been 
updated.
+     */
+    @Modified
+    public void modified(final Map<String, ?> properties) {
+        LOG.info("Modifying the {}", COMPONENT_LABEL);
+
+        // this time we really only need to make sure if it changed it isn't 
empty
+        if (properties.containsKey("salutation") && 
!properties.get("salutation").equals("")) {
+            try {
+                lock.writeLock().lock();
+                worker.setSalutation((String) properties.get("salutation"));
+            } finally {
+                lock.writeLock().unlock();
+            }
+        }
+
+        // same for name
+        if (properties.containsKey("name") && 
!properties.get("name").equals("")) {
+            try {
+                lock.writeLock().lock();
+                worker.setName((String) properties.get("name"));
+            } finally {
+                lock.writeLock().unlock();
+            }
+        }
+    }
+
+    public void startGreeter() {
+        try {
+            lock.writeLock().lock();
+            executor.execute(worker);
+        } finally {
+            lock.writeLock().unlock();
+        }
+    }
+
+    public void stopGreeter() {
+        try {
+            lock.writeLock().lock();
+            if (!executor.isTerminated()) {
+                executor.shutdownNow();
+            }
+        } finally {
+            lock.writeLock().unlock();
+        }
+    }
+
+    /**
+     * Thread worker that continuously prints a message.
+     */
+    private class Worker implements Runnable {
+
+        private String name;
+        private String salutation;
+
+        public void run() {
+            boolean running = true;
+            int messageCount = 0;
+            while (running) {
+                try {
+                    LOG.info("Message {}: {} {}", messageCount, salutation, 
name);
+                    Thread.sleep(1000);
+                } catch (InterruptedException e) {
+                    running = false;
+                    LOG.info("Thread shutting down");
+                }
+            }
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public void setSalutation(String salutation) {
+            this.salutation = salutation;
+        }
+    }
+
+}

Added: 
karaf/trunk/scr/examples/managed-service/src/main/resources/OSGI-INF/bundle.info
URL: 
http://svn.apache.org/viewvc/karaf/trunk/scr/examples/managed-service/src/main/resources/OSGI-INF/bundle.info?rev=1466815&view=auto
==============================================================================
--- 
karaf/trunk/scr/examples/managed-service/src/main/resources/OSGI-INF/bundle.info
 (added)
+++ 
karaf/trunk/scr/examples/managed-service/src/main/resources/OSGI-INF/bundle.info
 Thu Apr 11 09:46:12 2013
@@ -0,0 +1,10 @@
+\u001B[1mSYNOPSIS\u001B[0m
+    ${project.name}
+
+    ${project.description}
+
+    Maven URL:
+        
\u001B[33mmvn:${project.groupId}/${project.artifactId}/${project.version}\u001B[0m
+
+\u001B[1mDESCRIPTION\u001B[0m
+    An SCR example project for Managed Services.
\ No newline at end of file

Modified: karaf/trunk/scr/examples/pom.xml
URL: 
http://svn.apache.org/viewvc/karaf/trunk/scr/examples/pom.xml?rev=1466815&r1=1466814&r2=1466815&view=diff
==============================================================================
--- karaf/trunk/scr/examples/pom.xml (original)
+++ karaf/trunk/scr/examples/pom.xml Thu Apr 11 09:46:12 2013
@@ -29,58 +29,13 @@
     </parent>
 
     <artifactId>org.apache.karaf.scr.examples</artifactId>
-    <packaging>bundle</packaging>
+    <packaging>pom</packaging>
     <name>Apache Karaf :: SCR :: Examples</name>
-    <description>Building SCR Components using the BND Annotation 
Libraries</description>
 
-    <properties>
-        
<appendedResourcesDirectory>${basedir}/../../etc/appended-resources</appendedResourcesDirectory>
-    </properties>
-
-    <dependencies>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.scr</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>biz.aQute</groupId>
-            <artifactId>bndlib</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.compendium</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
-        </dependency>
-    </dependencies>
-
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.felix</groupId>
-                <artifactId>maven-bundle-plugin</artifactId>
-                <inherited>true</inherited>
-                <configuration>
-                    <instructions>
-                        <Export-Package>
-                            ${project.artifactId}.service
-                        </Export-Package>
-                        <Import-Package>
-                            !${project.artifactId}.service,
-                            *
-                        </Import-Package>
-                        <Private-Package>
-                            aQute.bnd.annotation.metatype,
-                            ${project.artifactId}.component,
-                            ${project.artifactId}.service.provider
-                        </Private-Package>
-                        <Service-Component>*</Service-Component>
-                    </instructions>
-                </configuration>
-            </plugin>
-        </plugins>
-    </build>
+    <modules>
+        <module>service</module>
+        <module>managed-service</module>
+        <module>component-factory</module>
+    </modules>
 
 </project>

Copied: karaf/trunk/scr/examples/service/NOTICE (from r1466551, 
karaf/trunk/scr/examples/NOTICE)
URL: 
http://svn.apache.org/viewvc/karaf/trunk/scr/examples/service/NOTICE?p2=karaf/trunk/scr/examples/service/NOTICE&p1=karaf/trunk/scr/examples/NOTICE&r1=1466551&r2=1466815&rev=1466815&view=diff
==============================================================================
    (empty)

Copied: karaf/trunk/scr/examples/service/pom.xml (from r1466551, 
karaf/trunk/scr/examples/pom.xml)
URL: 
http://svn.apache.org/viewvc/karaf/trunk/scr/examples/service/pom.xml?p2=karaf/trunk/scr/examples/service/pom.xml&p1=karaf/trunk/scr/examples/pom.xml&r1=1466551&r2=1466815&rev=1466815&view=diff
==============================================================================
--- karaf/trunk/scr/examples/pom.xml (original)
+++ karaf/trunk/scr/examples/service/pom.xml Thu Apr 11 09:46:12 2013
@@ -23,36 +23,33 @@
 
     <parent>
         <groupId>org.apache.karaf.scr</groupId>
-        <artifactId>scr</artifactId>
+        <artifactId>org.apache.karaf.scr.examples</artifactId>
         <version>3.0.0-SNAPSHOT</version>
         <relativePath>../pom.xml</relativePath>
     </parent>
 
-    <artifactId>org.apache.karaf.scr.examples</artifactId>
+    <groupId>org.apache.karaf.scr.examples</groupId>
+    <artifactId>org.apache.karaf.scr.examples.service</artifactId>
     <packaging>bundle</packaging>
-    <name>Apache Karaf :: SCR :: Examples</name>
+    <name>Apache Karaf :: SCR :: Examples :: Basic Service</name>
     <description>Building SCR Components using the BND Annotation 
Libraries</description>
 
-    <properties>
-        
<appendedResourcesDirectory>${basedir}/../../etc/appended-resources</appendedResourcesDirectory>
-    </properties>
-
     <dependencies>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.scr</artifactId>
-        </dependency>
+        <!-- contains the SCR Annotations -->
         <dependency>
             <groupId>biz.aQute</groupId>
             <artifactId>bndlib</artifactId>
         </dependency>
+        <!-- contains the SCR Binaries (only required if you need the low 
level SCR APIs -->
+        <!--
         <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.compendium</artifactId>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr</artifactId>
         </dependency>
+        -->
         <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
         </dependency>
     </dependencies>
 
@@ -61,20 +58,20 @@
             <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
                 <inherited>true</inherited>
                 <configuration>
                     <instructions>
                         <Export-Package>
-                            ${project.artifactId}.service
+                            ${project.artifactId}
                         </Export-Package>
                         <Import-Package>
-                            !${project.artifactId}.service,
+                            !${project.artifactId},
                             *
                         </Import-Package>
                         <Private-Package>
-                            aQute.bnd.annotation.metatype,
                             ${project.artifactId}.component,
-                            ${project.artifactId}.service.provider
+                            ${project.artifactId}.impl
                         </Private-Package>
                         <Service-Component>*</Service-Component>
                     </instructions>
@@ -83,4 +80,4 @@
         </plugins>
     </build>
 
-</project>
+</project>
\ No newline at end of file

Copied: 
karaf/trunk/scr/examples/service/src/main/java/org/apache/karaf/scr/examples/service/GreeterService.java
 (from r1466551, 
karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/component/MetaTypeManagedComponentConfig.java)
URL: 
http://svn.apache.org/viewvc/karaf/trunk/scr/examples/service/src/main/java/org/apache/karaf/scr/examples/service/GreeterService.java?p2=karaf/trunk/scr/examples/service/src/main/java/org/apache/karaf/scr/examples/service/GreeterService.java&p1=karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/component/MetaTypeManagedComponentConfig.java&r1=1466551&r2=1466815&rev=1466815&view=diff
==============================================================================
--- 
karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/component/MetaTypeManagedComponentConfig.java
 (original)
+++ 
karaf/trunk/scr/examples/service/src/main/java/org/apache/karaf/scr/examples/service/GreeterService.java
 Thu Apr 11 09:46:12 2013
@@ -14,14 +14,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.karaf.scr.examples.component;
+package org.apache.karaf.scr.examples.service;
 
-public interface MetaTypeManagedComponentConfig {
+/**
+ * The SCR Service interface we are going to publish
+ */
+public interface GreeterService {
 
-       String name();
-       
-       String salutation();
-       
-       Integer numberOfGreetings();
+    void printGreetings();
 
 }

Copied: 
karaf/trunk/scr/examples/service/src/main/java/org/apache/karaf/scr/examples/service/component/GreeterComponent.java
 (from r1466551, 
karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/component/SimpleComponent.java)
URL: 
http://svn.apache.org/viewvc/karaf/trunk/scr/examples/service/src/main/java/org/apache/karaf/scr/examples/service/component/GreeterComponent.java?p2=karaf/trunk/scr/examples/service/src/main/java/org/apache/karaf/scr/examples/service/component/GreeterComponent.java&p1=karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/component/SimpleComponent.java&r1=1466551&r2=1466815&rev=1466815&view=diff
==============================================================================
--- 
karaf/trunk/scr/examples/src/main/java/org/apache/karaf/scr/examples/component/SimpleComponent.java
 (original)
+++ 
karaf/trunk/scr/examples/service/src/main/java/org/apache/karaf/scr/examples/service/component/GreeterComponent.java
 Thu Apr 11 09:46:12 2013
@@ -14,64 +14,50 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.karaf.scr.examples.component;
-
-import org.apache.karaf.scr.examples.service.ExampleService;
-import org.osgi.service.log.LogService;
+package org.apache.karaf.scr.examples.service.component;
 
 import aQute.bnd.annotation.component.Activate;
 import aQute.bnd.annotation.component.Component;
 import aQute.bnd.annotation.component.Deactivate;
 import aQute.bnd.annotation.component.Reference;
+import org.apache.karaf.scr.examples.service.GreeterService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-@Component(name = SimpleComponent.COMPONENT_NAME)
-public class SimpleComponent {
-
-    public static final String COMPONENT_NAME = "SimpleComponent";
+@Component(name = GreeterComponent.COMPONENT_NAME)
+public class GreeterComponent {
 
-    public static final String COMPONENT_LABEL = "Example Component";
+    public static final String COMPONENT_NAME = "GreeterComponent";
+    public static final String COMPONENT_LABEL = "Greeter Service Component";
 
-    private LogService logService;
+    private static final Logger LOG = 
LoggerFactory.getLogger(GreeterComponent.class);
 
-    private ExampleService exampleService;
+    private GreeterService greeterService;
 
     /**
-     * Called when all of the SCR Components required dependencies have been
-     * satisfied.
+     * Called when all of the SCR Components required dependencies have been 
satisfied.
      */
     @Activate
     public void activate() {
-        logService.log(LogService.LOG_INFO, "Activating the " + 
COMPONENT_LABEL);
-        exampleService.setName("Scott");
-        exampleService.setSalutation("Hello");
-        exampleService.printGreetings();
+        LOG.info("Activating the {}", COMPONENT_LABEL);
+        greeterService.printGreetings();
     }
 
     /**
-     * Called when any of the SCR Components required dependencies become
-     * unsatisfied.
+     * Called when any of the SCR Components required dependencies become 
unsatisfied.
      */
     @Deactivate
     public void deactivate() {
-        logService.log(LogService.LOG_INFO, "Deactivating the " + 
COMPONENT_LABEL);
-    }
-
-    @Reference
-    public void setExampleService(final ExampleService exampleService) {
-        this.exampleService = exampleService;
-    }
-
-    public void unsetExampleService(final ExampleService exampleService) {
-        this.exampleService = null;
+        LOG.info("Deactivating the {}", COMPONENT_LABEL);
     }
 
     @Reference
-    protected void setLogService(LogService logService) {
-        this.logService = logService;
+    public void setGreeterService(final GreeterService greeterService) {
+        this.greeterService = greeterService;
     }
 
-    protected void unsetLogService(LogService logService) {
-        this.logService = null;
+    public void unsetGreeterService(final GreeterService greeterService) {
+        this.greeterService = null;
     }
 
 }

Added: 
karaf/trunk/scr/examples/service/src/main/java/org/apache/karaf/scr/examples/service/impl/GreeterServiceImpl.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/scr/examples/service/src/main/java/org/apache/karaf/scr/examples/service/impl/GreeterServiceImpl.java?rev=1466815&view=auto
==============================================================================
--- 
karaf/trunk/scr/examples/service/src/main/java/org/apache/karaf/scr/examples/service/impl/GreeterServiceImpl.java
 (added)
+++ 
karaf/trunk/scr/examples/service/src/main/java/org/apache/karaf/scr/examples/service/impl/GreeterServiceImpl.java
 Thu Apr 11 09:46:12 2013
@@ -0,0 +1,46 @@
+/*
+ * 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.karaf.scr.examples.service.impl;
+
+import aQute.bnd.annotation.component.Component;
+import org.apache.karaf.scr.examples.service.GreeterService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * <p>
+ *     The service implementation for our {@link GreeterService}
+ * </p>
+ * <p>
+ *     With the {@link Component} annotation, any declared interface on this 
class will automatically be
+ *     exported as a service. The DS annotations are build time only though 
and do not inherit.
+ * </p>
+ */
+@Component
+public class GreeterServiceImpl implements GreeterService {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(GreeterServiceImpl.class);
+
+    private String name = System.getProperty("user.name", "User name");
+
+    private String salutation = "Hello";
+
+    public void printGreetings() {
+        LOG.info("{} {}", salutation, name);
+    }
+
+}

Added: karaf/trunk/scr/examples/service/src/main/resources/OSGI-INF/bundle.info
URL: 
http://svn.apache.org/viewvc/karaf/trunk/scr/examples/service/src/main/resources/OSGI-INF/bundle.info?rev=1466815&view=auto
==============================================================================
--- karaf/trunk/scr/examples/service/src/main/resources/OSGI-INF/bundle.info 
(added)
+++ karaf/trunk/scr/examples/service/src/main/resources/OSGI-INF/bundle.info 
Thu Apr 11 09:46:12 2013
@@ -0,0 +1,10 @@
+\u001B[1mSYNOPSIS\u001B[0m
+    ${project.name}
+
+    ${project.description}
+
+    Maven URL:
+        
\u001B[33mmvn:${project.groupId}/${project.artifactId}/${project.version}\u001B[0m
+
+\u001B[1mDESCRIPTION\u001B[0m
+    An SCR example project for basic Services and Components.
\ No newline at end of file


Reply via email to