diff options
Diffstat (limited to 'src/com/ibm/ServerWizard2/model/SystemModel.java')
-rw-r--r-- | src/com/ibm/ServerWizard2/model/SystemModel.java | 132 |
1 files changed, 123 insertions, 9 deletions
diff --git a/src/com/ibm/ServerWizard2/model/SystemModel.java b/src/com/ibm/ServerWizard2/model/SystemModel.java index 64c349a..183f8bf 100644 --- a/src/com/ibm/ServerWizard2/model/SystemModel.java +++ b/src/com/ibm/ServerWizard2/model/SystemModel.java @@ -1,7 +1,9 @@ package com.ibm.ServerWizard2.model; +import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; +import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.Writer; @@ -29,7 +31,6 @@ 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; @@ -58,11 +59,12 @@ public class SystemModel { private TreeMap<String, TreeMap<String, Field>> globalSettings = new TreeMap<String, TreeMap<String, Field>>(); + private HashMap<String,Boolean> loadedLibraries = new HashMap<String,Boolean>(); + public Boolean partsMode = false; public Boolean cleanupMode = false; public Boolean errataUpdated = false; - public Vector<Target> getBusTypes() { return busTypes; } @@ -200,6 +202,11 @@ public class SystemModel { return null; } public void loadLibrary(String path) throws Exception { + if (this.loadedLibraries.containsKey(path)) { + ServerWizard2.LOGGER.info("Library already loaded: "+path); + return; + } + this.loadedLibraries.put(path, true); File xmlDir = new File(path); //Loads files in alphabetical order String[] filesStr = xmlDir.list(); @@ -252,12 +259,22 @@ public class SystemModel { 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); + ServerWizard2.LOGGER.warning(msg); + //MessageDialog.openError(null, "XML Load Error", msg); + ServerWizard2.LOGGER.warning("Attempting to convert..."); + String newName = this.xmlUpdate(filename); + if (newName.isEmpty()) { + ServerWizard2.LOGGER.info("Error converting file"); + MessageDialog.openError(null, "XML Load Error", "Old XML format found. Error converting file to new format"); + } else { + ServerWizard2.LOGGER.info("Converted file: "+newName); + MessageDialog.openInformation(null, "XML Converted", "Old XML format found. Converted file to:\n"+newName+"\nPlease open new file."); + } + return; } partsMode = false; String targetTag = "targetInstance"; - if (part != null) { + if (part != null) { partsMode = true; targetTag = "targetPart"; ServerWizard2.LOGGER.info("Setting Parts mode"); @@ -344,6 +361,9 @@ public class SystemModel { checkErrata(); } + /* + * Compare attributes in errata*.xml against currently loaded XML + */ public void checkErrata() { Vector<Errata> errataNew = new Vector<Errata>(); @@ -396,8 +416,9 @@ public class SystemModel { } } - /////////////////////////////////////////////// - // global settings + /* + * Global settings get/sets + */ public Field setGlobalSetting(String path, String attribute, String value) { TreeMap<String, Field> s = globalSettings.get(path); @@ -471,6 +492,9 @@ public class SystemModel { this.setGlobalSetting(targetId, property, value); } } + /* + * Read errata file + */ private void readErrata(Element setting) { String errata_id = SystemModel.getElement(setting, "id"); if (this.errata.containsKey(errata_id)) { @@ -479,8 +503,40 @@ public class SystemModel { } } - ///////////////////////////////////////////////// - // Writes MRW to file + /* + * Returns a vector of attributes located in the target and global settings + * associated with a particular target instance + */ + public Vector<Field> getAttributesAndGlobals(Target targetInstance, String path, Boolean showGlobalSettings) { + Vector<Field> attributes = new Vector<Field>(); + for (Map.Entry<String, Attribute> entry : targetInstance.getAttributes().entrySet()) { + Attribute attribute = entry.getValue(); + if (!attribute.isHidden()) { + if (attribute.isGlobal() && showGlobalSettings) { + if (!path.isEmpty()) { + Field field = getGlobalSetting(path, attribute.name); + if (field==null) { + setGlobalSetting(path, attribute.name, ""); + field = getGlobalSetting(path, attribute.name); + } + field.type = attribute.getValue().getType(); + if (field.type.equals("enumeration")) { + field.enumerator = attribute.getValue().getFields().get(0).enumerator; + } + attributes.add(field); + } + } else { + for (Field field : attribute.getValue().getFields()) + attributes.add(field); + } + } + } + return attributes; + } + + /* + * Write XML to a file + */ public void writeXML(String filename, Boolean partsMode) throws Exception { Writer out = new BufferedWriter(new FileWriter(filename)); String topTag = "systemInstance"; @@ -508,6 +564,9 @@ public class SystemModel { out.close(); } + /* + * Add a target instance to the model + */ public void addTarget(Target parentTarget, Target newTarget,Boolean pathMode) throws Exception { if (parentTarget == null) { this.rootTargets.add(newTarget); @@ -794,6 +853,61 @@ public class SystemModel { } } + private String xmlUpdate(String filename) { + + BufferedReader br; + BufferedWriter wr; + boolean found_settings = false; + boolean found_targets = false; + boolean found_start = false; + String newFilename = filename+".new.xml"; + + try { + br = new BufferedReader(new FileReader(filename)); + wr = new BufferedWriter(new FileWriter(newFilename)); + String line; + try { + wr.write("<systemInstance>\n"); + wr.write("<version>2.1</version>\n"); + wr.write("<enumerationTypes>\n"); + + while ((line = br.readLine()) != null) { + if (line.equals("<enumerationType>") && !found_start) { + found_start = true; + } + if (line.equals("<globalSetting>") && !found_settings) { + wr.write("</enumerationTypes>"); + wr.write("<globalSettings>\n"); + found_settings = true; + } + if (line.equals("<targetInstance>") && !found_targets) { + wr.write("</globalSettings>\n"); + wr.write("<targetInstances>\n"); + found_targets = true; + } + if (line.equals("</targetInstances>")) { + found_start = false; + } + if (found_start) { + wr.write(line+"\n"); + } + } + wr.write("</targetInstances>\n"); + wr.write("</systemInstance>\n"); + } catch (IOException e) { + e.printStackTrace(); + newFilename = ""; + } finally { + br.close(); + wr.close(); + } + } catch (Exception e) { + e.printStackTrace(); + newFilename = ""; + } + return newFilename; + } + private void xmlCleanup() { String path = "/"+this.getRootTarget().getName(); HashMap<String,Target> targets = new HashMap<String,Target>(); |