Esempio n. 1
0
  /** {@inheritDoc} */
  @Override
  public SBOLDocument read(InputStream in) throws IOException, SBOLValidationException {
    try {
      Unmarshaller unmarshaller = JAXB.CONTEXT.createUnmarshaller();

      if (validate) {
        unmarshaller.setSchema(JAXB.SCHEMA);
      }

      SBOLDocument doc = (SBOLDocument) unmarshaller.unmarshal(in);

      doc.accept(new PrecedeReferenceFinder());
      doc.accept(new DuplicateRemover());

      if (validate) {
        new SBOLValidatorImpl().validateWithoutSchema(doc);
      }

      return doc;
    } catch (SBOLValidationException e) {
      throw e;
    } catch (UnmarshalException e) {
      if (e.getLinkedException() != null) {
        throw new SBOLValidationException(e.getLinkedException());
      } else {
        throw new SBOLValidationException(e);
      }
    } catch (Exception e) {
      throw new IOException(e);
    }
  }
 public ArrayList validateXML(String xmlMessage) {
   StringBuffer validationError = new StringBuffer("");
   String result = "Pass";
   ArrayList list = new ArrayList();
   SubmitManufacturerPartyData sb = null;
   InputStream inFile = null;
   try {
     inFile = new ByteArrayInputStream(xmlMessage.getBytes());
     SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
     Schema schema = schemaFactory.newSchema(new File("PartydataManufacturer.xsd"));
     JAXBContext ctx = JAXBContext.newInstance(new Class[] {SubmitManufacturerPartyData.class});
     Unmarshaller um = ctx.createUnmarshaller();
     um.setSchema(schema);
     sb = (SubmitManufacturerPartyData) um.unmarshal(inFile);
   } catch (SAXException e) {
     result = "Fail";
     e.printStackTrace();
   } catch (UnmarshalException umex) {
     result = "Fail";
     System.out.println("---------- XML Validation Error -------------- ");
     System.out.println("#######" + umex.getLinkedException().getMessage());
     umex.printStackTrace();
   } catch (Exception e) {
     result = "Fail";
     e.printStackTrace();
   }
   list.add(sb);
   list.add(result);
   return list;
 }