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


Java Unmarshaller类代码示例

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


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


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