示例#1
0
文件: Import.java 项目: dlitz/resin
  public void resolve(Unmarshaller u) throws JAXBException {
    Object obj = null;

    try {
      obj = u.unmarshal(new URL(getSchemaLocation()));
    } catch (MalformedURLException e) {
    }

    File file = new File(getSchemaLocation());

    if (!file.exists()) {
      if (!file.getName().startsWith("/")) {
        file = new File(_location.getSystemId());

        file = file.getParentFile();

        if (file == null) throw new JAXBException("File not found: " + getSchemaLocation());

        file = new File(file, getSchemaLocation());
      }
    }

    obj = u.unmarshal(file);

    if (obj instanceof Schema) _schema = (Schema) obj;
  }
示例#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;
  }
  public void testJSONOutputStreamUTF8() throws Exception {
    marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
    unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");

    FlushRoot control = getControlObject();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    marshaller.marshal(control, baos);

    XMLInputFactory xif = XMLInputFactory.newFactory();
    Object test = unmarshaller.unmarshal(new ByteArrayInputStream(baos.toByteArray()));

    assertEquals(control, test);
  }
示例#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();
     }
   }
 }
  public void testOutputStreamUTF8() throws Exception {
    FlushRoot control = getControlObject();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    marshaller.marshal(control, baos);

    XMLInputFactory xif = XMLInputFactory.newFactory();
    Object test = unmarshaller.unmarshal(new ByteArrayInputStream(baos.toByteArray()));

    assertEquals(control, test);
  }
示例#6
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();
      }
    }
  public void testXMLStreamWriter() throws Exception {
    FlushRoot control = getControlObject();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    XMLOutputFactory xof = XMLOutputFactory.newFactory();
    XMLStreamWriter xsw = xof.createXMLStreamWriter(baos);
    marshaller.marshal(control, xsw);

    XMLInputFactory xif = XMLInputFactory.newFactory();
    XMLStreamReader xsr = xif.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray()));
    Object test = unmarshaller.unmarshal(xsr);

    assertEquals(control, test);
  }
示例#8
0
  /**
   * TDTEngine - constructor for a new Tag Data Translation engine
   *
   * @param confdir the string value of the path to a configuration directory consisting of two
   *     subdirectories, <code>schemes</code> and <code>auxiliary</code>.
   *     <p>When the class TDTEngine is constructed, the path to a local directory must be
   *     specified, by passing it as a single string parameter to the constructor method (without
   *     any trailing slash or file separator). e.g. <code>
   *     <pre>TDTEngine engine = new TDTEngine("/opt/TDT");</pre></code>
   *     <p>The specified directory must contain two subdirectories named auxiliary and schemes. The
   *     Tag Data Translation definition files for the various coding schemes should be located
   *     inside the subdirectory called <code>schemes</code>. Any auxiliary lookup files (such as
   *     <code>ManagerTranslation.xml</code>) should be located inside the subdirectory called
   *     <code>auxiliary</code>.
   *     <p>Files within the schemes directory ending in <code>.xml</code> are read in and
   *     unmarshalled using <a href = "http://www.castor.org">Castor</a>.
   */
  public TDTEngine(String confdir)
      throws FileNotFoundException, MarshalException, ValidationException, TDTException {
    xmldir = confdir;

    long t = System.currentTimeMillis();
    File[] dir =
        new java.io.File(confdir + File.separator + "schemes").listFiles(new XMLFilenameFilter());
    // java.util.Arrays.sort(dir); // Sort it
    if (dir == null) throw new TDTException("Cannot find schemes in " + confdir);
    Unmarshaller unmar = new Unmarshaller();
    for (File f : dir) {
      EpcTagDataTranslation tdt =
          (EpcTagDataTranslation) unmar.unmarshal(EpcTagDataTranslation.class, new FileReader(f));

      initFromTDT(tdt);
    }

    // need to populate the hashmap gs1cpi from the ManagerTranslation.xml table in auxiliary.
    // Unmarshaller unmar = new Unmarshaller();
    GEPC64Table cpilookup =
        (GEPC64Table)
            unmar.unmarshal(
                GEPC64Table.class,
                new FileReader(
                    confdir
                        + File.separator
                        + "auxiliary"
                        + File.separator
                        + "ManagerTranslation.xml"));
    for (Enumeration e = cpilookup.enumerateEntry(); e.hasMoreElements(); ) {
      Entry entry = (Entry) e.nextElement();
      String comp = entry.getCompanyPrefix();
      String indx = Integer.toString(entry.getIndex());
      gs1cpi.put(indx, comp);
      gs1cpi.put(comp, indx);
    }

    // System.out.println("Loaded schemas in " +
    //		   (System.currentTimeMillis() - t)
    //		   + " millisecs");

  }
示例#9
0
 public Object unmarshal(InputStream is) throws JAXBException {
   return unmarshaller.unmarshal(is);
 }