View Javadoc

1   package org.lsst.ccs.bus;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   
6   /**
7    * This command will configure (ie send parameter names and values to) modules
8    * in a subsystem.
9    * 
10   * @author aubourg
11   * 
12   */
13  @Deprecated
14  public class ModuleConfigCommand extends Command {
15  
16      private static final long serialVersionUID = 7420922024754348683L;
17  
18  	public ModuleConfigCommand() {
19          super("",0, (String) null, "",null) ;
20  
21  	}
22  
23  	// key = param name, can contain module-name/param-name if destination is
24  	// top subsystem
25  	// or just param name if destination is the module (ie
26  	// subsystem/module-name)
27  	Map<String, Object> configParams = new HashMap<String, Object>();
28  
29  	public Object put(String aKey, Object value) {
30  		return configParams.put(aKey, value);
31  	}
32  
33      public void putAll(Map<String,? extends Object> map) {
34          configParams.putAll(map);
35      }
36  
37      /*
38  	@Override
39  	public Object execute(CommandExecutor s) {
40          //@modified (bamade)
41          //if (!(s instanceof ModularSubsystem)) {
42  		if (!(s instanceof ModuleRegistry)) {
43  			String err = "subsystem " + s
44  					+ " is not a ModularSubsystem, cannot execute " + this;
45  			log.error(err);
46  			throw new RuntimeException(err);
47  		}
48  		// destination could be in the form "subsystem/module"
49  		String destModuleName = destination.contains("/") ? destination
50  				.substring(destination.indexOf('/') + 1) : null;
51  
52  		for (Entry<String, Object> e : configParams.entrySet()) {
53  			String m, p;
54  			if (e.getKey().contains("/")) {
55  				int i = e.getKey().indexOf('/');
56  				m = e.getKey().substring(0, i);
57  				p = e.getKey().substring(i + 1);
58  				if (destModuleName != null) {
59  					m = destModuleName + "/" + m;
60  				}
61  			} else {
62  				m = destModuleName;
63  				p = e.getKey();
64  			}
65  			log.debug("config set " + m + " : " + p + " <- " + e.getValue());
66              //@modified (bamade)
67              //Module module = ((ModularSubsystem) s).getModule(m);
68  			Module module = ((ModuleRegistry) s).getModule(m);
69  			try {
70  				BeanUtils.setProperty(module, p, e.getValue());
71  			} catch (IllegalAccessException e1) {
72  				// TODO abort, or return error
73  				log.error(e1);
74  				//e1.printStackTrace();
75  			} catch (InvocationTargetException e1) {
76  				log.error(e1);
77  				//e1.printStackTrace();
78  			}
79  		}
80  		return null;
81  	} */
82  
83  }