Browse Source

Polishing

pull/931/head
Juergen Hoeller 10 years ago
parent
commit
3c549ef9fa
  1. 7
      spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java
  2. 45
      spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java
  3. 55
      spring-core/src/main/java/org/springframework/core/io/PathResource.java
  4. 50
      spring-jms/src/main/java/org/springframework/jms/annotation/JmsListener.java
  5. 18
      spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java
  6. 47
      spring-messaging/src/main/java/org/springframework/messaging/MessageHeaders.java

7
spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@ -27,8 +27,8 @@ import org.springframework.util.ObjectUtils; @@ -27,8 +27,8 @@ import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/**
* {@link Resource} implementation for class path resources.
* Uses either a given ClassLoader or a given Class for loading resources.
* {@link Resource} implementation for class path resources. Uses either a
* given {@link ClassLoader} or a given {@link Class} for loading resources.
*
* <p>Supports resolution as {@code java.io.File} if the class path
* resource resides in the file system, but not for resources in a JAR.
@ -229,6 +229,7 @@ public class ClassPathResource extends AbstractFileResolvingResource { @@ -229,6 +229,7 @@ public class ClassPathResource extends AbstractFileResolvingResource {
return builder.toString();
}
/**
* This implementation compares the underlying class path locations.
*/

45
spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@ -115,6 +115,26 @@ public class FileSystemResource extends AbstractResource implements WritableReso @@ -115,6 +115,26 @@ public class FileSystemResource extends AbstractResource implements WritableReso
return new FileInputStream(this.file);
}
/**
* This implementation checks whether the underlying file is marked as writable
* (and corresponds to an actual file with content, not to a directory).
* @see java.io.File#canWrite()
* @see java.io.File#isDirectory()
*/
@Override
public boolean isWritable() {
return (this.file.canWrite() && !this.file.isDirectory());
}
/**
* This implementation opens a FileOutputStream for the underlying file.
* @see java.io.FileOutputStream
*/
@Override
public OutputStream getOutputStream() throws IOException {
return new FileOutputStream(this.file);
}
/**
* This implementation returns a URL for the underlying file.
* @see java.io.File#toURI()
@ -180,29 +200,6 @@ public class FileSystemResource extends AbstractResource implements WritableReso @@ -180,29 +200,6 @@ public class FileSystemResource extends AbstractResource implements WritableReso
}
// implementation of WritableResource
/**
* This implementation checks whether the underlying file is marked as writable
* (and corresponds to an actual file with content, not to a directory).
* @see java.io.File#canWrite()
* @see java.io.File#isDirectory()
*/
@Override
public boolean isWritable() {
return (this.file.canWrite() && !this.file.isDirectory());
}
/**
* This implementation opens a FileOutputStream for the underlying file.
* @see java.io.FileOutputStream
*/
@Override
public OutputStream getOutputStream() throws IOException {
return new FileOutputStream(this.file);
}
/**
* This implementation compares the underlying File references.
*/

55
spring-core/src/main/java/org/springframework/core/io/PathResource.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@ -37,6 +37,7 @@ import org.springframework.util.Assert; @@ -37,6 +37,7 @@ import org.springframework.util.Assert;
* Implements the extended {@link WritableResource} interface.
*
* @author Philippe Marschall
* @author Juergen Hoeller
* @since 4.0
* @see java.nio.file.Path
*/
@ -130,6 +131,29 @@ public class PathResource extends AbstractResource implements WritableResource { @@ -130,6 +131,29 @@ public class PathResource extends AbstractResource implements WritableResource {
return Files.newInputStream(this.path);
}
/**
* This implementation checks whether the underlying file is marked as writable
* (and corresponds to an actual file with content, not to a directory).
* @see java.nio.file.Files#isWritable(Path)
* @see java.nio.file.Files#isDirectory(Path, java.nio.file.LinkOption...)
*/
@Override
public boolean isWritable() {
return (Files.isWritable(this.path) && !Files.isDirectory(this.path));
}
/**
* This implementation opens a OutputStream for the underlying file.
* @see java.nio.file.spi.FileSystemProvider#newOutputStream(Path, OpenOption...)
*/
@Override
public OutputStream getOutputStream() throws IOException {
if (Files.isDirectory(this.path)) {
throw new FileNotFoundException(getPath() + " (is a directory)");
}
return Files.newOutputStream(this.path);
}
/**
* This implementation returns a URL for the underlying file.
* @see java.nio.file.Path#toUri()
@ -178,8 +202,8 @@ public class PathResource extends AbstractResource implements WritableResource { @@ -178,8 +202,8 @@ public class PathResource extends AbstractResource implements WritableResource {
*/
@Override
public long lastModified() throws IOException {
// we can not use the super class method since it uses conversion to a File and
// only Paths on the default file system can be converted to a File
// We can not use the superclass method since it uses conversion to a File and
// only a Path on the default file system can be converted to a File...
return Files.getLastModifiedTime(path).toMillis();
}
@ -207,31 +231,6 @@ public class PathResource extends AbstractResource implements WritableResource { @@ -207,31 +231,6 @@ public class PathResource extends AbstractResource implements WritableResource {
return "path [" + this.path.toAbsolutePath() + "]";
}
// implementation of WritableResource
/**
* This implementation checks whether the underlying file is marked as writable
* (and corresponds to an actual file with content, not to a directory).
* @see java.nio.file.Files#isWritable(Path)
* @see java.nio.file.Files#isDirectory(Path, java.nio.file.LinkOption...)
*/
@Override
public boolean isWritable() {
return Files.isWritable(this.path) && !Files.isDirectory(this.path);
}
/**
* This implementation opens a OutputStream for the underlying file.
* @see java.nio.file.spi.FileSystemProvider#newOutputStream(Path, OpenOption...)
*/
@Override
public OutputStream getOutputStream() throws IOException {
if (Files.isDirectory(this.path)) {
throw new FileNotFoundException(getPath() + " (is a directory)");
}
return Files.newOutputStream(this.path);
}
/**
* This implementation compares the underlying Path references.

50
spring-jms/src/main/java/org/springframework/jms/annotation/JmsListener.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@ -25,21 +25,20 @@ import java.lang.annotation.Target; @@ -25,21 +25,20 @@ import java.lang.annotation.Target;
import org.springframework.messaging.handler.annotation.MessageMapping;
/**
* Annotation that marks a method to be the target of a JMS message
* listener on the specified {@link #destination}. The {@link #containerFactory}
* identifies the {@link org.springframework.jms.config.JmsListenerContainerFactory
* JmsListenerContainerFactory} to use to build the JMS listener container. If not
* set, a <em>default</em> container factory is assumed to be available with a bean
* name of {@code jmsListenerContainerFactory} unless an explicit default has been
* provided through configuration.
* Annotation that marks a method to be the target of a JMS message listener on the
* specified {@link #destination}. The {@link #containerFactory} identifies the
* {@link org.springframework.jms.config.JmsListenerContainerFactory} to use to build
* the JMS listener container. If not set, a <em>default</em> container factory is
* assumed to be available with a bean name of {@code jmsListenerContainerFactory}
* unless an explicit default has been provided through configuration.
*
* <p>Processing of {@code @JmsListener} annotations is performed by
* registering a {@link JmsListenerAnnotationBeanPostProcessor}. This can be
* done manually or, more conveniently, through the {@code <jms:annotation-driven/>}
* element or {@link EnableJms @EnableJms} annotation.
* <p>Processing of {@code @JmsListener} annotations is performed by registering a
* {@link JmsListenerAnnotationBeanPostProcessor}. This can be done manually or,
* more conveniently, through the {@code <jms:annotation-driven/>} element or
* {@link EnableJms @EnableJms} annotation.
*
* <p>Annotated methods are allowed to have flexible signatures similar to what
* {@link MessageMapping} provides:
* <p>Annotated JMS listener methods are allowed to have flexible signatures similar
* to what {@link MessageMapping} provides:
* <ul>
* <li>{@link javax.jms.Session} to get access to the JMS session</li>
* <li>{@link javax.jms.Message} or one of its subclasses to get access to the raw JMS message</li>
@ -48,15 +47,15 @@ import org.springframework.messaging.handler.annotation.MessageMapping; @@ -48,15 +47,15 @@ import org.springframework.messaging.handler.annotation.MessageMapping;
* arguments, including support for validation</li>
* <li>{@link org.springframework.messaging.handler.annotation.Header @Header}-annotated method
* arguments to extract specific header values, including standard JMS headers defined by
* {@link org.springframework.jms.support.JmsHeaders JmsHeaders}</li>
* {@link org.springframework.jms.support.JmsHeaders}</li>
* <li>{@link org.springframework.messaging.handler.annotation.Headers @Headers}-annotated
* method argument that must also be assignable to {@link java.util.Map} for obtaining access to all
* headers</li>
* <li>{@link org.springframework.messaging.MessageHeaders MessageHeaders} arguments for
* obtaining access to all headers</li>
* <li>{@link org.springframework.messaging.support.MessageHeaderAccessor MessageHeaderAccessor}
* or {@link org.springframework.jms.support.JmsMessageHeaderAccessor JmsMessageHeaderAccessor}
* for convenient access to all method arguments</li>
* method argument that must also be assignable to {@link java.util.Map} for obtaining
* access to all headers</li>
* <li>{@link org.springframework.messaging.MessageHeaders} arguments for obtaining
* access to all headers</li>
* <li>{@link org.springframework.messaging.support.MessageHeaderAccessor} or
* {@link org.springframework.jms.support.JmsMessageHeaderAccessor} for convenient
* access to all method arguments</li>
* </ul>
*
* <p>Annotated methods may have a non-{@code void} return type. When they do,
@ -73,8 +72,8 @@ import org.springframework.messaging.handler.annotation.MessageMapping; @@ -73,8 +72,8 @@ import org.springframework.messaging.handler.annotation.MessageMapping;
*/
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@MessageMapping
@Documented
@MessageMapping
public @interface JmsListener {
/**
@ -85,7 +84,7 @@ public @interface JmsListener { @@ -85,7 +84,7 @@ public @interface JmsListener {
String id() default "";
/**
* The bean name of the {@link org.springframework.jms.config.JmsListenerContainerFactory JmsListenerContainerFactory}
* The bean name of the {@link org.springframework.jms.config.JmsListenerContainerFactory}
* to use to create the message listener container responsible for serving this endpoint.
* <p>If not specified, the default container factory is used, if any.
*/
@ -93,8 +92,7 @@ public @interface JmsListener { @@ -93,8 +92,7 @@ public @interface JmsListener {
/**
* The destination name for this listener, resolved through the container-wide
* {@link org.springframework.jms.support.destination.DestinationResolver DestinationResolver}
* strategy.
* {@link org.springframework.jms.support.destination.DestinationResolver} strategy.
*/
String destination();

18
spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@ -54,8 +54,8 @@ import org.springframework.util.StringUtils; @@ -54,8 +54,8 @@ import org.springframework.util.StringUtils;
/**
* Bean post-processor that registers methods annotated with {@link JmsListener}
* to be invoked by a JMS message listener container created under the cover
* by a {@link org.springframework.jms.config.JmsListenerContainerFactory} according
* to the parameters of the annotation.
* by a {@link org.springframework.jms.config.JmsListenerContainerFactory}
* according to the attributes of the annotation.
*
* <p>Annotated methods can use flexible arguments as defined by {@link JmsListener}.
*
@ -63,10 +63,10 @@ import org.springframework.util.StringUtils; @@ -63,10 +63,10 @@ import org.springframework.util.StringUtils;
* {@code <jms:annotation-driven>} XML element, and also by the {@link EnableJms}
* annotation.
*
* <p>Auto-detect any {@link JmsListenerConfigurer} instances in the container,
* <p>Autodetects any {@link JmsListenerConfigurer} instances in the container,
* allowing for customization of the registry to be used, the default container
* factory or for fine-grained control over endpoints registration. See
* {@link EnableJms} Javadoc for complete usage details.
* factory or for fine-grained control over endpoints registration. See the
* {@link EnableJms} javadocs for complete usage details.
*
* @author Stephane Nicoll
* @author Juergen Hoeller
@ -208,8 +208,8 @@ public class JmsListenerAnnotationBeanPostProcessor @@ -208,8 +208,8 @@ public class JmsListenerAnnotationBeanPostProcessor
});
if (annotatedMethods.isEmpty()) {
this.nonAnnotatedClasses.add(bean.getClass());
if (logger.isDebugEnabled()) {
logger.debug("No @JmsListener annotations found on bean class: " + bean.getClass());
if (logger.isTraceEnabled()) {
logger.trace("No @JmsListener annotations found on bean class: " + bean.getClass());
}
}
else {
@ -281,7 +281,7 @@ public class JmsListenerAnnotationBeanPostProcessor @@ -281,7 +281,7 @@ public class JmsListenerAnnotationBeanPostProcessor
return resolve(jmsListener.id());
}
else {
return "org.springframework.jms.JmsListenerEndpointContainer#" + counter.getAndIncrement();
return "org.springframework.jms.JmsListenerEndpointContainer#" + this.counter.getAndIncrement();
}
}

47
spring-messaging/src/main/java/org/springframework/messaging/MessageHeaders.java

@ -165,6 +165,7 @@ public class MessageHeaders implements Map<String, Object>, Serializable { @@ -165,6 +165,7 @@ public class MessageHeaders implements Map<String, Object>, Serializable {
return get(ERROR_CHANNEL);
}
@SuppressWarnings("unchecked")
public <T> T get(Object key, Class<T> type) {
Object value = this.headers.get(key);
@ -179,23 +180,6 @@ public class MessageHeaders implements Map<String, Object>, Serializable { @@ -179,23 +180,6 @@ public class MessageHeaders implements Map<String, Object>, Serializable {
}
@Override
public boolean equals(Object other) {
return (this == other ||
(other instanceof MessageHeaders && this.headers.equals(((MessageHeaders) other).headers)));
}
@Override
public int hashCode() {
return this.headers.hashCode();
}
@Override
public String toString() {
return this.headers.toString();
}
// Delegating Map implementation
public boolean containsKey(Object key) {
@ -275,11 +259,13 @@ public class MessageHeaders implements Map<String, Object>, Serializable { @@ -275,11 +259,13 @@ public class MessageHeaders implements Map<String, Object>, Serializable {
keysToRemove.add(entry.getKey());
}
}
for (String key : keysToRemove) {
if (logger.isInfoEnabled()) {
logger.info("Removing non-serializable header: " + key);
if (!keysToRemove.isEmpty()) {
if (logger.isDebugEnabled()) {
logger.debug("Removing non-serializable message headers: " + keysToRemove);
}
for (String key : keysToRemove) {
this.headers.remove(key);
}
this.headers.remove(key);
}
out.defaultWriteObject();
}
@ -288,4 +274,23 @@ public class MessageHeaders implements Map<String, Object>, Serializable { @@ -288,4 +274,23 @@ public class MessageHeaders implements Map<String, Object>, Serializable {
in.defaultReadObject();
}
// equals, hashCode, toString
@Override
public boolean equals(Object other) {
return (this == other ||
(other instanceof MessageHeaders && this.headers.equals(((MessageHeaders) other).headers)));
}
@Override
public int hashCode() {
return this.headers.hashCode();
}
@Override
public String toString() {
return this.headers.toString();
}
}

Loading…
Cancel
Save