本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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()));
}
示例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;
}
示例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());
}
示例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();
}
}
}
示例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");
}
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}