• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Unmarshaller类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.exolab.castor.xml.Unmarshaller的典型用法代码示例。如果您正苦于以下问题:Java Unmarshaller类的具体用法?Java Unmarshaller怎么用?Java Unmarshaller使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Unmarshaller类属于org.exolab.castor.xml包,在下文中一共展示了Unmarshaller类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: unMarshallString

import org.exolab.castor.xml.Unmarshaller; //导入依赖的package包/类
public static Object unMarshallString(Reader reader, Class objectClass) throws IOException {
    Unmarshaller unmarshaller = new Unmarshaller(objectClass);
    Object castor;
    try {
        InputSource is = new InputSource(reader);
        is.setSystemId("stringBuffer");
        castor = unmarshaller.unmarshal(is);
        reader.close();
    } catch (MarshalException marshalException) {
        //TODO Juzer throw proper exception so that calling function can handle it
        throw new IOException(marshalException.getMessage());
    } catch (ValidationException validationException) {
        throw new IOException(validationException.getMessage());
    }
    return castor;
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:17,代码来源:UncertaintyReader.java


示例2: getStatisticDescriptors

import org.exolab.castor.xml.Unmarshaller; //导入依赖的package包/类
@Override
public List<StatisticDescriptor> getStatisticDescriptors(String filePath)
		throws ParserException {
	try {
		Mapping mapping = new Mapping();
		mapping.loadMapping(FileUtils.findFileAsResource("StatisticDescriptorMapping.xml"));
		XMLContext context = new XMLContext();
		context.addMapping(mapping);
		InputSource source = new InputSource(FileUtils.findFileAsStream(filePath));
		Unmarshaller unmarshaller = context.createUnmarshaller();
		unmarshaller.setClass(StatisticList.class);
		StatisticList list = (StatisticList)unmarshaller.unmarshal(source);
		validate(list.getDescriptors());
		return list.getDescriptors();
	} catch (Exception e) {
		ParserException parserException = new ParserException("Exception parsing statistic descriptor files", e);
		Logger.getLogger(this.getClass()).error(parserException.getMessage(), parserException);
		throw parserException;
	} 
}
 
开发者ID:lafourchette,项目名称:solrmeter,代码行数:21,代码来源:StatisticsParserCastorImpl.java


示例3: readFromFile

import org.exolab.castor.xml.Unmarshaller; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static List<Synonym> readFromFile(String filename) throws Exception {
	Mapping mapping = getMapping();
	Unmarshaller unmarshaller = new Unmarshaller(ArrayList.class);
	unmarshaller.setMapping(mapping);

	File file = new File(filename);

       if (file.exists() && !file.isFile()) {
           throw new IOException("File " + file.getAbsolutePath() + " exists but is not a file.");
       }

	if (!file.exists() || file.length() == 0) {
		return Collections.emptyList();
	}

	Reader reader = new FileReader(file);
	return (List<Synonym>) unmarshaller.unmarshal(reader);
}
 
开发者ID:realrolfje,项目名称:anonimatron,代码行数:20,代码来源:SynonymMapper.java


示例4: setMapping

import org.exolab.castor.xml.Unmarshaller; //导入依赖的package包/类
/**
 * Initializes the Castor mapping instance.
 * @param mapping a Castor mapping. Shall not be <code>null</code>.
 * @throws NullPointerException if <code>mapping</code> is <code>null</code>.
 * @throws MappingException an exception indicating an invalid mapping error.
 */
private void setMapping(final Mapping mapping) throws MappingException
{
    _unmarshaller = new Unmarshaller(mapping); // May throw MappingException.
    _unmarshaller.setValidation(false);
    _unmarshaller.setIgnoreExtraElements(true);

    _marshaller = new Marshaller();
    _marshaller.setMapping(mapping); // May throw MappingException.
    _marshaller.setValidation(false);
    //_marshaller.setDebug(true);
    // Specifies whether to support XML namespaces by default. Default is false.
    //_marshaller.setProperty("org.exolab.castor.parser.namespaces", "true");
    // Specifies whether XML documents (as generated at marshalling) should use indentation or not. Default is false.
    //_marshaller.setProperty("org.exolab.castor.indent", "true");
}
 
开发者ID:LizzyProject,项目名称:Lizzy,代码行数:22,代码来源:XmlSerializer.java


示例5: unmarshal

import org.exolab.castor.xml.Unmarshaller; //导入依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @see marshalsec.MarshallerBase#unmarshal(java.lang.Object)
 */
@Override
public Object unmarshal ( String data ) throws Exception {
    XMLContext context = new XMLContext();
    Unmarshaller unmarshaller = context.createUnmarshaller();
    return unmarshaller.unmarshal(new StringReader(data));
}
 
开发者ID:mbechler,项目名称:marshalsec,代码行数:12,代码来源:Castor.java


示例6: unmarshalSaxReader

import org.exolab.castor.xml.Unmarshaller; //导入依赖的package包/类
@Override
protected Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource)
		throws XmlMappingException, IOException {

	UnmarshalHandler unmarshalHandler = createUnmarshaller().createHandler();
	try {
		ContentHandler contentHandler = Unmarshaller.getContentHandler(unmarshalHandler);
		xmlReader.setContentHandler(contentHandler);
		xmlReader.parse(inputSource);
		return unmarshalHandler.getObject();
	}
	catch (SAXException ex) {
		throw new UnmarshallingFailureException("SAX reader exception", ex);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:CastorMarshaller.java


示例7: customizeUnmarshaller

import org.exolab.castor.xml.Unmarshaller; //导入依赖的package包/类
/**
 * Template method that allows for customizing of the given Castor {@link Unmarshaller}.
 */
protected void customizeUnmarshaller(Unmarshaller unmarshaller) {
	unmarshaller.setValidation(this.validating);
	unmarshaller.setWhitespacePreserve(this.whitespacePreserve);
	unmarshaller.setIgnoreExtraAttributes(this.ignoreExtraAttributes);
	unmarshaller.setIgnoreExtraElements(this.ignoreExtraElements);
	unmarshaller.setObject(this.rootObject);
	unmarshaller.setReuseObjects(this.reuseObjects);
	unmarshaller.setClearCollections(this.clearCollections);
	if (this.namespaceToPackageMapping != null) {
		for (Map.Entry<String, String> mapping : this.namespaceToPackageMapping.entrySet()) {
			unmarshaller.addNamespaceToPackageMapping(mapping.getKey(), mapping.getValue());
		}
	}
	if (this.entityResolver != null) {
		unmarshaller.setEntityResolver(this.entityResolver);
	}
	if (this.classDescriptorResolver != null) {
		unmarshaller.setResolver(this.classDescriptorResolver);
	}
	if (this.idResolver != null) {
		unmarshaller.setIDResolver(this.idResolver);
	}
	if (this.objectFactory != null) {
		unmarshaller.setObjectFactory(this.objectFactory);
	}
	if (this.beanClassLoader != null) {
		unmarshaller.setClassLoader(this.beanClassLoader);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:33,代码来源:CastorMarshaller.java


示例8: unserializeTxnRes

import org.exolab.castor.xml.Unmarshaller; //导入依赖的package包/类
@Override
public TxnRes unserializeTxnRes(String xml) throws IOException {
	try {
        Unmarshaller unmarshaller = new Unmarshaller(_mapping);
        return (TxnRes) unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(xml.getBytes())));
        
	} catch (Exception e) {
		throw new IOException("Exception occured during XML unmarshalling.", e);
		
	}
}
 
开发者ID:neopeak,项目名称:brownsocks-payments-enets,代码行数:12,代码来源:CastorXMLSerializer.java


示例9: readFromFile

import org.exolab.castor.xml.Unmarshaller; //导入依赖的package包/类
public static Configuration readFromFile(String filename) throws Exception {
	Mapping mapping = getMapping();
	Unmarshaller unmarshaller = new Unmarshaller(mapping);

	File file = new File(filename);
	Reader reader = new FileReader(file);
	Configuration configuration = (Configuration)unmarshaller.unmarshal(reader);
	LOG.info("Configuration read from " + file.getAbsoluteFile());
	return configuration;
}
 
开发者ID:realrolfje,项目名称:anonimatron,代码行数:11,代码来源:Configuration.java


示例10: getXportData

import org.exolab.castor.xml.Unmarshaller; //导入依赖的package包/类
private Xport getXportData(String queryString) throws JRException {
    String rrdBinary = getRrdBinary();
       if(rrdBinary == null) {
           throw new JRException("rrd.binary property must be set either in opennms.properties or in iReport");
       }

	String command = rrdBinary + " xport " + queryString.replaceAll("[\r\n]+", " ").replaceAll("\\s+", " ");
	log().debug("getXportData: executing command: " + command);
	String[] commandArray = StringUtils.createCommandArray(command, '@');
	Xport data = null;
	try {
		Process process = Runtime.getRuntime().exec(commandArray);
		// this closes the stream when its finished
		byte[] byteArray = FileCopyUtils.copyToByteArray(process.getInputStream());             
		// this close the stream when its finished
		String errors = FileCopyUtils.copyToString(new InputStreamReader(process.getErrorStream()));
		if (errors.length() > 0) {
			log().error("getXportData: RRDtool command fail: " + errors);
			return null;
		}
		BufferedReader reader = null;
		try {
			InputStream is = new ByteArrayInputStream(byteArray);
			reader = new BufferedReader(new InputStreamReader(is));
			data = (Xport) Unmarshaller.unmarshal(Xport.class, reader);
		} finally {
			reader.close();
		}
	} catch (Exception e) {
		log().error("getXportData: can't execute command '" + command + ": ", e);
		throw new JRException("getXportData: can't execute command '" + command + ": ", e);
	}
	return data;
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:35,代码来源:RrdtoolXportCmd.java


示例11: XmpConfigFactory

import org.exolab.castor.xml.Unmarshaller; //导入依赖的package包/类
/**
 * <p>Constructor for XmpConfigFactory.</p>
 *
 * @param configFile a {@link java.lang.String} object.
 * @throws org.exolab.castor.xml.MarshalException if any.
 * @throws org.exolab.castor.xml.ValidationException if any.
 * @throws java.io.IOException if any.
 */
public XmpConfigFactory(String configFile) 
throws MarshalException, ValidationException, IOException 
{ 
    InputStream cfgIn = new FileInputStream(configFile);

    config = (XmpConfig)Unmarshaller.unmarshal(XmpConfig.class,
                                               new InputStreamReader(cfgIn, "UTF-8"));
    cfgIn.close();
    return; 
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:19,代码来源:XmpConfigFactory.java


示例12: duplicateObject

import org.exolab.castor.xml.Unmarshaller; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T duplicateObject(T object, Class<T> clazz) throws MarshalException, ValidationException {
    StringWriter stringWriter = new StringWriter();
    Marshaller.marshal(object, stringWriter);
    StringReader stringReader = new StringReader(stringWriter.toString());
    return (T) Unmarshaller.unmarshal(clazz, stringReader);
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:8,代码来源:CastorUtils.java


示例13: readCastorObject

import org.exolab.castor.xml.Unmarshaller; //导入依赖的package包/类
public Object readCastorObject( String inputFileName, Class expectedClass ) {
  Object o = null;
  try {
    // read in the object
    o = Unmarshaller.unmarshal( expectedClass, new FileReader( inputFileName ) );
  } catch ( Exception e ) {
    getLogger().error( e.getMessage(), e );
  }
  return o;
}
 
开发者ID:pentaho,项目名称:pentaho-reportwizard-core,代码行数:11,代码来源:CastorUtility.java


示例14: createUnmarshaller

import org.exolab.castor.xml.Unmarshaller; //导入依赖的package包/类
private Unmarshaller createUnmarshaller() {
	Unmarshaller unmarshaller = this.xmlContext.createUnmarshaller();
	customizeUnmarshaller(unmarshaller);
	return unmarshaller;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:6,代码来源:CastorMarshaller.java


示例15: createUnmarshaller

import org.exolab.castor.xml.Unmarshaller; //导入依赖的package包/类
public Unmarshaller createUnmarshaller(Exchange exchange) throws Exception {
    // need to create new marshaller as we may have concurrent processing
    Unmarshaller answer = xmlContext.createUnmarshaller();
    answer.setValidation(isValidation());
    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:7,代码来源:AbstractCastorDataFormat.java


示例16: getUnmarshaller

import org.exolab.castor.xml.Unmarshaller; //导入依赖的package包/类
/**
 * Returns the associated Castor unmarshaller.
 * @return a Castor unmarshaller. Shall not be <code>null</code>.
 */
public Unmarshaller getUnmarshaller()
{
    return _unmarshaller;
}
 
开发者ID:LizzyProject,项目名称:Lizzy,代码行数:9,代码来源:XmlSerializer.java


示例17: testRrdData

import org.exolab.castor.xml.Unmarshaller; //导入依赖的package包/类
@Test
public void testRrdData() throws Exception {
	Reader reader = new FileReader("src/test/resources/rrdtool-xport.xml");
	Xport xport = (Xport) Unmarshaller.unmarshal(Xport.class, reader);
	Assert.assertEquals("SampleData", xport.getMeta().getLegend().getEntry(0).getContent());
	Assert.assertEquals(13, xport.getData().getRowCount());
	RrdtoolDataSource ds = new RrdtoolDataSource(xport);

	Assert.assertTrue(ds.next());

	Date d1 = (Date) ds.getFieldValue(new RrdField("Timestamp", Date.class));
       Assert.assertEquals(new Date(1206312900000L).toString(), d1.toString());

	Double v1 = (Double) ds.getFieldValue(new RrdField("SampleData", Double.class));
	Assert.assertEquals(new Double(19.86), v1);

	Assert.assertTrue(ds.next());

	Date d2 = (Date) ds.getFieldValue(new RrdField("Timestamp", Date.class));
       Assert.assertEquals(new Date(1206313200000L).toString(), d2.toString());

	Double v2 = (Double) ds.getFieldValue(new RrdField("SampleData", Double.class));
	Assert.assertEquals(new Double(Double.NaN), v2);

	Assert.assertTrue(ds.next());

	Date d3 = (Date) ds.getFieldValue(new RrdField("Timestamp", Date.class));
       Assert.assertEquals(new Date(1206313500000L).toString(), d3.toString());

	Double v3 = (Double) ds.getFieldValue(new RrdField("SampleData", Double.class));
	Assert.assertEquals(new Double(Double.NaN), v3);

	Assert.assertTrue(ds.next());

	Date d4 = (Date) ds.getFieldValue(new RrdField("Timestamp", Date.class));
       Assert.assertEquals(new Date(1206313800000L).toString(), d4.toString());

	Double v4 = (Double) ds.getFieldValue(new RrdField("SampleData", Double.class));
	Assert.assertEquals(new Double(26.00), v4);

	for (int i=4; i<13; i++)
		ds.next();

	Date d13 = (Date) ds.getFieldValue(new RrdField("Timestamp", Date.class));
       Assert.assertEquals(new Date(1206316500000L).toString(), d13.toString());

	Double v13 = (Double) ds.getFieldValue(new RrdField("SampleData", Double.class));
	Assert.assertEquals(new Double(50.00), v13);

	Assert.assertFalse(ds.next());
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:52,代码来源:RrdtoolDataSourceTest.java


示例18: XmpCollectionFactory

import org.exolab.castor.xml.Unmarshaller; //导入依赖的package包/类
/**
 * <p>Constructor for XmpCollectionFactory.</p>
 *
 * @param configFile a {@link java.lang.String} object.
 * @throws org.exolab.castor.xml.MarshalException if any.
 * @throws org.exolab.castor.xml.ValidationException if any.
 * @throws java.io.IOException if any.
 */
public XmpCollectionFactory(String configFile) 
throws MarshalException, ValidationException, IOException { 

    InputStream cfgIn = new FileInputStream(configFile);

    config = (XmpDatacollectionConfig)Unmarshaller.unmarshal(XmpDatacollectionConfig.class,new InputStreamReader(cfgIn, "UTF-8"));

    cfgIn.close();

    rrdPath = null;

    // list out the collections I've found
    XmpCollection[] collections = config.getXmpCollection();
    for (XmpCollection coll: collections) {

        log().debug("XmpCollectionFactory: found collection "+
                    coll.getName());

        //System.out.println("XmpCollectionFactory: found collection "+
        //                    coll.getName());
    }

    return; 
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:33,代码来源:XmpCollectionFactory.java


示例19: unmarshal

import org.exolab.castor.xml.Unmarshaller; //导入依赖的package包/类
public static Varbindsdecode unmarshal(final Reader reader) throws MarshalException, ValidationException {
    return (Varbindsdecode) Unmarshaller.unmarshal(Varbindsdecode.class, reader);
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:4,代码来源:Varbindsdecode.java


示例20: unmarshal

import org.exolab.castor.xml.Unmarshaller; //导入依赖的package包/类
public static AlarmData unmarshal(final Reader reader) throws MarshalException, ValidationException {
    return (AlarmData) Unmarshaller.unmarshal(AlarmData.class, reader);
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:4,代码来源:AlarmData.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Util类代码示例发布时间:2022-05-21
下一篇:
Java VectorClockInconsistencyResolver类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap