summaryrefslogtreecommitdiffstats
path: root/src/com/ibm/ServerWizard2/model/Connection.java
blob: cbb64978298eeabb1030e822984df1ae59e33e13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.ibm.ServerWizard2.model;

import java.io.Writer;
import java.util.Map;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import com.ibm.ServerWizard2.ServerWizard2;


public class Connection {
	public int id = 0;
	public String busType = "";
	public ConnectionEndpoint source;
	public ConnectionEndpoint dest;
	public Boolean cabled=false;
	public Target busTarget;
	public String getName() {
		String seperator = " => ";
		if (cabled) {
			seperator=" =c=> ";
		}
		return source.getName()+seperator+dest.getName();
	}
	public void writeInstanceXML(Writer out) throws Exception {
		out.write("\t<bus>\n");
		out.write("\t\t<bus_id>"+getName()+"</bus_id>\n");
		out.write("\t\t<bus_type>"+busType+"</bus_type>\n");
		String c="no";
		if (cabled) { c="yes"; }
		out.write("\t\t<cable>"+c+"</cable>\n");
		out.write("\t\t<source_path>"+source.getPath()+"</source_path>\n");
		out.write("\t\t<source_target>"+source.getTargetName()+"</source_target>\n");
		out.write("\t\t<dest_path>"+dest.getPath()+"</dest_path>\n");
		out.write("\t\t<dest_target>"+dest.getTargetName()+"</dest_target>\n");

		//write attributes
		for (Map.Entry<String, Attribute> entry : busTarget.getAttributes().entrySet()) {
			Attribute attr = new Attribute(entry.getValue());
			attr.writeBusInstanceXML(out);
		}
		out.write("\t</bus>\n");
	}
	public void readInstanceXML(Element t) throws Exception {
		source = new ConnectionEndpoint();
		dest = new ConnectionEndpoint();
		busType = SystemModel.getElement(t, "bus_type");
		String cable = SystemModel.getElement(t, "cable");
		cabled=false;
		if (cable.equals("yes")) { cabled=true; }
		source.setPath(SystemModel.getElement(t, "source_path"));
		source.setTargetName(SystemModel.getElement(t, "source_target"));
		dest.setPath(SystemModel.getElement(t, "dest_path"));
		dest.setTargetName(SystemModel.getElement(t, "dest_target"));
		
		NodeList attrList = t.getElementsByTagName("bus_attribute");
		for (int j = 0; j < attrList.getLength(); ++j) {
			Element attr = (Element) attrList.item(j);
			if (attr==null) {
				throw new Exception("Problem with bus source="+source.getPath());
			}
			String id = SystemModel.getElement(attr, "id");
			Attribute a = busTarget.getAttributes().get(id);
			if (a==null) {
				ServerWizard2.LOGGER.warning("Attribute: "+id+" is invalid for bus "+source.getPath());
			} else {
				a.value.readInstanceXML(attr);
			}
		}
	}
}
OpenPOWER on IntegriCloud