= JAXBContext.newInstance(Plugins.class, PluginDescription.class, PhasePluginDescription.class); final Unmarshaller unmarshaller = context.createUnmarshaller(); final Object root = unmarshaller.unmarshal(configFile); } catch (final JAXBException e) { System.err.println("An error occured while loading plugin configuration '" + file + "'."); logger.error(e.getMessage(), e); return false;
Unmarshaller u = jc.createUnmarshaller(); u.setEventHandler(eventHandler); return u.unmarshal( new javax.xml.transform.stream.StreamSource( new java.io.StringReader(str)) ); JAXBResult result = XmlUtils.prepareJAXBResult(jc); XmlUtils.transform( new StreamSource(new java.io.StringReader(str)), mcPreprocessorXslt, null, result); return result.getResult(); } catch (Exception e) { throw new JAXBException("Preprocessing exception", e);
ObjectFactory objFactory = new ObjectFactory(); MyRootElement root = objFactory.createMyRootElement(); ... // Set root properties ... if (!writeDocument(objFactory.createMyRootElement(root), output)) { System.err.println("Failed to marshal XML document"); } ... private boolean writeDocument(JAXBElement document, OutputStream output) { Class<?> clazz = document.getValue().getClass(); try { JAXBContext context = JAXBContext.newInstance(clazz.getPackage().getName()); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(document, output); return true; } catch (JAXBException e) { e.printStackTrace(System.err); return false; } }
/** * XML转对象 * @param xmlStr xml字串 * @param t 对象类型 * @return 对象 */ @SuppressWarnings("unchecked") public static <T> T xmlToBean(String xmlStr, Class<T> t) { try { JAXBContext context = JAXBContext.newInstance(t); Unmarshaller unmarshaller = context.createUnmarshaller(); return (T) unmarshaller.unmarshal(new StringReader(xmlStr)); } catch (JAXBException e) { e.printStackTrace(); return null; } }
public static SearchresultsType unmarshalSearch(String string) throws JAXBException { try (StringReader reader = new StringReader(string)){ @SuppressWarnings("unchecked") JAXBElement<SearchresultsType> unmarshal = (JAXBElement<SearchresultsType>) newUnmarshallerSearch().unmarshal(reader); return unmarshal.getValue(); } catch (ClassCastException e) { throw new JAXBException("Parse error: " + e, e); } }
public static CustomReportType unmarshalCR(String reportXML) throws RaptorException { //CustomReport cr = null; try { JAXBContext jc = JAXBContext.newInstance("org.onap.portalsdk.analytics.xmlobj"); Unmarshaller u = jc.createUnmarshaller(); javax.xml.bind.JAXBElement<CustomReportType> doc = (javax.xml.bind.JAXBElement<CustomReportType>) u.unmarshal(new java.io.StringReader( reportXML)); return doc.getValue(); } catch (JAXBException ex) { ex.printStackTrace(); throw new RaptorException (ex.getMessage(), ex.getCause()); } } // unmarshal
public T convert(String xml) throws JAXBException { final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); URL schemaURL = initSchemaURL(); try { unmarshaller.setSchema(SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(schemaURL)); } catch (SAXException e) { throw new JAXBException("Error while initializing schema from URL " + schemaURL, e); } return (T) unmarshaller.unmarshal(new StringReader(xml)); }
private Tenants unmarshallTenants() throws JAXBException { final Unmarshaller unmarshaller = JAXB_TENANTS_CONTEXT.createUnmarshaller(); unmarshaller.setSchema(tenantsSchema); try { final XMLStreamReader xsr = XmlUtils.createSafeReader(new StreamSource(tenantsFile)); final JAXBElement<Tenants> element = unmarshaller.unmarshal(xsr, Tenants.class); return element.getValue(); } catch (XMLStreamException e) { throw new JAXBException("Error unmarshalling tenants", e); } }
public static User fromXml(String xml) { InputStream in = null; try { in = IOUtils.toInputStream(xml); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); return unmarshaller.unmarshal(new StreamSource(in), JaxbUser.class).getValue(); } catch (JAXBException e) { throw new IllegalStateException(e.getLinkedException() != null ? e.getLinkedException() : e); } finally { IOUtils.closeQuietly(in); } }
final JAXBContext jaxbContext = JAXBContext.newInstance( ObjectFactory.class ); final Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.marshal( report, reportFile ); exceptionMessages.append( e.getMessage() );
public static void enteredTc(BindingTraverserState btState, NodeIterator nodeIterator) { Node n = nodeIterator.nextNode(); //It is never null if (n!=null) { try { Unmarshaller u = Context.jc.createUnmarshaller(); u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); Object jaxb = u.unmarshal(n); btState.tcStack.push( (Tc)jaxb ); } catch (ClassCastException e) { log.error("Couldn't cast to RPr!"); } catch (JAXBException e) { log.error(e.getMessage(), e); } } }
@Override protected Object readFromSource(Class<?> clazz, HttpHeaders headers, Source source) throws Exception { try { source = processSource(source); Unmarshaller unmarshaller = createUnmarshaller(clazz); if (clazz.isAnnotationPresent(XmlRootElement.class)) { return unmarshaller.unmarshal(source); } else { JAXBElement<?> jaxbElement = unmarshaller.unmarshal(source, clazz); return jaxbElement.getValue(); } } catch (NullPointerException ex) { if (!isSupportDtd()) { throw new IllegalStateException("NPE while unmarshalling. " + "This can happen due to the presence of DTD declarations which are disabled.", ex); } throw ex; } catch (UnmarshalException ex) { throw ex; } catch (JAXBException ex) { throw new HttpMessageConversionException("Invalid JAXB setup: " + ex.getMessage(), ex); } }
public ExternalMessage<?> read(Document doc) throws CoreException { ExternalMessage<?> res = null; JAXBElement<Texternalmessage> jmess = null; try { jmess = ViperJAXBContext.getInstance().getJaxbContext().createUnmarshaller().unmarshal(doc, Texternalmessage.class); res = new ExternalMessageImpl(jmess.getValue(), null); } catch (JAXBException e) { throw new CoreException(e.getMessage()); } return res; }
ctx = JAXBContext.newInstance(classes); obj = ctx.createUnmarshaller().unmarshal(getElement()); } catch (PrivilegedActionException pae) throw new JAXBException(pae); jaxbObject = ((JAXBElement) obj).getValue(); return (T) jaxbObject;
Object jaxb = null; try { Unmarshaller u = Context.jc.createUnmarshaller(); u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); jaxb = u.unmarshal(n); } catch (JAXBException e1) { e1.printStackTrace(); if (jb.getDeclaredType() .getName() .equals("org.docx4j.dml.wordprocessingDrawing.Inline")) { this.inline = (Inline) jb.getValue(); } else if (jb .getDeclaredType() .getName() .equals("org.docx4j.dml.wordprocessingDrawing.Anchor")) {
private static String toXml(Statistics stats) { try { JAXBContext context = JAXBContext.newInstance(StatisticsEntity.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); StringWriter writer = new StringWriter(); marshaller.marshal(StatisticsEntity.from(stats), writer); return writer.toString(); } catch (JAXBException ex) { // don't do this in real live return ex.toString(); } }
public void marshal(java.io.OutputStream os) throws JAXBException { try { Marshaller marshaller = Context.jcContentTypes.createMarshaller(); NamespacePrefixMapperUtils.setProperty(marshaller, NamespacePrefixMapperUtils.getPrefixMapper() ); log.debug("marshalling " + this.getClass().getName() + " ..." ); marshaller.marshal(buildTypes(), os); } catch (JAXBException e) { //e.printStackTrace(); log.error(e.getMessage(), e); throw e; } }
testContext = JAXBContext.newInstance("org.docx4j.relationships",classLoader ); throw new JAXBException("Couldn't create context for org.docx4j.relationships. Everything is broken!"); Marshaller m=testContext.createMarshaller(); m.setProperty("com.sun.xml.internal.bind.namespacePrefixMapper", c.newInstance() ); log.info("Using NamespacePrefixMapperSunInternal, which is suitable for Java 6"); prefixMapper = c.newInstance();
public static ClusterNodeInformation unmarshal(final InputStream is) throws JAXBException { try { final Unmarshaller unmarshaller = JAXB_CONTEXT.createUnmarshaller(); final XMLStreamReader xsr = XmlUtils.createSafeReader(is); return (ClusterNodeInformation) unmarshaller.unmarshal(xsr); } catch (XMLStreamException e) { throw new JAXBException("Error unmarshalling the cluster node information", e); } } }
public void save(File file) { try { JAXBContext jaxbContext = JAXBContext.newInstance(JarSettings.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.marshal(this, file); } catch (JAXBException e) { e.printStackTrace(); } }