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,
 * 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.AbstractTransformer that delegates to an OXM org.springframework.oxm.Marshaller.

Mark Fisher
Jonas Partner
public class MarshallingTransformer extends AbstractTransformer {
	private final Marshaller marshaller;
	private volatile ResultFactory resultFactory;
	private volatile boolean extractPayload = true;
	public MarshallingTransformer(Marshaller marshallerResultTransformer resultTransformerthrows ParserConfigurationException {
		Assert.notNull(marshaller"a marshaller is required");
		this. = marshaller;
		this. = resultTransformer;
	public void setResultFactory(ResultFactory resultFactory) {
		Assert.notNull(resultFactory"ResultFactory must not be null");
		this. = resultFactory;

Specify whether the source Message's payload should be extracted prior to marshalling. This value is set to "true" by default. To send the Message itself as input to the Marshaller instead, set this to "false".
	public void setExtractPayload(boolean extractPayload) {
		this. = extractPayload;
	public Object doTransform(Message<?> message) {
		Object source = (this.) ? message.getPayload() : message;
		Object transformedPayload = null;
		Result result = this..createResult(source);
		if (result == null) {
			throw new MessagingException(
					"Unable to marshal payload, ResultFactory returned null.");
		try {
			transformedPayload = result;
		catch (IOException e) {
			throw new MessagingException("Failed to marshal payload"e);
		if (this. != null) {
			transformedPayload = this..transformResult(result);
		return transformedPayload;
New to GrepCode? Check out our FAQ X