List of usage examples for javax.xml.bind JAXBContext createUnmarshaller
public abstract Unmarshaller createUnmarshaller() throws JAXBException;
From source file:cz.lbenda.dataman.db.ExtConfFactory.java
private void loadExConfType(Reader reader) { if (reader == null) { loadExConfType((ExConfType) null); } else {// www . j av a 2 s. co m try { JAXBContext jc = JAXBContext.newInstance(cz.lbenda.dataman.schema.exconf.ObjectFactory.class); Unmarshaller u = jc.createUnmarshaller(); JAXBElement o = (JAXBElement) u.unmarshal(reader); if (o.getValue() instanceof ExConfType) { loadExConfType((ExConfType) o.getValue()); } else { LOG.error("The file didn't contains expected configuration: " + o.getClass().getName()); } } catch (JAXBException e) { LOG.error("Problem with reading extended configuration: " + e.toString(), e); } } }
From source file:be.fedict.eid.applet.service.signer.xps.XPSSignatureVerifier.java
public XPSSignatureVerifier() { try {/*from w w w. jav a 2 s .c o m*/ JAXBContext relationshipsJAXBContext = JAXBContext.newInstance(ObjectFactory.class); this.relationshipsUnmarshaller = relationshipsJAXBContext.createUnmarshaller(); } catch (JAXBException e) { throw new RuntimeException("JAXB error: " + e.getMessage(), e); } }
From source file:eu.learnpad.core.impl.cw.XwikiBridgeInterfaceRestResource.java
@Override public PFResults getFeedbacks(String modelSetId) throws LpRestException { HttpClient httpClient = this.getClient(); String uri = String.format("%s/learnpad/cw/bridge/%s/feedbacks", DefaultRestResource.REST_URI, modelSetId); GetMethod getMethod = new GetMethod(uri); getMethod.addRequestHeader("Accept", "application/xml"); InputStream pfStream = null;/* w w w .j av a 2s. c o m*/ PFResults pf = null; try { httpClient.executeMethod(getMethod); pfStream = getMethod.getResponseBodyAsStream(); JAXBContext jc = JAXBContext.newInstance(PFResults.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); pf = (PFResults) unmarshaller.unmarshal(pfStream); } catch (JAXBException | IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause()); } return pf; }
From source file:gov.nih.nci.cabig.caaers.web.admin.InvestigatorImporter.java
public void processEntities(File xmlFile, ImportCommand command) { boolean valid = validateAgainstSchema(xmlFile, command, getXSDLocation(INVESTIGATOR_IMPORT)); if (!valid) { return;//from ww w .ja v a 2 s . c om } try { //DefaultInvestigatorMigratorService svc = (DefaultInvestigatorMigratorService) getApplicationContext().getBean("investigatorMigratorService"); JAXBContext jaxbContext = JAXBContext .newInstance("gov.nih.nci.cabig.caaers.integration.schema.investigator"); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); Object importObject = unmarshaller.unmarshal(xmlFile); if (!validRootElement(importObject, INVESTIGATOR_IMPORT, command)) return; gov.nih.nci.cabig.caaers.integration.schema.investigator.Staff staff = (gov.nih.nci.cabig.caaers.integration.schema.investigator.Staff) importObject; for (InvestigatorType xmlInvestigator : staff.getInvestigator()) { DomainObjectImportOutcome<Investigator> investigatorOutcome = investigatorMigratorService .processInvestigator(xmlInvestigator); List<String> errors = domainObjectValidator.validate(investigatorOutcome.getImportedDomainObject()); if (investigatorOutcome.isSavable() && errors.size() == 0) { command.addImportableInvestigator(investigatorOutcome); } else { for (String errMsg : errors) { investigatorOutcome.addErrorMessage(errMsg, Severity.ERROR); } command.addNonImportableInvestigator(investigatorOutcome); } } //Remove Duplicate Investigators from the ImportableInvestigators List. List<DomainObjectImportOutcome<Investigator>> dupList = new ArrayList<DomainObjectImportOutcome<Investigator>>(); for (int k = 0; k < command.getImportableInvestigators().size() - 1; k++) { Investigator inv1 = command.getImportableInvestigators().get(k).getImportedDomainObject(); for (int l = k + 1; l < command.getImportableInvestigators().size(); l++) { Investigator inv2 = command.getImportableInvestigators().get(l).getImportedDomainObject(); if (inv1.equals(inv2)) { command.getImportableInvestigators().get(l).addErrorMessage("Duplicate Investigator", Severity.ERROR); command.addNonImportableInvestigator(command.getImportableInvestigators().get(l)); dupList.add(command.getImportableInvestigators().get(l)); logger.debug("Duplicate Investigator :: " + inv2.getFullName()); break; } } } for (DomainObjectImportOutcome<Investigator> obj : dupList) { command.getImportableInvestigators().remove(obj); } } catch (JAXBException e) { throw new RuntimeException("JAXB Exception", e); } }
From source file:org.jasig.portlet.announcements.Importer.java
private void importAnnouncements() { try {/*from w w w. j ava 2 s. c o m*/ JAXBContext jc = JAXBContext.newInstance(Announcement.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); File[] files = dataDirectory.listFiles(new AnnouncementImportFileFilter()); if (files == null) { errors.add("Directory " + dataDirectory + " is not a valid directory"); } else { for (File f : files) { log.info("Processing file " + f.toString()); StreamSource xml = new StreamSource(f.getAbsoluteFile()); try { JAXBElement<Announcement> je1 = unmarshaller.unmarshal(xml, Announcement.class); Announcement announcement = je1.getValue(); if (StringUtils.isBlank(announcement.getTitle())) { String msg = "Error parsing " + f.toString() + "; did not get valid record:\n" + announcement.toString(); log.error(msg); errors.add(msg); } else if (announcement.getParent() == null || StringUtils.isBlank(announcement.getParent().getTitle())) { String msg = "Announcement in file " + f.toString() + " does not reference a topic with a title"; log.error(msg); errors.add(msg); } else { Topic topic = findTopicForAnnouncement(announcement); announcement.setParent(topic); announcementService.addOrSaveAnnouncement(announcement); log.info("Successfully imported announcement '" + announcement.getTitle() + "'"); } } catch (ImportException e) { log.error(e.getMessage()); errors.add(e.getMessage()); } catch (JAXBException e) { String msg = "JAXB exception " + e.getCause().getMessage() + " processing file " + f.toString(); log.error(msg, e); errors.add(msg + ". See stack trace"); } catch (HibernateException e) { String msg = "Hibernate exception " + e.getCause().getMessage() + " processing file " + f.toString(); log.error(msg, e); errors.add(msg + ". See stack trace"); } } } } catch (JAXBException e) { String msg = "Fatal JAXBException in importAnnouncements - no Announcements imported"; log.fatal(msg, e); errors.add(msg + ". See stack trace"); } }
From source file:de.extra.client.plugins.configplugin.controller.ConfigPluginController.java
/** * Unmarshalling der Profildatei./* ww w. jav a2 s . c o m*/ * * @param dateiName * Vollstaendiger Pfad der Profildatei * @return JaxB-Element */ private ProfilkonfigurationType unmarshalConfig(final File profileFile) { ProfilkonfigurationType pkt = null; JAXBContext jc; try { // Initialisieren des JaxB-Contextes jc = JAXBContext.newInstance(ConfigConstants.UNMARSHAL_CONFIG); // Aufruf des Unmarshallers Unmarshaller u = jc.createUnmarshaller(); pkt = (ProfilkonfigurationType) u.unmarshal(profileFile); } catch (JAXBException e) { LOG.error("Fehler beim Verarbeiten des XML", e); } catch (Exception e) { LOG.error("Fehler beim Verarbeiten des XML", e); } return pkt; }
From source file:gov.nih.nci.cabig.caaers.web.admin.SubjectImporter.java
public void processEntities(File xmlFile, ImportCommand command) { boolean valid = validateAgainstSchema(xmlFile, command, getXSDLocation(SUBJECT_IMPORT)); if (!valid) { return;/*from w w w . java 2 s . c o m*/ } Participants participants; try { JAXBContext jaxbContext = JAXBContext .newInstance("gov.nih.nci.cabig.caaers.integration.schema.participant"); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); Object importObject = unmarshaller.unmarshal(xmlFile); if (!validRootElement(importObject, SUBJECT_IMPORT, command)) return; participants = (Participants) importObject; if (participants != null) { for (ParticipantType participantDto : participants.getParticipant()) { DomainObjectImportOutcome<Participant> participantImportOutcome = participantServiceImpl .processParticipant(participantDto); List<String> errors = domainObjectValidator .validate(participantImportOutcome.getImportedDomainObject()); if (participantImportOutcome.isSavable() && errors.size() == 0) { command.addImportableParticipant(participantImportOutcome); } else { for (String errMsg : errors) { participantImportOutcome.addErrorMessage(errMsg, Severity.ERROR); } command.addNonImportableParticipant(participantImportOutcome); } } //Remove Duplicate Participants from the ImportableParticipants List. List<DomainObjectImportOutcome<Participant>> dupList = new ArrayList<DomainObjectImportOutcome<Participant>>(); for (int k = 0; k < command.getImportableParticipants().size() - 1; k++) { Participant par1 = command.getImportableParticipants().get(k).getImportedDomainObject(); for (int l = k + 1; l < command.getImportableParticipants().size(); l++) { Participant par2 = command.getImportableParticipants().get(l).getImportedDomainObject(); if (par1.equals(par2)) { command.getImportableParticipants().get(l) .addErrorMessage("Participant Identifier already used", Severity.ERROR); command.addNonImportableParticipant(command.getImportableParticipants().get(l)); dupList.add(command.getImportableParticipants().get(l)); logger.debug("Duplicate Participant :: " + par2.getFullName()); break; } } } for (DomainObjectImportOutcome<Participant> obj : dupList) { command.getImportableParticipants().remove(obj); } } } catch (JAXBException e) { throw new CaaersSystemException( "There was an error converting participant data transfer object to participant domain object", e); } }
From source file:gov.nih.nci.cabig.caaers.web.admin.ResearchStaffImporter.java
public void processEntities(File xmlFile, ImportCommand command) { boolean valid = validateAgainstSchema(xmlFile, command, getXSDLocation(RESEARCH_STAFF_IMPORT)); if (!valid) { return;//ww w . j a v a 2s .co m } try { //DefaultResearchStaffMigratorService svc = (DefaultResearchStaffMigratorService) getApplicationContext().getBean("researchStaffMigratorService"); JAXBContext jaxbContext = JAXBContext .newInstance("gov.nih.nci.cabig.caaers.integration.schema.researchstaff"); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); Object importObject = unmarshaller.unmarshal(xmlFile); if (!validRootElement(importObject, RESEARCH_STAFF_IMPORT, command)) return; gov.nih.nci.cabig.caaers.integration.schema.researchstaff.Staff staff = (gov.nih.nci.cabig.caaers.integration.schema.researchstaff.Staff) importObject; for (ResearchStaffType researchStaff : staff.getResearchStaff()) { DomainObjectImportOutcome<ResearchStaff> researchStaffOutcome = researchStaffMigratorService .processResearchStaff(researchStaff); List<String> errors = domainObjectValidator .validate(researchStaffOutcome.getImportedDomainObject()); if (researchStaffOutcome.isSavable() && errors.size() == 0) { command.addImportableResearchStaff(researchStaffOutcome); } else { for (String errMsg : errors) { researchStaffOutcome.addErrorMessage(errMsg, Severity.ERROR); } command.addNonImportableResearchStaff(researchStaffOutcome); } } //Remove Duplicate Investigators from the ImportableInvestigators List. List<DomainObjectImportOutcome<ResearchStaff>> dupList = new ArrayList<DomainObjectImportOutcome<ResearchStaff>>(); for (int k = 0; k < command.getImportableResearchStaff().size() - 1; k++) { ResearchStaff rStaff1 = command.getImportableResearchStaff().get(k).getImportedDomainObject(); for (int l = k + 1; l < command.getImportableResearchStaff().size(); l++) { ResearchStaff rStaff2 = command.getImportableResearchStaff().get(l).getImportedDomainObject(); if (rStaff1.equals(rStaff2)) { command.getImportableResearchStaff().get(l).addErrorMessage("Duplicate ResearchStaff", Severity.ERROR); command.addNonImportableResearchStaff(command.getImportableResearchStaff().get(l)); dupList.add(command.getImportableResearchStaff().get(l)); logger.debug("Duplicate Investigator :: " + rStaff2.getFullName()); break; } } } for (DomainObjectImportOutcome<ResearchStaff> obj : dupList) { command.getImportableResearchStaff().remove(obj); } } catch (JAXBException e) { throw new RuntimeException("JAXB Exception", e); } }
From source file:com.aionemu.commons.scripting.scriptmanager.ScriptManager.java
/** * Loads script contexes from descriptor * /*from ww w. ja va 2s . co m*/ * @param scriptDescriptor * xml file that describes contexes * @throws Exception * if can't load file */ public synchronized void load(File scriptDescriptor) throws Exception { FileInputStream fin = new FileInputStream(scriptDescriptor); JAXBContext c = JAXBContext.newInstance(ScriptInfo.class, ScriptList.class); Unmarshaller u = c.createUnmarshaller(); ScriptList list = null; try { list = (ScriptList) u.unmarshal(fin); } catch (Exception e) { throw e; } finally { if (fin != null) fin.close(); } for (ScriptInfo si : list.getScriptInfos()) { ScriptContext context = createContext(si, null); if (context != null) { contexts.add(context); context.init(); } } }
From source file:org.usd.edu.btl.cli.ConvertBets.java
public void toGalaxy(String input, String output) { InputStream infile = null;/*from w w w. j a v a 2s . co m*/ Tool myTool = null; try { JAXBContext jaxbContext = JAXBContext.newInstance(Tool.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); //Unmarshalling Convert XML content into a Java Object. infile = new FileInputStream("./test_inputs/test_galaxy.xml"); Tool test_tool = (Tool) unmarshaller.unmarshal(infile); myTool = test_tool; //System.out.println(test_tool.toString()); //print the test_tool } catch (FileNotFoundException e) { System.err.println(e.getMessage()); } catch (JAXBException e) { System.err.println(e.getMessage()); } finally { try { if (infile != null) { infile.close(); } } catch (IOException e) { System.err.println("You're rubbish, you can't even close a file"); System.err.println(e.getMessage()); } } //JAXB-Marshall Java back to XML try { JAXBContext jaxbContext = JAXBContext.newInstance(Tool.class); Marshaller marshaller = jaxbContext.createMarshaller(); //Marshalling Convert a Java object into a XML file. marshaller.marshal(myTool, System.out); //print XML out } catch (JAXBException e) { System.err.println("JAXB dun goofed"); System.err.println(e.getMessage()); } // RUN GALAXY TO BETS CONVERSION BETSV1 betsOutput = GalaxyConverter.toBETS(myTool); try { System.err.println("************************************************\n" + "*********PRINTING OUT CONVERSION************\n" + "----------Galaxy --> Bets--------------\n" + "************************************************\n"); //print objects as Json using jackson System.err.println("=== BLD TO BETS JSON === \n"); System.out.println(betsOutput); } catch (Exception e) { System.err.println(e.getMessage()); } }