当前位置: 首页>>代码示例>>Java>>正文


Java Unmarshaller类代码示例

本文整理汇总了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);
  }
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:21,代码来源:GameFile.java

示例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);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:20,代码来源:TestTableScan.java

示例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;

}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:26,代码来源:ProjectExportController.java

示例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;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:SCDBasedBindingSet.java

示例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());
}
 
开发者ID:avedensky,项目名称:JavaRushTasks,代码行数:27,代码来源:Solution.java

示例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");
	}

}
 
开发者ID:theits,项目名称:CharmMylynConnector,代码行数:17,代码来源:CharmAttachmentMessageBodyReader.java

示例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);
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:17,代码来源:XSLTServiceTest.java

示例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));
		}
	}
}
 
开发者ID:mshaw323,项目名称:stdds-monitor,代码行数:41,代码来源:StatusMessageParserV4.java

示例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");
	}

}
 
开发者ID:theits,项目名称:CharmMylynConnector,代码行数:18,代码来源:CharmTaskMessageBodyReader.java

示例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;
    }
}
 
开发者ID:Audiveris,项目名称:omr-dataset-tools,代码行数:27,代码来源:SheetAnnotations.java

示例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();
}
 
开发者ID:oxygenxml,项目名称:oxygen-dita-translation-package-builder,代码行数:26,代码来源:MilestoneUtil.java

示例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);
  }
}
 
开发者ID:VerifAPS,项目名称:stvs,代码行数:33,代码来源:XmlSessionImporter.java

示例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;
}
 
开发者ID:ernw,项目名称:AndroTickler,代码行数:19,代码来源:XMLReader.java

示例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");
    }
}
 
开发者ID:xipki,项目名称:xitk,代码行数:26,代码来源:FileHttpServersConf.java

示例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);
    }
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:29,代码来源:DebugUtils.java


注:本文中的javax.xml.bind.Unmarshaller类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。