private StructureType assignStructureType(Element structure) throws VisualizerLoadException { String name = structure.getName().toLowerCase(); if (name.compareTo("graph") == 0) { if (structure.getAttributeValue("weighted").compareTo("true") == 0) return new Graph_Network("NETWORK"); else return new Graph_Network("GRAPH"); } else if (name.equals("array")) return new MD_Array(); else if (name.equals("no3darray")) return new No3darray(); else if (name.equals("linkedlist")) return new VisLinkedList(); else if (name.equals("no3dlinkedlist")) return new No3dLinkedList(); else if (name.equals("linkedlistnonull")) return new VisLinkedListNoNull(); else if (name.equals("bargraph")) return new BarScat("BAR"); else if (name.equals("scattergraph")) return new BarScat( "SCAT"); // not implemented in xml dtd, and does not have a load-from-xml method defined else if (name.equals("stack")) return new Stack(); else if (name.equals("queue")) return new Queue(); else if (name.equals("tree")) { if (structure.getChild("binary_node") != null) return new BinaryTree(); else return new GeneralTree(); } else if (name.equals("text")) return new TextStructure(); // if the XML element name is different from your structure's name, you can do something like // this: // else if( name.equalsIgnoreCase("node")) // return new Node(); else if (name.equals("legend")) return new LegendofColors(); else { // try dynamic typing try { return assignStructureType(name); } catch (Exception e) { throw new VisualizerLoadException( "Unable to instantiate class \"" + name + "\":\n" + e.getMessage()); } } }
private /*synchronized*/ void readQuestions(StringTokenizer st) throws VisualizerLoadException { String tmpStr = "STARTQUESTIONS\n"; // When CG's QuestionFactory parses from a string, it looks for // a line with STARTQUESTIONS -- hence we add it artificially here try { // Build the string for the QuestionFactory while (st.hasMoreTokens()) { tmpStr += st.nextToken() + "\n"; } } catch (Exception e) { e.printStackTrace(); throw new VisualizerLoadException("Ooof! bad question format"); } try { // System.out.println(tmpStr); // Problem -- must make this be line oriented GaigsAV.questionCollection = QuestionFactory.parseScript(tmpStr); } catch (QuestionParseException e) { e.printStackTrace(); System.out.println("Error parsing questions."); throw new VisualizerLoadException("Ooof! bad question format"); // throw new IOException(); } } // readQuestions(st)