Author: pderop
Date: Mon Jun 21 09:46:37 2010
New Revision: 956519

URL: http://svn.apache.org/viewvc?rev=956519&view=rev
Log:
Modified the sample in order to use GOGO shell

Modified:
    felix/trunk/dependencymanager/samples.annotation/README
    felix/trunk/dependencymanager/samples.annotation/pom.xml
    
felix/trunk/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/DictionaryImpl.java
    
felix/trunk/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/SpellChecker.java

Modified: felix/trunk/dependencymanager/samples.annotation/README
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/samples.annotation/README?rev=956519&r1=956518&r2=956519&view=diff
==============================================================================
--- felix/trunk/dependencymanager/samples.annotation/README (original)
+++ felix/trunk/dependencymanager/samples.annotation/README Mon Jun 21 09:46:37 
2010
@@ -2,20 +2,22 @@ This sample illustrates the usage of the
 
 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 @@ How to test:
      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".
   

Modified: felix/trunk/dependencymanager/samples.annotation/pom.xml
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/samples.annotation/pom.xml?rev=956519&r1=956518&r2=956519&view=diff
==============================================================================
--- felix/trunk/dependencymanager/samples.annotation/pom.xml (original)
+++ felix/trunk/dependencymanager/samples.annotation/pom.xml Mon Jun 21 
09:46:37 2010
@@ -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>
+       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>
+       <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>
+       <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>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>
+                       <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>

Modified: 
felix/trunk/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/DictionaryImpl.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/DictionaryImpl.java?rev=956519&r1=956518&r2=956519&view=diff
==============================================================================
--- 
felix/trunk/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/DictionaryImpl.java
 (original)
+++ 
felix/trunk/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/DictionaryImpl.java
 Mon Jun 21 09:46:37 2010
@@ -49,8 +49,7 @@ import org.apache.felix.dm.annotation.ap
             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)

Modified: 
felix/trunk/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/SpellChecker.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/SpellChecker.java?rev=956519&r1=956518&r2=956519&view=diff
==============================================================================
--- 
felix/trunk/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/SpellChecker.java
 (original)
+++ 
felix/trunk/dependencymanager/samples.annotation/src/main/java/org/apache/felix/dm/samples/annotation/SpellChecker.java
 Mon Jun 21 09:46:37 2010
@@ -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}, 
+         propertie...@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 @@ public class SpellChecker implements Com
         m_dictionaries.remove(dictionary);
     }
 
-    // --- Felix Shell Command interface ---
-
-    public String getName()
-    {
-        return "spellcheck";
-    }
-
-    public String getUsage()
-    {
-        return "spellcheck word";
-    }
-
-    public String getShortDescription()
-    {
-        return "Spell checker application using DependencyManager annotations";
-    }
+    // --- Gogo Shell command
 
-    public void execute(String commandLine, PrintStream out, PrintStream err)
+    @Descriptor("checks if word is found from an available dictionary")
+    public void spellcheck(@Descriptor("the word to check")String word)
     {
-        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");
     }
 }


Reply via email to