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