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


Java XmlMappingException类代码示例

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


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

示例1: marshal

import org.springframework.oxm.XmlMappingException; //导入依赖的package包/类
/**
 * Marshals the object graph with the given root into the provided {@code javax.xml.transform.Result}.
 * <p>This implementation inspects the given result, and calls {@code marshalDomResult},
 * {@code marshalSaxResult}, or {@code marshalStreamResult}.
 * @param graph the root of the object graph to marshal
 * @param result the result to marshal to
 * @throws IOException if an I/O exception occurs
 * @throws XmlMappingException if the given object cannot be marshalled to the result
 * @throws IllegalArgumentException if {@code result} if neither a {@code DOMResult},
 * a {@code SAXResult}, nor a {@code StreamResult}
 * @see #marshalDomResult(Object, javax.xml.transform.dom.DOMResult)
 * @see #marshalSaxResult(Object, javax.xml.transform.sax.SAXResult)
 * @see #marshalStreamResult(Object, javax.xml.transform.stream.StreamResult)
 */
@Override
public final void marshal(Object graph, Result result) throws IOException, XmlMappingException {
	if (result instanceof DOMResult) {
		marshalDomResult(graph, (DOMResult) result);
	}
	else if (StaxUtils.isStaxResult(result)) {
		marshalStaxResult(graph, result);
	}
	else if (result instanceof SAXResult) {
		marshalSaxResult(graph, (SAXResult) result);
	}
	else if (result instanceof StreamResult) {
		marshalStreamResult(graph, (StreamResult) result);
	}
	else {
		throw new IllegalArgumentException("Unknown Result type: " + result.getClass());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:33,代码来源:AbstractMarshaller.java

示例2: marshalStaxResult

import org.springframework.oxm.XmlMappingException; //导入依赖的package包/类
/**
 * Template method for handling {@code StaxResult}s.
 * <p>This implementation delegates to {@code marshalXMLSteamWriter} or
 * {@code marshalXMLEventConsumer}, depending on what is contained in the
 * {@code StaxResult}.
 * @param graph the root of the object graph to marshal
 * @param staxResult a JAXP 1.4 {@link StAXSource}
 * @throws XmlMappingException if the given object cannot be marshalled to the result
 * @throws IllegalArgumentException if the {@code domResult} is empty
 * @see #marshalDomNode(Object, org.w3c.dom.Node)
 */
protected void marshalStaxResult(Object graph, Result staxResult) throws XmlMappingException {
	XMLStreamWriter streamWriter = StaxUtils.getXMLStreamWriter(staxResult);
	if (streamWriter != null) {
		marshalXmlStreamWriter(graph, streamWriter);
	}
	else {
		XMLEventWriter eventWriter = StaxUtils.getXMLEventWriter(staxResult);
		if (eventWriter != null) {
			marshalXmlEventWriter(graph, eventWriter);
		}
		else {
			throw new IllegalArgumentException("StaxResult contains neither XMLStreamWriter nor XMLEventConsumer");
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:AbstractMarshaller.java

示例3: unmarshal

import org.springframework.oxm.XmlMappingException; //导入依赖的package包/类
/**
 * Unmarshals the given provided {@code javax.xml.transform.Source} into an object graph.
 * <p>This implementation inspects the given result, and calls {@code unmarshalDomSource},
 * {@code unmarshalSaxSource}, or {@code unmarshalStreamSource}.
 * @param source the source to marshal from
 * @return the object graph
 * @throws IOException if an I/O Exception occurs
 * @throws XmlMappingException if the given source cannot be mapped to an object
 * @throws IllegalArgumentException if {@code source} is neither a {@code DOMSource},
 * a {@code SAXSource}, nor a {@code StreamSource}
 * @see #unmarshalDomSource(javax.xml.transform.dom.DOMSource)
 * @see #unmarshalSaxSource(javax.xml.transform.sax.SAXSource)
 * @see #unmarshalStreamSource(javax.xml.transform.stream.StreamSource)
 */
@Override
public final Object unmarshal(Source source) throws IOException, XmlMappingException {
	if (source instanceof DOMSource) {
		return unmarshalDomSource((DOMSource) source);
	}
	else if (StaxUtils.isStaxSource(source)) {
		return unmarshalStaxSource(source);
	}
	else if (source instanceof SAXSource) {
		return unmarshalSaxSource((SAXSource) source);
	}
	else if (source instanceof StreamSource) {
		return unmarshalStreamSource((StreamSource) source);
	}
	else {
		throw new IllegalArgumentException("Unknown Source type: " + source.getClass());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:33,代码来源:AbstractMarshaller.java

示例4: unmarshalDomSource

import org.springframework.oxm.XmlMappingException; //导入依赖的package包/类
/**
 * Template method for handling {@code DOMSource}s.
 * <p>This implementation delegates to {@code unmarshalDomNode}.
 * If the given source is empty, an empty source {@code Document}
 * will be created as a placeholder.
 * @param domSource the {@code DOMSource}
 * @return the object graph
 * @throws XmlMappingException if the given source cannot be mapped to an object
 * @throws IllegalArgumentException if the {@code domSource} is empty
 * @see #unmarshalDomNode(org.w3c.dom.Node)
 */
protected Object unmarshalDomSource(DOMSource domSource) throws XmlMappingException {
	if (domSource.getNode() == null) {
		domSource.setNode(buildDocument());
	}
	try {
		return unmarshalDomNode(domSource.getNode());
	}
	catch (NullPointerException ex) {
		if (!isSupportDtd()) {
			throw new UnmarshallingFailureException("NPE while unmarshalling. " +
					"This can happen on JDK 1.6 due to the presence of DTD " +
					"declarations, which are disabled.", ex);
		}
		throw ex;
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:28,代码来源:AbstractMarshaller.java

示例5: unmarshalStaxSource

import org.springframework.oxm.XmlMappingException; //导入依赖的package包/类
/**
 * Template method for handling {@code StaxSource}s.
 * <p>This implementation delegates to {@code unmarshalXmlStreamReader} or
 * {@code unmarshalXmlEventReader}.
 * @param staxSource the {@code StaxSource}
 * @return the object graph
 * @throws XmlMappingException if the given source cannot be mapped to an object
 */
protected Object unmarshalStaxSource(Source staxSource) throws XmlMappingException {
	XMLStreamReader streamReader = StaxUtils.getXMLStreamReader(staxSource);
	if (streamReader != null) {
		return unmarshalXmlStreamReader(streamReader);
	}
	else {
		XMLEventReader eventReader = StaxUtils.getXMLEventReader(staxSource);
		if (eventReader != null) {
			return unmarshalXmlEventReader(eventReader);
		}
		else {
			throw new IllegalArgumentException("StaxSource contains neither XMLStreamReader nor XMLEventReader");
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:AbstractMarshaller.java

示例6: unmarshalStreamSource

import org.springframework.oxm.XmlMappingException; //导入依赖的package包/类
/**
 * Template method for handling {@code StreamSource}s.
 * <p>This implementation delegates to {@code unmarshalInputStream} or {@code unmarshalReader}.
 * @param streamSource the {@code StreamSource}
 * @return the object graph
 * @throws IOException if an I/O exception occurs
 * @throws XmlMappingException if the given source cannot be mapped to an object
 */
protected Object unmarshalStreamSource(StreamSource streamSource) throws XmlMappingException, IOException {
	if (streamSource.getInputStream() != null) {
		if (isProcessExternalEntities() && isSupportDtd()) {
			return unmarshalInputStream(streamSource.getInputStream());
		}
		else {
			InputSource inputSource = new InputSource(streamSource.getInputStream());
			inputSource.setEncoding(getDefaultEncoding());
			return unmarshalSaxSource(new SAXSource(inputSource));
		}
	}
	else if (streamSource.getReader() != null) {
		if (isProcessExternalEntities() && isSupportDtd()) {
			return unmarshalReader(streamSource.getReader());
		}
		else {
			return unmarshalSaxSource(new SAXSource(new InputSource(streamSource.getReader())));
		}
	}
	else {
		return unmarshalSaxSource(new SAXSource(new InputSource(streamSource.getSystemId())));
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:32,代码来源:AbstractMarshaller.java

示例7: marshal

import org.springframework.oxm.XmlMappingException; //导入依赖的package包/类
@Override
public void marshal(Object graph, Result result, MimeContainer mimeContainer) throws XmlMappingException {
	try {
		Marshaller marshaller = createMarshaller();
		if (this.mtomEnabled && mimeContainer != null) {
			marshaller.setAttachmentMarshaller(new Jaxb2AttachmentMarshaller(mimeContainer));
		}
		if (StaxUtils.isStaxResult(result)) {
			marshalStaxResult(marshaller, graph, result);
		}
		else {
			marshaller.marshal(graph, result);
		}
	}
	catch (JAXBException ex) {
		throw convertJaxbException(ex);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:Jaxb2Marshaller.java

示例8: convertJaxbException

import org.springframework.oxm.XmlMappingException; //导入依赖的package包/类
/**
 * Convert the given {@code JAXBException} to an appropriate exception from the
 * {@code org.springframework.oxm} hierarchy.
 * @param ex {@code JAXBException} that occured
 * @return the corresponding {@code XmlMappingException}
 */
protected XmlMappingException convertJaxbException(JAXBException ex) {
	if (ex instanceof ValidationException) {
		return new ValidationFailureException("JAXB validation exception", ex);
	}
	else if (ex instanceof MarshalException) {
		return new MarshallingFailureException("JAXB marshalling exception", ex);
	}
	else if (ex instanceof UnmarshalException) {
		return new UnmarshallingFailureException("JAXB unmarshalling exception", ex);
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown JAXB exception", ex);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:Jaxb2Marshaller.java

示例9: convertCastorException

import org.springframework.oxm.XmlMappingException; //导入依赖的package包/类
/**
 * Convert the given {@code XMLException} to an appropriate exception from the
 * {@code org.springframework.oxm} hierarchy.
 * <p>A boolean flag is used to indicate whether this exception occurs during marshalling or
 * unmarshalling, since Castor itself does not make this distinction in its exception hierarchy.
 * @param ex Castor {@code XMLException} that occurred
 * @param marshalling indicates whether the exception occurs during marshalling ({@code true}),
 * or unmarshalling ({@code false})
 * @return the corresponding {@code XmlMappingException}
 */
protected XmlMappingException convertCastorException(XMLException ex, boolean marshalling) {
	if (ex instanceof ValidationException) {
		return new ValidationFailureException("Castor validation exception", ex);
	}
	else if (ex instanceof MarshalException) {
		if (marshalling) {
			return new MarshallingFailureException("Castor marshalling exception", ex);
		}
		else {
			return new UnmarshallingFailureException("Castor unmarshalling exception", ex);
		}
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown Castor exception", ex);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:28,代码来源:CastorMarshaller.java

示例10: convertXStreamException

import org.springframework.oxm.XmlMappingException; //导入依赖的package包/类
/**
    * Convert the given XStream exception to an appropriate exception from the
    * {@code org.springframework.oxm} hierarchy.
    * <p>A boolean flag is used to indicate whether this exception occurs during marshalling or
    * unmarshalling, since XStream itself does not make this distinction in its exception hierarchy.
    * @param ex XStream exception that occurred
    * @param marshalling indicates whether the exception occurs during marshalling ({@code true}),
    * or unmarshalling ({@code false})
    * @return the corresponding {@code XmlMappingException}
    */
protected XmlMappingException convertXStreamException(Exception ex, boolean marshalling) {
	if (ex instanceof StreamException || ex instanceof CannotResolveClassException ||
			ex instanceof ConversionException) {
		if (marshalling) {
			return new MarshallingFailureException("XStream marshalling exception",  ex);
		}
		else {
			return new UnmarshallingFailureException("XStream unmarshalling exception", ex);
		}
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown XStream exception", ex);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:XStreamMarshaller.java

示例11: convertXmlBeansException

import org.springframework.oxm.XmlMappingException; //导入依赖的package包/类
/**
 * Convert the given XMLBeans exception to an appropriate exception from the
 * {@code org.springframework.oxm} hierarchy.
 * <p>A boolean flag is used to indicate whether this exception occurs during marshalling or
 * unmarshalling, since XMLBeans itself does not make this distinction in its exception hierarchy.
 * @param ex XMLBeans Exception that occured
 * @param marshalling indicates whether the exception occurs during marshalling ({@code true}),
 * or unmarshalling ({@code false})
 * @return the corresponding {@code XmlMappingException}
 */
protected XmlMappingException convertXmlBeansException(Exception ex, boolean marshalling) {
	if (ex instanceof XMLStreamValidationException) {
		return new ValidationFailureException("XMLBeans validation exception", ex);
	}
	else if (ex instanceof XmlException || ex instanceof SAXException) {
		if (marshalling) {
			return new MarshallingFailureException("XMLBeans marshalling exception",  ex);
		}
		else {
			return new UnmarshallingFailureException("XMLBeans unmarshalling exception", ex);
		}
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown XMLBeans exception", ex);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:28,代码来源:XmlBeansMarshaller.java

示例12: write

import org.springframework.oxm.XmlMappingException; //导入依赖的package包/类
/**
 * Write the value objects and flush them to the file.
 *
 * @param items
 *            the value object
 * @throws IOException
 * @throws XmlMappingException
 */
public void write(List<? extends T> items) throws XmlMappingException,
Exception {

	currentRecordCount += items.size();

	for (Object object : items) {
		Assert.state(marshaller.supports(object.getClass()),
				"Marshaller must support the class of the marshalled object");
		Result result = StaxUtils.getResult(eventWriter);
		marshaller.marshal(object, result);
	}
	try {
		eventWriter.flush();
	} catch (XMLStreamException e) {
		throw new WriteFailedException("Failed to flush the events", e);
	}

}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:27,代码来源:StaxEventItemWriter.java

示例13: outputIsSameAsInput

import org.springframework.oxm.XmlMappingException; //导入依赖的package包/类
@Test
public void outputIsSameAsInput() throws ClassNotFoundException, SQLException, XmlMappingException, IOException {
    EmbeddedDatabase embeddedDatabase = createMinimalEmbeddedDatabase(ALL_RELATIONS_SCRIPT);

    Metadata meta = extractor.extract(embeddedDatabase.getConnection());


    assertThat(countTables(meta)).isEqualTo(18);
    assertThat(countColumns(meta)).isEqualTo(49);
    assertThat(countPrimaryKeys(meta)).isEqualTo(18);
    assertThat(countIndexes(meta)).isEqualTo(21);
    assertThat(countEnums(meta)).isEqualTo(3);

    File tempFile = File.createTempFile(getClass().getName(), ".xml");
    tempFile.deleteOnExit();
    loader.write(meta, tempFile);

    Metadata loadedMeta = loader.load(tempFile);
    assertThat(countTables(meta)).isEqualTo(countTables(loadedMeta));
    assertThat(countColumns(meta)).isEqualTo(countColumns(loadedMeta));
    assertThat(countPrimaryKeys(meta)).isEqualTo(countPrimaryKeys(loadedMeta));
    assertThat(countIndexes(meta)).isEqualTo(countIndexes(loadedMeta));
    assertThat(countEnums(meta)).isEqualTo(countEnums(loadedMeta));

    embeddedDatabase.shutdown();
}
 
开发者ID:jaxio,项目名称:celerio,代码行数:27,代码来源:MetaDataExtractorTest.java

示例14: marshal

import org.springframework.oxm.XmlMappingException; //导入依赖的package包/类
/**
 * Marshals the object graph with the given root into the provided {@code javax.xml.transform.Result}.
 * <p>This implementation inspects the given result, and calls {@code marshalDomResult},
 * {@code marshalSaxResult}, or {@code marshalStreamResult}.
 * @param graph the root of the object graph to marshal
 * @param result the result to marshal to
 * @throws IOException if an I/O exception occurs
 * @throws XmlMappingException if the given object cannot be marshalled to the result
 * @throws IllegalArgumentException if {@code result} if neither a {@code DOMResult},
 * a {@code SAXResult}, nor a {@code StreamResult}
 * @see #marshalDomResult(Object, javax.xml.transform.dom.DOMResult)
 * @see #marshalSaxResult(Object, javax.xml.transform.sax.SAXResult)
 * @see #marshalStreamResult(Object, javax.xml.transform.stream.StreamResult)
 */
public final void marshal(Object graph, Result result) throws IOException, XmlMappingException {
	if (result instanceof DOMResult) {
		marshalDomResult(graph, (DOMResult) result);
	}
	else if (StaxUtils.isStaxResult(result)) {
		marshalStaxResult(graph, result);
	}
	else if (result instanceof SAXResult) {
		marshalSaxResult(graph, (SAXResult) result);
	}
	else if (result instanceof StreamResult) {
		marshalStreamResult(graph, (StreamResult) result);
	}
	else {
		throw new IllegalArgumentException("Unknown Result type: " + result.getClass());
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:32,代码来源:AbstractMarshaller.java

示例15: marshalDomResult

import org.springframework.oxm.XmlMappingException; //导入依赖的package包/类
/**
 * Template method for handling {@code DOMResult}s.
 * <p>This implementation delegates to {@code marshalDomNode}.
 * @param graph the root of the object graph to marshal
 * @param domResult the {@code DOMResult}
 * @throws XmlMappingException if the given object cannot be marshalled to the result
 * @throws IllegalArgumentException if the {@code domResult} is empty
 * @see #marshalDomNode(Object, org.w3c.dom.Node)
 */
protected void marshalDomResult(Object graph, DOMResult domResult) throws XmlMappingException {
	if (domResult.getNode() == null) {
		try {
			synchronized (this.documentBuilderFactoryMonitor) {
				if (this.documentBuilderFactory == null) {
					this.documentBuilderFactory = createDocumentBuilderFactory();
				}
			}
			DocumentBuilder documentBuilder = createDocumentBuilder(this.documentBuilderFactory);
			domResult.setNode(documentBuilder.newDocument());
		}
		catch (ParserConfigurationException ex) {
			throw new UnmarshallingFailureException(
					"Could not create document placeholder for DOMResult: " + ex.getMessage(), ex);
		}
	}
	marshalDomNode(graph, domResult.getNode());
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:28,代码来源:AbstractMarshaller.java


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