+ jaxbe.getLocalizedMessage(), jaxbe);
@Override public <T> T from(String serializedRepresentation, Class<T> classTo) { T obj = null; try { Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); obj = classTo.cast(unmarshaller.unmarshal(new StringReader(serializedRepresentation))); } catch (JAXBException ex) { LOGGER.error(ex.getLocalizedMessage()); } return obj; }
void writeXml(Writer output, Collection<Resource> resources, SerializationManager manager) throws IOException { try { JaxbResourceCollection jaxb = JaxbFactory.createJaxbResources(resources, manager); // wrapping is required for 'xsi:type' attribute. JAXBElement<?> e = new JAXBElement<>(new QName(NS_OGEMA_REST, "resources", "og"), JaxbResourceCollection.class, jaxb); collectionsMarshaller.marshal(e, output); // marshaller.marshal(o, output); } catch (JAXBException ex) { throw new IOException(ex.getLocalizedMessage(), ex); } }
void writeXml(Writer output, Schedule sched, long start, long end, SerializationManager sman) throws IOException { try { JaxbResource jaxb = JaxbFactory.createJaxbSchedule(sched, sman, start, end); // wrapping is required for 'xsi:type' attribute. JAXBElement<?> e = new JAXBElement<>(new QName(JaxbResource.NS_OGEMA_REST, "resource", "og"), JaxbResource.class, jaxb); marshaller.marshal(e, output); } catch (JAXBException ex) { throw new IOException(ex.getLocalizedMessage(), ex); } }
void writeXml(Writer output, Resource resource, SerializationManager manager) throws IOException { try { JaxbResource jaxb = JaxbFactory.createJaxbResource(resource, manager); // wrapping is required for 'xsi:type' attribute. JAXBElement<?> e = new JAXBElement<>(new QName(JaxbResource.NS_OGEMA_REST, "resource", "og"), JaxbResource.class, jaxb); marshaller.marshal(e, output); // marshaller.marshal(o, output); } catch (JAXBException ex) { throw new IOException(ex.getLocalizedMessage(), ex); } }
@Override public <T> String to(T object) { Writer writer = new StringWriter(); try { Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(object, writer); } catch (JAXBException ex) { LOGGER.error(ex.getLocalizedMessage()); } return writer.toString(); }
@Override public <T> String to(T object) { Writer writer = new StringWriter(); try { Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json"); marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, Boolean.TRUE); marshaller.setProperty(MarshallerProperties.JSON_NAMESPACE_SEPARATOR, ':'); marshaller.setProperty(MarshallerProperties.JSON_ATTRIBUTE_PREFIX, "@"); marshaller.marshal(object, writer); } catch (JAXBException ex) { LOGGER.error(ex.getLocalizedMessage()); } return writer.toString(); }
@Override @Transactional(TxType.REQUIRED) public String getDashBoardXml(String blogId, PagingParams pagingParams) throws QBlogException { LOGGER.log(Level.FINEST, "getDashBoardXml with id {0}", blogId); StringWriter xml = new StringWriter(); try { BlogDashboardDTO dto = getDashBoard(blogId, pagingParams); JAXBContext context; context = JAXBContext.newInstance(BlogDashboardDTO.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(new JAXBElement<>( new QName("", "BlogDashboardDTO"), BlogDashboardDTO.class, null, dto), xml); xml.flush(); } catch (JAXBException ex) { LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex); throw new QJAXBError(ex.getLocalizedMessage()); } return xml.toString(); }
/** * This will load the jobs which have already completed * and persisted in the jobs.xml * @return JobsInfos which contains information about completed jobs */ @Override public JobInfos getCompletedJobs(File jobsFile) { synchronized (jobsFile) { try { if (jaxbContext == null) jaxbContext = JAXBContext.newInstance(JobInfos.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); if (jobsFile != null && jobsFile.exists()) { JobInfos jobInfos = (JobInfos)unmarshaller.unmarshal(jobsFile); return jobInfos; } } catch (JAXBException e) { throw new RuntimeException(adminStrings.getLocalString("error.reading.completed.jobs","Error reading completed jobs ", e.getLocalizedMessage()), e); } return null; } }
/** * Helper static class that does the work to write a policy set to an output stream. * * @author pameladragosh * */ public static void writePolicyFile(OutputStream os, PolicyType policy) { JAXBElement<PolicyType> policySetElement = new ObjectFactory().createPolicy(policy); try { JAXBContext context = JAXBContext.newInstance(PolicyType.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(policySetElement, os); } catch (JAXBException e) { logger.error("writePolicyFile failed: " + e.getLocalizedMessage()); } }
/** * Helper static class that does the work to write a policy set to an output stream. * * @author pameladragosh * */ public static void writePolicyFile(OutputStream os, PolicyType policy) { JAXBElement<PolicyType> policySetElement = new ObjectFactory().createPolicy(policy); try { JAXBContext context = JAXBContext.newInstance(PolicyType.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(policySetElement, os); } catch (JAXBException e) { logger.error("writePolicyFile failed: " + e.getLocalizedMessage()); } }
/** * Helper static class that does the work to write a policy to a file on disk. * * @author pameladragosh * */ public static Path writePolicyFile(Path filename, PolicyType policy) { JAXBElement<PolicyType> policyElement = new ObjectFactory().createPolicy(policy); try { JAXBContext context = JAXBContext.newInstance(PolicyType.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(policyElement, filename.toFile()); if (Files.exists(filename)) { return filename; } else { logger.error("File does not exist after marshalling."); return null; } } catch (JAXBException e) { logger.error("writePolicyFile failed: " + e.getLocalizedMessage()); return null; } } /**
/** * Helper static class that does the work to write a policy set to an output stream. * * @author pameladragosh * */ public static void writePolicyFile(OutputStream os, PolicySetType policySet) { JAXBElement<PolicySetType> policySetElement = new ObjectFactory().createPolicySet(policySet); try { JAXBContext context = JAXBContext.newInstance(PolicySetType.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(policySetElement, os); } catch (JAXBException e) { logger.error("writePolicyFile failed: " + e.getLocalizedMessage()); } }
/** * Helper static class that does the work to write a policy set to an output stream. * * @author pameladragosh * */ public static void writePolicyFile(OutputStream os, PolicySetType policySet) { JAXBElement<PolicySetType> policySetElement = new ObjectFactory().createPolicySet(policySet); try { JAXBContext context = JAXBContext.newInstance(PolicySetType.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(policySetElement, os); } catch (JAXBException e) { logger.error("writePolicyFile failed: " + e.getLocalizedMessage()); } }
/** * Helper static class that does the work to write a policy set to a file on disk. * * @author pameladragosh * */ public static Path writePolicyFile(Path filename, PolicySetType policySet) { JAXBElement<PolicySetType> policySetElement = new ObjectFactory().createPolicySet(policySet); try { JAXBContext context = JAXBContext.newInstance(PolicySetType.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(policySetElement, filename.toFile()); if (Files.exists(filename)) { return filename; } else { logger.error("File does not exist after marshalling."); return null; } } catch (JAXBException e) { logger.error("writePolicyFile failed: " + e.getLocalizedMessage()); return null; } }
/** * Helper static class that does the work to write a policy set to a file on disk. * * @author pameladragosh * */ public static Path writePolicyFile(Path filename, PolicySetType policySet) { JAXBElement<PolicySetType> policySetElement = new ObjectFactory().createPolicySet(policySet); try { JAXBContext context = JAXBContext.newInstance(PolicySetType.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(policySetElement, filename.toFile()); if (Files.exists(filename)) { return filename; } else { logger.error("File does not exist after marshalling."); return null; } } catch (JAXBException e) { logger.error("writePolicyFile failed: " + e.getLocalizedMessage()); return null; } }
/** * Helper static class that does the work to write a policy to a file on disk. * * @author pameladragosh * */ public static Path writePolicyFile(Path filename, PolicyType policy) { JAXBElement<PolicyType> policyElement = new ObjectFactory().createPolicy(policy); try { JAXBContext context = JAXBContext.newInstance(PolicyType.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(policyElement, filename.toFile()); if (Files.exists(filename)) { return filename; } else { logger.error("File does not exist after marshalling."); return null; } } catch (JAXBException e) { logger.error("writePolicyFile failed: " + e.getLocalizedMessage()); return null; } } /**
public static Object unmarshall( String jaxbPackage, URL schemaLocation, InputStream input, Workspace workspace ) throws JAXBException { Object o = null; Unmarshaller u = getUnmarshaller( jaxbPackage, schemaLocation, workspace ); try { o = u.unmarshal( input ); } catch ( JAXBException e ) { LOG.error( "Error in configuration file: " + e.getLocalizedMessage() ); // whyever they use the linked exception here... // http://www.jaxb.com/how/to/hide/important/information/from/the/user/of/the/api/unknown_xml_format.xml if ( e.getLinkedException() != null ) { LOG.error( "Error: " + e.getLinkedException().getLocalizedMessage() ); } LOG.error( "Hint: Try validating the file with an XML-schema aware editor." ); throw e; } catch ( Exception e ) { LOG.error( "Error in configuration file: {}", e.getLocalizedMessage() ); LOG.error( "Hint: Try validating the file with an XML-schema aware editor." ); } return o; }
public void doPersist(JobInfos jobInfos, JobInfo jobInfo) { File file = jobInfo.getJobsFile(); synchronized (file) { if (jobInfos == null) { jobInfos = new JobInfos(); } try { JAXBContext jaxbContext = JAXBContext.newInstance(JobInfos.class); jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); CopyOnWriteArrayList<JobInfo> jobList = new CopyOnWriteArrayList<JobInfo>(jobInfos.getJobInfoList()); jobInfos.setJobInfoList(jobList); jobList.add(jobInfo); jaxbMarshaller.marshal(jobInfos, file); jobManager.addToCompletedJobs(new CompletedJob(jobInfo.jobId,jobInfo.commandCompletionDate,jobInfo.getJobsFile())); jobManager.purgeJob(jobInfo.jobId); } catch (JAXBException e) { throw new RuntimeException(adminStrings.getLocalString("error.persisting.jobs","Error while persisting jobs",jobInfo.jobId,e.getLocalizedMessage()),e); } } }
/** * <p> * reloadAndReStart * </p> */ private void reloadAndReStart() { EventBuilder ebldr = null; try { initializeConfiguration(); ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_SUCCESSFUL_UEI, getName()); ebldr.addParam(EventConstants.PARM_DAEMON_NAME, DAEMON_NAME); this.stop(); this.init(); this.start(); } catch (JAXBException e) { LOG.error("Unable to initialize the Access Point Monitor configuration factory", e); ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_FAILED_UEI, getName()); ebldr.addParam(EventConstants.PARM_DAEMON_NAME, DAEMON_NAME); ebldr.addParam(EventConstants.PARM_REASON, e.getLocalizedMessage().substring(0, 128)); } catch (IOException e) { LOG.error("Unable to initialize the Access Point Monitor configuration factory", e); ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_FAILED_UEI, getName()); ebldr.addParam(EventConstants.PARM_DAEMON_NAME, DAEMON_NAME); ebldr.addParam(EventConstants.PARM_REASON, e.getLocalizedMessage().substring(0, 128)); } m_eventMgr.sendNow(ebldr.getEvent()); }