Modified the sample in order to use GOGO shell
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@956519 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/samples.annotation/README b/dependencymanager/samples.annotation/README
index a8d97a4..6c04f5b 100644
--- a/dependencymanager/samples.annotation/README
+++ b/dependencymanager/samples.annotation/README
@@ -2,20 +2,22 @@
Sample description:
- This sample shows a basic "SpellChecker" application which provides a Felix "spellcheck" shell
- command. The SpellChecker class is a Felix Shell command (it provides a "Command" service),
- which accepts a string as parameter. So, when you type a string, the command just says if the
- specified string has been found from one of its injected dictionaries. The SpellChecker class has a
- required/multiple (1..N) dependency over any available DictionaryService.
+ This sample shows a basic "SpellChecker" application which provides a Felix "spellcheck" GOGO shell
+ command. The GOGO "spellcheck" command accepts a string as parameter, which is checked for proper
+ existance. The SpellChecker class has a required/multiple (1..N) dependency over every available
+ "DictionaryService" services, which are internally used by the SpellChecker command, when checking
+ word existance).
A DictionaryService is defined using a FactoryConfigurationAdapterService annotation, allowing to
- instantiate many DictionaryService service instances from webconsole. This annotation actually registers
- a ManagedServiceFactory into the Registry, and you can specify the meta type informations regarding
- the properties metadata.
-
- So, before testing, you first have to go to webconsole Configuration panel, and specify some
- dictionaries (see the DictionaryService Factory PID).
- Then, go to the felix shell, and you will then see the "spellcheck" command (when typing "help").
+ instantiate many "DictionaryService" service 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.
+ From WebConsole, each time you instantiate a factory configuration from the pid "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 DictionaryService Factory PID).
+ Then, go to the felix GOGO shell, and you will then see the "spellcheck" command (when typing
+ "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
@@ -38,12 +40,12 @@
org.apache.felix.dependencymanager.samples.annotation
2) Start felix
- 3) Go to web console, in the Configuration pannel
- 4) 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
- 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 shell.
+ 3) Go to web console, in the Configuration pannel, and 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
+ 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 shell.
5) Just type "spellcheck hello", and the command should reply a fantastic message, like "word hello is correct".
diff --git a/dependencymanager/samples.annotation/pom.xml b/dependencymanager/samples.annotation/pom.xml
index 345d401..bd20d67 100644
--- a/dependencymanager/samples.annotation/pom.xml
+++ b/dependencymanager/samples.annotation/pom.xml
@@ -1,73 +1,73 @@
<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/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <packaging>bundle</packaging>
- <groupId>test</groupId>
- <artifactId>org.apache.felix.dependencymanager.samples.annotation</artifactId>
- <version>3.0.0-SNAPSHOT</version>
- <name>Apache Felix Dependency Manager Annotation Samples</name>
-
- <dependencies>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- <version>4.1.0</version>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
- <version>4.1.0</version>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.shell</artifactId>
- <version>1.4.1</version>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.dependencymanager.annotation</artifactId>
- <version>3.0.0-SNAPSHOT</version>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
-
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>1.4.0</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-Name>Apache Felix Dependency Manager Annotation Sample</Bundle-Name>
- <Bundle-SymbolicName>org.apache.felix.dependencymanager.samples.annotation</Bundle-SymbolicName>
- <Import-Package>*</Import-Package>
- <Private-Package>org.apache.felix.dm.samples.annotation</Private-Package>
- </instructions>
- </configuration>
- </plugin>
-
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.dependencymanager.annotation</artifactId>
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>bundle</packaging>
+ <groupId>test</groupId>
+ <artifactId>org.apache.felix.dependencymanager.samples.annotation</artifactId>
<version>3.0.0-SNAPSHOT</version>
- <executions>
- <execution>
- <goals>
- <goal>scan</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
+ <name>Apache Felix Dependency Manager Annotation Samples</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>4.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>4.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.dependencymanager.annotation</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.gogo.runtime</artifactId>
+ <version>0.6.0</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>1.4.0</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Name>Apache Felix Dependency Manager Annotation Sample</Bundle-Name>
+ <Bundle-SymbolicName>org.apache.felix.dependencymanager.samples.annotation</Bundle-SymbolicName>
+ <Import-Package>*</Import-Package>
+ <Private-Package>org.apache.felix.dm.samples.annotation</Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.dependencymanager.annotation</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>scan</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
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 b762f75..9b1c346 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
@@ -49,8 +49,7 @@
cardinality=1),
@PropertyMetaData(
heading="Dictionary words",
- description="Declare here the list of words supported by this dictionary. " +
- "This property is private and won't be propagated along with the dictionary service property.",
+ description="Declare here the list of words supported by this dictionary.",
defaults={"hello", "world"},
id="words",
cardinality=Integer.MAX_VALUE)
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 af50f8e..9bbda68 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
@@ -18,21 +18,27 @@
*/
package org.apache.felix.dm.samples.annotation;
-import java.io.PrintStream;
import java.util.concurrent.CopyOnWriteArrayList;
+import org.apache.felix.dm.annotation.api.Property;
import org.apache.felix.dm.annotation.api.Service;
+import org.apache.felix.dm.annotation.api.ServiceDependency;
import org.apache.felix.dm.annotation.api.Start;
import org.apache.felix.dm.annotation.api.Stop;
-import org.apache.felix.dm.annotation.api.ServiceDependency;
-import org.apache.felix.shell.Command;
+import org.apache.felix.service.command.CommandProcessor;
+import org.apache.felix.service.command.Descriptor;
import org.osgi.service.log.LogService;
/**
- * Felix "spellcheck" Shell Command, used to check correct word spelling.
+ * Felix "spellcheck" Gogo Shell Command. This command allows to check if some given words are valid or not.
+ * This command will be activated only if (at least) one DictionaryService has been injected.
+ * To create a Dictionary Service, you have to go the the web console and define a "Dictionary Services" factory
+ * configuration instance, which will fire an instantiation of the corresponding dictionary service.
*/
-@Service
-public class SpellChecker implements Command
+@Service(provide={SpellChecker.class},
+ properties={@Property(name=CommandProcessor.COMMAND_SCOPE, value="dmsample.annotation"),
+ @Property(name=CommandProcessor.COMMAND_FUNCTION, values={"spellcheck"})})
+public class SpellChecker
{
/**
* We'll use the OSGi log service for logging. If no log service is available, then we'll use a NullObject.
@@ -81,44 +87,22 @@
m_dictionaries.remove(dictionary);
}
- // --- Felix Shell Command interface ---
+ // --- Gogo Shell command
- public String getName()
+ @Descriptor("checks if word is found from an available dictionary")
+ public void spellcheck(@Descriptor("the word to check")String word)
{
- return "spellcheck";
- }
-
- public String getUsage()
- {
- return "spellcheck word";
- }
-
- public String getShortDescription()
- {
- return "Spell checker application using DependencyManager annotations";
- }
-
- public void execute(String commandLine, PrintStream out, PrintStream err)
- {
- String[] tokens = commandLine.split(" ");
- if (tokens == null || tokens.length < 2)
- {
- err.println("Invalid parameters: " + commandLine + ". Usage: " + getUsage());
- return;
- }
- String word = tokens[1];
-
m_log.log(LogService.LOG_DEBUG, "Checking spelling of word \"" + word
+ "\" using the following dictionaries: " + m_dictionaries);
for (DictionaryService dictionary : m_dictionaries)
{
- if (dictionary.checkWord(tokens[1]))
+ if (dictionary.checkWord(word))
{
- out.println("word " + word + " is correct");
+ System.out.println("word " + word + " is correct");
return;
}
}
- err.println("word " + word + " is incorrect");
+ System.err.println("word " + word + " is incorrect");
}
}