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/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)