01: package org.objectweb.celtix.bus.busimpl;
02:
03: import java.util.Map;
04:
05: import org.objectweb.celtix.Bus;
06: import org.objectweb.celtix.configuration.CommandLineOption;
07: import org.objectweb.celtix.configuration.Configuration;
08: import org.objectweb.celtix.configuration.ConfigurationBuilder;
09: import org.objectweb.celtix.configuration.ConfigurationBuilderFactory;
10:
11: public class BusConfigurationBuilder {
12:
13: public static final String BUS_ID_PROPERTY = "org.objectweb.celtix.BusId";
14: public static final String BUS_CONFIGURATION_URI = "http://celtix.objectweb.org/bus/bus-config";
15: private static final CommandLineOption BUS_ID_OPT;
16: private static final String DEFAULT_BUS_ID = "celtix";
17:
18: static {
19: BUS_ID_OPT = new CommandLineOption("-BUSid");
20: }
21:
22: Configuration build(String[] args, Map<String, Object> properties) {
23: String id = getBusId(args, properties);
24: ConfigurationBuilder builder = ConfigurationBuilderFactory
25: .getBuilder(null);
26: Configuration c = builder.getConfiguration(
27: BUS_CONFIGURATION_URI, id);
28: if (null == c) {
29: c = builder.buildConfiguration(BUS_CONFIGURATION_URI, id);
30: }
31: return c;
32: }
33:
34: private static String getBusId(String[] args,
35: Map<String, Object> properties) {
36:
37: String busId = null;
38:
39: // first check command line arguments
40: BUS_ID_OPT.initialize(args);
41: busId = (String) BUS_ID_OPT.getValue();
42: if (null != busId && !"".equals(busId)) {
43: return busId;
44: }
45:
46: // next check properties
47: busId = (String) properties.get(BUS_ID_PROPERTY);
48: if (null != busId && !"".equals(busId)) {
49: return busId;
50: }
51:
52: // next check system properties
53: busId = System.getProperty(Bus.BUS_CLASS_PROPERTY);
54: if (null != busId && !"".equals(busId)) {
55: return busId;
56: }
57:
58: // otherwise use default
59: return DEFAULT_BUS_ID;
60: }
61: }
|