當前位置: 首頁>>代碼示例>>Java>>正文


Java Unmarshaller.unmarshal方法代碼示例

本文整理匯總了Java中javax.xml.bind.Unmarshaller.unmarshal方法的典型用法代碼示例。如果您正苦於以下問題:Java Unmarshaller.unmarshal方法的具體用法?Java Unmarshaller.unmarshal怎麽用?Java Unmarshaller.unmarshal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.xml.bind.Unmarshaller的用法示例。


在下文中一共展示了Unmarshaller.unmarshal方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: retrieveJAXB

import javax.xml.bind.Unmarshaller; //導入方法依賴的package包/類
/**
 * Non-validating
 *
 * @param path   path to input file
 * @param _class class of xml root object
 * @return root object
 */
public static Object retrieveJAXB(String path, Class _class) {
    Object obj = null;
    /*
        Block parser from reaching out externally see:
        https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Prevention_Cheat_Sheet#SAXTransformerFactory
    */
    try {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setFeature("http://xml.org/sax/features/external-general-entities", false);
        spf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
        spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);

        Source xmlSource = new SAXSource(spf.newSAXParser().getXMLReader(),
                new InputSource(new FileReader(new File(path))));
        JAXBContext jc = JAXBContext.newInstance(_class);
        Unmarshaller um = jc.createUnmarshaller();
        obj = um.unmarshal(xmlSource);
    } catch (JAXBException | FileNotFoundException | SAXException | ParserConfigurationException e) {
        e.printStackTrace();
    }
    return obj;
}
 
開發者ID:phweda,項目名稱:MFM,代碼行數:30,代碼來源:PersistUtils.java

示例2: loadAllMAME

import javax.xml.bind.Unmarshaller; //導入方法依賴的package包/類
private static Mame loadAllMAME() {
    Mame mame = null;
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(Mame.class);
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();

        if (MFM.isSystemDebug()) {
            jaxbUnmarshaller.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
        }

        Process process = MAMEexe.run("-listxml");
        InputStream inputStream = process.getInputStream();
        mame = (Mame) jaxbUnmarshaller.unmarshal(inputStream);
    } catch (JAXBException | MAMEexe.MAME_Exception e) {
        e.printStackTrace();
    }
    return mame;
}
 
開發者ID:phweda,項目名稱:MFM,代碼行數:19,代碼來源:ParseAllMachinesInfo.java

示例3: getByName

import javax.xml.bind.Unmarshaller; //導入方法依賴的package包/類
public ServiceDefinition getByName(String name) throws JAXBException, IOException {
	ServiceDefinition data = new ServiceDefinition();
	ArrayList<String> sDefs = util.getResourcesWithExtension("srvc", containerName);
	Unmarshaller unmarshaller = JAXBContext.newInstance(ServiceDefinition.class).createUnmarshaller();
	for (String sDef : sDefs) {
		File file = new File(sDef);
		if (file.exists() && StringUtils.contains(file.getName(), name)) {
			String content = FileUtils.readFileToString(file);
			data = (ServiceDefinition) unmarshaller.unmarshal(new StringReader(content));
			break;
		}
	}
	return data;
}
 
開發者ID:dstl,項目名稱:Open_Source_ECOA_Toolset_AS5,代碼行數:15,代碼來源:ServicesUtil.java

示例4: testSimpleFilter

import javax.xml.bind.Unmarshaller; //導入方法依賴的package包/類
@Test
public void testSimpleFilter() throws IOException, JAXBException {
  StringBuilder builder = new StringBuilder();
  builder = new StringBuilder();
  builder.append("/*");
  builder.append("?");
  builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
  builder.append("&");
  builder.append(Constants.SCAN_START_ROW + "=aaa");
  builder.append("&");
  builder.append(Constants.SCAN_END_ROW + "=aay");
  builder.append("&");
  builder.append(Constants.SCAN_FILTER + "=" + URLEncoder.encode("PrefixFilter('aab')", "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);
  assertEquals(1, count);
  assertEquals("aab", new String(model.getRows().get(0).getCells().get(0).getValue()));
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:24,代碼來源:TestTableScan.java

示例5: getWorkerXml

import javax.xml.bind.Unmarshaller; //導入方法依賴的package包/類
Manager getWorkerXml(final String balancerManagerContent) {
    Manager manager;
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(Manager.class);
        Unmarshaller unmarshal = jaxbContext.createUnmarshaller();
        manager = (Manager) unmarshal.unmarshal(IOUtils.toInputStream(balancerManagerContent));
        List<Manager.Balancer> balancers = manager.getBalancers();
        for (Manager.Balancer balancer : balancers) {
            LOGGER.info(balancer.getName());
            List<Manager.Balancer.Worker> balancer_workers = balancer.getWorkers();
            for (Manager.Balancer.Worker worker : balancer_workers) {
                LOGGER.info(worker.getName() + " " + worker.getRoute());
            }
        }
    } catch (JAXBException e) {
        LOGGER.error(e.toString());
        throw new ApplicationException("Failed to Parsing the Balancer Manager XML ", e);
    }
    return manager;
}
 
開發者ID:cerner,項目名稱:jwala,代碼行數:21,代碼來源:BalancerManagerXmlParser.java

示例6: 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

示例7: processRequest

import javax.xml.bind.Unmarshaller; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
// blocking
public <T> T processRequest(Object request, Class<T> responseClass, String soapUri, boolean needsAuthentification)
		throws Exception {
	SOAPConnection soapConnection = null;
	try {
		soapConnection = soapConnectionFactory.createConnection();
		SOAPMessage soapMessage = processSoapMessage(request, needsAuthentification);
		SOAPMessage soapResponse = soapConnection.call(soapMessage, soapUri);
		// get new each time? - no
		Unmarshaller unmarshaller = getUnmarshaller(responseClass);
		return (T) unmarshaller.unmarshal(soapResponse.getSOAPBody().extractContentAsDocument());
	} finally {
		if (soapConnection != null) {
			soapConnection.close();
		}
	}

}
 
開發者ID:D2Edev,項目名稱:onvifjava,代碼行數:21,代碼來源:SoapClient.java

示例8: unmarshalExtensionInfo

import javax.xml.bind.Unmarshaller; //導入方法依賴的package包/類
@Nullable
private ExtensionInfo unmarshalExtensionInfo(@NotNull final File file) {
    Validate.notNull(file);

    try {
        if (null == EXTENSION_INFO_JAXB_CONTEXT) {
            LOG.error(String.format(
                "Can not unmarshal '%s' because JAXBContext has not been created.", file.getAbsolutePath()
            ));

            return null;
        }

        final Unmarshaller jaxbUnmarshaller = EXTENSION_INFO_JAXB_CONTEXT.createUnmarshaller();

        return (ExtensionInfo) jaxbUnmarshaller.unmarshal(file);
    } catch (JAXBException e) {
        LOG.error("Can not unmarshal " + file.getAbsolutePath(), e);
    }

    return null;
}
 
開發者ID:AlexanderBartash,項目名稱:hybris-integration-intellij-idea-plugin,代碼行數:23,代碼來源:RegularHybrisModuleDescriptor.java

示例9: main

import javax.xml.bind.Unmarshaller; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    JAXBContext jc = JAXBContext.newInstance("testjaxbcontext");
    Unmarshaller u = jc.createUnmarshaller();
    Object result = u.unmarshal(new File(System.getProperty("test.src", ".") + "/test.xml"));
    StringWriter sw = new StringWriter();
    Marshaller m = jc.createMarshaller();
    m.marshal(result, sw);
    System.out.println("Expected:" + EXPECTED);
    System.out.println("Observed:" + sw.toString());
    if (!EXPECTED.equals(sw.toString())) {
        throw new Exception("Unmarshal/Marshal generates different content");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:14,代碼來源:Test.java

示例10: unmarshal

import javax.xml.bind.Unmarshaller; //導入方法依賴的package包/類
/**
 * @param <T> 戻り値としてほしいクラス
 * @param reader XML入力ストリーム
 * @param elementClass 要素クラス
 * @return unmarshalされたクラス
 * @throws IOException IO上の問題があったとき投げられる例外
 * @throws JAXBException JAXB上の問題があったとき投げられる例外
 */
@SuppressWarnings("unchecked")
public static <T> T unmarshal(final Reader reader, final Class<T> elementClass) throws IOException, JAXBException {
    Unmarshaller u = context.createUnmarshaller();
    Object object = u.unmarshal(reader);
    if (object instanceof JAXBElement) {
        object = ((JAXBElement<?>) object).getValue();
    }
    return (T) object;
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:18,代碼來源:ObjectIo.java

示例11: initInnerFucntion

import javax.xml.bind.Unmarshaller; //導入方法依賴的package包/類
/**.
	 * 初始化內置函數
	 * functionParam
	 */
	public static void initInnerFucntion() {
		
		FunctionXml xml=null;
		try {
			InputStream input = Core.class.getResourceAsStream("function.xml");
			JAXBContext context = JAXBContext.newInstance(FunctionXml.class,FunctionParam.class);
			Unmarshaller unmarshaller = context.createUnmarshaller(); 
			xml = (FunctionXml)unmarshaller.unmarshal(input);
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(0);
		}
		List<FunctionParam> xmlFuctions = xml.getFunctions();
		for(FunctionParam param:xmlFuctions){
			if(param.getFunctionType().indexOf("-mono-k")!=-1){
				Constants.LINE_LIST.add(param);
			}else if(param.getFunctionType().indexOf("-mono")!=-1){
				//如果min==max則為常數,係統沒有非常數的
				if(param.getMin()==param.getMax()){
					Constants.CONSTANT_LIST.add(param);
				}
			}else if(param.getFunctionType().indexOf("-sin")!=-1){
				Constants.SIN_LIST.add(param);
			}else if(param.getFunctionType().indexOf("-square")!=-1){
				Constants.SQUARE_LIST.add(param);
			}else if(param.getFunctionType().indexOf("-random")!=-1){
				Constants.RANDOM_LIST.add(param);
			}
		}
//		System.out.println("line:"+Constants.LINE_LIST.size());
//		System.out.println("sinList:"+Constants.SIN_LIST.size());
//		System.out.println("squareList:"+Constants.SQUARE_LIST.size());
//		System.out.println("randomList:"+Constants.RANDOM_LIST.size());
//		System.out.println("constantList:"+Constants.CONSTANT_LIST.size());
	}
 
開發者ID:dbiir,項目名稱:ts-benchmark,代碼行數:40,代碼來源:Core.java

示例12: unmarshalNode

import javax.xml.bind.Unmarshaller; //導入方法依賴的package包/類
/**
 * @param <T> 戻り値としてほしいクラス
 * @param node XMLノード
 * @param elementClass 要素クラス
 * @return unmarshalされたクラス
 * @throws IOException IO上の問題があったとき投げられる例外
 * @throws JAXBException JAXB上の問題があったとき投げられる例外
 */
@SuppressWarnings("unchecked")
public static <T> T unmarshalNode(final Node node, final Class<T> elementClass) throws IOException, JAXBException {
    Unmarshaller u = context.createUnmarshaller();
    Object object = u.unmarshal(node);
    if (object instanceof JAXBElement) {
        object = ((JAXBElement<?>) object).getValue();
    }
    return (T) object;
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:18,代碼來源:ObjectIo.java

示例13: getSelectedSimpleType

import javax.xml.bind.Unmarshaller; //導入方法依賴的package包/類
public Simple getSelectedSimpleType(String text, Class<Simple> clazz) throws JAXBException {
	Simple simple = new Simple();
	Unmarshaller unmarshaller = JAXBContext.newInstance(Library.class).createUnmarshaller();
	Library lib = (Library) unmarshaller.unmarshal(new StringReader(editorText));
	for (Object obj : lib.getTypes().getSimpleOrRecordOrConstant()) {
		if (obj instanceof Simple) {
			Simple temp = (Simple) obj;
			if (temp.getName().equalsIgnoreCase(text))
				simple = temp;
		}
	}
	return simple;
}
 
開發者ID:dstl,項目名稱:Open_Source_ECOA_Toolset_AS5,代碼行數:14,代碼來源:TypesUtil.java

示例14: unmarshallTenants

import javax.xml.bind.Unmarshaller; //導入方法依賴的package包/類
private Tenants unmarshallTenants() throws JAXBException {
    final Unmarshaller unmarshaller = JAXB_TENANTS_CONTEXT.createUnmarshaller();
    unmarshaller.setSchema(tenantsSchema);

    final JAXBElement<Tenants> element = unmarshaller.unmarshal(new StreamSource(tenantsFile), Tenants.class);
    return element.getValue();
}
 
開發者ID:apache,項目名稱:nifi-registry,代碼行數:8,代碼來源:FileUserGroupProvider.java

示例15: getSelectedEventOp

import javax.xml.bind.Unmarshaller; //導入方法依賴的package包/類
public Event getSelectedEventOp(String text, Class<Event> clazz) throws JAXBException {
	Event event = new Event();
	Unmarshaller unmarshaller = JAXBContext.newInstance(ServiceDefinition.class).createUnmarshaller();
	ServiceDefinition sDef = (ServiceDefinition) unmarshaller.unmarshal(new StringReader(editorText));
	for (Object obj : sDef.getOperations().getDataOrEventOrRequestresponse()) {
		if (obj instanceof Event) {
			Event temp = (Event) obj;
			if (temp.getName().equalsIgnoreCase(text))
				event = temp;
		}
	}
	return event;
}
 
開發者ID:dstl,項目名稱:Open_Source_ECOA_Toolset_AS5,代碼行數:14,代碼來源:ServicesUtil.java


注:本文中的javax.xml.bind.Unmarshaller.unmarshal方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。