1 package org
.argeo
.slc
.execution
;
3 import java
.io
.FileInputStream
;
4 import java
.io
.FileNotFoundException
;
5 import java
.io
.IOException
;
8 import java
.util
.Properties
;
10 import org
.apache
.commons
.io
.IOUtils
;
11 import org
.apache
.commons
.logging
.Log
;
12 import org
.apache
.commons
.logging
.LogFactory
;
13 import org
.argeo
.slc
.logging
.Log4jUtils
;
14 import org
.argeo
.slc
.process
.SlcExecution
;
15 import org
.springframework
.beans
.MutablePropertyValues
;
16 import org
.springframework
.beans
.PropertyValue
;
17 import org
.springframework
.beans
.factory
.config
.BeanDefinition
;
18 import org
.springframework
.beans
.factory
.support
.BeanDefinitionRegistry
;
19 import org
.springframework
.beans
.factory
.support
.SimpleBeanDefinitionRegistry
;
20 import org
.springframework
.beans
.factory
.xml
.XmlBeanDefinitionParser
;
21 import org
.springframework
.beans
.factory
.xml
.XmlBeanDefinitionReader
;
22 import org
.springframework
.context
.ApplicationEvent
;
23 import org
.springframework
.context
.ApplicationListener
;
24 import org
.springframework
.context
.support
.FileSystemXmlApplicationContext
;
25 import org
.springframework
.context
.support
.GenericApplicationContext
;
27 public class EfLauncher
implements ApplicationListener
{
28 private final Log log
;
30 private boolean running
= false;
33 Properties userProperties
= new Properties();
34 FileInputStream in
= null;
36 in
= new FileInputStream("src/slc/conf/slc.properties");
37 userProperties
.load(in
);
38 } catch (Exception e
) {
41 IOUtils
.closeQuietly(in
);
44 // Set as System properties
45 for (Object obj
: userProperties
.keySet()) {
46 String key
= obj
.toString();
47 System
.setProperty(key
, userProperties
.getProperty(key
));
51 System
.setProperty("log4j.defaultInitOverride", "true");
53 Log4jUtils
.initLog4j(null);
54 log
= LogFactory
.getLog(EfLauncher
.class);
57 public void launch(String script
) {
60 GenericApplicationContext context
= new GenericApplicationContext();
61 XmlBeanDefinitionReader reader
= new XmlBeanDefinitionReader(context
);
62 reader
.loadBeanDefinitions(script
);
63 // FileSystemXmlApplicationContext context = new
64 // FileSystemXmlApplicationContext(
66 context
.addApplicationListener(this);
69 log
.debug("Context initialized");
71 SlcExecution slcExecution
= new SlcExecution();
72 slcExecution
.getAttributes().put("slc.flows", "main");
75 context
.publishEvent(new NewExecutionEvent(this, slcExecution
));
81 } catch (InterruptedException e
) {
87 public synchronized boolean isRunning() {
91 public synchronized void setRunning(boolean running
) {
92 this.running
= running
;
95 public void onApplicationEvent(ApplicationEvent event
) {
96 if (event
instanceof ExecutionFinishedEvent
) {
97 ExecutionContext executionContext
= ((ExecutionFinishedEvent
) event
)
98 .getExecutionContext();
99 log
.debug("Execution " + executionContext
.getUuid()
100 + " finished, stopping launcher...");
101 synchronized (this) {
109 public static void main(String
[] args
) {
110 String script
= "file:src/slc/conf/main.xml";
111 new EfLauncher().launch(script
);
114 private static void describe(String script
) {
115 SimpleBeanDefinitionRegistry registry
= new SimpleBeanDefinitionRegistry();
116 XmlBeanDefinitionReader reader
= new XmlBeanDefinitionReader(registry
);
117 reader
.loadBeanDefinitions(script
);
118 new ConsoleContextDescriber().describeContext(registry
);