KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > annotations > SimpleAnnotatedModule


1 // Copyright 2007 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.annotations;
16
17 import hivemind.test.services.StringHolder;
18 import hivemind.test.services.impl.StringHolderImpl;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.List JavaDoc;
22
23 import org.apache.hivemind.annotations.definition.Configuration;
24 import org.apache.hivemind.annotations.definition.Contribution;
25 import org.apache.hivemind.annotations.definition.Service;
26
27 public class SimpleAnnotatedModule extends AbstractAnnotatedModule
28 {
29     @Service(id = "Test")
30     public Runnable JavaDoc getRunnable()
31     {
32         return new Runnable JavaDoc()
33         {
34
35             public void run()
36             {
37                 List JavaDoc<String JavaDoc> demoList = (List JavaDoc<String JavaDoc>) configuration("Demo", List JavaDoc.class);
38                 for (String JavaDoc entry : demoList)
39                 {
40                     System.out.println(entry);
41                 }
42                 String JavaDoc one = (String JavaDoc) configuration("SingleElement", String JavaDoc.class);
43                 System.out.println(one);
44                 StringHolderImpl holder = (StringHolderImpl) configuration("StringHolder", StringHolderImpl.class);
45                 System.out.println(holder.getValue());
46                 
47                 StringHolderImpl holderService = (StringHolderImpl) service("StringHolder", StringHolderImpl.class);
48                 System.out.println(holderService.getValue());
49             }
50         };
51     }
52
53     @Configuration(id = "Demo")
54     public List JavaDoc<String JavaDoc> getDemo()
55     {
56         List JavaDoc<String JavaDoc> result = new ArrayList JavaDoc<String JavaDoc>();
57         result.add("initial-data");
58         return result;
59     }
60
61     @Contribution(configurationId = "Demo")
62     public void contributeData(List JavaDoc<String JavaDoc> container)
63     {
64         container.add("contributed-data");
65     }
66
67     @Contribution(configurationId = "Demo")
68     public List JavaDoc<String JavaDoc> contributeData2()
69     {
70         List JavaDoc<String JavaDoc> data = new ArrayList JavaDoc<String JavaDoc>();
71         data.add("contributed-data-2");
72         return data;
73     }
74     
75     @Configuration(id = "SingleElement")
76     public String JavaDoc getSingleElementConfig()
77     {
78         return null;
79     }
80
81     @Contribution(configurationId = "SingleElement")
82     public String JavaDoc contributeSingleElement()
83     {
84         return "The One and Only";
85     }
86     
87     @Configuration(id = "StringHolder")
88     public StringHolderImpl getStringHolder()
89     {
90         StringHolderImpl result = new StringHolderImpl();
91         result.setValue("test");
92         return result;
93     }
94     
95     @Service(id = "StringHolder")
96     public StringHolderImpl getStringHolderService()
97     {
98         StringHolderImpl result = new StringHolderImpl();
99         result.setValue("test");
100         return result;
101     }
102
103 // @Contribution(configurationId = "hivemind.ApplicationDefaults")
104
// public void contributeDefaults(HashMap<String,FactoryDefault> container)
105
// {
106
// container.put("testsymbol", new FactoryDefault("testsymbol", "value"));
107
// }
108

109 }
110
Popular Tags