fixed dictionary aspect, which is now using the "(lang=en)" filter

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@960397 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/samples.annotation/README b/dependencymanager/samples.annotation/README
index e9cde3c..8a598c4 100644
--- a/dependencymanager/samples.annotation/README
+++ b/dependencymanager/samples.annotation/README
@@ -9,10 +9,11 @@
   word existence.
   
   A DictionaryService is defined using a FactoryConfigurationAdapterService annotation, allowing to
-  instantiate many "DictionaryService" service instances from webconsole. This annotation actually
+  instantiate many "DictionaryService" instances from webconsole. This annotation actually
   registers a ManagedServiceFactory into the Registry, and you can specify some meta type
-  informations in the annotation, allowing to display the configuration parameters from WebConsole. 
-  Each time you instantiate a factory configuration whose factory pid is "Dictionary Services", 
+  informations in the annotation, allowing to configure the DictionaryService words and language from 
+  WebConsole. 
+  Each time you instantiate a factory configuration whose factory pid equals "Dictionary Services", 
   then a corresponding "DictionaryService" service is instantiated and is then injected
   into the SpellChecker service. So, before testing, you first have to go to webconsole
   Configuration panel, and specify some dictionaries (see the "Dictionary Services" Factory PID).  
@@ -20,11 +21,8 @@
   "help"). 
   
   Notice that in the sample, you will also find a DictionaryAspect Service (DictionaryAspect.java), which
-  decorates the EnglishDictionary service, by adding some additional words to *all* provided 
-  DictionaryService services. The DictionaryAspect also shows how to use a ConfigurationDependency annotation, 
-  allowing to configure some words from webconsole. A ConfigurationDependency actually registers a ManagedService 
-  object in the Registry, which also implements a MetaTypeProvider service for metatype support.
-
+  decorates the EnglishDictionary service, by adding some additional words to it. 
+  
 How to test:
 
   1) Install the following bundles:
@@ -42,14 +40,15 @@
   2) Start felix
   3) Go to web console: in the Configuration panel, edit the "Dictionary Services"
      Configuration, add some dictionaries. By default, an English dictionary is displayed. Just 
-     click on "save", then click on your refresh web browser: you will see a new dictionary service
+     click on "save", *then click on your refresh web browser*: you will see a new dictionary service
      instance. At this point, a DictionaryService service will be enabled (with the service property "lang=en"),  
      and the SpellCheck component will be injected with it. Then you should see the "spellcheck"
      command, when typing  "help" on the gogo shell.
 
   5) Just type "spellcheck hello", and the command should reply a fantastic message, like "word hello is correct".
   
-  6) You can also click on the "Aspect Dictionary" button, in order to decorate *all* Dictionaries using some custom words.
+  6) You can also click on the "Aspect Dictionary" button, in order to decorate the english dictionary with some 
+     custom words.
      By default, the "aspect" word is pre configured, but you can click on the "+" button in order to add more words. 
-     Then click on Save. At this point, all DictionaryService instances will be decorated with the aspect service.
+     Then click on Save. At this point, the English DictionaryService will be decorated with the aspect service.
      So, now, if you type "spellcheck aspect", then the message: "word aspect is correct" should be displayed. 
diff --git a/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/DictionaryAspect.java b/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/DictionaryAspect.java
index 828f47f..ff65610 100644
--- a/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/DictionaryAspect.java
+++ b/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/DictionaryAspect.java
@@ -1,19 +1,12 @@
 /*
- * 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
+ * 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.dm.samples.annotation;
@@ -25,13 +18,14 @@
 import org.apache.felix.dm.annotation.api.PropertyMetaData;
 import org.apache.felix.dm.annotation.api.ConfigurationDependency;
 import org.apache.felix.dm.annotation.api.ServiceDependency;
+import org.apache.felix.dm.annotation.api.Start;
 import org.osgi.service.log.LogService;
 
 /**
- * This aspect applies to all available Dictionary Services, and checks some custom words, configurable from
- * config admin.
+ * This aspect applies to the English DictionaryService, and allow to decorate it with some
+ * custom english words, which are configurable from webconsole.
  */
-@AspectService( ranking = 10 )
+@AspectService(ranking = 10, filter = "(lang=en)")
 public class DictionaryAspect implements DictionaryService
 {
     /**
@@ -40,53 +34,72 @@
     private volatile DictionaryService m_originalDictionary;
 
     /**
-     * We store all configured words in a thread-safe data structure, because ConfigAdmin
-     * may invoke our updated method at any time.
+     * We store all configured words in a thread-safe data structure, because ConfigAdmin may
+     * invoke our updated method at any time.
      */
     private CopyOnWriteArrayList<String> m_words = new CopyOnWriteArrayList<String>();
-    
+
     /**
-     * We'll use the OSGi log service for logging. If no log service is available, then we'll use a NullObject.
+     * We'll use the OSGi log service for logging. If no log service is available, then we'll
+     * use a NullObject.
      */
     @ServiceDependency(required = false)
     private LogService m_log;
 
     /**
-     * Defines a configuration dependency for retrieving our custom words (by default, our PID is our full class name).
-     * This annotation actually provides a ManagedService into the registry, and you can specify meta information regarding
-     * all the configuration properties (required by webconsole).
+     * Defines a configuration dependency for retrieving our english custom words (by default,
+     * our PID is our full class name).
      */
     @ConfigurationDependency(
-        heading="Aspect Dictionary", 
-        description="Declare here some words to check",
-        propagate=false,
-        metadata={
-            @PropertyMetaData(
-                heading="Dictionary aspect words",
-                description="Declare here the list of words supported by this dictionary aspect. ",
-                defaults={"aspect"},
-                id="words",
-                cardinality=Integer.MAX_VALUE)
+        propagate = false, 
+        heading = "Aspect Dictionary",
+        description = "Declare here some additional english words", 
+        metadata = { 
+            @PropertyMetaData(heading = "Dictionary aspect words", 
+                              description = "Declare here the list of english words to be added into the default english dictionary",
+                              defaults = { "aspect" }, 
+                              id = "words", 
+                              cardinality = Integer.MAX_VALUE) 
         }
     )
-    protected void updated(Dictionary<String, ?> config) {
+    protected void updated(Dictionary<String, ?> config)
+    {
         m_words.clear();
         String[] words = (String[]) config.get("words");
-        for (String word : words) {
+        for (String word : words)
+        {
             m_words.add(word);
         }
     }
 
     /**
+     * Our Aspect Service is starting and is about to be registered in the OSGi regsitry.
+     */
+    @Start
+    protected void start()
+    {
+        m_log.log(LogService.LOG_INFO, "Starting aspect Dictionary with words: " + m_words
+                + "; original dictionary service=" + m_originalDictionary);
+    }
+
+    /**
      * Checks if a word is found from our custom word list. if not, delegate to the decorated
      * dictionary.
      */
     public boolean checkWord(String word)
     {
-        m_log.log(LogService.LOG_DEBUG, "DictionaryAspect: checking word " + word);
-        if ("aspect".equals(word)) {
+        m_log.log(LogService.LOG_INFO, "DictionaryAspect: checking word " + word
+                + " (original dictionary=" + m_originalDictionary + ")");
+        if (m_words.contains(word))
+        {
             return true;
         }
         return m_originalDictionary.checkWord(word);
     }
+
+    public String toString()
+    {
+        return "DictionaryAspect: words=" + m_words + "; original dictionary="
+                + m_originalDictionary;
+    }
 }
diff --git a/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/DictionaryImpl.java b/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/DictionaryImpl.java
index 9b1c346..a0a6204 100644
--- a/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/DictionaryImpl.java
+++ b/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/DictionaryImpl.java
@@ -23,12 +23,15 @@
 
 import org.apache.felix.dm.annotation.api.PropertyMetaData;
 import org.apache.felix.dm.annotation.api.FactoryConfigurationAdapterService;
+import org.apache.felix.dm.annotation.api.ServiceDependency;
+import org.apache.felix.dm.annotation.api.Start;
+import org.osgi.service.log.LogService;
 
 /**
  * A Dictionary Service. This service uses a FactoryConfigurationAdapterService annotation, 
  * allowing to instantiate this service from webconsole. This annotation will actually register
- * a ManagedServiceFactory in the registry, and also supports meta types for describing metadata of
- * all configuration properties.
+ * a ManagedServiceFactory in the registry, and also supports meta types for configuring this
+ * service from WebConsole.
  * 
  * You must configure at least one Dictionary from web console, since the SpellCheck won't start if no Dictionary
  * Service is available.
@@ -46,7 +49,7 @@
                 "This property will be propagated with the Dictionary Service properties.",
             defaults={"en"},
             id="lang",
-            cardinality=1),
+            cardinality=0),
         @PropertyMetaData(
             heading="Dictionary words",
             description="Declare here the list of words supported by this dictionary.",
@@ -64,16 +67,38 @@
     private CopyOnWriteArrayList<String> m_words = new CopyOnWriteArrayList<String>();
     
     /**
+     * We'll use the OSGi log service for logging. If no log service is available, then we'll use a NullObject.
+     */
+    @ServiceDependency(required = false)
+    private LogService m_log;
+
+    /**
+     * Our Dictionary language.
+     */
+    private String m_lang;
+
+    /**
      * Our service will be initialized from ConfigAdmin.
      * @param config The configuration where we'll lookup our words list (key="words").
      */
     protected void updated(Dictionary<String, ?> config) {
+        m_lang = (String) config.get("lang");
         m_words.clear();
         String[] words = (String[]) config.get("words");
         for (String word : words) {
             m_words.add(word);
         }
     }
+
+    /**
+     * A new Dictionary Service is starting (because a new factory configuration has been created
+     * from webconsole).
+     */
+    @Start
+    protected void start() 
+    {
+        m_log.log(LogService.LOG_INFO, "Starting Dictionary Service with language: " + m_lang);
+    }
            
     /**
      * Check if a word exists if the list of words we have been configured from ConfigAdmin/WebConsole.
@@ -82,4 +107,10 @@
     {
         return m_words.contains(word);
     }
+    
+    @Override
+    public String toString() 
+    {
+        return "Dictionary: language=" + m_lang + ", words=" + m_words;
+    }
 }
diff --git a/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/SpellChecker.java b/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/SpellChecker.java
index 9bbda68..735382e 100644
--- a/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/SpellChecker.java
+++ b/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/SpellChecker.java
@@ -92,7 +92,7 @@
     @Descriptor("checks if word is found from an available dictionary")
     public void spellcheck(@Descriptor("the word to check")String word)
     {
-        m_log.log(LogService.LOG_DEBUG, "Checking spelling of word \"" + word
+        m_log.log(LogService.LOG_INFO, "Checking spelling of word \"" + word
             + "\" using the following dictionaries: " + m_dictionaries);
 
         for (DictionaryService dictionary : m_dictionaries)