1 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 ; 21 import java.util.List ; 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 getRunnable() 31 { 32 return new Runnable () 33 { 34 35 public void run() 36 { 37 List <String > demoList = (List <String >) configuration("Demo", List .class); 38 for (String entry : demoList) 39 { 40 System.out.println(entry); 41 } 42 String one = (String ) configuration("SingleElement", String .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 <String > getDemo() 55 { 56 List <String > result = new ArrayList <String >(); 57 result.add("initial-data"); 58 return result; 59 } 60 61 @Contribution(configurationId = "Demo") 62 public void contributeData(List <String > container) 63 { 64 container.add("contributed-data"); 65 } 66 67 @Contribution(configurationId = "Demo") 68 public List <String > contributeData2() 69 { 70 List <String > data = new ArrayList <String >(); 71 data.add("contributed-data-2"); 72 return data; 73 } 74 75 @Configuration(id = "SingleElement") 76 public String getSingleElementConfig() 77 { 78 return null; 79 } 80 81 @Contribution(configurationId = "SingleElement") 82 public String 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 109 } 110 | Popular Tags |