Exemplo n.º 1
0
  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;
  }
Exemplo 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;
  }
Exemplo n.º 3
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");

  }
Exemplo n.º 4
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();
      }
    }
Exemplo n.º 5
0
 public Object unmarshal(InputStream is) throws JAXBException {
   return unmarshaller.unmarshal(is);
 }