package sdl; // DOM import org.jdom.*; import org.jdom.output.*; import com.softwareag.tamino.db.api.accessor.*; import com.softwareag.tamino.db.api.response.*; import com.softwareag.tamino.db.api.objectModel.*; import com.softwareag.tamino.db.api.common.*; import com.softwareag.tamino.db.api.connection.*; import com.softwareag.tamino.db.api.objectModel.jdom.*; /** * This class demonstrates the creation of a new JDOM Document from scratch */ public class CreateNew { /** * Main method. * @param args command-line arguments */ public CreateNew(String databaseURI, String collection) throws TConnectionException { // Obtain the connection factory TConnectionFactory connectionFactory = TConnectionFactory.getInstance(); // Obtain the connection to the database connection = connectionFactory.newConnection(databaseURI); // Obtain the concrete TXMLObjectAccessor using the JDOM object model accessor = connection.newXMLObjectAccessor(TAccessLocation.newInstance( collection), TJDOMObjectModel.getInstance()); } public static void main(String[] args) { try { // System.out.println("XML Document examples"); // Build and print a TXMLDocument via a JDOM Document Element root = new Element("Submission"); Element submissionID = new Element("SubmissionID"); root.addContent(submissionID); Element identifier = new Element("Identifier"); Element reportType = new Element("ReportType"); reportType.setText("WSP"); Element date = new Element("Date"); identifier.addContent(reportType); identifier.addContent(date); root.addContent(identifier); Element draft = new Element("DraftYN"); root.addContent(draft); Element period = new Element("Period"); Element from = new Element("From"); Element to = new Element("To"); to.setText("2003-10-10"); period.addContent(from); period.addContent(to); root.addContent(period); //Organisation Organisation orga = new Organisation(DATABASE_URI, COLLECTION); Element organisation = orga.show(); Element numOfEmp = new Element("NoOfEmployees"); Element annualPayroll = new Element("AnnualPayroll"); organisation.addContent(numOfEmp); organisation.addContent(annualPayroll); organisation = organisation.detach(); root.addContent(organisation); //SDF SDF s = new SDF(DATABASE_URI, COLLECTION); Element sd = s.showSDF("1"); sd = (Element) sd.detach(); root.addContent(sd); //ActivitySummary ActivitySummary activity = new ActivitySummary("http://localhost/tamino/X-App", COLLECTION); Element as = activity.show(); //XMLOutputter outputter = new XMLOutputter(); //outputter.output(actS, System.out); as.detach(); root.addContent(as); //SkillsPriority SkillsPriority sp = new SkillsPriority(DATABASE_URI, COLLECTION); Element skill = sp.show("WSP", "March2005"); skill = (Element) skill.detach(); root.addContent(skill); //SectionQuestion SectionQuestion sq = new SectionQuestion(DATABASE_URI, COLLECTION); Element secQ = sq.show("WSP", "March2004"); secQ = (Element) secQ.detach(); root.addContent(secQ); //QualitativeMatrix QualitativeMatrix qm = new QualitativeMatrix(DATABASE_URI, COLLECTION); Element qualit = qm.show("WSP", "March2004", "New Vacancy"); qualit = (Element) qualit.detach(); root.addContent(qualit); //PlannedMovements PlannedMovement pm = new PlannedMovement(DATABASE_URI, COLLECTION); Element planM = pm.show("WSP", "March2004"); if (planM == null) { System.out.println(""); } else { planM = (Element) planM.detach(); root.addContent(planM); } //Signatories Signatories sign = new Signatories(DATABASE_URI, COLLECTION); Element signat = sign.show("WSP", "March2007"); signat = (Element) signat.detach(); root.addContent(signat); XMLOutputter outputter = new XMLOutputter(); outputter.output(root, System.out); //Insert new document into Tamino TXMLObject submission = TXMLObject.newInstance(root); TResponse response = accessor.insert(submission); System.out.println("Response to insert: " + response.getReturnValue()); }catch (Exception e) { System.out.println("Exception: " + e); e.printStackTrace(); } } private final static String DATABASE_URI = "http://10.1.61.10/tamino/SkillsLevyAlpha"; // Constant for the collection private final static String COLLECTION = "sdl"; // The database connection private TConnection connection = null; // The accessor instance, here a high level TXMLObjectAccessor. private static TXMLObjectAccessor accessor = null; }