001 // Copyright 2007 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.examples.annotations.panorama;
016
017 import java.util.ArrayList;
018 import java.util.List;
019
020 import org.apache.commons.logging.LogFactory;
021 import org.apache.examples.panorama.startup.impl.Task;
022 import org.apache.examples.panorama.startup.impl.TaskExecutor;
023 import org.apache.hivemind.ErrorLog;
024 import org.apache.hivemind.annotations.AbstractAnnotatedModule;
025 import org.apache.hivemind.annotations.definition.Configuration;
026 import org.apache.hivemind.annotations.definition.Contribution;
027 import org.apache.hivemind.annotations.definition.Service;
028 import org.apache.hivemind.impl.DefaultErrorHandler;
029 import org.apache.hivemind.impl.ErrorLogImpl;
030 import org.apache.hivemind.impl.MessageFormatter;
031
032 public class PanoramaStartupModule extends AbstractAnnotatedModule
033 {
034
035 @Service( id="Startup" )
036 public Runnable getStartupService()
037 {
038 TaskExecutor executor = new TaskExecutor();
039 executor.setTasks(configuration("tasks", List.class));
040 // Some of the logic which is automatically provided by the builder factory
041 // must be done manually
042 ErrorLog errorLog = new ErrorLogImpl(new DefaultErrorHandler(), LogFactory.getLog(TaskExecutor.class));
043 executor.setErrorLog(errorLog);
044 executor.setMessages(new MessageFormatter(PanoramaStartupModule.class, "panorama"));
045 executor.setLog(LogFactory.getLog(TaskExecutor.class));
046
047 return executor;
048 }
049
050 @Configuration( id="tasks" )
051 public List<Task> getTasks()
052 {
053 return new ArrayList<Task>();
054 }
055
056 @Contribution( configurationId="hivemind.Startup" )
057 public void contributeStartupServices(List services)
058 {
059 services.add(service("Startup", Runnable.class));
060 }
061
062 }