本文整理汇总了Java中org.exolab.castor.xml.XMLContext类的典型用法代码示例。如果您正苦于以下问题:Java XMLContext类的具体用法?Java XMLContext怎么用?Java XMLContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XMLContext类属于org.exolab.castor.xml包,在下文中一共展示了XMLContext类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例4: marshal
import org.exolab.castor.xml.XMLContext; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @see marshalsec.MarshallerBase#marshal(java.lang.Object)
*/
@Override
public String marshal ( Object o ) throws Exception {
XMLContext context = new XMLContext();
Marshaller m = context.createMarshaller();
StringWriter sw = new StringWriter();
m.setWriter(sw);
return sw.toString();
}
示例5: unmarshal
import org.exolab.castor.xml.XMLContext; //导入依赖的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));
}
示例6: getWriteXmlContext
import org.exolab.castor.xml.XMLContext; //导入依赖的package包/类
private XMLContext getWriteXmlContext()
{
String targetVersion = JRPropertiesUtil.getInstance(jasperReportsContext).getProperty(
JRXmlBaseWriter.PROPERTY_REPORT_VERSION);
if (log.isDebugEnabled())
{
log.debug("using write mappings for version " + targetVersion);
}
return getXmlContext(CASTOR_WRITE_XML_CONTEXT_KEY, targetVersion);
}
示例7: getReadXmlContext
import org.exolab.castor.xml.XMLContext; //导入依赖的package包/类
private XMLContext getReadXmlContext()
{
return getXmlContext(CASTOR_READ_XML_CONTEXT_KEY, null);//always reading with the last version mappings
}
示例8: AbstractCastorDataFormat
import org.exolab.castor.xml.XMLContext; //导入依赖的package包/类
public AbstractCastorDataFormat(XMLContext xmlContext) {
this.xmlContext = xmlContext;
}
示例9: setXmlContext
import org.exolab.castor.xml.XMLContext; //导入依赖的package包/类
public void setXmlContext(XMLContext xmlContext) {
this.xmlContext = xmlContext;
}
示例10: CastorDataFormat
import org.exolab.castor.xml.XMLContext; //导入依赖的package包/类
public CastorDataFormat(XMLContext xmlContext) {
super(xmlContext);
}
示例11: init
import org.exolab.castor.xml.XMLContext; //导入依赖的package包/类
private void init(String[] springCtxList) {
appCtx = new ClassPathXmlApplicationContext( springCtxList );
xmlContext = (XMLContext) appCtx.getBean(Util.CASTOR_CONTEXT_BEAN);
}
示例12: getContext
import org.exolab.castor.xml.XMLContext; //导入依赖的package包/类
/**
* @return the context
*/
public static XMLContext getContext() {
return context;
}
示例13: setContext
import org.exolab.castor.xml.XMLContext; //导入依赖的package包/类
/**
* @param aContext the context to set
*/
public static void setContext(XMLContext aContext) {
context = aContext;
}