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 | |
| 5 | This sample shows a basic "SpellChecker" application which provides a Felix "spellcheck" shell |
Pierre De Rop | a97580d | 2010-05-24 21:42:18 +0000 | [diff] [blame^] | 6 | command. The SpellChecker class is a Felix Shell command (it provides a "Command" service), |
Pierre De Rop | 6b4a6c4 | 2010-04-25 22:57:56 +0000 | [diff] [blame] | 7 | which accepts a string as parameter. So, when you type a string, the command just says if the |
| 8 | specified string has been found from one of its injected dictionaries. The SpellChecker class has a |
Pierre De Rop | a97580d | 2010-05-24 21:42:18 +0000 | [diff] [blame^] | 9 | required/multiple (1..N) dependency over any available DictionaryService. |
| 10 | |
| 11 | A DictionaryService is defined using a FactoryConfigurationAdapterService annotation, allowing to |
| 12 | instantiate many DictionaryService service instances from webconsole. This annotation actually registers |
| 13 | a ManagedServiceFactory into the Registry, and you can specify the meta type informations regarding |
| 14 | the properties metadata. |
| 15 | |
Pierre De Rop | 6b4a6c4 | 2010-04-25 22:57:56 +0000 | [diff] [blame] | 16 | So, before testing, you first have to go to webconsole Configuration panel, and specify some |
Pierre De Rop | a97580d | 2010-05-24 21:42:18 +0000 | [diff] [blame^] | 17 | dictionaries (see the DictionaryService Factory PID). |
| 18 | Then, go to the felix shell, and you will then see the "spellcheck" command (when typing "help"). |
| 19 | |
| 20 | Notice that in the sample, you will also find a DictionaryAspect Service (DictionaryAspect.java), which |
| 21 | decorates the EnglishDictionary service, by adding some additional words to *all* provided |
| 22 | DictionaryService services. The DictionaryAspect also show how to use a ConfigurationDependency annotation, |
| 23 | allowing to configure the words from webconsole. A ConfigurationDependency actually registers a ManagedService object |
| 24 | 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] | 25 | |
| 26 | How to test: |
| 27 | |
| 28 | 1) Install the following bundles: |
| 29 | |
| 30 | org.apache.felix.configadmin |
| 31 | org.apache.felix.metatype |
| 32 | org.apache.felix.http.jetty |
| 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 |
| 41 | 3) Go to web console, in the Configuration pannel |
Pierre De Rop | a97580d | 2010-05-24 21:42:18 +0000 | [diff] [blame^] | 42 | 4) Edit the "Dictionary Services" Configuration, add some dictionaries. By default, an English dictionary is |
| 43 | displayed. Just click on "save", then click on your refresh web browser: you will see a new dictionary service |
| 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" command, when typing |
| 46 | "help" on the shell. |
Pierre De Rop | 6b4a6c4 | 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 | 6b4a6c4 | 2010-04-25 22:57:56 +0000 | [diff] [blame] | 49 | |
Pierre De Rop | a97580d | 2010-05-24 21:42:18 +0000 | [diff] [blame^] | 50 | 6) You can also click on the "Aspect Dictionary" button, in order to decorate *all* Dictionaries using some custom words. |
| 51 | By default, the "aspect" word is pre configured, but you can click on the "+" button in order to add more words. |
| 52 | Then click on Save. At this point, all DictionaryService instances will be decorated with the aspect service. |
| 53 | So, now, if you type "spellcheck aspect", then the message: "word aspect is correct" should be displayed. |
| 54 | |