JAXBContext jaxbContext = JAXBContext.newInstance(Person.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); StringReader reader = new StringReader("xml string here"); Person person = (Person) unmarshaller.unmarshal(reader);
static Unmarshaller getUnmarsheller() throws JAXBException { if (versionClusterUnmarshaller == null) { RemoteAdmin.versionClusterUnmarshaller = JAXBContext.newInstance( StorageClusterVersionModel.class).createUnmarshaller(); } return RemoteAdmin.versionClusterUnmarshaller; }
package forum11221136; import java.io.File; import javax.xml.bind.*; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Tests.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); File xml = new File("src/forum11221136/input.xml"); Tests tests = (Tests) unmarshaller.unmarshal(xml); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(tests, System.out); } }
final File configFile = new File(file); = JAXBContext.newInstance(Plugins.class, PluginDescription.class, PhasePluginDescription.class); final Unmarshaller unmarshaller = context.createUnmarshaller(); final Object root = unmarshaller.unmarshal(configFile);
JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); Customer customer = (Customer) jaxbUnmarshaller.unmarshal(new File("C:\\file.xml"));
final File authorizedUsersFile = new File(legacyAuthorizedUsersFile); if (!authorizedUsersFile.exists()) { throw new AuthorizerCreationException("Legacy Authorized Users File '" + legacyAuthorizedUsersFile + "' does not exists"); final Unmarshaller unmarshaller = JAXB_USERS_CONTEXT.createUnmarshaller(); unmarshaller.setSchema(usersSchema); final JAXBElement<org.apache.nifi.user.generated.Users> element = unmarshaller.unmarshal( xsr, org.apache.nifi.user.generated.Users.class); final org.apache.nifi.user.generated.Users users = element.getValue(); if (users.getUser().isEmpty()) { logger.info("Legacy Authorized Users File contained no users, nothing to convert");
@Override @SneakyThrows public FillerRuleDefinitionEntity load(final String fillerRuleDefinitionFile) { InputStream inputStream = FillerRuleDefinitionEntityLoader.class.getClassLoader().getResourceAsStream(fillerRuleDefinitionFile); Preconditions.checkNotNull(inputStream, "Cannot load SQL filler rule definition file :%s, ", fillerRuleDefinitionFile); return (FillerRuleDefinitionEntity) JAXBContext.newInstance(FillerRuleDefinitionEntity.class).createUnmarshaller().unmarshal(inputStream); } }
@Override public T convert(ResponseBody value) throws IOException { try { Unmarshaller unmarshaller = context.createUnmarshaller(); XMLStreamReader streamReader = xmlInputFactory.createXMLStreamReader(value.charStream()); return unmarshaller.unmarshal(streamReader, type).getValue(); } catch (JAXBException | XMLStreamException e) { throw new RuntimeException(e); } finally { value.close(); } } }
public static StandardSnippet deserialize(final InputStream inStream) { try { JAXBContext context = JAXBContext.newInstance(StandardSnippet.class); Unmarshaller unmarshaller = context.createUnmarshaller(); XMLStreamReader xsr = XmlUtils.createSafeReader(inStream); JAXBElement<StandardSnippet> snippetElement = unmarshaller.unmarshal(xsr, StandardSnippet.class); return snippetElement.getValue(); } catch (final JAXBException | XMLStreamException e) { throw new FlowSerializationException(e); } } }
@BeforeClass public static void setUpBeforeClass() throws Exception { conf = TEST_UTIL.getConfiguration(); conf.setBoolean(RESTServer.REST_CSRF_ENABLED_KEY, csrfEnabled); extraHdr = new BasicHeader(RESTServer.REST_CSRF_CUSTOM_HEADER_DEFAULT, ""); TEST_UTIL.startMiniCluster(); REST_TEST_UTIL.startServletContainer(conf); context = JAXBContext.newInstance( CellModel.class, CellSetModel.class, RowModel.class); marshaller = context.createMarshaller(); unmarshaller = context.createUnmarshaller(); client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())); Admin admin = TEST_UTIL.getAdmin(); if (admin.tableExists(TABLE)) { return; } HTableDescriptor htd = new HTableDescriptor(TABLE); htd.addFamily(new HColumnDescriptor(CFA)); htd.addFamily(new HColumnDescriptor(CFB)); admin.createTable(htd); }
public JaxbSolutionFileIO(Class... jaxbAnnotatedClasses) { try { JAXBContext jaxbContext = JAXBContext.newInstance(jaxbAnnotatedClasses); marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); unmarshaller = jaxbContext.createUnmarshaller(); } catch (JAXBException e) { throw new IllegalArgumentException("JAXB creation for classes (" + Arrays.toString(jaxbAnnotatedClasses) + ") has failed.", e); } }
Marshaller marshaller=jc.createMarshaller(); org.w3c.dom.Document doc = org.docx4j.XmlUtils.neww3cDomDocument(); marshaller.marshal(pkg, doc); Unmarshaller u = jc.createUnmarshaller(); u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); javax.xml.bind.util.JAXBResult result = new javax.xml.bind.util.JAXBResult(u );
package nov18; import java.io.File; import javax.xml.bind.*; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(FosterHome.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); FosterHome fosterHome = (FosterHome) unmarshaller.unmarshal(new File("src/nov18/input.xml")); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(fosterHome, System.out); } }
/** * Load a Sequitur FSA in XML format and store it in Sphinx' OpenFst * binary/serialized format. * * @param args * filename of input file, filename of output file * @throws JAXBException * indicating that XML could not be read * @throws IOException * indicating that file-handling does not work */ public static void main(String... args) throws JAXBException, IOException { JAXBContext context = JAXBContext.newInstance(FSA.class); Unmarshaller unmarshaller = context.createUnmarshaller(); FSA fsa = (FSA) unmarshaller.unmarshal(new File(args[0])); edu.cmu.sphinx.fst.Fst fst = fsa.toFst(); fst.saveModel(args[1]); System.out .println("The Sequitur G2P XML-formatted FST " + args[0] + " has been converted to Sphinx' OpenFst binary format in the file " + args[1]); // uncomment this to test your model: // edu.cmu.sphinx.linguist.g2p.G2PConverter d = new // edu.cmu.sphinx.linguist.g2p.G2PConverter(args[1]); // List<edu.cmu.sphinx.linguist.g2p.Path> path = // d.phoneticize("wahnsinn", 5); // System.err.println(path); } }
protected static org.docx4j.wml.P loadParagraph(String filename) throws Exception { java.io.File f = new java.io.File(filename); java.io.InputStream is = new java.io.FileInputStream(f); JAXBContext jc = org.docx4j.jaxb.Context.jc; Unmarshaller u = jc.createUnmarshaller(); //u.setSchema(org.docx4j.jaxb.WmlSchema.schema); u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); return (org.docx4j.wml.P)u.unmarshal( is ); }
final File authorizedUsersFile = new File(legacyAuthorizedUsersFile); if (!authorizedUsersFile.exists()) { throw new AuthorizerCreationException("Legacy Authorized Users File '" + legacyAuthorizedUsersFile + "' does not exists"); final Unmarshaller unmarshaller = JAXB_USERS_CONTEXT.createUnmarshaller(); unmarshaller.setSchema(usersSchema); throw new JAXBException("Error reading authorized users file", e); final JAXBElement<Users> element = unmarshaller.unmarshal( xsr, org.apache.nifi.user.generated.Users.class); final org.apache.nifi.user.generated.Users users = element.getValue(); if (users.getUser().isEmpty()) { logger.info("Legacy Authorized Users File contained no users, nothing to convert");
@Override @SneakyThrows public SQLStatementRuleDefinitionEntity load(final String sqlStatementRuleDefinitionFile) { InputStream inputStream = SQLStatementRuleDefinitionEntityLoader.class.getClassLoader().getResourceAsStream(sqlStatementRuleDefinitionFile); Preconditions.checkNotNull(inputStream, "Cannot load SQL statement rule definition file :%s, ", sqlStatementRuleDefinitionFile); return (SQLStatementRuleDefinitionEntity) JAXBContext.newInstance(SQLStatementRuleDefinitionEntity.class).createUnmarshaller().unmarshal(inputStream); } }
private Authorizations unmarshallAuthorizations() throws JAXBException { try { final XMLStreamReader xsr = XmlUtils.createSafeReader(new StreamSource(authorizationsFile)); final Unmarshaller unmarshaller = JAXB_AUTHORIZATIONS_CONTEXT.createUnmarshaller(); unmarshaller.setSchema(authorizationsSchema); final JAXBElement<Authorizations> element = unmarshaller.unmarshal(xsr, Authorizations.class); return element.getValue(); } catch (XMLStreamException e) { logger.error("Encountered an error reading authorizations file: ", e); throw new JAXBException("Error reading authorizations file", e); } }
/** * Convert a single CustomGeometry object, i.e. from xmlbeans */ public static CustomGeometry convertCustomGeometry(XMLStreamReader staxReader) { try { JAXBContext jaxbContext = JAXBContext.newInstance(BINDING_PACKAGE); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); JAXBElement<CTCustomGeometry2D> el = unmarshaller.unmarshal(staxReader, CTCustomGeometry2D.class); return new CustomGeometry(el.getValue()); } catch (JAXBException e) { LOG.log(POILogger.ERROR, "Unable to parse single custom geometry", e); return null; } }
RootElementClass adr = new RootElementClass(); FileInputStream adrFile = null; try { adrFile = new FileInputStream("test"); JAXBContext ctx = JAXBContext.newInstance(RootElementClass.class); Unmarshaller um = ctx.createUnmarshaller(); adr = (RootElementClass) um.unmarshal(adrFile); } catch(IOException exc) { } catch(JAXBException exc) { } finally { }