本文整理匯總了Java中javax.xml.bind.Unmarshaller類的典型用法代碼示例。如果您正苦於以下問題:Java Unmarshaller類的具體用法?Java Unmarshaller怎麽用?Java Unmarshaller使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Unmarshaller類屬於javax.xml.bind包,在下文中一共展示了Unmarshaller類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getGameFileFromFile
import javax.xml.bind.Unmarshaller; //導入依賴的package包/類
private static GameFile getGameFileFromFile(String file) throws JAXBException, IOException {
final JAXBContext jaxbContext = JAXBContext.newInstance(GameFile.class);
final Unmarshaller um = jaxbContext.createUnmarshaller();
try (InputStream inputStream = FileUtilities.getGameResource(file)) {
// try to get compressed game file
final GZIPInputStream zipStream = new GZIPInputStream(inputStream);
return (GameFile) um.unmarshal(zipStream);
} catch (final ZipException e) {
// if it fails to load the compressed file, get it from plain XML
InputStream stream = null;
stream = FileUtilities.getGameResource(file);
if (stream == null) {
return null;
}
return (GameFile) um.unmarshal(stream);
}
}
示例2: testNegativeCustomFilter
import javax.xml.bind.Unmarshaller; //導入依賴的package包/類
@Test
public void testNegativeCustomFilter() throws IOException, JAXBException {
StringBuilder builder = new StringBuilder();
builder = new StringBuilder();
builder.append("/b*");
builder.append("?");
builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
builder.append("&");
builder.append(Constants.SCAN_FILTER + "=" + URLEncoder.encode("CustomFilter('abc')", "UTF-8"));
Response response =
client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML);
assertEquals(200, response.getCode());
JAXBContext ctx = JAXBContext.newInstance(CellSetModel.class);
Unmarshaller ush = ctx.createUnmarshaller();
CellSetModel model = (CellSetModel) ush.unmarshal(response.getStream());
int count = TestScannerResource.countCellSet(model);
// Should return no rows as the filters conflict
assertEquals(0, count);
}
示例3: loadSimSetup
import javax.xml.bind.Unmarshaller; //導入依賴的package包/類
/**
* Loads the simulation setup with the specified name
* @param setupName The setup to be loaded
* @return The setup
* @throws JAXBException Parsing the setup file failed
* @throws IOException Reading the setup file failed
*/
private SimulationSetup loadSimSetup(String setupName) throws JAXBException, IOException {
// --- Determine the setup file path ----------
String setupFileName = this.project.getSimulationSetups().get(setupName);
String setupFileFullPath = this.project.getSubFolder4Setups(true) + File.separator + setupFileName;
File setupFile = new File(setupFileFullPath);
// --- Load the setup -------------
JAXBContext pc;
SimulationSetup simSetup = null;
pc = JAXBContext.newInstance(this.project.getSimulationSetups().getCurrSimSetup().getClass());
Unmarshaller um = pc.createUnmarshaller();
FileReader fr = new FileReader(setupFile);
simSetup = (SimulationSetup) um.unmarshal(fr);
fr.close();
return simSetup;
}
示例4: apply
import javax.xml.bind.Unmarshaller; //導入依賴的package包/類
/**
* Applies the additional binding customizations.
*/
public void apply(XSSchemaSet schema, ErrorReceiver errorReceiver) {
if(topLevel!=null) {
this.errorReceiver = errorReceiver;
Unmarshaller u = BindInfo.getCustomizationUnmarshaller();
this.unmarshaller = u.getUnmarshallerHandler();
ValidatorHandler v = BindInfo.bindingFileSchema.newValidator();
v.setErrorHandler(errorReceiver);
loader = new ForkContentHandler(v,unmarshaller);
topLevel.applyAll(schema.getSchemas());
this.loader = null;
this.unmarshaller = null;
this.errorReceiver = null;
}
}
示例5: main
import javax.xml.bind.Unmarshaller; //導入依賴的package包/類
public static void main(String[] args) throws JAXBException {
String xmlData =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
"<shop>\n" +
" <goods>\n" +
" <names>S1</names>\n" +
" <names>S2</names>\n" +
" </goods>\n" +
" <count>12</count>\n" +
" <profit>123.4</profit>\n" +
" <secretData>String1</secretData>\n" +
" <secretData>String2</secretData>\n" +
" <secretData>String3</secretData>\n" +
" <secretData>String4</secretData>\n" +
" <secretData>String5</secretData>\n" +
"</shop>";
StringReader reader = new StringReader(xmlData);
JAXBContext context = JAXBContext.newInstance(getClassName());
Unmarshaller unmarshaller = context.createUnmarshaller();
Object o = unmarshaller.unmarshal(reader);
System.out.println(o.toString());
}
示例6: readFrom
import javax.xml.bind.Unmarshaller; //導入依賴的package包/類
@Override
public CharmAttachmentMeta readFrom(Class<CharmAttachmentMeta> type, Type genericType, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
throws IOException, WebApplicationException {
try {
JAXBContext context = JAXBContext.newInstance(CharmAttachmentMeta.class);
Unmarshaller attachmentUnmarshaller = context.createUnmarshaller();
return (CharmAttachmentMeta) attachmentUnmarshaller.unmarshal(entityStream);
} catch (JAXBException e) {
throw new ProcessingException("Error deserializing Attachment");
}
}
示例7: generateDetailedReport
import javax.xml.bind.Unmarshaller; //導入依賴的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);
String htmlDetailedReport = service.generateDetailedReport(writer.toString());
assertTrue(Utils.isStringNotEmpty(htmlDetailedReport));
logger.debug("Detailed report html : " + htmlDetailedReport);
}
示例8: parseAPDSStatusMessage
import javax.xml.bind.Unmarshaller; //導入依賴的package包/類
@Override
protected void parseAPDSStatusMessage(Tracon tracon, String messageText) {
long timestamp = System.currentTimeMillis();
AirportDataServiceStatus apdsMessage = null;
try {
JAXBContext context = JAXBContext.newInstance(AirportDataServiceStatus.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
StringReader reader = new StringReader(messageText);
apdsMessage = (AirportDataServiceStatus) unmarshaller.unmarshal(reader);
} catch (Exception e) {
e.printStackTrace();
}
Service service = tracon.getService(Constants.APDS);
if ((service == null) && (DYNAMIC_MODE)) {
service = new Service();
service.setName(Constants.APDS);
tracon.addService(service);
}
if (service != null) {
service.setTimeStamp(timestamp);
RVRExternalLinks rvrLinks = apdsMessage.getRvrLinks();
if (rvrLinks != null) {
for (ExternalLink exLink : rvrLinks.getRvrLink()) {
handleLink(timestamp, service, tracon.getName(), exLink);
}
}
// Don't set the service status if not configured for override
boolean changed = false;
if (!OVERRIDE_STATUS) {
changed = service.setStatus(getMessageStatus(apdsMessage.getServiceStatus()));
} else {
changed = service.refreshStatus();
}
if (changed) {
notificationRepo.save(new Notification(timestamp, service.getStatus(),
service.getName(), tracon.getName(), NotificationType.SERVICE));
}
}
}
示例9: readFrom
import javax.xml.bind.Unmarshaller; //導入依賴的package包/類
@Override
public CharmTask readFrom(Class<CharmTask> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
throws IOException, WebApplicationException {
try {
JAXBContext context = JAXBContext.newInstance(CharmTask.class);
Unmarshaller taskUnmarshaller = context.createUnmarshaller();
return (CharmTask) taskUnmarshaller.unmarshal(entityStream);
} catch (JAXBException e) {
throw new ProcessingException("Error deserializing Task");
}
}
示例10: unmarshal
import javax.xml.bind.Unmarshaller; //導入依賴的package包/類
/**
* Load SheetAnnotations from the annotations XML file.
*
* @param path to the XML input file.
* @return the unmarshalled SheetAnnotations object
* @throws IOException in case of IO problem
*/
public static SheetAnnotations unmarshal (Path path)
throws IOException
{
logger.debug("SheetAnnotations unmarshalling {}", path);
try {
InputStream is = Files.newInputStream(path, StandardOpenOption.READ);
Unmarshaller um = getJaxbContext().createUnmarshaller();
SheetAnnotations sheetInfo = (SheetAnnotations) um.unmarshal(is);
logger.debug("Unmarshalled {}", sheetInfo);
is.close();
return sheetInfo;
} catch (JAXBException ex) {
logger.warn("Error unmarshalling " + path + " " + ex, ex);
return null;
}
}
示例11: getMilestoneCreationDate
import javax.xml.bind.Unmarshaller; //導入依賴的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();
}
示例12: doImportFromXmlNode
import javax.xml.bind.Unmarshaller; //導入依賴的package包/類
/**
* Imports a {@link StvsRootModel} from {@code source}.
*
* @param source Node to import
* @return imported model
* @throws ImportException Exception while importing.
*/
@Override
public StvsRootModel doImportFromXmlNode(Node source) throws ImportException {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Session importedSession =
((JAXBElement<Session>) jaxbUnmarshaller.unmarshal(source)).getValue();
// Code
Code code = new Code();
code.updateSourcecode(importedSession.getCode().getPlaintext());
VerificationScenario scenario = new VerificationScenario(code);
List<Type> typeContext = Optional.ofNullable(code.getParsedCode())
.map(ParsedCode::getDefinedTypes).orElse(Arrays.asList(TypeInt.INT, TypeBool.BOOL));
// Tabs
List<HybridSpecification> hybridSpecs = importTabs(importedSession, typeContext);
return new StvsRootModel(hybridSpecs, currentConfig, currentHistory, scenario,
new File(System.getProperty("user.home")), "");
} catch (JAXBException e) {
throw new ImportException(e);
}
}
示例13: unmarshalManifest
import javax.xml.bind.Unmarshaller; //導入依賴的package包/類
public void unmarshalManifest() {
Manifest man=new Manifest();
File manifest = new File(this.manifestFile);
try {
JAXBContext context = JAXBContext.newInstance(Manifest.class);
Unmarshaller jaxbUnmarshaller = context.createUnmarshaller();
man = (Manifest) jaxbUnmarshaller.unmarshal(manifest);
}
catch(Exception e)
{
System.out.println("ERROR: Manifest cannot be parsed");
e.printStackTrace();
}
this.manifest = man;
}
示例14: setConfFile
import javax.xml.bind.Unmarshaller; //導入依賴的package包/類
public void setConfFile(String confFile) throws Exception {
this.confFile = confFile;
Object root;
try {
JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
Unmarshaller jaxbUnmarshaller = context.createUnmarshaller();
final SchemaFactory schemaFact = SchemaFactory.newInstance(
javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
URL url = ObjectFactory.class.getResource("/xsd/httpserver.xsd");
jaxbUnmarshaller.setSchema(schemaFact.newSchema(url));
root = jaxbUnmarshaller.unmarshal(new File(confFile));
} catch (Exception ex) {
throw new Exception("parsing config file failed, message: " + ex.getMessage(), ex);
}
if (root instanceof Httpservers) {
this.conf = (Httpservers) root;
} else if (root instanceof JAXBElement) {
this.conf = (Httpservers) ((JAXBElement<?>) root).getValue();
} else {
throw new Exception("invalid root element type");
}
}
示例15: createHydrographDebugInfo
import javax.xml.bind.Unmarshaller; //導入依賴的package包/類
/**
* Creates the object of type {@link HydrographDebugInfo} from the graph xml of type
* {@link Document}.
* <p>
* The method uses jaxb framework to unmarshall the xml document
*
* @param graphDocument the xml document with all the graph contents to unmarshall
* @return an object of type {@link HydrographDebugInfo}
* @throws SAXException
*/
public static HydrographDebugInfo createHydrographDebugInfo(Document graphDocument, String debugXSDLocation) throws SAXException {
try {
LOG.trace("Creating DebugJAXB object.");
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(ClassLoader.getSystemResource(debugXSDLocation));
JAXBContext context = JAXBContext.newInstance(Debug.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setSchema(schema);
unmarshaller.setEventHandler(new ComponentValidationEventHandler());
Debug debug = (Debug) unmarshaller.unmarshal(graphDocument);
HydrographDebugInfo hydrographDebugInfo = new HydrographDebugInfo(debug);
LOG.trace("DebugJAXB object created successfully");
return hydrographDebugInfo;
} catch (JAXBException e) {
LOG.error("Error while creating JAXB objects from debug XML.", e);
throw new RuntimeException("Error while creating JAXB objects from debug XML.", e);
}
}