本文整理汇总了Java中javax.xml.bind.JAXBContext.createUnmarshaller方法的典型用法代码示例。如果您正苦于以下问题:Java JAXBContext.createUnmarshaller方法的具体用法?Java JAXBContext.createUnmarshaller怎么用?Java JAXBContext.createUnmarshaller使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.bind.JAXBContext
的用法示例。
在下文中一共展示了JAXBContext.createUnmarshaller方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unMarshal
import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static Object unMarshal(InputStream is, Class<? extends Object> classz) {
Object objTmp = null;
try {
InputStreamReader inputStreamReader = new InputStreamReader(is);
JAXBContext jaxbContext = JAXBContext.newInstance(classz);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
XMLStreamReader xsr = XMLInputFactory.newFactory().createXMLStreamReader(inputStreamReader);
XMLReaderWithoutNamespace xr = new XMLReaderWithoutNamespace(xsr);
JAXBElement<Object> jaxbElement = (JAXBElement<Object>) jaxbUnmarshaller.unmarshal(xr, classz);
objTmp = jaxbElement.getValue();
} catch (Exception e) {
e.printStackTrace();
}
return objTmp;
}
示例2: getMilestoneCreationDate
import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
/**
* Loads the last creation date of the milestone file.
*
* @param rootDir The location of the "special file"(milestone file).
*
* @return The last creation date of the "special file"(milestone).
*
* @throws JAXBException Problems with JAXB, serialization/deserialization of a file.
*/
public static Date getMilestoneCreationDate(URL rootMap) throws JAXBException, IOException {
File rootMapFile = getFile(rootMap);
File milestoneFile = new File(rootMapFile.getParentFile(),MilestoneUtil.getMilestoneFileName(rootMapFile));
if (!milestoneFile.exists()) {
throw new IOException("No milestone was created.");
}
JAXBContext jaxbContext = JAXBContext.newInstance(InfoResources.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
InfoResources resources = (InfoResources) jaxbUnmarshaller.unmarshal(milestoneFile);
return resources.getMilestoneCreation();
}
示例3: fetchUniprotEntry
import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
/**
* Method fetching data from UniProt
*
* @param geneId gene id in any database
* @throws ExternalDbUnavailableException
*/
public Uniprot fetchUniprotEntry(String geneId) throws ExternalDbUnavailableException {
ParameterNameValue[] params = new ParameterNameValue[]{new ParameterNameValue("query", geneId),
new ParameterNameValue("format", "xml")};
String location = UNIPROT_SERVER + UNIPROT_TOOL + "/?";
String uniprotData = httpDataManager.fetchData(location, params);
try {
JAXBContext jaxbContext = JAXBContext.newInstance("com.epam.catgenome.manager.externaldb.bindings.uniprot");
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
StringReader reader = new StringReader(uniprotData);
Object uniprotObject = unmarshaller.unmarshal(reader);
if (uniprotObject instanceof Uniprot) {
fetchedUniprotData = (Uniprot) uniprotObject;
}
return fetchedUniprotData;
} catch (JAXBException e) {
throw new ExternalDbUnavailableException("Unexpected result format", e);
}
}
示例4: readFrom
import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
public AccessToken readFrom(Class<AccessToken> type, Type genericType, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
throws IOException, WebApplicationException {
try {
JAXBContext jc = JAXBContext.newInstance(AccessToken.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
// Set it to true if you need to include the JSON root element in
// the
// JSON input
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
StreamSource streamSource = new StreamSource(entityStream);
AccessToken accessToken = unmarshaller.unmarshal(streamSource, AccessToken.class).getValue();
return accessToken;
} catch (JAXBException e) {
LOG.error("can't unmarshall response",e);
throw new RuntimeException("can't unmarshall response");
}
}
示例5: loadMetroConfig
import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
private static MetroConfig loadMetroConfig(@NotNull URL resourceUrl) {
MetroConfig result = null;
try {
JAXBContext jaxbContext = createJAXBContext();
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
XMLInputFactory factory = XmlUtil.newXMLInputFactory(true);
final JAXBElement<MetroConfig> configElement = unmarshaller.unmarshal(factory.createXMLStreamReader(resourceUrl.openStream()), MetroConfig.class);
result = configElement.getValue();
} catch (Exception e) {
LOGGER.warning(TubelineassemblyMessages.MASM_0010_ERROR_READING_CFG_FILE_FROM_LOCATION(resourceUrl.toString()), e);
}
return result;
}
示例6: process
import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
@Override
public void process(ProcessingContext<Corpus> ctx, Corpus corpus) throws ModuleException {
Logger logger = getLogger(ctx);
try {
// logger.info("creating the External module object ");
TEESClassifyExternal teesClassifyExt = new TEESClassifyExternal(ctx);
// logger.info("producing a interaction xml ");
JAXBContext jaxbContext = JAXBContext.newInstance(CorpusTEES.class);
Marshaller jaxbm = jaxbContext.createMarshaller();
jaxbm.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbm.marshal(this.prepareTEESCorpora(ctx, corpus), teesClassifyExt.getInput());
logger.info("Predicting with TEES");
callExternal(ctx, "run-tees-predict", teesClassifyExt, INTERNAL_ENCODING, "tees-classify.py");
logger.info("Reading TEES output");
Unmarshaller jaxbu = jaxbContext.createUnmarshaller();
CorpusTEES corpusTEES = (CorpusTEES) jaxbu.unmarshal(teesClassifyExt.getPredictionFile());
// logger.info("adding detected relations to Corpus ");
setRelations2CorpusAlvis(corpusTEES);
logger.info("number of documents : " + corpusTEES.getDocument().size());
}
catch (JAXBException|IOException e) {
rethrow(e);
}
}
示例7: getPolicyConfig
import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
/**
* Gets the policy config.
*
* @return the policy config
* @throws RuntimeException
* the runtime exception
* @throws SAXException
* the SAX exception
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public PolicyConfig getPolicyConfig() throws RuntimeException, SAXException, IOException {
if(policyConfig !=null){
return policyConfig;
}
else{
try{
JAXBContext jaxbContext = JAXBContext.newInstance(PolicyConfig.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setExpandEntityReferences(false);
dbf.setFeature(Constants.DISALLOW_DOCTYPE_DECLARATION,true);
DocumentBuilder builder = dbf.newDocumentBuilder();
String[] configFileList = getFilteredFiles(CONFIG_FILES_PATH + SEPARATOR + Messages.XMLConfigUtil_POLICY, getFileNameFilter(Messages.XMLConfigUtil_FILE_EXTENTION));
for (int i = 0; i < configFileList.length; i++) {
if(validateXMLSchema(POLICY_CONFIG_XSD_PATH, CONFIG_FILES_PATH + SEPARATOR + Messages.XMLConfigUtil_POLICY + SEPARATOR + configFileList[i])) {
Document document = builder.parse(new File(CONFIG_FILES_PATH + SEPARATOR
+ Messages.XMLConfigUtil_POLICY + SEPARATOR + configFileList[i]));
policyConfig = (PolicyConfig) unmarshaller.unmarshal(document);
builder.reset();
}
}
return policyConfig;
}catch(JAXBException | SAXException | IOException | ParserConfigurationException exception){
Status status = new Status(IStatus.ERROR,Activator.PLUGIN_ID, "XML read failed", exception);
StatusManager.getManager().handle(status, StatusManager.BLOCK);
logger.error(exception.getMessage());
throw new RuntimeException("Faild in reading XML Config files", exception); //$NON-NLS-1$
}
}
}
示例8: getPayload
import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
@Override
public Object getPayload(JAXBContext context) {
// if(context == ctxt) {
// return o;
// }
try {
Source payloadSrc = getPayload();
if (payloadSrc == null)
return null;
Unmarshaller unmarshaller = context.createUnmarshaller();
return unmarshaller.unmarshal(payloadSrc);
} catch (JAXBException e) {
throw new WebServiceException(e);
}
}
示例9: loadConfig
import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
private void loadConfig(ServletContext servletContext) {
try {
final JAXBContext context = JAXBContext
.newInstance(RoleBasedFilterConfig.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
StreamSource source = new StreamSource(
servletContext.getResourceAsStream(CONFIG_FILE_LOCATION));
config = unmarshaller.unmarshal(source, RoleBasedFilterConfig.class)
.getValue();
} catch (JAXBException e) {
throw new IllegalArgumentException(e);
}
}
示例10: deSerialize
import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
public static MintleafConfiguration deSerialize(String configFileName) throws MintleafException {
MintleafReader reader = new TextContentStreamReader(configFileName);
reader.read();
try {
JAXBContext jc = JAXBContext.newInstance(MintleafXmlConfiguration.class);
Unmarshaller marshaller = jc.createUnmarshaller();
StringReader sr = new StringReader(reader.toString());
MintleafXmlConfiguration configurationRoot = (MintleafXmlConfiguration) marshaller.unmarshal(sr);
return configurationRoot;
} catch (JAXBException e) {
throw new MintleafException(e);
}
}
示例11: makeTabs
import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
/**
* Extracts the tabs from the {@link StvsRootModel} and converts them into {@link Session.Tabs}.
*
* @param source model to export the tabs from
* @return exported tabs
* @throws ExportException exception while exporting
*/
private Session.Tabs makeTabs(StvsRootModel source) throws ExportException {
try {
Session.Tabs tabs = objectFactory.createSessionTabs();
for (int i = 0; i < source.getHybridSpecifications().size(); i++) {
HybridSpecification hybridSpec = source.getHybridSpecifications().get(i);
// One tab corresponds to one HybridSpecification
Tab tab = objectFactory.createTab();
tab.setId(BigInteger.valueOf(i));
tab.setReadOnly(!hybridSpec.isEditable());
tab.setOpen(false);
Node constraintSpecNode = constraintSpecExporter.exportToXmlNode(hybridSpec);
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
SpecificationTable constraintSpec =
((JAXBElement<SpecificationTable>) jaxbUnmarshaller.unmarshal(constraintSpecNode))
.getValue();
tab.getSpecification().add(constraintSpec);
ConcreteSpecification concreteSpecification = null;
if (hybridSpec.getConcreteInstance().isPresent()) {
concreteSpecification = hybridSpec.getConcreteInstance().get();
} else if (hybridSpec.getCounterExample().isPresent()) {
concreteSpecification = hybridSpec.getCounterExample().get();
}
if (concreteSpecification != null) {
Node concreteSpecNode = concreteSpecExporter.exportToXmlNode(concreteSpecification);
SpecificationTable concreteSpec =
((JAXBElement<SpecificationTable>) jaxbUnmarshaller.unmarshal(concreteSpecNode))
.getValue();
tab.getSpecification().add(concreteSpec);
}
tabs.getTab().add(tab);
}
return tabs;
} catch (JAXBException exception) {
throw new ExportException(exception);
}
}
示例12: loadStateMachine
import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
private States loadStateMachine(String filename)
throws StateMachineException {
logger.debug("filename: " + filename);
ClassLoader loader = Thread.currentThread().getContextClassLoader();
try (InputStream stream = loader.getResourceAsStream("statemachines/"
+ filename);) {
JAXBContext jaxbContext = JAXBContext.newInstance(States.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
return (States) jaxbUnmarshaller.unmarshal(stream);
} catch (Exception e) {
throw new StateMachineException(
"Failed to load state machine definition file: " + filename,
e);
}
}
示例13: paresManfiest
import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
public static Manifest paresManfiest(File manifestFile) throws JAXBException {
String manifestXml = AXMLPrint.decodeManifest(manifestFile);
JAXBContext context = JAXBContext.newInstance(Manifest.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
InputStream stream = new ByteArrayInputStream(manifestXml.getBytes(StandardCharsets.UTF_8));
Manifest manifest = (Manifest) unmarshaller.unmarshal(stream);
return manifest;
}
示例14: generateSimpleReportMulti
import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
@Test
public void generateSimpleReportMulti() throws Exception {
JAXBContext context = JAXBContext.newInstance(SimpleReport.class.getPackage().getName());
Unmarshaller unmarshaller = context.createUnmarshaller();
Marshaller marshaller = context.createMarshaller();
SimpleReport simpleReport = (SimpleReport) unmarshaller.unmarshal(new File("src/test/resources/simple-report-multi-signatures.xml"));
assertNotNull(simpleReport);
StringWriter writer = new StringWriter();
marshaller.marshal(simpleReport, writer);
FileOutputStream fos = new FileOutputStream("target/simpleReportMulti.pdf");
service.generateSimpleReport(writer.toString(), fos);
}
示例15: generateDetailedReport
import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
@Test
public void generateDetailedReport() throws Exception {
JAXBContext context = JAXBContext.newInstance(DetailedReport.class.getPackage().getName());
Unmarshaller unmarshaller = context.createUnmarshaller();
Marshaller marshaller = context.createMarshaller();
DetailedReport detailedReport = (DetailedReport) unmarshaller.unmarshal(new File("src/test/resources/detailedReport.xml"));
assertNotNull(detailedReport);
StringWriter writer = new StringWriter();
marshaller.marshal(detailedReport, writer);
FileOutputStream fos = new FileOutputStream("target/detailedReport.pdf");
service.generateDetailedReport(writer.toString(), fos);
}