Skip to content

Commit d8e640d

Browse files
committed
polishing
1 parent 0f75ceb commit d8e640d

File tree

5 files changed

+122
-120
lines changed

5 files changed

+122
-120
lines changed

org.springframework.jms/src/main/java/org/springframework/jms/support/converter/MarshallingMessageConverter.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -57,10 +57,11 @@ public class MarshallingMessageConverter implements MessageConverter, Initializi
5757

5858
private MessageType targetType = MessageType.BYTES;
5959

60+
6061
/**
61-
* Construct a new <code>MarshallingMessageConverter</code> with no {@link Marshaller} or {@link Unmarshaller} set.
62-
* The marshaller must be set after construction by invoking {@link #setMarshaller(Marshaller)} and
63-
* {@link #setUnmarshaller(Unmarshaller)} .
62+
* Construct a new <code>MarshallingMessageConverter</code> with no {@link Marshaller}
63+
* or {@link Unmarshaller} set. The marshaller must be set after construction by invoking
64+
* {@link #setMarshaller(Marshaller)} and {@link #setUnmarshaller(Unmarshaller)} .
6465
*/
6566
public MarshallingMessageConverter() {
6667
}
@@ -80,7 +81,7 @@ public MarshallingMessageConverter(Marshaller marshaller) {
8081
if (!(marshaller instanceof Unmarshaller)) {
8182
throw new IllegalArgumentException(
8283
"Marshaller [" + marshaller + "] does not implement the Unmarshaller " +
83-
"interface. Please set an Unmarshaller explicitely by using the " +
84+
"interface. Please set an Unmarshaller explicitly by using the " +
8485
"MarshallingMessageConverter(Marshaller, Unmarshaller) constructor.");
8586
}
8687
else {
@@ -127,6 +128,7 @@ public void setUnmarshaller(Unmarshaller unmarshaller) {
127128
* @see MessageType#TEXT
128129
*/
129130
public void setTargetType(MessageType targetType) {
131+
Assert.notNull(targetType, "MessageType must not be null");
130132
this.targetType = targetType;
131133
}
132134

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

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

258260

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

311-
throw new IllegalArgumentException(
312-
"MarshallingMessageConverter only supports TextMessages and BytesMessages");
313+
throw new IllegalArgumentException("Unsupported message type [" + message.getClass() +
314+
"]. MarshallingMessageConverter by default only supports TextMessages and BytesMessages.");
313315
}
314316

315317
}

org.springframework.oxm/src/main/java/org/springframework/oxm/xstream/XStreamMarshaller.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -110,11 +110,12 @@ public class XStreamMarshaller extends AbstractMarshaller implements Initializin
110110

111111
private ClassLoader classLoader;
112112

113+
113114
/**
114115
* Returns the XStream instance used by this marshaller.
115116
*/
116117
public XStream getXStream() {
117-
return xstream;
118+
return this.xstream;
118119
}
119120

120121
/**
@@ -150,7 +151,6 @@ else if (converters[i] instanceof SingleValueConverter) {
150151
/**
151152
* Sets an alias/type map, consisting of string aliases mapped to classes. Keys are aliases; values are either
152153
* {@code Class} instances, or String class names.
153-
*
154154
* @see XStream#alias(String, Class)
155155
*/
156156
public void setAliases(Map<String, ?> aliases) throws ClassNotFoundException {
@@ -165,7 +165,6 @@ public void setAliases(Map<String, ?> aliases) throws ClassNotFoundException {
165165
* Sets the aliases by type map, consisting of string aliases mapped to classes. Any class that is assignable to
166166
* this type will be aliased to the same name. Keys are aliases; values are either
167167
* {@code Class} instances, or String class names.
168-
*
169168
* @see XStream#aliasType(String, Class)
170169
*/
171170
public void setAliasesByType(Map<String, ?> aliases) throws ClassNotFoundException {
@@ -325,9 +324,9 @@ public void setAnnotatedClasses(Class<?>[] annotatedClasses) {
325324
}
326325

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

361-
public final void afterPropertiesSet() throws Exception {
362-
customizeXStream(getXStream());
363-
}
364-
365360
public void setBeanClassLoader(ClassLoader classLoader) {
366361
this.classLoader = classLoader;
367362
}
368363

364+
365+
public final void afterPropertiesSet() throws Exception {
366+
customizeXStream(getXStream());
367+
}
368+
369369
/**
370370
* Template to allow for customizing of the given {@link XStream}.
371-
* <p>Default implementation is empty.
371+
* <p>The default implementation is empty.
372372
* @param xstream the {@code XStream} instance
373373
*/
374374
protected void customizeXStream(XStream xstream) {
375375
}
376376

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

439440
@Override
440441
protected void marshalWriter(Object graph, Writer writer) throws XmlMappingException, IOException {
441-
if (streamDriver != null) {
442-
marshal(graph, streamDriver.createWriter(writer));
442+
if (this.streamDriver != null) {
443+
marshal(graph, this.streamDriver.createWriter(writer));
443444
}
444445
else {
445446
marshal(graph, new CompactWriter(writer));
@@ -467,6 +468,7 @@ private void marshal(Object graph, HierarchicalStreamWriter streamWriter) {
467468
}
468469
}
469470

471+
470472
// Unmarshalling
471473

472474
@Override

0 commit comments

Comments
 (0)