diff options
| author | njames <nkskjames@gmail.com> | 2016-08-25 11:34:00 -0500 |
|---|---|---|
| committer | njames <nkskjames@gmail.com> | 2016-08-25 11:34:00 -0500 |
| commit | 05dfb231193d0bb3ec61e639d9d5960dc30d29df (patch) | |
| tree | 9887f4050e3b209758bdb6c651170646890b2ba7 /src/com/ibm/ServerWizard2/model | |
| parent | 99ae87285d0ebf27b37204bef1d4f25dd4d0215a (diff) | |
| download | serverwiz-05dfb231193d0bb3ec61e639d9d5960dc30d29df.tar.gz serverwiz-05dfb231193d0bb3ec61e639d9d5960dc30d29df.zip | |
Major refactor for P9:
- cleaned up package organization
- added html summary
- breakout parts library into seperate files
- added support for external parts library
- cleaned up MVC cheats
- removed unused methods
Diffstat (limited to 'src/com/ibm/ServerWizard2/model')
| -rw-r--r-- | src/com/ibm/ServerWizard2/model/Attribute.java | 169 | ||||
| -rw-r--r-- | src/com/ibm/ServerWizard2/model/AttributeValue.java | 51 | ||||
| -rw-r--r-- | src/com/ibm/ServerWizard2/model/AttributeValueComplex.java | 112 | ||||
| -rw-r--r-- | src/com/ibm/ServerWizard2/model/AttributeValueNative.java | 73 | ||||
| -rw-r--r-- | src/com/ibm/ServerWizard2/model/AttributeValueSimple.java | 109 | ||||
| -rw-r--r-- | src/com/ibm/ServerWizard2/model/Connection.java | 72 | ||||
| -rw-r--r-- | src/com/ibm/ServerWizard2/model/ConnectionEndpoint.java | 29 | ||||
| -rw-r--r-- | src/com/ibm/ServerWizard2/model/Enumerator.java | 40 | ||||
| -rw-r--r-- | src/com/ibm/ServerWizard2/model/Errata.java | 87 | ||||
| -rw-r--r-- | src/com/ibm/ServerWizard2/model/Field.java | 34 | ||||
| -rw-r--r-- | src/com/ibm/ServerWizard2/model/SystemModel.java | 834 | ||||
| -rw-r--r-- | src/com/ibm/ServerWizard2/model/Target.java | 569 | ||||
| -rw-r--r-- | src/com/ibm/ServerWizard2/model/XmlHandler.java | 35 |
13 files changed, 2214 insertions, 0 deletions
diff --git a/src/com/ibm/ServerWizard2/model/Attribute.java b/src/com/ibm/ServerWizard2/model/Attribute.java new file mode 100644 index 0000000..17b346c --- /dev/null +++ b/src/com/ibm/ServerWizard2/model/Attribute.java @@ -0,0 +1,169 @@ +package com.ibm.ServerWizard2.model; + +import java.io.Writer; + +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +public class Attribute implements java.io.Serializable { + private static final long serialVersionUID = 1L; + public String name = ""; + public String group = ""; + public AttributeValue value; + + public String inherited = ""; + public String desc = ""; + public String compareStr = ""; + public Boolean readable = false; + public Boolean writeable = false; + public Boolean readonly = false; + public Persistency persistency = Persistency.NO_PERSISTENCY; + public Boolean hide = false; + private Boolean bitmask = false; + private Boolean global = false; + + public enum Persistency { + NO_PERSISTENCY, VOLATILE_ZEROED, NON_VOLATILE, VOLATILE + }; + + public Attribute() { + } + + public Attribute(Attribute a) { + this.name = a.name; + this.desc = a.desc; + this.group = a.group; + this.persistency = a.persistency; + this.readable = a.readable; + this.writeable = a.writeable; + this.inherited = a.inherited; + this.hide = a.hide; + this.bitmask = a.bitmask; + this.global = a.global; + + if (a.value instanceof AttributeValueComplex) { + this.value = new AttributeValueComplex((AttributeValueComplex)a.value); + } + else if(a.value instanceof AttributeValueSimple) { + this.value = new AttributeValueSimple((AttributeValueSimple)a.value); + } + else if(a.value instanceof AttributeValueNative) { + this.value = new AttributeValueNative((AttributeValueNative)a.value); + } + else { + + } + + } + + public AttributeValue getValue() { + return value; + } + public boolean isReadable() { + return readable; + } + public boolean isWriteable() { + return writeable; + } + public boolean isHidden() { + return hide; + } + + public boolean isGlobal() { + return this.global; + } + + public String toString() { + String rtn="Attribute: "+name+" = "; + rtn="Attribute: "+name+" = "+value.toString()+" inherited="+this.inherited; + return rtn; + } + + public void setPersistence(String p) { + if (p.equals("non-volatile")) { + persistency = Persistency.NON_VOLATILE; + } else if (p.equals("volatile-zeroed")) { + persistency = Persistency.VOLATILE_ZEROED; + } else if (p.equals("volatile")) { + persistency = Persistency.VOLATILE; + } else { + throw new NullPointerException("Invalid Peristence: "+p); + } + } + public String getPersistence() { + if (persistency == Persistency.NON_VOLATILE) { + return "non-volatile"; + } else if(persistency == Persistency.VOLATILE_ZEROED) { + return "volatile-zeroed"; + } else if(persistency == Persistency.NO_PERSISTENCY) { + return ""; + } else if(persistency == Persistency.VOLATILE) { + return "volatile"; + } else { return ""; } + + } + public void readModelXML(Element attribute) { + name = SystemModel.getElement(attribute, "id"); + desc = SystemModel.getElement(attribute,"description"); + group = SystemModel.getElement(attribute,"group"); + + String p = SystemModel.getElement(attribute,"persistency"); + if (!p.isEmpty()) { setPersistence(p); } + + if (SystemModel.isElementDefined(attribute,"bitmask")) { + bitmask=true; + } + if (SystemModel.isElementDefined(attribute,"global")) { + global=true; + } + + if (SystemModel.isElementDefined(attribute,"readable")) { + readable=true; + } + if (SystemModel.isElementDefined(attribute,"writeable")) { + writeable=true; + } + if (SystemModel.isElementDefined(attribute,"serverwizHide") || + name.equals("MODEL") || name.equals("TYPE") || name.equals("CLASS")) { + hide=true; + } + if (SystemModel.isElementDefined(attribute,"serverwizReadonly")) { + readonly=true; + } + Node simpleType = attribute.getElementsByTagName("simpleType").item(0); + if (simpleType!=null) { + value = new AttributeValueSimple(this); + value.readonly = readonly; + value.readXML((Element)simpleType); + } + Node complexType = attribute.getElementsByTagName("complexType").item(0); + if (complexType!=null) { + value = new AttributeValueComplex(this); + value.readonly = readonly; + value.readXML((Element)complexType); + } + Node nativeType = attribute.getElementsByTagName("nativeType").item(0); + if (nativeType!=null) { + value = new AttributeValueNative(this); + value.readonly = readonly; + value.readXML((Element)nativeType); + } + } + public void writeBusInstanceXML(Writer out) throws Exception { + out.write("\t\t<bus_attribute>\n"); + out.write("\t\t\t<id>"+name+"</id>\n"); + value.writeInstanceXML(out); + out.write("\t\t</bus_attribute>\n"); + } + public void writeInstanceXML(Writer out) throws Exception { + out.write("\t<attribute>\n"); + out.write("\t\t<id>"+name+"</id>\n"); + value.writeInstanceXML(out); + out.write("\t</attribute>\n"); + } + + public String compare(Object o) { + Attribute a = (Attribute) o; + return value.compare(a.getValue()); + } +} diff --git a/src/com/ibm/ServerWizard2/model/AttributeValue.java b/src/com/ibm/ServerWizard2/model/AttributeValue.java new file mode 100644 index 0000000..f155c58 --- /dev/null +++ b/src/com/ibm/ServerWizard2/model/AttributeValue.java @@ -0,0 +1,51 @@ +package com.ibm.ServerWizard2.model; + +import java.io.Writer; +import java.util.Vector; + +import org.w3c.dom.Element; + +public abstract class AttributeValue { + + protected String type=""; + protected Vector<Field> fields; + protected Attribute attribute = null; + protected boolean readonly = true; + + public abstract void readXML(Element value); + public abstract void readInstanceXML(Element value); + public abstract void writeInstanceXML(Writer out) throws Exception; + public abstract String getValue(); + public abstract void setValue(AttributeValue value); + public abstract void setValue(String value); + public abstract String toString(); + public abstract Boolean isEmpty(); + public abstract String compare(Object o); + + public void setEnumerator(Enumerator enumerator) { + for (Field f : fields) { + f.enumerator=enumerator; + } + } + + public AttributeValue(Attribute attribute) { + fields = new Vector<Field>(); + this.attribute=attribute; + } + public AttributeValue(AttributeValue a) { + fields = new Vector<Field>(); + for (Field f : a.fields) { + Field f2 = new Field(f); + fields.add(f2); + } + type = a.type; + attribute = a.attribute; + readonly = a.readonly; + } + public String getType() { + return type; + } + public Vector<Field> getFields() { + return fields; + } +} diff --git a/src/com/ibm/ServerWizard2/model/AttributeValueComplex.java b/src/com/ibm/ServerWizard2/model/AttributeValueComplex.java new file mode 100644 index 0000000..9b96f07 --- /dev/null +++ b/src/com/ibm/ServerWizard2/model/AttributeValueComplex.java @@ -0,0 +1,112 @@ +package com.ibm.ServerWizard2.model; + +import java.io.Writer; +import java.util.Vector; + +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +public class AttributeValueComplex extends AttributeValue { + + public AttributeValueComplex(Attribute a) { + super(a); + } + public AttributeValueComplex(AttributeValueComplex a) { + super(a); + } + + public void readXML(Element value) { + fields = new Vector<Field>(); + type="complex"; + NodeList fieldList = value.getElementsByTagName("field"); + for (int i = 0; i < fieldList.getLength(); ++i) { + Field f = new Field(); + f.attributeName = this.attribute.name; + f.name = SystemModel.getElement((Element) fieldList.item(i), "name"); + f.desc = SystemModel + .getElement((Element) fieldList.item(i), "description"); + f.group = SystemModel.getElement((Element) fieldList.item(i), "group"); + f.type = SystemModel.getElement((Element) fieldList.item(i), "type"); + f.bits = SystemModel.getElement((Element) fieldList.item(i), "bits"); + f.defaultv = SystemModel.getElement((Element) fieldList.item(i), "default"); + f.readonly = this.readonly; + fields.add(f); + } + } + public void readInstanceXML(Element value) { + NodeList fieldList = value.getElementsByTagName("field"); + for (int i = 0; i < fieldList.getLength(); ++i) { + String fid=SystemModel.getElement((Element) fieldList.item(i), "id"); + String v=SystemModel.getElement((Element) fieldList.item(i), "value"); + for(int x=0;x<fields.size();x++) { + Field f = fields.get(x); + if (f.name.equals(fid)) { + f.value=v; + } + } + } + } + @Override + public void writeInstanceXML(Writer out) throws Exception { + String t="\t\t"; + String r=t+"<default>\n"; + for (int i=0;i<fields.size();i++) { + Field f = new Field(fields.get(i)); + r=r+t+"\t\t<field><id>"+f.name+"</id><value>"+f.value+"</value></field>\n"; + } + r=r+t+"</default>\n"; + out.write(r); + } + + @Override + public String getValue() { + return "complex"; + } + + @Override + public String toString() { + String r="COMPLEX:\n"; + for (int i=0;i<this.fields.size();i++) { + Field f = new Field(this.fields.get(i)); + r=f.name+"="+f.value; + } + return r; + } + @Override + public void setValue(String value) { + // TODO Auto-generated method stub + + } + @Override + public Boolean isEmpty() { + return false; + } + @Override + public void setValue(AttributeValue value) { + fields.clear(); + AttributeValueComplex c = (AttributeValueComplex)value; + for (int i=0;i<c.fields.size();i++) { + Field f = new Field(c.fields.get(i)); + fields.add(f); + } + } + @Override + public String compare(Object o) { + AttributeValueComplex a = (AttributeValueComplex) o; + String cmp = ""; + for (Field f : fields) { + Boolean found = false; + for (Field fc : a.fields) { + if (f.name.equals(fc.name)) { + found = true; + if (!f.value.equals(fc.value)) { + cmp = cmp + f.attributeName +"(" +f.name +")" +" : "+f.value+" != "+fc.value+"\n"; + ; + } + } + } + if (!found) { return "invalid attribute"; } + } + return cmp; + } +} diff --git a/src/com/ibm/ServerWizard2/model/AttributeValueNative.java b/src/com/ibm/ServerWizard2/model/AttributeValueNative.java new file mode 100644 index 0000000..df8688e --- /dev/null +++ b/src/com/ibm/ServerWizard2/model/AttributeValueNative.java @@ -0,0 +1,73 @@ +package com.ibm.ServerWizard2.model; + +import java.io.Writer; + +import org.w3c.dom.Element; + +public class AttributeValueNative extends AttributeValue { + private Field field; + + public AttributeValueNative(Attribute a) { + super(a); + field = new Field(); + field.attributeName=a.name; + field.desc=a.desc; + field.group=a.group; + fields.add(field); + } + public AttributeValueNative(AttributeValueNative a) { + super(a); + field=fields.get(0); + } + public void readXML(Element e) { + field.value = SystemModel.getElement(e, "default"); + field.name = SystemModel.getElement(e, "name"); + field.readonly = this.readonly; + } + + public void readInstanceXML(Element e) { + field.value = SystemModel.getElement(e, "default"); + } + + @Override + public void writeInstanceXML(Writer out) throws Exception { + out.write("\t\t<default>" + field.value + "</default>\n"); + } + + @Override + public String getValue() { + return field.value; + } + + @Override + public String toString() { + return "default(" + field.name + ")"; + } + + @Override + public void setValue(String value) { + field.value = value; + } + + @Override + public Boolean isEmpty() { + return field.value.isEmpty(); + } + + @Override + public void setValue(AttributeValue value) { + AttributeValueNative n = (AttributeValueNative) value; + field.value = n.field.value; + field.name = n.field.name; + } + + @Override + public String compare(Object o) { + String cmp = ""; + AttributeValueNative s = (AttributeValueNative) o; + if (!field.value.equals(s.field.value)) { + cmp = field.attributeName +" : "+field.value + " != "+s.field.value; + } + return cmp; + } +} diff --git a/src/com/ibm/ServerWizard2/model/AttributeValueSimple.java b/src/com/ibm/ServerWizard2/model/AttributeValueSimple.java new file mode 100644 index 0000000..434efb2 --- /dev/null +++ b/src/com/ibm/ServerWizard2/model/AttributeValueSimple.java @@ -0,0 +1,109 @@ +package com.ibm.ServerWizard2.model; + +import java.io.Writer; + +import org.w3c.dom.Element; + +public class AttributeValueSimple extends AttributeValue { + + private String array = ""; + private Field field; + + public AttributeValueSimple(Attribute a) { + super(a); + field = new Field(); + field.attributeName = a.name; + field.desc=a.desc; + field.group=a.group; + fields.add(field); + } + public AttributeValueSimple(AttributeValueSimple a) { + super(a); + field=fields.get(0); + } + + @Override + public void readXML(Element e) { + // value = e.getElementsByTagName("default").; + Element a = (Element) e.getElementsByTagName("uint8_t").item(0); + if (a != null) { + type = "uint8_t"; + field.value = SystemModel.getElement(a, "default"); + field.type=type; + } + a = (Element) e.getElementsByTagName("uint16_t").item(0); + if (a != null) { + type = "uint16_t"; + field.value = SystemModel.getElement(a, "default"); + field.type=type; + } + a = (Element) e.getElementsByTagName("uint32_t").item(0); + if (a != null) { + type = "uint32_t"; + field.value = SystemModel.getElement(a, "default"); + field.type=type; + } + a = (Element) e.getElementsByTagName("string").item(0); + if (a != null) { + type = "string"; + field.value = SystemModel.getElement(a, "default"); + field.type=type; + } + a = (Element) e.getElementsByTagName("enumeration").item(0); + if (a != null) { + type = "enumeration"; + field.value = SystemModel.getElement(a, "default"); + field.name = SystemModel.getElement(a, "id"); + field.type=type; + } + array = SystemModel.getElement(e, "array"); + field.array = array; + field.readonly = this.readonly; + } + + public void readInstanceXML(Element e) { + field.value = SystemModel.getElement(e, "default"); + } + + @Override + public void writeInstanceXML(Writer out) throws Exception { + out.write("\t\t<default>" + field.value + "</default>\n"); + } + + @Override + public String getValue() { + return field.value; + } + + @Override + public String toString() { + // TODO Auto-generated method stub + return "Simple: "+field.value + " (" + type + ")"; + } + + @Override + public void setValue(String value) { + field.value = value; + } + + @Override + public Boolean isEmpty() { + return field.value.isEmpty(); + } + + @Override + public void setValue(AttributeValue value) { + AttributeValueSimple n = (AttributeValueSimple) value; + field.value = n.field.value; + field.name = n.field.name; + } + @Override + public String compare(Object o) { + String cmp = ""; + AttributeValueSimple s = (AttributeValueSimple) o; + if (!field.value.equals(s.field.value)) { + cmp = field.attributeName +" : "+field.value + " != "+s.field.value; + } + return cmp; + } +} diff --git a/src/com/ibm/ServerWizard2/model/Connection.java b/src/com/ibm/ServerWizard2/model/Connection.java new file mode 100644 index 0000000..cbb6497 --- /dev/null +++ b/src/com/ibm/ServerWizard2/model/Connection.java @@ -0,0 +1,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); + } + } + } +} diff --git a/src/com/ibm/ServerWizard2/model/ConnectionEndpoint.java b/src/com/ibm/ServerWizard2/model/ConnectionEndpoint.java new file mode 100644 index 0000000..21c893b --- /dev/null +++ b/src/com/ibm/ServerWizard2/model/ConnectionEndpoint.java @@ -0,0 +1,29 @@ +package com.ibm.ServerWizard2.model; + +public class ConnectionEndpoint { + //private Target target; + private String path=""; + private String targetName=""; + + //public Target getTarget() { + // return target; + //} + public String getTargetName() { + return targetName; + } + public void setTargetName(String targetName) { + this.targetName = targetName; + } + //public void setTarget(Target target) { + // this.target = target; + //} + public String getPath() { + return path; + } + public void setPath(String path) { + this.path = path; + } + public String getName() { + return path+targetName; + } +} diff --git a/src/com/ibm/ServerWizard2/model/Enumerator.java b/src/com/ibm/ServerWizard2/model/Enumerator.java new file mode 100644 index 0000000..e0c56e6 --- /dev/null +++ b/src/com/ibm/ServerWizard2/model/Enumerator.java @@ -0,0 +1,40 @@ +package com.ibm.ServerWizard2.model; + +import java.util.HashMap; +import java.util.Vector; + +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +public class Enumerator { + public String id=""; + public String desc=""; + public String group=""; + public HashMap<String,String> enumValues = new HashMap<String,String>(); + public Vector<String> enumList = new Vector<String>(); + + + public void addEnum(String name,String value) { + enumValues.put(name, value); + enumList.add(name); + } + public void readXML(Element e) { + id = SystemModel.getElement(e, "id"); + desc = SystemModel.getElement(e,"description"); + group = SystemModel.getElement(e,"group"); + NodeList enumList = e.getElementsByTagName("enumerator"); + for (int i = 0; i < enumList.getLength(); ++i) { + Element en=(Element)enumList.item(i); + String name=SystemModel.getElement(en, "name"); + String value=SystemModel.getElement(en, "value"); + addEnum(name,value); + } + } + public Integer getEnumInt(String e) { + return Integer.decode(enumValues.get(e)); + } + public String getEnumStr(String e) { + return enumValues.get(e); + } + +} diff --git a/src/com/ibm/ServerWizard2/model/Errata.java b/src/com/ibm/ServerWizard2/model/Errata.java new file mode 100644 index 0000000..30093ab --- /dev/null +++ b/src/com/ibm/ServerWizard2/model/Errata.java @@ -0,0 +1,87 @@ +package com.ibm.ServerWizard2.model;
+
+import java.util.HashMap;
+import java.util.Vector;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+public class Errata {
+ private String id = "";
+ private String desc = "";
+ private Boolean applied = false;
+ private Vector<Attribute> attributes = new Vector<Attribute>();
+ private String compareDetail = "";
+ private Vector<Target> targets = new Vector<Target>();
+ private String targetType = "";
+
+ public Errata() {
+
+ }
+ public Errata(Errata e) {
+ id = e.id;
+ desc = e.desc;
+ applied = e.applied;
+ targetType = e.targetType;
+ //don't deep copy attributes
+ attributes = e.attributes;
+ }
+ public void addTarget(Target t) {
+ targets.add(t);
+ }
+ public String getDetail() {
+ return compareDetail;
+ }
+ public void setDetail(String d) {
+ this.compareDetail = d;
+ }
+ public void setApplied(Boolean applied) {
+ this.applied = applied;
+ }
+ public Boolean isApplied() {
+ return applied;
+ }
+ public String getTargetType() {
+ return this.targetType;
+ }
+ public void updateAttributes() {
+ for (Target t : targets) {
+ for (Attribute a : attributes) {
+ Attribute attrNew = new Attribute(a);
+ t.getAttributes().put(attrNew.name,attrNew);
+ }
+ }
+ }
+ public void read(Element t, HashMap<String, Attribute> attributeModel) {
+ attributes.removeAllElements();
+ this.id = SystemModel.getElement(t, "errata_id");
+ this.desc = SystemModel.getElement(t, "description");
+ this.targetType = SystemModel.getElement(t, "target_type");
+ NodeList attributeList = t.getElementsByTagName("attribute");
+ for (int j = 0; j < attributeList.getLength(); ++j) {
+ String attrId = SystemModel.getElement((Element) attributeList.item(j), "id");
+ Attribute aModel = attributeModel.get(attrId);
+ if (aModel == null) {
+ MessageDialog.openError(null, "Error", "Invalid attribute " + attrId + " in Errata: " + id);
+ return;
+ } else {
+ Attribute a = new Attribute(aModel);
+ a.value.readInstanceXML((Element) attributeList.item(j));
+ attributes.add(a);
+ }
+ }
+ }
+ public String getId() {
+ return id;
+ }
+ public String getDesc() {
+ return desc;
+ }
+ public Vector<Attribute> getAttributes() {
+ return attributes;
+ }
+ public void readInstance() {
+
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/model/Field.java b/src/com/ibm/ServerWizard2/model/Field.java new file mode 100644 index 0000000..e616642 --- /dev/null +++ b/src/com/ibm/ServerWizard2/model/Field.java @@ -0,0 +1,34 @@ +package com.ibm.ServerWizard2.model; + + + +public class Field { + public String attributeName=""; + public String name=""; + public String desc=""; + public String group=""; + public String type=""; + public String bits=""; + public String defaultv=""; + public String value=""; + public Enumerator enumerator = null; + public String array = ""; + public boolean readonly = false; + + public Field() { + + } + public Field(Field f) { + attributeName = f.attributeName; + name=f.name; + desc=f.desc; + group=f.group; + type=f.type; + bits=f.bits; + value=f.value; + defaultv=f.defaultv; + enumerator=f.enumerator; + array = f.array; + readonly = f.readonly; + } +} diff --git a/src/com/ibm/ServerWizard2/model/SystemModel.java b/src/com/ibm/ServerWizard2/model/SystemModel.java new file mode 100644 index 0000000..b2470ce --- /dev/null +++ b/src/com/ibm/ServerWizard2/model/SystemModel.java @@ -0,0 +1,834 @@ +package com.ibm.ServerWizard2.model; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; +import java.util.Vector; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.MessageDialog; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import com.ibm.ServerWizard2.ServerWizard2; +import com.ibm.ServerWizard2.view.ErrataViewer; + +public class SystemModel { + // public Target rootTarget; + public Vector<Target> rootTargets = new Vector<Target>(); + private DocumentBuilder builder; + + // From target instances + private HashMap<String, Target> targetInstances = new HashMap<String, Target>(); + private Vector<Target> targetUnitList = new Vector<Target>(); + private HashMap<String, Target> targetUnitModels = new HashMap<String,Target>(); + + // From target types + private TreeMap<String, Target> targetModels = new TreeMap<String, Target>(); + private HashMap<String, Vector<Target>> childTargetTypes = new HashMap<String, Vector<Target>>(); + + // From attribute types + public TreeMap<String, Enumerator> enumerations = new TreeMap<String, Enumerator>(); + private HashMap<String, Attribute> attributes = new HashMap<String, Attribute>(); + private TreeMap<String, Vector<String>> attributeGroups = new TreeMap<String, Vector<String>>(); + private TreeMap<String, Errata> errata = new TreeMap<String, Errata>(); + + // List of targets in current system + private Vector<Target> targetList = new Vector<Target>(); + private HashMap<String, Target> targetLookup = new HashMap<String, Target>(); + private TreeMap<String, Errata> errataList = new TreeMap<String, Errata>(); + + private TreeMap<String, Target> busTypesTree = new TreeMap<String, Target>(); + private Vector<Target> busTypes = new Vector<Target>(); + + private TreeMap<String, TreeMap<String, Field>> globalSettings = new TreeMap<String, TreeMap<String, Field>>(); + + public Boolean partsMode = false; + public Boolean cleanupMode = false; + public Boolean errataUpdated = false; + + + public Vector<Target> getBusTypes() { + return busTypes; + } + + public Target getTarget(String t) { + return targetLookup.get(t); + } + + public HashMap<String, Target> getTargetLookup() { + return this.targetLookup; + } + + public Vector<Target> getTargetList() { + return this.targetList; + } + + public Collection<Target> getTargetInstances() { + return targetInstances.values(); + } + + public Target getRootTarget() { + return rootTargets.get(0); + } + + public Vector<Target> getTopLevelTargets() { + //TODO: need a better way to determine top level targets + Vector<Target> topLevel = new Vector<Target>(); + for (Target target : targetModels.values()) { + String type = target.getType(); + if (type.equals("chip") || type.startsWith("sys") || type.equals("targetoverride")) { + topLevel.add(target); + } + } + return topLevel; + } + + public Vector<Target> getUnitTargets(Boolean override) { + //TODO: need a better way to determine top level targets + Vector<Target> topLevel = new Vector<Target>(); + for (Target target : targetModels.values()) { + if (override == false) { + if (target.isUnit()) { topLevel.add(target); } + } else { + if (target.isOverride()) { + topLevel.add(target); + } + } + } + return topLevel; + } + + public Vector<Target> getConnectionCapableTargets() { + Vector<Target> cards = new Vector<Target>(); + for (Target target : targetList) { + if (target.isCard() || target.isSystem() || target.isNode()) { + cards.add(target); + } + } + return cards; + } + + public void initBusses(Target target) { + target.initBusses(busTypes); + } + + public Vector<Target> getChildTargetTypes(String targetType) { + if (targetType.equals("")) { + Vector<Target> a = new Vector<Target>(); + for (Target t : this.targetModels.values()) { + a.add(t); + } + return a; + } + if (childTargetTypes.get(targetType) != null) { + Collections.sort(childTargetTypes.get(targetType)); + } + return childTargetTypes.get(targetType); + } + + + private void writeErrata(Writer out) throws Exception { + out.write("<appliedErratas>\n"); + for (String e : errataList.keySet()) { + out.write("<appliedErrata>"); + out.write("\t<id>" + e + "</id>"); + out.write("\t<is_applied>" + errataList.get(e).isApplied() + "</is_applied>"); + out.write("</appliedErrata>\n"); + } + out.write("</appliedErratas>\n"); + } + + + private void writeGroups(Writer out) throws Exception { + out.write("<attributeGroups>\n"); + for (String group : attributeGroups.keySet()) { + out.write("<attributeGroup>\n"); + out.write("\t<id>" + group + "</id>\n"); + for (String attribute : attributeGroups.get(group)) { + out.write("\t<attribute>" + attribute + "</attribute>\n"); + } + out.write("</attributeGroup>\n"); + } + out.write("</attributeGroups>\n"); + } + private void writeEnumeration(Writer out) throws Exception { + out.write("<enumerationTypes>\n"); + for (String enumeration : enumerations.keySet()) { + Enumerator e = enumerations.get(enumeration); + out.write("<enumerationType>\n"); + out.write("\t<id>" + enumeration + "</id>\n"); + for (Map.Entry<String, String> entry : e.enumValues.entrySet()) { + out.write("\t\t<enumerator>\n"); + out.write("\t\t<name>" + entry.getKey() + "</name>\n"); + out.write("\t\t<value>" + entry.getValue() + "</value>\n"); + out.write("\t\t</enumerator>\n"); + } + out.write("</enumerationType>\n"); + } + out.write("</enumerationTypes>\n"); + } + + private NodeList isXMLValid(Document document, String tag) { + NodeList n = document.getElementsByTagName(tag); + if (n != null) { + if (n.item(0) != null) { + String version = SystemModel.getElement((Element)n.item(0), "version"); + if (!version.isEmpty()) { + ServerWizard2.LOGGER.info("XML Version found: "+version); + if (Double.valueOf(version) >= ServerWizard2.VERSION_MAJOR) { + return n; + } + } + } + } + return null; + } + public void loadLibrary(String path) throws Exception { + File xmlDir = new File(path); + File[] filesList = xmlDir.listFiles(); + if (filesList == null) { + ServerWizard2.LOGGER.warning("No library loaded"); + } else { + for (File file : filesList) { + if (file.isFile() && file.getAbsolutePath().endsWith(".xml")) { + if (file.getName().startsWith("attribute_types")) { + this.loadAttributes(file.getPath()); + } + if (file.getName().startsWith("target_types")) { + this.loadTargetTypes(file.getPath()); + } + } + } + } + File partsDir = new File(path+File.separator+"parts"+File.separator); + filesList = partsDir.listFiles(); + if (filesList == null) { + ServerWizard2.LOGGER.warning("No parts loaded"); + } else { + for (File file : filesList) { + if (file.isFile() && file.getAbsolutePath().endsWith(".xml")) { + this.loadTargets(file.getPath()); + } + } + } + } + + // Reads a previously saved MRW + public void readXML(String filename) throws Exception { + ServerWizard2.LOGGER.info("Reading XML: "+filename); + File f = new File(filename); + this.loadLibrary(f.getParent()); + long startTime = System.currentTimeMillis(); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + // delete all existing instances + this.deleteAllInstances(); + this.addUnitInstances(); + + DocumentBuilder builder = factory.newDocumentBuilder(); + builder.setErrorHandler(new XmlHandler()); + Document document = builder.parse(filename); + + NodeList system = isXMLValid(document,"systemInstance"); + NodeList part = isXMLValid(document,"partInstance"); + if (system == null && part == null) { + String msg = "ServerWiz cannot read this version of XML: "+filename; + ServerWizard2.LOGGER.severe(msg); + MessageDialog.openError(null, "XML Load Error", msg); + } + partsMode = false; + String targetTag = "targetInstance"; + if (part != null) { + partsMode = true; + targetTag = "targetPart"; + ServerWizard2.LOGGER.info("Setting Parts mode"); + } + + NodeList settingList = document.getElementsByTagName("globalSettings"); + Element t = (Element) settingList.item(0); + if (t != null) { + NodeList settingList2 = t.getElementsByTagName("globalSetting"); + for (int j = 0; j < settingList2.getLength(); ++j) { + Element t2 = (Element) settingList2.item(j); + this.readGlobalSettings(t2); + } + } + NodeList errataList = document.getElementsByTagName("appliedErratas"); + Element te = (Element) errataList.item(0); + if (te != null) { + NodeList errataList2 = te.getElementsByTagName("appliedErrata"); + for (int j = 0; j < errataList2.getLength(); ++j) { + Element t2 = (Element) errataList2.item(j); + this.readErrata(t2); + } + } + NodeList targetInstances = document.getElementsByTagName("targetInstances"); + t = (Element) targetInstances.item(0); + NodeList targetInstanceList = t.getElementsByTagName(targetTag); + + for (int i = 0; i < targetInstanceList.getLength(); ++i) { + t = (Element) targetInstanceList.item(i); + String type = SystemModel.getElement(t, "type"); + if (type.length() > 0) { + Target targetModel = this.getTargetModel(type); + if (targetModel == null) { + ServerWizard2.LOGGER.severe("Invalid target type: " + type); + throw new Exception("Invalid target type: " + type); + } else { + Target target = new Target(targetModel); + target.initBusses(busTypes); + target.readInstanceXML(t, targetModels); + this.targetLookup.put(target.getName(), target); + this.targetList.add(target); + + if (target.isRoot()) { + this.rootTargets.add(target); + } + /////// + // Check to see if new children defined in model + Target targetInst = this.targetInstances.get(target.getType()); + if (targetInst != null) { + HashMap <String,Boolean> childTest = new HashMap<String,Boolean>(); + for (String child : target.getAllChildren()) { + childTest.put(child, true); + } + for (String child : targetInst.getChildren()) { + if (childTest.get(child)==null) { + target.addChild(child, false); + if (!this.targetLookup.containsKey(child)) { + this.targetLookup.put(child, target); + this.targetList.add(target); + } + childTest.put(child, true); + } + } + for (String child : targetInst.getHiddenChildren()) { + if (childTest.get(child)==null) { + target.addChild(child, true); + if (!this.targetLookup.containsKey(child)) { + this.targetLookup.put(child,target); + this.targetList.add(target); + } + childTest.put(child, true); + } + } + } + } + } else { + throw new Exception("Empty Target Type"); + } + } + if (cleanupMode) { this.xmlCleanup(); } + long endTime = System.currentTimeMillis(); + ServerWizard2.LOGGER.info("Loaded XML in " + (endTime - startTime) + " milliseconds"); + + checkErrata(); + } + + public void checkErrata() { + Vector<Errata> errataNew = new Vector<Errata>(); + + //Determine errata that has not been acknowledged + for (String errata_id : errata.keySet()) { + if (!errataList.containsKey(errata_id)) { + Errata e = new Errata(errata.get(errata_id)); + errataNew.add(e); + } + } + + HashMap<String,Errata> errataCheck = new HashMap<String,Errata>(); + for (Target tchk : this.targetLookup.values()) { + for (Errata e : errataNew) { + if (e.getTargetType().equals(tchk.getType())) { + Boolean found = false; + String cmpSummary = e.getDesc()+"\n===========================================\n"; + for (Attribute errataAttr : e.getAttributes()) { + if (tchk.attributeExists(errataAttr.name)) { + Attribute currentAttr = tchk.getAttributes().get(errataAttr.name); + String cmp = errataAttr.compare(currentAttr); + if (!cmp.isEmpty()) { + cmpSummary = cmpSummary + cmp +"\n"; + errataCheck.put(e.getId(), e); + e.setDetail(cmpSummary); + found = true; + } + } + } + if (found) { e.addTarget(tchk); } + } + } + } + Vector<Errata> errataV = new Vector<Errata>(); + for (Errata e : errataCheck.values()) { + errataV.add(e); + } + if (errataCheck.size() > 0) { + ErrataViewer dlg = new ErrataViewer(null,errataV); + int rtn = dlg.open(); + if (rtn == Dialog.OK) { + for (Errata e : errataV) { + if (e.isApplied()) { + e.updateAttributes(); + } + errataUpdated = true; + errataList.put(e.getId(), e); + } + } + } + } + + /////////////////////////////////////////////// + // global settings + + public Field setGlobalSetting(String path, String attribute, String value) { + TreeMap<String, Field> s = globalSettings.get(path); + if (s == null) { + s = new TreeMap<String, Field>(); + globalSettings.put(path, s); + } + Field f = s.get(attribute); + if (f == null) { + f = new Field(); + f.attributeName = attribute; + s.put(attribute, f); + } + f.value = value; + return f; + } + + public Boolean isGlobalSetting(String path, String attribute) { + TreeMap<String, Field> s = globalSettings.get(path); + if (s == null) { + return false; + } + Field f=s.get(attribute); + if (f==null) { + return false; + } + return true; + } + + public Field getGlobalSetting(String path, String attribute) { + TreeMap<String, Field> s = globalSettings.get(path); + if (s == null) { + if (s == null) { + s = new TreeMap<String, Field>(); + globalSettings.put(path, s); + } + return null; + } + Field f=s.get(attribute); + return f; + } + + public TreeMap<String, Field> getGlobalSettings(String path) { + TreeMap<String, Field> s = globalSettings.get(path); + return s; + } + + private void writeGlobalSettings(Writer out) throws Exception { + out.write("<globalSettings>\n"); + for (Map.Entry<String, TreeMap<String, Field>> entry : this.globalSettings.entrySet()) { + out.write("<globalSetting>\n"); + out.write("\t<id>" + entry.getKey() + "</id>\n"); + for (Map.Entry<String, Field> setting : entry.getValue().entrySet()) { + out.write("\t<property>\n"); + out.write("\t<id>" + setting.getKey() + "</id>\n"); + out.write("\t<value>" + setting.getValue().value + "</value>\n"); + out.write("\t</property>\n"); + } + out.write("</globalSetting>\n"); + } + out.write("</globalSettings>\n"); + } + + private void readGlobalSettings(Element setting) { + String targetId = SystemModel.getElement(setting, "id"); + NodeList propertyList = setting.getElementsByTagName("property"); + for (int i = 0; i < propertyList.getLength(); ++i) { + Element t = (Element) propertyList.item(i); + String property = SystemModel.getElement(t, "id"); + String value = SystemModel.getElement(t, "value"); + this.setGlobalSetting(targetId, property, value); + } + } + private void readErrata(Element setting) { + String errata_id = SystemModel.getElement(setting, "id"); + if (this.errata.containsKey(errata_id)) { + Errata e = new Errata(this.errata.get(errata_id)); + errataList.put(errata_id, e); + } + } + + ///////////////////////////////////////////////// + // Writes MRW to file + public void writeXML(String filename, Boolean partsMode) throws Exception { + Writer out = new BufferedWriter(new FileWriter(filename)); + String topTag = "systemInstance"; + if (partsMode) { topTag = "partInstance"; } + + out.write("<"+topTag+">\n"); + out.write("<version>"+ServerWizard2.getVersionString()+"</version>\n"); + if (!partsMode) { + this.writeEnumeration(out); + this.writeGlobalSettings(out); + this.writeGroups(out); + this.writeErrata(out); + } + out.write("<targetInstances>\n"); + HashMap<String, Boolean> targetWritten = new HashMap<String, Boolean>(); + for (Target target : targetList) { + if (partsMode) { + target.writeTargetXML(out, targetLookup, targetWritten); + } else { + target.writeInstanceXML(out, targetLookup, targetWritten); + } + } + out.write("</targetInstances>\n"); + out.write("</"+topTag+">\n"); + out.close(); + } + + public void addTarget(Target parentTarget, Target newTarget,Boolean pathMode) throws Exception { + if (parentTarget == null) { + this.rootTargets.add(newTarget); + newTarget.setRoot(); + if (pathMode) { + newTarget.parent = newTarget.getType(); + newTarget.setType(newTarget.parent+"-"+newTarget.getRawName()); + } + } else { + newTarget.clearRoot(); + if (pathMode) { + String name = newTarget.getRawName(); + if (name.isEmpty()) { name = newTarget.getIdPrefix(); } + newTarget.setName(parentTarget.getName()+"."+name); + } + parentTarget.addChild(newTarget.getName(), false); + } + this.updateTargetList(newTarget); + initBusses(newTarget); + } + public void loadTargetTypes(String fileName) throws SAXException, + IOException, ParserConfigurationException { + ServerWizard2.LOGGER.info("Loading Target Types: " + fileName); + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + builder = factory.newDocumentBuilder(); + builder.setErrorHandler(new XmlHandler()); + + Document document = builder.parse(fileName); + NodeList targetList = document.getElementsByTagName("targetType"); + for (int i = 0; i < targetList.getLength(); ++i) { + Element t = (Element) targetList.item(i); + Target target = new Target(); + target.readModelXML(t, attributes); + targetModels.put(target.getType(), target); + } + for (Map.Entry<String, Target> entry : targetModels.entrySet()) { + Target target = entry.getValue(); + + // add inherited attributes + addParentAttributes(target, target); + if (target.getAttribute("CLASS").equals("BUS")) { + busTypesTree.put(entry.getKey(),target); + } + } + busTypes.removeAllElements(); + for (Target t : busTypesTree.values()) { + busTypes.add(t); + } + } + + public void loadAttributes(String fileName) throws SAXException, + IOException, ParserConfigurationException { + ServerWizard2.LOGGER.info("Loading Attributes: " + fileName); + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + builder = factory.newDocumentBuilder(); + builder.setErrorHandler(new XmlHandler()); + + Document document = builder.parse(fileName); + NodeList enumList = document.getElementsByTagName("enumerationType"); + for (int i = 0; i < enumList.getLength(); ++i) { + Element t = (Element) enumList.item(i); + Enumerator en = new Enumerator(); + en.readXML(t); + enumerations.put(en.id, en); + } + NodeList attrList = document.getElementsByTagName("attribute"); + for (int i = 0; i < attrList.getLength(); ++i) { + Element t = (Element) attrList.item(i); + Attribute a = new Attribute(); + a.readModelXML(t); + attributes.put(a.name, a); + + if (!a.group.isEmpty()) { + Vector<String> grp = attributeGroups.get(a.group); + if (grp == null) { + grp = new Vector<String>(); + attributeGroups.put(a.group, grp); + } + grp.add(a.name); + } + + if (a.getValue().getType().equals("enumeration")) { + a.getValue().setEnumerator(enumerations.get(a.value.getFields().get(0).name)); + } + } + } + + public void loadTargets(String filename) throws Exception { + ServerWizard2.LOGGER.info("Loading Part: " + filename); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + builder.setErrorHandler(new XmlHandler()); + Document document = builder.parse(filename); + NodeList targetInstanceList = document.getElementsByTagName("targetPart"); + for (int i = 0; i < targetInstanceList.getLength(); ++i) { + Element t = (Element) targetInstanceList.item(i); + String type = SystemModel.getElement(t, "type"); + Target tmodel = targetModels.get(type); + Target target = null; + if (tmodel == null) { + target = new Target(); + } else { + target = new Target(tmodel); + } + target.readTargetXML(t, targetModels, attributes); + addParentAttributes(target, target); + if (target.isRoot()) { + target.clearRoot(); + targetModels.put(target.getType(), target); + targetInstances.put(target.getType(), target); + Vector<String> parentTypes = target.getParentType(); + for (int j = 0; j < parentTypes.size(); j++) { + String parentType = parentTypes.get(j); + + Vector<Target> childTypes = childTargetTypes.get(parentType); + if (childTypes == null) { + childTypes = new Vector<Target>(); + childTargetTypes.put(parentType, childTypes); + } + childTypes.add(target); + } + } else { + if (!targetUnitModels.containsKey(target.getName())) { + this.targetUnitList.add(target); + this.targetUnitModels.put(target.getName(), target); + } + if (!targetModels.containsKey(target.getType())) { + targetModels.put(target.getType(), target); + } + } + } + } + public void loadErrata(String filename) throws Exception { + ServerWizard2.LOGGER.info("Loading Errata: " + filename); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + builder.setErrorHandler(new XmlHandler()); + Document document = builder.parse(filename); + NodeList list = document.getElementsByTagName("errata"); + for (int i = 0; i < list.getLength(); ++i) { + Element t = (Element) list.item(i); + Errata e = new Errata(); + e.read(t, attributes); + errata.put(e.getId(), e); + } + } + + //////////////////////////////////////////////////////////////////////// + // Target manipulation + public Target getTargetInstance(String type) { + return targetInstances.get(type); + } + + public HashMap<String,Target> getUnitTargetModel() { + return this.targetUnitModels; + } + // Add target to target database. + // only contains targets that user has added + // not library targets + private void updateTargetList(Target target) throws Exception { + String id = target.getName(); + if (!this.targetLookup.containsKey(id)) { + this.targetLookup.put(id, target); + this.targetList.add(target); + } else { + String msg="Duplicate Target: "+target.getName(); + ServerWizard2.LOGGER.warning(msg); + throw new Exception(msg); + } + } + + private void addParentAttributes(Target childTarget, Target t) { + if (t == null) { + return; + } + if (t.parent == null || t.parent.isEmpty()) { + return; + } + Target parent = targetModels.get(t.parent); + if (parent == null) { + MessageDialog.openError(null, "Error", "Invalid parent target: "+t.parent ); + } + childTarget.copyAttributesFromParent(parent); + addParentAttributes(childTarget, parent); + } + + public void addUnitInstances() { + for (Target target : this.targetUnitList) { + this.targetLookup.put(target.getName(), target); + } + } + + public void updateTargetPosition(Target target, Target parentTarget, int position) { + if (position > 0) { + target.setPosition(position); + return; + } + if (parentTarget == null) { + target.setName(target.getIdPrefix()); + target.setPosition(-1); + return; + } + int p = -1; + // set target position to +1 of any target found of same type + for (Target t : targetList) { + if (t.getType().equals(target.getType())) { + if (t.getPosition() >= p) { + p = t.getPosition(); + } + } + } + target.setPosition(p + 1); + target.setSpecialAttributes(); + } + public TreeMap<String, Target> getTargetModels() { + return targetModels; + } + + public Target getTargetModel(String t) { + return targetModels.get(t); + } + + public void deleteAllInstances() { + errataUpdated = false; + this.targetList.clear(); + this.targetLookup.clear(); + this.rootTargets.clear(); + this.globalSettings.clear(); + this.errataList.clear(); + } + + public void deleteTarget(Target deleteTarget) { + //if (deleteTarget == null) { + // return; + //} + targetList.remove(deleteTarget); + //Vector<String> children = deleteTarget.getAllChildren(); + //for (String s : children) { + // Target d = targetLookup.get(s); + // deleteTarget(d); + //} + + for (Target t : targetList) { + t.removeChildren(deleteTarget.getName()); + } + this.targetLookup.remove(deleteTarget.getName()); + } + + ///////////////////////////////////////////////////////////////// + // Utility static methods + public static String getElement(Element a, String e) { + Node n = a.getElementsByTagName(e).item(0); + if (n != null) { + Node cn = n.getChildNodes().item(0); + if (cn == null) { + return ""; + } + return cn.getNodeValue(); + } + return ""; + } + + public static Boolean isElementDefined(Element a, String e) { + Node n = a.getElementsByTagName(e).item(0); + if (n != null) { + Node cn = n.getChildNodes().item(0); + if (cn == null) { + return true; + } + return true; + } + return false; + } + + ////////////////////////////////////////////////////////////////////////////// + // Special method to cleanup past bugs + private void targetWalk(Target target, String path, HashMap<String,Target> targets) { + targets.put(path, target); + for (String child : target.getChildren()) { + Target childTarget = getTarget(child); + targetWalk(childTarget, path + "/" + child, targets); + } + } + + private void xmlCleanup() { + String path = "/"+this.getRootTarget().getName(); + HashMap<String,Target> targets = new HashMap<String,Target>(); + targetWalk(this.getRootTarget(),path,targets); + + ServerWizard2.LOGGER.info("Running XML cleanup..."); + + // IO_CONFIG_SELECT bug + TreeMap<String, TreeMap<String,Field>> tmpSettings = new TreeMap<String, TreeMap<String,Field>>(globalSettings); + + for (Map.Entry<String, TreeMap<String,Field>> settings : tmpSettings.entrySet()) { + TreeMap<String,Field> tmpFields = new TreeMap<String,Field>(settings.getValue()); + Target t = targets.get(settings.getKey()); + if (t == null) { + ServerWizard2.LOGGER.warning("Target not found, removing: "+settings.getKey()); + globalSettings.remove(settings.getKey()); + } else { + for (Field f : tmpFields.values()) { + Attribute a = t.getAttributes().get(f.attributeName); + if (a == null) { + ServerWizard2.LOGGER.info("Not an attribute in target, removing: "+f.attributeName); + globalSettings.get(settings.getKey()).remove(f.attributeName); + } else { + if (!a.isGlobal()) { + globalSettings.get(settings.getKey()).remove(f.attributeName); + ServerWizard2.LOGGER.info("Removing global property: "+f.attributeName); + } + } + } + } + TreeMap<String,Field> tmpSettings2 = globalSettings.get(settings.getKey()); + + if (tmpSettings2 != null) { + if (tmpSettings2.isEmpty()) { + ServerWizard2.LOGGER.info("Removing global target: "+settings.getKey()); + globalSettings.remove(settings.getKey()); + } + } + } + // End IO_CONFIG_SELECT bug + } + +} diff --git a/src/com/ibm/ServerWizard2/model/Target.java b/src/com/ibm/ServerWizard2/model/Target.java new file mode 100644 index 0000000..ef452f4 --- /dev/null +++ b/src/com/ibm/ServerWizard2/model/Target.java @@ -0,0 +1,569 @@ +package com.ibm.ServerWizard2.model; + +import java.io.Writer; +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; +import java.util.Vector; + +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import com.ibm.ServerWizard2.ServerWizard2; + +public class Target implements Comparable<Target>, java.io.Serializable { + private static final long serialVersionUID = 1L; + + private String name = ""; + private String type = ""; + private int position = -1; + public String parent = ""; // says which parent to inherit attributes from + + private Vector<String> parentType = new Vector<String>(); + private TreeMap<String, Attribute> attributes = new TreeMap<String, Attribute>(); + private Vector<String> children = new Vector<String>(); + private Vector<String> childrenHidden = new Vector<String>(); + private TreeMap<Target,Vector<Connection>> busses = new TreeMap<Target,Vector<Connection>>(); + private Boolean busInited=false; + private Boolean hidden = false; + private Boolean root = false; + private HashMap<String,Boolean> childrenBusTypes = new HashMap<String,Boolean>(); + + public Target() { + } + + public Target(Target s) { + this.setName(s.name); + this.setType(s.type); + this.parent = s.parent; + this.position = s.position; + this.hidden = s.hidden; + this.root = s.root; + this.parentType.addAll(s.parentType); + + for (Map.Entry<String, Attribute> entry : s.getAttributes().entrySet()) { + String key = new String(entry.getKey()); + Attribute value = new Attribute(entry.getValue()); + this.attributes.put(key, value); + } + } + public TreeMap<Target,Vector<Connection>> getBusses() { + return busses; + } + + public Boolean isHidden() { + return this.hidden; + } + + public String getName() { + if (position==-1 && !name.isEmpty()) { + return name; + } + if (!name.isEmpty()) { + return name + "-" + position; + } + return getIdPrefix() + "-" + position; + } + + public String getRawName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public void setRoot() { this.root = true; } + public void clearRoot() { this.root = false; } + public Boolean isRoot() { + //this is for backwards compatibility + if (this.getAttribute("CLASS").equals("SYS")) { + this.root = true; + } + return this.root; + } + //////////////////////////////////////////// + // Target children handling + public Vector<String> getChildren() { + return this.children; + } + public Vector<String> getHiddenChildren() { + return this.childrenHidden; + } + public Vector<String> getAllChildren() { + Vector<String> all = new Vector<String>(); + all.addAll(this.children); + all.addAll(this.childrenHidden); + return all; + } + public void copyChildren(Target t) { + for (String c : t.children) { + this.children.add(c); + } + for (String c : t.childrenHidden) { + this.childrenHidden.add(c); + } + } + public void removeChildren(String child) { + children.remove(child); + childrenHidden.remove(child); + } + public void addChild(String child,boolean hidden) { + if (hidden) { + childrenHidden.add(child); + } else { + children.add(child); + } + } + + public Boolean isPluggable() { + String c = this.getAttribute("CLASS"); + + if (c == null) { + return false; + } + + if (c.equals("CONNECTOR")) { + return true; + } + return false; + } + + public void setPosition(String pos) { + this.position = Integer.parseInt(pos); + } + + public void setPosition(int pos) { + this.position = pos; + } + + public int getPosition() { + return this.position; + } + + public Vector<String> getParentType() { + return this.parentType; + } + public void addParentType(String parent_type) { + this.parentType.add(parent_type); + } + public void setType(String type) { + this.type = type; + } + + public String getType() { + return this.type; + } + + public String getIdPrefix() { + String s[] = type.split("-"); + if (s.length == 1) { return this.name; } + + if (s[1].equals("processor")) { + s[1] = "proc"; + } + return s[1]; + } + + //////////////////////////////////////////////////////// + // Attribute handling + public TreeMap<String, Attribute> getAttributes() { + return attributes; + } + + public void deepCopyAttributes(HashMap<String,Target> model,HashMap<String,Target> instances) { + ServerWizard2.LOGGER.info("Defaulting attributes for: "+this.getName()); + Target source = model.get(this.getName()); + if (source == null) { + source = instances.get(this.getName()); + } + for (Map.Entry<String, Attribute> entry : source.getAttributes().entrySet()) { + String key = new String(entry.getKey()); + Attribute value = new Attribute(entry.getValue()); + this.attributes.put(key, value); + } + for (String c : this.getAllChildren()) { + Target child = instances.get(c); + child.deepCopyAttributes(model, instances); + } + } + + public boolean attributeExists(String attribute) { + if (attributes.get(attribute) == null) { + return false; + } + return true; + } + public String getAttribute(String attribute) { + if (attributes.get(attribute) == null) { + return ""; + } + return attributes.get(attribute).getValue().getValue(); + } + + void copyAttributesFromParent(Target s) { + for (Map.Entry<String, Attribute> entry : s.getAttributes().entrySet()) { + String key = entry.getKey(); + Attribute tmpAttribute = entry.getValue(); + Attribute localAttribute = this.attributes.get(key); + // inherited attribute was already added when instance created + if (localAttribute != null) { + localAttribute.inherited = s.type; + } + else { + Attribute attribute = new Attribute(tmpAttribute); + attribute.inherited = s.type; + this.attributes.put(key, attribute); + } + } + } + + public Boolean isInput() { + String dir = this.getAttribute("DIRECTION"); + if (dir.equals("IN") || dir.equals("INOUT")) { + return true; + } + return false; + } + public Boolean isOutput() { + String dir = this.getAttribute("DIRECTION"); + if (dir.equals("OUT") || dir.equals("INOUT")) { + return true; + } + return false; + } + + public Boolean isSystem() { + return (this.getAttribute("CLASS").equals("SYS")); + } + Boolean isCard() { + return (this.getAttribute("CLASS").equals("CARD") || this.getAttribute("CLASS").equals( + "MOTHERBOARD")); + } + public Boolean isConnector() { + return (this.getAttribute("CLASS").equals("CONNECTOR")); + } + public Boolean isNode() { + return (this.getAttribute("CLASS").equals("ENC")); + } + Boolean isUnit() { + return (this.getAttribute("CLASS").equals("UNIT") && !this.type.equals("unit") && type.startsWith("unit-")); + } + Boolean isOverrideGroup() { + return (this.getAttribute("MRW_TYPE").equals("TARGET_OVERRIDE_GROUP")); + } + Boolean isOverride() { + return (this.getAttribute("MRW_TYPE").equals("TARGET_OVERRIDE")); + } + + + private void setAttributeValue(String attr, String value) { + Attribute attribute = this.attributes.get(attr); + if (attribute == null) { + return; + } + attribute.getValue().setValue(value); + } + + public void setSpecialAttributes() { + this.setAttributeValue("POSITION", String.valueOf(this.getPosition())); + + } + public int compareTo(Target arg0) { + Target t = (Target)arg0; + return this.getType().compareTo(t.getType()); + } + + /////////////////////////////////////////////////// + // connection/bus handling + public Boolean isBusHidden(String busType) { + return !this.childrenBusTypes.containsKey(busType); + } + public HashMap<String,Boolean> hideBusses(HashMap<String,Target> targetLookup) { + HashMap<String,Boolean> childBusTypes; + childrenBusTypes.clear(); + String thisBusType = this.getAttribute("BUS_TYPE"); + if (!thisBusType.isEmpty() &&!thisBusType.equals("NA")) { + this.childrenBusTypes.put(thisBusType,true); + } + for (String childStr : this.getChildren()) { + Target child = targetLookup.get(childStr); + if (child==null) { + ServerWizard2.LOGGER.severe("Child Target "+childStr+" not found"); + } + String busType = child.getAttribute("BUS_TYPE"); + if (!busType.isEmpty() && !busType.equals("NA")) { + this.childrenBusTypes.put(busType, true); + } + childBusTypes = child.hideBusses(targetLookup); + for (String bus : childBusTypes.keySet()) { + this.childrenBusTypes.put(bus, true); + } + } + return this.childrenBusTypes; + } + public Connection addConnection(Target busTarget,ConnectionEndpoint source,ConnectionEndpoint dest, boolean cabled) { + if (busTarget==null || source==null || dest==null) { + //TODO: error message + return null; + } + Vector<Connection> c = busses.get(busTarget); + if (c==null) { + c = new Vector<Connection>(); + busses.put(busTarget, c); + } + Connection conn = new Connection(); + conn.busType = busTarget.getType(); + conn.source=source; + conn.dest=dest; + conn.cabled = cabled; + conn.busTarget = new Target(busTarget); + c.add(conn); + return conn; + } + public void deleteConnection(Target busTarget,Connection conn) { + Vector<Connection> connList = busses.get(busTarget); + connList.remove(conn); + } + public void initBusses(Vector<Target> v) { + if (busInited) { return; } + this.busInited=true; + + for (Target s : v) { + Vector<Connection> connections = new Vector<Connection>(); + this.busses.put(s, connections); + } + } + + //////////////////////////////////////////////////// + // XML file handling + public void readModelXML(Element target, HashMap<String, Attribute> attrMap) { + type = SystemModel.getElement(target, "id"); + parent = SystemModel.getElement(target, "parent"); + NodeList parentList = target.getElementsByTagName("parent_type"); + for (int i = 0; i < parentList.getLength(); i++) { + Element e = (Element) parentList.item(i); + parentType.add(e.getChildNodes().item(0).getNodeValue()); + } + NodeList attributeList = target.getElementsByTagName("attribute"); + for (int i = 0; i < attributeList.getLength(); ++i) { + String attrId = SystemModel.getElement((Element) attributeList.item(i), "id"); + Attribute attributeLookup = attrMap.get(attrId); + if (attributeLookup == null) { + throw new NullPointerException("Invalid attribute id: " + attrId + "(" + type + ")"); + } + Attribute a = new Attribute(attributeLookup); + if (a.value==null) { + throw new NullPointerException("Unknown attribute value type: " + attrId + "(" + type + ")"); + } + attributes.put(a.name, a); + a.value.readInstanceXML((Element) attributeList.item(i)); + } + } + + public void readInstanceXML(Element t, TreeMap<String, Target> targetModels) throws Exception { + name = SystemModel.getElement(t, "instance_name"); + type = SystemModel.getElement(t, "type"); + String rootStr = SystemModel.getElement(t, "is_root"); + if (rootStr.equals("true")) { this.root = true; } + + if (name.isEmpty()) { + name = SystemModel.getElement(t, "id"); + } else { + String tmpPos = SystemModel.getElement(t, "position"); + if (!tmpPos.isEmpty()) { + setPosition(tmpPos); + } + } + + NodeList childList = t.getElementsByTagName("child_id"); + for (int j = 0; j < childList.getLength(); ++j) { + Element attr = (Element) childList.item(j); + children.add(attr.getFirstChild().getNodeValue()); + } + childList = t.getElementsByTagName("hidden_child_id"); + for (int j = 0; j < childList.getLength(); ++j) { + Element attr = (Element) childList.item(j); + childrenHidden.add(attr.getFirstChild().getNodeValue()); + } + + NodeList attrList = t.getElementsByTagName("attribute"); + for (int j = 0; j < attrList.getLength(); ++j) { + Element attr = (Element) attrList.item(j); + String id = SystemModel.getElement(attr, "id"); + Attribute a = attributes.get(id); + if (a==null) { + ServerWizard2.LOGGER.info("Attribute dropped: "+id+" from "+this.getName()); + } else { + a.value.readInstanceXML(attr); + } + } + NodeList busList = t.getElementsByTagName("bus"); + for (int j = 0; j < busList.getLength(); ++j) { + Element bus = (Element) busList.item(j); + String busType = SystemModel.getElement(bus, "bus_type"); + Connection conn = new Connection(); + conn.busType=busType; + Target busTarget=targetModels.get(busType); + if (busTarget==null) { + throw new Exception("Invalid Bus Type "+busType+" for target "+this.getName()); + } + conn.busTarget = new Target(busTarget); + conn.readInstanceXML(bus); + busses.get(busTarget).add(conn); + } + } + + public void writeInstanceXML(Writer out,HashMap<String,Target> targetLookup,HashMap<String,Boolean>targetWritten) throws Exception { + if (targetWritten.containsKey(this.getName())) { + return; + } + targetWritten.put(this.getName(), true); + out.write("<targetInstance>\n"); + out.write("\t<id>" + this.getName() + "</id>\n"); + out.write("\t<type>" + this.getType() + "</type>\n"); + String rootStr = "false"; + if (this.isRoot()) { rootStr = "true"; } + out.write("\t<is_root>" + rootStr + "</is_root>\n"); + if (!this.name.isEmpty()) { + out.write("\t<instance_name>" + this.name + "</instance_name>\n"); + } else { + out.write("\t<instance_name>" + this.getIdPrefix() + "</instance_name>\n"); + } + + out.write("\t<position>" + getPosition() + "</position>\n"); + //write children + for (String childStr : this.children) { + out.write("\t<child_id>"+childStr+"</child_id>\n"); + } + for (String childStr : this.childrenHidden) { + out.write("\t<hidden_child_id>"+childStr+"</hidden_child_id>\n"); + } + //write attributes + for (Map.Entry<String, Attribute> entry : getAttributes().entrySet()) { + Attribute attr = new Attribute(entry.getValue()); + attr.writeInstanceXML(out); + + } + //write busses + for (Map.Entry<Target, Vector<Connection>> entry : busses.entrySet()) { + for (Connection conn : entry.getValue()) { + conn.writeInstanceXML(out); + } + } + out.write("</targetInstance>\n"); + + //recursively write children + for (String childStr : this.getAllChildren()) { + Target child = targetLookup.get(childStr); + child.writeInstanceXML(out, targetLookup, targetWritten); + } + } + + // New format + public void readTargetXML(Element t, TreeMap<String, Target> targetModels, HashMap<String, Attribute> attributeModels) throws Exception { + name = SystemModel.getElement(t, "instance_name"); + type = SystemModel.getElement(t, "type"); + String rootStr = SystemModel.getElement(t, "is_root"); + if (rootStr.equals("true")) { this.root = true; } + + String tmpPos = SystemModel.getElement(t, "position"); + if (!tmpPos.isEmpty()) { + setPosition(tmpPos); + } + parent = SystemModel.getElement(t, "parent"); + parentType.removeAllElements(); + NodeList parentList = t.getElementsByTagName("parent_type"); + for (int i = 0; i < parentList.getLength(); i++) { + Element e = (Element) parentList.item(i); + parentType.add(e.getChildNodes().item(0).getNodeValue()); + } + + NodeList childList = t.getElementsByTagName("child_id"); + for (int j = 0; j < childList.getLength(); ++j) { + Element attr = (Element) childList.item(j); + children.add(attr.getFirstChild().getNodeValue()); + } + childList = t.getElementsByTagName("hidden_child_id"); + for (int j = 0; j < childList.getLength(); ++j) { + Element attr = (Element) childList.item(j); + childrenHidden.add(attr.getFirstChild().getNodeValue()); + } + + NodeList attrList = t.getElementsByTagName("attribute"); + for (int j = 0; j < attrList.getLength(); ++j) { + Element attr = (Element) attrList.item(j); + String id = SystemModel.getElement(attr, "id"); + Attribute a = attributeModels.get(id); + if (a==null) { + ServerWizard2.LOGGER.info("Attribute dropped: "+id+" from "+this.getName()); + } else { + Attribute newA = new Attribute(a); + attributes.put(newA.name, newA); + newA.value.readInstanceXML(attr); + } + } + NodeList busList = t.getElementsByTagName("bus"); + for (int j = 0; j < busList.getLength(); ++j) { + Element bus = (Element) busList.item(j); + String busType = SystemModel.getElement(bus, "bus_type"); + Connection conn = new Connection(); + conn.busType=busType; + Target busTarget=targetModels.get(busType); + if (busTarget==null) { + throw new Exception("Invalid Bus Type "+busType+" for target "+this.getName()); + } + conn.busTarget = new Target(busTarget); + conn.readInstanceXML(bus); + busses.get(busTarget).add(conn); + } + } + public void writeTargetXML(Writer out,HashMap<String,Target> targetLookup, HashMap<String,Boolean>targetWritten) throws Exception { + if (targetWritten.containsKey(this.getName())) { + return; + } + targetWritten.put(this.getName(), true); + out.write("<targetPart>\n"); + out.write("\t<id>" + this.getName() + "</id>\n"); + out.write("\t<type>" + this.getType() + "</type>\n"); + String rootStr = "false"; + if (this.isRoot()) { rootStr = "true"; } + out.write("\t<is_root>" + rootStr + "</is_root>\n"); + if (!this.name.isEmpty()) { + out.write("\t<instance_name>" + this.name + "</instance_name>\n"); + } else { + out.write("\t<instance_name>" + this.getIdPrefix() + "</instance_name>\n"); + } + + out.write("\t<position>" + getPosition() + "</position>\n"); + out.write("\t<parent>" + this.parent + "</parent>\n"); + for (String p_type : this.parentType) { + out.write("\t<parent_type>" + p_type + "</parent_type>\n"); + } + + //write children + for (String childStr : this.children) { + out.write("\t<child_id>"+childStr+"</child_id>\n"); + } + for (String childStr : this.childrenHidden) { + out.write("\t<hidden_child_id>"+childStr+"</hidden_child_id>\n"); + } + //write attributes + for (Map.Entry<String, Attribute> entry : getAttributes().entrySet()) { + Attribute attr = new Attribute(entry.getValue()); + attr.writeInstanceXML(out); + + } + //write busses + for (Map.Entry<Target, Vector<Connection>> entry : busses.entrySet()) { + for (Connection conn : entry.getValue()) { + conn.writeInstanceXML(out); + } + } + out.write("</targetPart>\n"); + + //recursively write children + for (String childStr : this.getAllChildren()) { + Target child = targetLookup.get(childStr); + child.writeTargetXML(out, targetLookup, targetWritten); + } + } +} diff --git a/src/com/ibm/ServerWizard2/model/XmlHandler.java b/src/com/ibm/ServerWizard2/model/XmlHandler.java new file mode 100644 index 0000000..0849ef5 --- /dev/null +++ b/src/com/ibm/ServerWizard2/model/XmlHandler.java @@ -0,0 +1,35 @@ +package com.ibm.ServerWizard2.model; + +import java.util.ArrayList; + +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.helpers.DefaultHandler; + +public class XmlHandler extends DefaultHandler { + + + private ArrayList<String> warnings = new ArrayList<String>(); + + private String detailedErrorString = ""; + + public void error(SAXParseException exception) throws SAXException { + detailedErrorString += "Line:" + exception.getLineNumber() + " , Col:" + exception.getColumnNumber() + ", Error:" + exception.getMessage() + "\n"; + } + + public void fatalError(SAXParseException exception) throws SAXException { + detailedErrorString += "Line:" + exception.getLineNumber() + " , Col:" + exception.getColumnNumber() + ", Error:" + exception.getMessage() + "\n"; + } + + public void warning(SAXParseException exception) throws SAXException { + warnings.add(exception.getMessage()); + } + + public String getDetailedErrorString(){ + return detailedErrorString; + } + + public ArrayList<String> getWarnings(){ + return warnings; + } +}
\ No newline at end of file |

