當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。