Pierre De Rop | 804f4be | 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 | 452f438 | 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 |
Pierre De Rop | 7e98d67 | 2010-07-03 21:56:18 +0000 | [diff] [blame] | 7 | existence. The SpellChecker class has a required/multiple (1..N) dependency over every available |
Pierre De Rop | 452f438 | 2010-06-21 09:46:37 +0000 | [diff] [blame] | 8 | "DictionaryService" services, which are internally used by the SpellChecker command, when checking |
Pierre De Rop | 4c13848 | 2010-07-03 22:25:18 +0000 | [diff] [blame] | 9 | word existence. |
Pierre De Rop | d9c4e3c | 2010-05-24 21:42:18 +0000 | [diff] [blame] | 10 | |
| 11 | A DictionaryService is defined using a FactoryConfigurationAdapterService annotation, allowing to |
Pierre De Rop | 10839cc | 2010-07-04 21:07:59 +0000 | [diff] [blame] | 12 | instantiate many "DictionaryService" instances from webconsole. This annotation actually |
Pierre De Rop | 452f438 | 2010-06-21 09:46:37 +0000 | [diff] [blame] | 13 | registers a ManagedServiceFactory into the Registry, and you can specify some meta type |
Pierre De Rop | 10839cc | 2010-07-04 21:07:59 +0000 | [diff] [blame] | 14 | informations in the annotation, allowing to configure the DictionaryService words and language from |
| 15 | WebConsole. |
| 16 | Each time you instantiate a factory configuration whose factory pid equals "Dictionary Services", |
Pierre De Rop | 7e98d67 | 2010-07-03 21:56:18 +0000 | [diff] [blame] | 17 | then a corresponding "DictionaryService" service is instantiated and is then injected |
Pierre De Rop | 452f438 | 2010-06-21 09:46:37 +0000 | [diff] [blame] | 18 | into the SpellChecker service. So, before testing, you first have to go to webconsole |
Pierre De Rop | 7e98d67 | 2010-07-03 21:56:18 +0000 | [diff] [blame] | 19 | Configuration panel, and specify some dictionaries (see the "Dictionary Services" Factory PID). |
Pierre De Rop | 452f438 | 2010-06-21 09:46:37 +0000 | [diff] [blame] | 20 | Then, go to the felix GOGO shell, and you will then see the "spellcheck" command (when typing |
| 21 | "help"). |
Pierre De Rop | d9c4e3c | 2010-05-24 21:42:18 +0000 | [diff] [blame] | 22 | |
| 23 | Notice that in the sample, you will also find a DictionaryAspect Service (DictionaryAspect.java), which |
Pierre De Rop | 10839cc | 2010-07-04 21:07:59 +0000 | [diff] [blame] | 24 | decorates the EnglishDictionary service, by adding some additional words to it. |
| 25 | |
Pierre De Rop | 804f4be | 2010-04-25 22:57:56 +0000 | [diff] [blame] | 26 | How to test: |
| 27 | |
| 28 | 1) Install the following bundles: |
| 29 | |
| 30 | org.apache.felix.configadmin |
| 31 | org.apache.felix.metatype |
Pierre De Rop | 7e98d67 | 2010-07-03 21:56:18 +0000 | [diff] [blame] | 32 | org.apache.felix.http.jetty (from trunk, because the latest released version seems to have a problem) |
Pierre De Rop | 804f4be | 2010-04-25 22:57:56 +0000 | [diff] [blame] | 33 | org.apache.felix.webconsole |
| 34 | |
| 35 | org.apache.felix.dependencymanager |
| 36 | org.apache.felix.dependencymanager.shell |
| 37 | org.apache.felix.dependencymanager.runtime |
| 38 | org.apache.felix.dependencymanager.samples.annotation |
| 39 | |
| 40 | 2) Start felix |
Pierre De Rop | 4c13848 | 2010-07-03 22:25:18 +0000 | [diff] [blame] | 41 | 3) Go to web console: in the Configuration panel, edit the "Dictionary Services" |
Pierre De Rop | 452f438 | 2010-06-21 09:46:37 +0000 | [diff] [blame] | 42 | Configuration, add some dictionaries. By default, an English dictionary is displayed. Just |
Pierre De Rop | 10839cc | 2010-07-04 21:07:59 +0000 | [diff] [blame] | 43 | click on "save", *then click on your refresh web browser*: you will see a new dictionary service |
Pierre De Rop | 452f438 | 2010-06-21 09:46:37 +0000 | [diff] [blame] | 44 | instance. At this point, a DictionaryService service will be enabled (with the service property "lang=en"), |
| 45 | and the SpellCheck component will be injected with it. Then you should see the "spellcheck" |
Pierre De Rop | 7e98d67 | 2010-07-03 21:56:18 +0000 | [diff] [blame] | 46 | command, when typing "help" on the gogo shell. |
Pierre De Rop | 804f4be | 2010-04-25 22:57:56 +0000 | [diff] [blame] | 47 | |
| 48 | 5) Just type "spellcheck hello", and the command should reply a fantastic message, like "word hello is correct". |
Pierre De Rop | 804f4be | 2010-04-25 22:57:56 +0000 | [diff] [blame] | 49 | |
Pierre De Rop | 10839cc | 2010-07-04 21:07:59 +0000 | [diff] [blame] | 50 | 6) You can also click on the "Aspect Dictionary" button, in order to decorate the english dictionary with some |
| 51 | custom words. |
Pierre De Rop | d9c4e3c | 2010-05-24 21:42:18 +0000 | [diff] [blame] | 52 | By default, the "aspect" word is pre configured, but you can click on the "+" button in order to add more words. |
Pierre De Rop | 10839cc | 2010-07-04 21:07:59 +0000 | [diff] [blame] | 53 | Then click on Save. At this point, the English DictionaryService will be decorated with the aspect service. |
Pierre De Rop | d9c4e3c | 2010-05-24 21:42:18 +0000 | [diff] [blame] | 54 | So, now, if you type "spellcheck aspect", then the message: "word aspect is correct" should be displayed. |