Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2002-2014 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
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * 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;
 
 import java.io.File;
 
 
 
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, java.io.File, 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.

Author(s):
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.

Parameters:
sourceFactory The source factory.
 
 	public void setSourceFactory(SourceFactory sourceFactory) {
 		Assert.notNull(sourceFactory"sourceFactory must not be null");
 		this. = sourceFactory;
 	}

If true always delegate to the org.springframework.integration.xml.source.SourceFactory.

Parameters:
alwaysUseSourceFactory true to always use the source factory.
 
 	public void setAlwaysUseSourceFactory(boolean alwaysUseSourceFactory) {
 		this. = alwaysUseSourceFactory;
 	}
 
 	public String getComponentType() {
 		return "xml:unmarshalling-transformer";
 	}
 
 	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