KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > examples > annotations > panorama > PanoramaStartupModule


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.examples.annotations.panorama;
16
17 import java.util.ArrayList JavaDoc;
18 import java.util.List JavaDoc;
19
20 import org.apache.commons.logging.LogFactory;
21 import org.apache.examples.panorama.startup.impl.Task;
22 import org.apache.examples.panorama.startup.impl.TaskExecutor;
23 import org.apache.hivemind.ErrorLog;
24 import org.apache.hivemind.annotations.AbstractAnnotatedModule;
25 import org.apache.hivemind.annotations.definition.Configuration;
26 import org.apache.hivemind.annotations.definition.Contribution;
27 import org.apache.hivemind.annotations.definition.Service;
28 import org.apache.hivemind.impl.DefaultErrorHandler;
29 import org.apache.hivemind.impl.ErrorLogImpl;
30 import org.apache.hivemind.impl.MessageFormatter;
31
32 public class PanoramaStartupModule extends AbstractAnnotatedModule
33 {
34
35     @Service( id="Startup" )
36     public Runnable JavaDoc getStartupService()
37     {
38         TaskExecutor executor = new TaskExecutor();
39         executor.setTasks(configuration("tasks", List JavaDoc.class));
40         // Some of the logic which is automatically provided by the builder factory
41
// must be done manually
42
ErrorLog errorLog = new ErrorLogImpl(new DefaultErrorHandler(), LogFactory.getLog(TaskExecutor.class));
43         executor.setErrorLog(errorLog);
44         executor.setMessages(new MessageFormatter(PanoramaStartupModule.class, "panorama"));
45         executor.setLog(LogFactory.getLog(TaskExecutor.class));
46         
47         return executor;
48     }
49     
50     @Configuration( id="tasks" )
51     public List JavaDoc<Task> getTasks()
52     {
53         return new ArrayList JavaDoc<Task>();
54     }
55     
56     @Contribution( configurationId="hivemind.Startup" )
57     public void contributeStartupServices(List JavaDoc services)
58     {
59         services.add(service("Startup", Runnable JavaDoc.class));
60     }
61     
62 }
63
Popular Tags