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 |
Pierre De Rop | 2b71cb1 | 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 | cf7d7a6 | 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 | 047d5ec | 2010-07-03 22:25:18 +0000 | [diff] [blame] | 9 | word existence. |
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 | 9eca99b | 2010-07-04 21:07:59 +0000 | [diff] [blame] | 12 | instantiate many "DictionaryService" instances from webconsole. This annotation actually |
Pierre De Rop | cf7d7a6 | 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 | 9eca99b | 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 | 2b71cb1 | 2010-07-03 21:56:18 +0000 | [diff] [blame] | 17 | then a corresponding "DictionaryService" service is instantiated and is then injected |
Pierre De Rop | cf7d7a6 | 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 | 2b71cb1 | 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 | cf7d7a6 | 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 | a97580d | 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 | 9eca99b | 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 | 6b4a6c4 | 2010-04-25 22:57:56 +0000 | [diff] [blame] | 26 | How to test: |
| 27 | |
Pierre De Rop | 48a5aee | 2010-08-19 20:15:12 +0000 | [diff] [blame^] | 28 | - Install the following bundles: |
Pierre De Rop | 6b4a6c4 | 2010-04-25 22:57:56 +0000 | [diff] [blame] | 29 | |
Pierre De Rop | 48a5aee | 2010-08-19 20:15:12 +0000 | [diff] [blame^] | 30 | org.apache.felix.configadmin |
| 31 | org.apache.felix.metatype |
| 32 | org.apache.felix.http.jetty |
Pierre De Rop | 6b4a6c4 | 2010-04-25 22:57:56 +0000 | [diff] [blame] | 33 | org.apache.felix.webconsole |
| 34 | |
Pierre De Rop | 48a5aee | 2010-08-19 20:15:12 +0000 | [diff] [blame^] | 35 | - compile dependency manager from trunk: |
Pierre De Rop | 6b4a6c4 | 2010-04-25 22:57:56 +0000 | [diff] [blame] | 36 | |
Pierre De Rop | 48a5aee | 2010-08-19 20:15:12 +0000 | [diff] [blame^] | 37 | svn checkout http://svn.apache.org/repos/asf/felix/trunk/dependencymanager dependencymanager |
| 38 | cd dependencymanager |
| 39 | mvn -Dmaven.test.skip=true install |
| 40 | |
| 41 | - install the DM bundles into the fwk |
| 42 | |
| 43 | dependencymanager/core/target/org.apache.felix.dependencymanager-3.0.0-SNAPSHOT.jar |
| 44 | dependencymanager/shell/target/org.apache.felix.dependencymanager.shell-3.0.0-SNAPSHOT.jar |
| 45 | dependencymanager/runtime/target/org.apache.felix.dependencymanager.runtime-3.0.0-SNAPSHOT.jar |
| 46 | dependencymanager/samples.annotation/target/org.apache.felix.dependencymanager.samples.annotation-3.0.0-SNAPSHOT.jar |
| 47 | |
| 48 | - Start felix |
| 49 | |
| 50 | At this point, you should have the following running bundles: |
| 51 | |
| 52 | START LEVEL 1 |
| 53 | ID|State |Level|Name |
| 54 | 0|Active | 0|System Bundle (3.0.1) |
| 55 | 1|Active | 1|Apache Felix Bundle Repository (1.6.2) |
| 56 | 7|Active | 1|Apache Felix Gogo Command (0.6.0) |
| 57 | 8|Active | 1|Apache Felix Gogo Runtime (0.6.0) |
| 58 | 9|Active | 1|Apache Felix Gogo Shell (0.6.0) |
| 59 | 10|Active | 1|Apache Felix Http Jetty (2.0.4) |
| 60 | 11|Active | 1|Apache Felix Metatype Service (1.0.4) |
| 61 | 12|Active | 1|Apache Felix Web Management Console (3.1.2) |
| 62 | 2|Active | 1|Apache Felix Configuration Admin Service (1.2.4) |
| 63 | 3|Active | 1|Apache Felix Dependency Manager (3.0.0.SNAPSHOT) |
| 64 | 6|Active | 1|Apache Felix Dependency Manager Shell (3.0.0.SNAPSHOT) |
| 65 | 4|Active | 1|Apache Felix Dependency Manager Runtime (3.0.0.SNAPSHOT) |
| 66 | 5|Active | 1|Apache Felix Dependency Manager Annotation Sample (3.0.0.SNAPSHOT) |
| 67 | |
| 68 | - Go to web console: in the Configuration panel, edit the "Dictionary Services" |
Pierre De Rop | cf7d7a6 | 2010-06-21 09:46:37 +0000 | [diff] [blame] | 69 | Configuration, add some dictionaries. By default, an English dictionary is displayed. Just |
Pierre De Rop | 9eca99b | 2010-07-04 21:07:59 +0000 | [diff] [blame] | 70 | click on "save", *then click on your refresh web browser*: you will see a new dictionary service |
Pierre De Rop | cf7d7a6 | 2010-06-21 09:46:37 +0000 | [diff] [blame] | 71 | instance. At this point, a DictionaryService service will be enabled (with the service property "lang=en"), |
| 72 | and the SpellCheck component will be injected with it. Then you should see the "spellcheck" |
Pierre De Rop | 2b71cb1 | 2010-07-03 21:56:18 +0000 | [diff] [blame] | 73 | command, when typing "help" on the gogo shell. |
Pierre De Rop | 6b4a6c4 | 2010-04-25 22:57:56 +0000 | [diff] [blame] | 74 | |
Pierre De Rop | 48a5aee | 2010-08-19 20:15:12 +0000 | [diff] [blame^] | 75 | - 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] | 76 | |
Pierre De Rop | 48a5aee | 2010-08-19 20:15:12 +0000 | [diff] [blame^] | 77 | - You can also click on the "Aspect Dictionary" button, in order to decorate the english dictionary with some |
Pierre De Rop | 9eca99b | 2010-07-04 21:07:59 +0000 | [diff] [blame] | 78 | custom words. |
Pierre De Rop | a97580d | 2010-05-24 21:42:18 +0000 | [diff] [blame] | 79 | By default, the "aspect" word is pre configured, but you can click on the "+" button in order to add more words. |
Pierre De Rop | 9eca99b | 2010-07-04 21:07:59 +0000 | [diff] [blame] | 80 | Then click on Save. At this point, the English DictionaryService will be decorated with the aspect service. |
Pierre De Rop | a97580d | 2010-05-24 21:42:18 +0000 | [diff] [blame] | 81 | So, now, if you type "spellcheck aspect", then the message: "word aspect is correct" should be displayed. |