Skip to content

Commit

Permalink
polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Dec 11, 2011
1 parent 0f75ceb commit d8e640d
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 120 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 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.
Expand Down Expand Up @@ -57,10 +57,11 @@ public class MarshallingMessageConverter implements MessageConverter, Initializi

private MessageType targetType = MessageType.BYTES;


/**
* Construct a new <code>MarshallingMessageConverter</code> with no {@link Marshaller} or {@link Unmarshaller} set.
* The marshaller must be set after construction by invoking {@link #setMarshaller(Marshaller)} and
* {@link #setUnmarshaller(Unmarshaller)} .
* Construct a new <code>MarshallingMessageConverter</code> with no {@link Marshaller}
* or {@link Unmarshaller} set. The marshaller must be set after construction by invoking
* {@link #setMarshaller(Marshaller)} and {@link #setUnmarshaller(Unmarshaller)} .
*/
public MarshallingMessageConverter() {
}
Expand All @@ -80,7 +81,7 @@ public MarshallingMessageConverter(Marshaller marshaller) {
if (!(marshaller instanceof Unmarshaller)) {
throw new IllegalArgumentException(
"Marshaller [" + marshaller + "] does not implement the Unmarshaller " +
"interface. Please set an Unmarshaller explicitely by using the " +
"interface. Please set an Unmarshaller explicitly by using the " +
"MarshallingMessageConverter(Marshaller, Unmarshaller) constructor.");
}
else {
Expand Down Expand Up @@ -127,6 +128,7 @@ public void setUnmarshaller(Unmarshaller unmarshaller) {
* @see MessageType#TEXT
*/
public void setTargetType(MessageType targetType) {
Assert.notNull(targetType, "MessageType must not be null");
this.targetType = targetType;
}

Expand Down Expand Up @@ -251,8 +253,8 @@ protected BytesMessage marshalToBytesMessage(Object object, Session session, Mar
protected Message marshalToMessage(Object object, Session session, Marshaller marshaller, MessageType targetType)
throws JMSException, IOException, XmlMappingException {

throw new IllegalArgumentException(
"Unsupported message type [" + targetType + "]. Cannot marshal to the specified message type.");
throw new IllegalArgumentException("Unsupported message type [" + targetType +
"]. MarshallingMessageConverter by default only supports TextMessages and BytesMessages.");
}


Expand Down Expand Up @@ -308,8 +310,8 @@ protected Object unmarshalFromBytesMessage(BytesMessage message, Unmarshaller un
protected Object unmarshalFromMessage(Message message, Unmarshaller unmarshaller)
throws JMSException, IOException, XmlMappingException {

throw new IllegalArgumentException(
"MarshallingMessageConverter only supports TextMessages and BytesMessages");
throw new IllegalArgumentException("Unsupported message type [" + message.getClass() +
"]. MarshallingMessageConverter by default only supports TextMessages and BytesMessages.");
}

}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 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.
Expand Down Expand Up @@ -110,11 +110,12 @@ public class XStreamMarshaller extends AbstractMarshaller implements Initializin

private ClassLoader classLoader;


/**
* Returns the XStream instance used by this marshaller.
*/
public XStream getXStream() {
return xstream;
return this.xstream;
}

/**
Expand Down Expand Up @@ -150,7 +151,6 @@ else if (converters[i] instanceof SingleValueConverter) {
/**
* Sets an alias/type map, consisting of string aliases mapped to classes. Keys are aliases; values are either
* {@code Class} instances, or String class names.
*
* @see XStream#alias(String, Class)
*/
public void setAliases(Map<String, ?> aliases) throws ClassNotFoundException {
Expand All @@ -165,7 +165,6 @@ public void setAliases(Map<String, ?> aliases) throws ClassNotFoundException {
* Sets the aliases by type map, consisting of string aliases mapped to classes. Any class that is assignable to
* this type will be aliased to the same name. Keys are aliases; values are either
* {@code Class} instances, or String class names.
*
* @see XStream#aliasType(String, Class)
*/
public void setAliasesByType(Map<String, ?> aliases) throws ClassNotFoundException {
Expand Down Expand Up @@ -325,9 +324,9 @@ public void setAnnotatedClasses(Class<?>[] annotatedClasses) {
}

/**
* Set the auto-detection mode of XStream.
* <p><strong>Note</strong> that auto-detection implies that the XStream is configured while it is processing the
* XML steams, and thus introduces a potential concurrency problem.
* Set the autodetection mode of XStream.
* <p><strong>Note</strong> that auto-detection implies that the XStream is configured while
* it is processing the XML streams, and thus introduces a potential concurrency problem.
* @see XStream#autodetectAnnotations(boolean)
*/
public void setAutodetectAnnotations(boolean autodetectAnnotations) {
Expand Down Expand Up @@ -358,22 +357,24 @@ public void setSupportedClasses(Class[] supportedClasses) {
this.supportedClasses = supportedClasses;
}

public final void afterPropertiesSet() throws Exception {
customizeXStream(getXStream());
}

public void setBeanClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}


public final void afterPropertiesSet() throws Exception {
customizeXStream(getXStream());
}

/**
* Template to allow for customizing of the given {@link XStream}.
* <p>Default implementation is empty.
* <p>The default implementation is empty.
* @param xstream the {@code XStream} instance
*/
protected void customizeXStream(XStream xstream) {
}


public boolean supports(Class clazz) {
if (ObjectUtils.isEmpty(this.supportedClasses)) {
return true;
Expand Down Expand Up @@ -438,8 +439,8 @@ protected void marshalSaxHandlers(Object graph, ContentHandler contentHandler, L

@Override
protected void marshalWriter(Object graph, Writer writer) throws XmlMappingException, IOException {
if (streamDriver != null) {
marshal(graph, streamDriver.createWriter(writer));
if (this.streamDriver != null) {
marshal(graph, this.streamDriver.createWriter(writer));
}
else {
marshal(graph, new CompactWriter(writer));
Expand Down Expand Up @@ -467,6 +468,7 @@ private void marshal(Object graph, HierarchicalStreamWriter streamWriter) {
}
}


// Unmarshalling

@Override
Expand Down

0 comments on commit d8e640d

Please sign in to comment.