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


Java XMLContext.addMapping方法代码示例

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


在下文中一共展示了XMLContext.addMapping方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createXMLContext

import org.exolab.castor.xml.XMLContext; //导入方法依赖的package包/类
/**
 * Create the Castor {@code XMLContext}. Subclasses can override this to create a custom context.
 * <p>The default implementation loads mapping files if defined, or the target class or packages if defined.
 * @return the created resolver
 * @throws MappingException when the mapping file cannot be loaded
 * @throws IOException in case of I/O errors
 * @see XMLContext#addMapping(org.exolab.castor.mapping.Mapping)
 * @see XMLContext#addClass(Class)
 */
protected XMLContext createXMLContext(Resource[] mappingLocations, Class<?>[] targetClasses,
		String[] targetPackages) throws MappingException, ResolverException, IOException {

	XMLContext context = new XMLContext();
	if (!ObjectUtils.isEmpty(mappingLocations)) {
		Mapping mapping = new Mapping();
		for (Resource mappingLocation : mappingLocations) {
			mapping.loadMapping(SaxResourceUtils.createInputSource(mappingLocation));
		}
		context.addMapping(mapping);
	}
	if (!ObjectUtils.isEmpty(targetClasses)) {
		context.addClasses(targetClasses);
	}
	if (!ObjectUtils.isEmpty(targetPackages)) {
		context.addPackages(targetPackages);
	}
	if (this.castorProperties != null) {
		for (Map.Entry<String, String> property : this.castorProperties.entrySet()) {
			context.setProperty(property.getKey(), property.getValue());
		}
	}
	return context;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:34,代码来源:CastorMarshaller.java

示例2: getStatisticDescriptors

import org.exolab.castor.xml.XMLContext; //导入方法依赖的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: createXMLContext

import org.exolab.castor.xml.XMLContext; //导入方法依赖的package包/类
/**
 * Create the Castor {@code XMLContext}. Subclasses can override this to create a custom context.
 * <p>The default implementation loads mapping files if defined, or the target class or packages if defined.
 * @return the created resolver
 * @throws MappingException when the mapping file cannot be loaded
 * @throws IOException in case of I/O errors
 * @see XMLContext#addMapping(org.exolab.castor.mapping.Mapping)
 * @see XMLContext#addClass(Class)
 */
protected XMLContext createXMLContext(Resource[] mappingLocations, Class[] targetClasses, String[] targetPackages)
		throws MappingException, ResolverException, IOException {

	XMLContext context = new XMLContext();
	if (!ObjectUtils.isEmpty(mappingLocations)) {
		Mapping mapping = new Mapping();
		for (Resource mappingLocation : mappingLocations) {
			mapping.loadMapping(SaxResourceUtils.createInputSource(mappingLocation));
		}
		context.addMapping(mapping);
	}
	if (!ObjectUtils.isEmpty(targetClasses)) {
		context.addClasses(targetClasses);
	}
	if (!ObjectUtils.isEmpty(targetPackages)) {
		context.addPackages(targetPackages);
	}
	if (this.castorProperties != null) {
		for (Map.Entry<String, String> property : this.castorProperties.entrySet()) {
			context.setProperty(property.getKey(), property.getValue());
		}
	}
	return context;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:34,代码来源:CastorMarshaller.java


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