Pierre De Rop | 6b4a6c4 | 2010-04-25 22:57:56 +0000 | [diff] [blame] | 1 | This sample illustrates the usage of the new DependencyManager annotations. |
| 2 | |
| 3 | Sample description: |
| 4 | |
Pierre De Rop | cf7d7a6 | 2010-06-21 09:46:37 +0000 | [diff] [blame] | 5 | This sample shows a basic "SpellChecker" application which provides a Felix "spellcheck" GOGO shell |
| 6 | command. The GOGO "spellcheck" command accepts a string as parameter, which is checked for proper |
| 7 | existance. The SpellChecker class has a required/multiple (1..N) dependency over every available |
| 8 | "DictionaryService" services, which are internally used by the SpellChecker command, when checking |
| 9 | word existance). |
Pierre De Rop | a97580d | 2010-05-24 21:42:18 +0000 | [diff] [blame] | 10 | |
| 11 | A DictionaryService is defined using a FactoryConfigurationAdapterService annotation, allowing to |
Pierre De Rop | cf7d7a6 | 2010-06-21 09:46:37 +0000 | [diff] [blame] | 12 | instantiate many "DictionaryService" service instances from webconsole. This annotation actually |
| 13 | registers a ManagedServiceFactory into the Registry, and you can specify some meta type |
| 14 | informations in the annotation, allowing to display the configuration parameters from WebConsole. |
| 15 | From WebConsole, each time you instantiate a factory configuration from the pid "Dictionary |
| 16 | Services", then a corresponding "DictionaryService" service is instantiated and is then injected |
| 17 | into the SpellChecker service. So, before testing, you first have to go to webconsole |
| 18 | Configuration panel, and specify some dictionaries (see the DictionaryService Factory PID). |
| 19 | Then, go to the felix GOGO shell, and you will then see the "spellcheck" command (when typing |
| 20 | "help"). |
Pierre De Rop | a97580d | 2010-05-24 21:42:18 +0000 | [diff] [blame] | 21 | |
| 22 | Notice that in the sample, you will also find a DictionaryAspect Service (DictionaryAspect.java), which |
| 23 | decorates the EnglishDictionary service, by adding some additional words to *all* provided |
| 24 | DictionaryService services. The DictionaryAspect also show how to use a ConfigurationDependency annotation, |
| 25 | allowing to configure the words from webconsole. A ConfigurationDependency actually registers a ManagedService object |
| 26 | in the Registry, which also implements a MetaTypeProvider service for metatype support. |
Pierre De Rop | 6b4a6c4 | 2010-04-25 22:57:56 +0000 | [diff] [blame] | 27 | |
| 28 | How to test: |
| 29 | |
| 30 | 1) Install the following bundles: |
| 31 | |
| 32 | org.apache.felix.configadmin |
| 33 | org.apache.felix.metatype |
| 34 | org.apache.felix.http.jetty |
| 35 | org.apache.felix.webconsole |
| 36 | |
| 37 | org.apache.felix.dependencymanager |
| 38 | org.apache.felix.dependencymanager.shell |
| 39 | org.apache.felix.dependencymanager.runtime |
| 40 | org.apache.felix.dependencymanager.samples.annotation |
| 41 | |
| 42 | 2) Start felix |
Pierre De Rop | cf7d7a6 | 2010-06-21 09:46:37 +0000 | [diff] [blame] | 43 | 3) Go to web console, in the Configuration pannel, and edit the "Dictionary Services" |
| 44 | Configuration, add some dictionaries. By default, an English dictionary is displayed. Just |
| 45 | click on "save", then click on your refresh web browser: you will see a new dictionary service |
| 46 | instance. At this point, a DictionaryService service will be enabled (with the service property "lang=en"), |
| 47 | and the SpellCheck component will be injected with it. Then you should see the "spellcheck" |
| 48 | command, when typing "help" on the shell. |
Pierre De Rop | 6b4a6c4 | 2010-04-25 22:57:56 +0000 | [diff] [blame] | 49 | |
| 50 | 5) Just type "spellcheck hello", and the command should reply a fantastic message, like "word hello is correct". |
Pierre De Rop | 6b4a6c4 | 2010-04-25 22:57:56 +0000 | [diff] [blame] | 51 | |
Pierre De Rop | a97580d | 2010-05-24 21:42:18 +0000 | [diff] [blame] | 52 | 6) You can also click on the "Aspect Dictionary" button, in order to decorate *all* Dictionaries using some custom words. |
| 53 | By default, the "aspect" word is pre configured, but you can click on the "+" button in order to add more words. |
| 54 | Then click on Save. At this point, all DictionaryService instances will be decorated with the aspect service. |
| 55 | So, now, if you type "spellcheck aspect", then the message: "word aspect is correct" should be displayed. |
| 56 | |