作者:firespace | 来源:互联网 | 2023-10-12 12:44
本文整理了Java中org.exolab.castor.xml.XMLContext.addPackages()
方法的一些代码示例,展示了XMLContext.addPackages()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLContext.addPackages()
方法的具体详情如下:
包路径:org.exolab.castor.xml.XMLContext
类名称:XMLContext
方法名:addPackages
XMLContext.addPackages介绍
[英]Loads class descriptors from the packages specified. The use of this method is useful when no mapping is used, as happens when the domain classes hase been generated using the XML code generator (in which case instead of a mapping file class descriptor files will be generated).
Please note that this functionality will work only if you provide the .castor.cdr files with your generated classes (as generated by the XML code generator).
[中]从指定的包加载类描述符。当不使用映射时,使用此方法很有用,当使用XML代码生成器生成域类时,就会发生这种情况(在这种情况下,将生成类描述符文件而不是映射文件)。
请注意,只有在您提供的情况下,此功能才会起作用。卡斯特。cdr文件和生成的类(由XML代码生成器生成)。
代码示例
代码示例来源:origin: apache/servicemix-bundles
context.addPackages(targetPackages);
代码示例来源:origin: org.apache.camel/camel-castor
protected XMLContext createXMLContext(ClassResolver resolver, ClassLoader contextClassLoader) throws Exception {
XMLContext xmlCOntext= new XMLContext();
if (ObjectHelper.isNotEmpty(getMappingFile())) {
Mapping xmlMap;
if (contextClassLoader != null) {
xmlMap = new Mapping(contextClassLoader);
} else {
xmlMap = new Mapping();
}
xmlMap.loadMapping(resolver.loadResourceAsURL(getMappingFile()));
xmlContext.addMapping(xmlMap);
}
if (getPackages() != null) {
xmlContext.addPackages(getPackages());
}
if (getClassNames() != null) {
for (String name : getClassNames()) {
Class> clazz = resolver.resolveClass(name);
xmlContext.addClass(clazz);
}
}
return xmlContext;
}