@Test (enabled=true, expectedExceptions=IllegalArgumentException.class) public void exportBadFile() throws IOException, ValidationException{ XMLPersistence.marshal(newCompWOChildren(), null); }
public static void marshal(ComponentListType primaryObject, File file) throws IOException, ValidationException{ String errStr = null; if (primaryObject == null || primaryObject.getComponent() == null || primaryObject.getComponent().size() == 0) { return; } ObjectFactory objFactory = new ObjectFactory(); JAXBElement<ComponentListType> element = objFactory.createComponents(primaryObject); ValidationEventCollector validationEventCollector = new ValidationEventCollector(); FileOutputStream fileOut = null; if (file == null || file.equals("")) { throw new IllegalArgumentException( "XMLPersistence: File name is null or empty string"); } try { fileOut = new FileOutputStream(file); Marshaller marshaller = createNewMarshaller(primaryObject); Schema schema = getSchema(); marshaller.setSchema(schema); marshaller.setEventHandler(validationEventCollector); marshaller.marshal(element, fileOut); fileOut.close(); } catch (JAXBException e) { errStr = String.format("JAXBException on file:%s due to: %s", file, e.getMessage()); } catch (FileNotFoundException e) { errStr = String.format("Unable to find schema for xml file: %s Cause: %s. " + "Ensure Schema Path is set.", file, e.getMessage()); } catch (IOException e) { errStr = String.format("IOException on file:%s due to: %s", file, e.getMessage()); } catch (SAXException e) { errStr = String.format("SAXException on file:%s due to: %s", file, e.getMessage()); } finally { handleError(errStr, validationEventCollector, file); } }
XMLPersistence { public static void marshal(ComponentListType primaryObject, File file) throws IOException, ValidationException{ String errStr = null; if (primaryObject == null || primaryObject.getComponent() == null || primaryObject.getComponent().size() == 0) { return; } ObjectFactory objFactory = new ObjectFactory(); JAXBElement<ComponentListType> element = objFactory.createComponents(primaryObject); ValidationEventCollector validationEventCollector = new ValidationEventCollector(); FileOutputStream fileOut = null; if (file == null || file.equals("")) { throw new IllegalArgumentException( "XMLPersistence: File name is null or empty string"); } try { fileOut = new FileOutputStream(file); Marshaller marshaller = createNewMarshaller(primaryObject); Schema schema = getSchema(); marshaller.setSchema(schema); marshaller.setEventHandler(validationEventCollector); marshaller.marshal(element, fileOut); fileOut.close(); } catch (JAXBException e) { errStr = String.format("JAXBException on file:%s due to: %s", file, e.getMessage()); } catch (FileNotFoundException e) { errStr = String.format("Unable to find schema for xml file: %s Cause: %s. " + "Ensure Schema Path is set.", file, e.getMessage()); } catch (IOException e) { errStr = String.format("IOException on file:%s due to: %s", file, e.getMessage()); } catch (SAXException e) { errStr = String.format("SAXException on file:%s due to: %s", file, e.getMessage()); } finally { handleError(errStr, validationEventCollector, file); } } }
XMLPersistence { public static void marshal(ComponentListType primaryObject, File file) throws IOException, ValidationException{ String errStr = null; if (primaryObject == null || primaryObject.getComponent() == null || primaryObject.getComponent().size() == 0) { return; } ObjectFactory objFactory = new ObjectFactory(); JAXBElement<ComponentListType> element = objFactory.createComponents(primaryObject); ValidationEventCollector validationEventCollector = new ValidationEventCollector(); FileOutputStream fileOut = null; if (file == null || file.equals("")) { throw new IllegalArgumentException( "XMLPersistence: File name is null or empty string"); } try { fileOut = new FileOutputStream(file); Marshaller marshaller = createNewMarshaller(primaryObject); Schema schema = getSchema(); marshaller.setSchema(schema); marshaller.setEventHandler(validationEventCollector); marshaller.marshal(element, fileOut); fileOut.close(); } catch (JAXBException e) { errStr = String.format("JAXBException on file:%s due to: %s", file, e.getMessage()); } catch (FileNotFoundException e) { errStr = String.format("Unable to find schema for xml file: %s Cause: %s. " + "Ensure Schema Path is set.", file, e.getMessage()); } catch (IOException e) { errStr = String.format("IOException on file:%s due to: %s", file, e.getMessage()); } catch (SAXException e) { errStr = String.format("SAXException on file:%s due to: %s", file, e.getMessage()); } finally { handleError(errStr, validationEventCollector, file); } } private  XMLPersistence(); }
XMLPersistence { public static void marshal(ComponentListType primaryObject, File file) throws IOException, ValidationException{ String errStr = null; if (primaryObject == null || primaryObject.getComponent() == null || primaryObject.getComponent().size() == 0) { return; } ObjectFactory objFactory = new ObjectFactory(); JAXBElement<ComponentListType> element = objFactory.createComponents(primaryObject); ValidationEventCollector validationEventCollector = new ValidationEventCollector(); FileOutputStream fileOut = null; if (file == null || file.equals("")) { throw new IllegalArgumentException( "XMLPersistence: File name is null or empty string"); } try { fileOut = new FileOutputStream(file); Marshaller marshaller = createNewMarshaller(primaryObject); Schema schema = getSchema(); marshaller.setSchema(schema); marshaller.setEventHandler(validationEventCollector); marshaller.marshal(element, fileOut); fileOut.close(); } catch (JAXBException e) { errStr = String.format("JAXBException on file:%s due to: %s", file, e.getMessage()); } catch (FileNotFoundException e) { errStr = String.format("Unable to find schema for xml file: %s Cause: %s. " + "Ensure Schema Path is set.", file, e.getMessage()); } catch (IOException e) { errStr = String.format("IOException on file:%s due to: %s", file, e.getMessage()); } catch (SAXException e) { errStr = String.format("SAXException on file:%s due to: %s", file, e.getMessage()); } finally { handleError(errStr, validationEventCollector, file); } } private  XMLPersistence(); static void marshal(ComponentListType primaryObject, File file); static String marshal(T toBeMarshalled); static ComponentListType unmarshal(File xmlFile); static ExtendedProperties unmarshal(String props); }
XMLPersistence { public static void marshal(ComponentListType primaryObject, File file) throws IOException, ValidationException{ String errStr = null; if (primaryObject == null || primaryObject.getComponent() == null || primaryObject.getComponent().size() == 0) { return; } ObjectFactory objFactory = new ObjectFactory(); JAXBElement<ComponentListType> element = objFactory.createComponents(primaryObject); ValidationEventCollector validationEventCollector = new ValidationEventCollector(); FileOutputStream fileOut = null; if (file == null || file.equals("")) { throw new IllegalArgumentException( "XMLPersistence: File name is null or empty string"); } try { fileOut = new FileOutputStream(file); Marshaller marshaller = createNewMarshaller(primaryObject); Schema schema = getSchema(); marshaller.setSchema(schema); marshaller.setEventHandler(validationEventCollector); marshaller.marshal(element, fileOut); fileOut.close(); } catch (JAXBException e) { errStr = String.format("JAXBException on file:%s due to: %s", file, e.getMessage()); } catch (FileNotFoundException e) { errStr = String.format("Unable to find schema for xml file: %s Cause: %s. " + "Ensure Schema Path is set.", file, e.getMessage()); } catch (IOException e) { errStr = String.format("IOException on file:%s due to: %s", file, e.getMessage()); } catch (SAXException e) { errStr = String.format("SAXException on file:%s due to: %s", file, e.getMessage()); } finally { handleError(errStr, validationEventCollector, file); } } private  XMLPersistence(); static void marshal(ComponentListType primaryObject, File file); static String marshal(T toBeMarshalled); static ComponentListType unmarshal(File xmlFile); static ExtendedProperties unmarshal(String props);  }