@Test (enabled=true, dataProvider="increasingingComplextInputData") public void importTest(String inputFilename, String expectedRootID) throws Exception { File file = new File(inputFilename); ComponentListType components = XMLPersistence.unmarshal(file); ComponentType component = components.getComponent().get(0); Assert.assertNotNull(component); Assert.assertEquals(component.getComponentId(), expectedRootID); }
public static ComponentListType unmarshal(File xmlFile) throws IOException, ValidationException { if (xmlFile == null || xmlFile.equals("") || !xmlFile.exists()) { throw new IllegalArgumentException( "XMLPersistence: File name is null, the empty string, or does not" + " exist."); } ValidationEventCollector validationEventCollector = new ValidationEventCollector(); Schema schema; JAXBElement<ComponentListType> root = null; String errStr = null; ComponentListType componentListType = null; try { JAXBContext jaxbContext = JAXBContext.newInstance( ComponentListType.class.getPackage().getName(), XMLPersistence.class.getClassLoader()); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); schema = getSchema(); unmarshaller.setSchema(schema); unmarshaller.setEventHandler(validationEventCollector); root = unmarshaller.unmarshal(new StreamSource(xmlFile), ComponentListType.class); componentListType = root.getValue(); } catch (SAXException saxe) { errStr = String.format("SAXException on file:%s due to: %s ", xmlFile, saxe.getMessage()); } catch (JAXBException jaxbe) { errStr = String.format("JAXBException on file:%s due to: %s", xmlFile, jaxbe.toString()); } catch (FileNotFoundException e) { errStr = String.format("Unable to find schema for xml file: %s Cause: %s. " + "Ensure Schema Path is set.", xmlFile, e.getMessage()); } finally { handleError(errStr, validationEventCollector, xmlFile); } return componentListType; }
XMLPersistence { public static ComponentListType unmarshal(File xmlFile) throws IOException, ValidationException { if (xmlFile == null || xmlFile.equals("") || !xmlFile.exists()) { throw new IllegalArgumentException( "XMLPersistence: File name is null, the empty string, or does not" + " exist."); } ValidationEventCollector validationEventCollector = new ValidationEventCollector(); Schema schema; JAXBElement<ComponentListType> root = null; String errStr = null; ComponentListType componentListType = null; try { JAXBContext jaxbContext = JAXBContext.newInstance( ComponentListType.class.getPackage().getName(), XMLPersistence.class.getClassLoader()); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); schema = getSchema(); unmarshaller.setSchema(schema); unmarshaller.setEventHandler(validationEventCollector); root = unmarshaller.unmarshal(new StreamSource(xmlFile), ComponentListType.class); componentListType = root.getValue(); } catch (SAXException saxe) { errStr = String.format("SAXException on file:%s due to: %s ", xmlFile, saxe.getMessage()); } catch (JAXBException jaxbe) { errStr = String.format("JAXBException on file:%s due to: %s", xmlFile, jaxbe.toString()); } catch (FileNotFoundException e) { errStr = String.format("Unable to find schema for xml file: %s Cause: %s. " + "Ensure Schema Path is set.", xmlFile, e.getMessage()); } finally { handleError(errStr, validationEventCollector, xmlFile); } return componentListType; } }
XMLPersistence { public static ComponentListType unmarshal(File xmlFile) throws IOException, ValidationException { if (xmlFile == null || xmlFile.equals("") || !xmlFile.exists()) { throw new IllegalArgumentException( "XMLPersistence: File name is null, the empty string, or does not" + " exist."); } ValidationEventCollector validationEventCollector = new ValidationEventCollector(); Schema schema; JAXBElement<ComponentListType> root = null; String errStr = null; ComponentListType componentListType = null; try { JAXBContext jaxbContext = JAXBContext.newInstance( ComponentListType.class.getPackage().getName(), XMLPersistence.class.getClassLoader()); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); schema = getSchema(); unmarshaller.setSchema(schema); unmarshaller.setEventHandler(validationEventCollector); root = unmarshaller.unmarshal(new StreamSource(xmlFile), ComponentListType.class); componentListType = root.getValue(); } catch (SAXException saxe) { errStr = String.format("SAXException on file:%s due to: %s ", xmlFile, saxe.getMessage()); } catch (JAXBException jaxbe) { errStr = String.format("JAXBException on file:%s due to: %s", xmlFile, jaxbe.toString()); } catch (FileNotFoundException e) { errStr = String.format("Unable to find schema for xml file: %s Cause: %s. " + "Ensure Schema Path is set.", xmlFile, e.getMessage()); } finally { handleError(errStr, validationEventCollector, xmlFile); } return componentListType; } private  XMLPersistence(); }
XMLPersistence { public static ComponentListType unmarshal(File xmlFile) throws IOException, ValidationException { if (xmlFile == null || xmlFile.equals("") || !xmlFile.exists()) { throw new IllegalArgumentException( "XMLPersistence: File name is null, the empty string, or does not" + " exist."); } ValidationEventCollector validationEventCollector = new ValidationEventCollector(); Schema schema; JAXBElement<ComponentListType> root = null; String errStr = null; ComponentListType componentListType = null; try { JAXBContext jaxbContext = JAXBContext.newInstance( ComponentListType.class.getPackage().getName(), XMLPersistence.class.getClassLoader()); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); schema = getSchema(); unmarshaller.setSchema(schema); unmarshaller.setEventHandler(validationEventCollector); root = unmarshaller.unmarshal(new StreamSource(xmlFile), ComponentListType.class); componentListType = root.getValue(); } catch (SAXException saxe) { errStr = String.format("SAXException on file:%s due to: %s ", xmlFile, saxe.getMessage()); } catch (JAXBException jaxbe) { errStr = String.format("JAXBException on file:%s due to: %s", xmlFile, jaxbe.toString()); } catch (FileNotFoundException e) { errStr = String.format("Unable to find schema for xml file: %s Cause: %s. " + "Ensure Schema Path is set.", xmlFile, e.getMessage()); } finally { handleError(errStr, validationEventCollector, xmlFile); } return componentListType; } 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 ComponentListType unmarshal(File xmlFile) throws IOException, ValidationException { if (xmlFile == null || xmlFile.equals("") || !xmlFile.exists()) { throw new IllegalArgumentException( "XMLPersistence: File name is null, the empty string, or does not" + " exist."); } ValidationEventCollector validationEventCollector = new ValidationEventCollector(); Schema schema; JAXBElement<ComponentListType> root = null; String errStr = null; ComponentListType componentListType = null; try { JAXBContext jaxbContext = JAXBContext.newInstance( ComponentListType.class.getPackage().getName(), XMLPersistence.class.getClassLoader()); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); schema = getSchema(); unmarshaller.setSchema(schema); unmarshaller.setEventHandler(validationEventCollector); root = unmarshaller.unmarshal(new StreamSource(xmlFile), ComponentListType.class); componentListType = root.getValue(); } catch (SAXException saxe) { errStr = String.format("SAXException on file:%s due to: %s ", xmlFile, saxe.getMessage()); } catch (JAXBException jaxbe) { errStr = String.format("JAXBException on file:%s due to: %s", xmlFile, jaxbe.toString()); } catch (FileNotFoundException e) { errStr = String.format("Unable to find schema for xml file: %s Cause: %s. " + "Ensure Schema Path is set.", xmlFile, e.getMessage()); } finally { handleError(errStr, validationEventCollector, xmlFile); } return componentListType; } private  XMLPersistence(); static void marshal(ComponentListType primaryObject, File file); static String marshal(T toBeMarshalled); static ComponentListType unmarshal(File xmlFile); static ExtendedProperties unmarshal(String props);  }