Ejemplo n.º 1
0
  /**
   * Marshalls a scenario object and writes into output XML file
   *
   * @throws JAXBException, SiriusException
   */
  public void marshallIntoXML(Scenario scenarioToWrite)
      throws JAXBException, FileNotFoundException, BeatsException {

    JAXBContext jaxbContext = JAXBContext.newInstance("edu.berkeley.path.beats.jaxb");
    Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
    jaxbMarshaller.setSchema(this.getSchema());
    jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    jaxbMarshaller.marshal(scenarioToWrite, new File(this.outputFileName));
  }
Ejemplo n.º 2
0
  /**
   * Takes input XML file and unmarshalls it
   *
   * @throws JAXBException, FileNotFoundException, SiriusException
   * @returns Scenario
   */
  public edu.berkeley.path.beats.jaxb.Scenario readAndUnmarshallXML()
      throws JAXBException, FileNotFoundException, BeatsException {

    JAXBContext jaxbContext = JAXBContext.newInstance("edu.berkeley.path.beats.jaxb");
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    javax.xml.validation.Schema schema = this.getSchema();
    jaxbUnmarshaller.setSchema(schema);
    edu.berkeley.path.beats.simulator.ObjectFactory.setObjectFactory(
        jaxbUnmarshaller, new JaxbObjectFactory());
    Scenario scenario =
        (Scenario) jaxbUnmarshaller.unmarshal(new FileInputStream(this.inputFileName));
    return scenario;
  }
Ejemplo n.º 3
0
    Context(Class clazz) {
      try {
        jaxbContext = JAXBContext.newInstance(clazz);

        marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.setSchema(null);

        unmarshaller = jaxbContext.createUnmarshaller();
        unmarshaller.setSchema(null);
      } catch (JAXBException e) {
        e.printStackTrace();
      }
    }
Ejemplo n.º 4
0
 /** Used to retrieve the root document bound through JAXB */
 private static void getRootDocument() {
   if (rDocument == null) {
     try {
       JAXBContext jaxbCtxt = JAXBContext.newInstance("odin.odin.xml");
       Unmarshaller jaxbU = jaxbCtxt.createUnmarshaller();
       jaxbU.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
       File fRoot = new File("home.root.xml");
       JAXBElement<Root> rElement = jaxbU.unmarshal(new StreamSource(fRoot), Root.class);
       rDocument = rElement.getValue();
     } catch (JAXBException jaxbX) {
       System.err.println(
           "An error was caught while trying to read information from the server's root information document.");
       jaxbX.printStackTrace();
     }
   }
 }