public XMLElement saveSelf () throws XMLCannotSaveException { XMLElement result=super.saveSelf(); result.setName(shortXMLName); result.addAttribute(new XMLAttribute ("random-chance",random_chance)); result.addAttribute(new XMLAttribute ("gamma",gamma)); return result; }
private static String writeOscarsXML(Connection db) throws Exception { /*Create and open new oscars.xml file*/ PrintStream oscarFile = new PrintStream("oscars.XML"); oscarFile.println("<?xml version=\"1.0\"?>"); oscarFile.println("<oscars>"); /* Get oscars */ Statement stmt = db.createStatement(); ResultSet results = stmt.executeQuery("SELECT * FROM Oscar;"); ResultSetMetaData rsmd = results.getMetaData(); /* Create oscar XMLElements */ while (results.next()) { XMLElement oscar = new XMLElement("oscar", null, false, 1); String oscarID; if (results.getString(2) == null) { oscarID = "O" + results.getString(4) + "0000000"; } else { oscarID = "O" + results.getString(4) + results.getString(2); } oscar.addAttribute("id", oscarID); ArrayList<XMLElement> children = new ArrayList<XMLElement>(); /* Create children elements if needed */ for (int i = 3; i < 5; i++) { if (results.getString(i) != null) { XMLElement child = new XMLElement(rsmd.getColumnLabel(i), results.getString(i), false, 2); children.add(child); } } /*Add movie Attribute*/ oscar.addAttribute("movie_id", "M" + results.getString(1)); /*Add actor Attribute */ if (results.getString(2) != null) { oscar.addAttribute("person_id", "P" + results.getString(2)); } /*write oscar element and it's children to the file*/ oscarFile.println(oscar.getOpenTag()); for (XMLElement child : children) { oscarFile.println(child.inlineElement()); } oscarFile.println(oscar.getCloseTag()); } oscarFile.println("</oscars>"); oscarFile.close(); return "oscar.xml has been written"; }
/** * Helper class to write an person attribute if needed * * @param name name of the attribute * @param element element that the attribute will be added to * @param rs ResultSet than includes the values of the attribute * @throws SQLException * @throws Exception */ private static void writeMovieAtt(String name, XMLElement element, ResultSet rs) throws SQLException, Exception { if (rs.next()) { element.addAttribute(name, "M" + rs.getString(1)); while (rs.next()) { element.appendAttribute(name, "M" + rs.getString(1)); } } }
public XMLElement saveSelf () throws XMLCannotSaveException { XMLElement result=new XMLElement("pktlval"); result.addAttribute(new XMLAttribute("tl-id",tl.getId())); result.addAttribute(new XMLAttribute("pos",pos)); result.addAttribute(new XMLAttribute("destination",destination.getId())); result.addAttribute(new XMLAttribute("light",light)); result.addAttribute(new XMLAttribute("newtl-id",tl_new.getId())); result.addAttribute(new XMLAttribute("new-pos",pos_new)); result.addAttribute(new XMLAttribute("value",value)); result.addAttribute(new XMLAttribute("ktl",Ktl)); return result; }
public XMLElement saveSelf () throws XMLCannotSaveException { XMLElement result=new XMLElement("count"); result.addAttribute(new XMLAttribute("tl-id",tl.getId())); result.addAttribute(new XMLAttribute("pos",pos)); result.addAttribute(new XMLAttribute("destination",destination.getId())); result.addAttribute(new XMLAttribute("light",light)); result.addAttribute(new XMLAttribute("newtl-id",tl_new.getId())); result.addAttribute(new XMLAttribute("new-pos",pos_new)); result.addAttribute(new XMLAttribute("ktl",Ktl)); result.addAttribute(new XMLAttribute("value",value)); if ( ! infrastructure.laneDictionary.containsKey (new Integer (tl.getId()))) { System.out.println ("WARNING : Unknown Trafficlight ID "+tl.getId()+ " in TC3$CountEntry. Loading will go wrong"); } return result; }
/** * Start an element. * * @param namespaceURI : element namespace. * @param localName : local element. * @param qName : qualified name. * @param atts : attribute * @throws org.xml.sax.SAXException : occurs if the element cannot be parsed correctly. * @see org.xml.sax.ContentHandler#startElement(String, String, String, org.xml.sax.Attributes) */ public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { String namespace = namespaceURI; if (namespaceURI != null && (namespaceURI.equalsIgnoreCase(CorePluginFactory.NAMESPACE))) { namespace = null; // Remove the 'org.apache.felix.ipojo' namespace } // System.out.println("XML.e/// " + namespace + ":" + localName); XMLElement elem = new XMLElement(localName, namespace); for (int i = 0; i < atts.getLength(); i++) { String name = (String) atts.getLocalName(i); String ns = (String) atts.getURI(i); String value = (String) atts.getValue(i); // System.out.println("XML.a/// " + ns + ":" + name + "=" + value); XMLAttribute att = new XMLAttribute(name, ns, value); elem.addAttribute(att); } addElement(elem); // System.out.println("XML/// good"); }
/** * Helper class to write an Oscar attribute if needed * * @param name Name of the attribute * @param element the element that the attribute will be added to * @param rs the result set that includes the values of the attributes * @throws SQLException * @throws Exception */ private static void writeOscarAtt(String name, XMLElement element, ResultSet rs) throws SQLException, Exception { String oscAtt = ""; if (rs.next()) { if (rs.getString(2) == null) { oscAtt = "O" + rs.getString(1) + "0000000"; } else { oscAtt = "O" + rs.getString(1) + rs.getString(2); } element.addAttribute(name, oscAtt); while (rs.next()) { if (rs.getString(2) == null) { oscAtt = "O" + rs.getString(1) + "0000000"; } else { oscAtt = "O" + rs.getString(1) + rs.getString(2); } element.appendAttribute(name, oscAtt); } } }
public XMLElement saveSelf () throws XMLCannotSaveException { XMLElement result=new XMLElement("target"); result.addAttribute(new XMLAttribute("tl-id",tl.getId())); result.addAttribute(new XMLAttribute("pos",pos)); return result; }
public XMLElement saveSelf() throws XMLCannotSaveException { XMLElement result = new XMLElement("destfreq"); result.addAttribute(new XMLAttribute("ru-type", ruType)); result.addAttribute(new XMLAttribute("freq", freq)); return result; }
/** * Private class that opens the xmL file, performs the queries, create the elements and write them * to the movies.xml file * * @param db The database that is being queried * @return a success message * @throws Exception */ private static String writeMovieXML(Connection db) throws Exception { /*Create and open new movie.xml file*/ PrintStream movieFile = new PrintStream("movies.XML"); movieFile.println("<?xml version=\"1.0\"?>"); movieFile.println("<movies>"); /* Get movies */ Statement stmt = db.createStatement(); ResultSet results = stmt.executeQuery("SELECT * FROM Movie;"); ResultSetMetaData rsmd = results.getMetaData(); /* Create movie XMLElements */ while (results.next()) { XMLElement movie = new XMLElement("movie", null, false, 1); movie.addAttribute("id", "M" + results.getString(1)); ArrayList<XMLElement> children = new ArrayList<XMLElement>(); /* Create children elements if needed */ for (int i = 2; i < 8; i++) { if (results.getString(i) != null) { XMLElement child = new XMLElement(rsmd.getColumnLabel(i), results.getString(i), false, 2); children.add(child); } } /*Add Directors Attribute*/ Statement dir = db.createStatement(); ResultSet directors = dir.executeQuery( "SELECT director_id FROM Director " + "WHERE movie_id = \"" + results.getString(1) + "\""); writePersonAtt("director", movie, directors); /*Add Actors Attribute */ Statement act = db.createStatement(); ResultSet actors = act.executeQuery( "SELECT actor_id FROM Actor " + "WHERE movie_id = \"" + results.getString(1) + "\""); writePersonAtt("actors", movie, actors); /*Add Oscars Attribute */ Statement osc = db.createStatement(); ResultSet oscars = osc.executeQuery( "SELECT year, person_id FROM Oscar" + " WHERE movie_id = \"" + results.getString(1) + "\""); writeOscarAtt("oscars", movie, oscars); /*write movie and it's children to the file*/ movieFile.println(movie.getOpenTag()); for (XMLElement child : children) { movieFile.println(child.inlineElement()); } movieFile.println(movie.getCloseTag()); } movieFile.println("</movies>"); movieFile.close(); return "movies.xml has been written."; }
private static String writePeopleXML(Connection db) throws Exception { /*Create and open new xml file*/ PrintStream peopleFile = new PrintStream("people.XML"); peopleFile.println("<?xml version=\"1.0\"?>"); peopleFile.println("<people>"); /* Get People results */ Statement stmt = db.createStatement(); ResultSet results = stmt.executeQuery("SELECT * FROM Person;"); ResultSetMetaData rsmd = results.getMetaData(); /* Create person XMLElements */ while (results.next()) { XMLElement person = new XMLElement("person", null, false, 1); person.addAttribute("id", "P" + results.getString(1)); ArrayList<XMLElement> children = new ArrayList<XMLElement>(); /* Create children elements if needed */ for (int i = 2; i < 5; i++) { if (results.getString(i) != null) { XMLElement child = new XMLElement(rsmd.getColumnLabel(i), results.getString(i), false, 2); children.add(child); } } /*Add directed Attribute*/ Statement dir = db.createStatement(); ResultSet directed = dir.executeQuery( "SELECT movie_id FROM Director " + "WHERE director_id = \"" + results.getString(1) + "\""); writeMovieAtt("directed", person, directed); /*Add actedIn Attribute */ Statement mov = db.createStatement(); ResultSet movie = mov.executeQuery( "SELECT movie_id FROM Actor " + "WHERE actor_id = \"" + results.getString(1) + "\""); writeMovieAtt("actedIn", person, movie); /*Add Oscars Attribute */ Statement osc = db.createStatement(); ResultSet oscars = osc.executeQuery( "SELECT year, person_id FROM Oscar" + " WHERE person_id = \"" + results.getString(1) + "\""); writeOscarAtt("oscars", person, oscars); /*write people element and it's children to the file*/ peopleFile.println(person.getOpenTag()); for (XMLElement child : children) { peopleFile.println(child.inlineElement()); } peopleFile.println(person.getCloseTag()); } peopleFile.println("</people>"); peopleFile.close(); return "people.xml has been written"; }
public XMLElement saveSelf() throws XMLCannotSaveException { XMLElement result = super.saveSelf(); result.setName("node-junction"); result.addAttribute(new XMLAttribute("width", width)); return result; }