Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright 2002-2010 the original author or authors.
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
 package org.springframework.integration.xml.transformer;
An implementation of org.springframework.integration.transformer.Transformer that delegates to an OXM org.springframework.oxm.Unmarshaller. Expects the payload to be of type org.w3c.dom.Document, java.lang.String,, javax.xml.transform.Source or to have an instance of org.springframework.integration.xml.source.SourceFactory that can convert to a javax.xml.transform.Source. If alwaysUseSourceFactory is set to true, then the org.springframework.integration.xml.source.SourceFactory will be used to create the javax.xml.transform.Source regardless of payload type.

The Unmarshaller may return a Message, but if the return value is not already a Message instance, a new Message will be created with that return value as its payload.

Jonas Partner
 	private final Unmarshaller unmarshaller;
 	private volatile SourceFactory sourceFactory = new DomSourceFactory();
 	private volatile boolean alwaysUseSourceFactory = false;
 	public UnmarshallingTransformer(Unmarshaller unmarshaller) {
 		this. = unmarshaller;

Provide the SourceFactory to be used. Must not be null.
 	public void setSourceFactory(SourceFactory sourceFactory) {
 		Assert.notNull(sourceFactory"sourceFactory must not be null");
 		this. = sourceFactory;

 	public void setAlwaysUseSourceFactory(boolean alwaysUseSourceFactory) {
 		this. = alwaysUseSourceFactory;
 	public Object transformPayload(Object payload) {
 		Source source = null;
 		if (this.) {
 			source = this..createSource(payload);
 		else if (payload instanceof String) {
 			source = new StringSource((Stringpayload);
 		else if (payload instanceof File) {
 			source = new StreamSource((Filepayload);
 		else if (payload instanceof Document) {
 			source = new DOMSource((Documentpayload);
 		else if (payload instanceof Source) {
 			source = (Sourcepayload;
 		else {
			source = this..createSource(payload);
		if (source == null) {
			throw new MessagingException(
					"failed to transform message, payload not assignable from javax.xml.transform.Source and no conversion possible");
		try {
			return this..unmarshal(source);
		catch (IOException e) {
			throw new MessagingException("failed to unmarshal payload"e);
New to GrepCode? Check out our FAQ X