Browse Source

Polishing

pull/1681/head
Juergen Hoeller 8 years ago
parent
commit
d3cee45f30
  1. 31
      spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheResolverAdapter.java
  2. 4
      spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/CacheResolverAdapterTests.java
  3. 3
      spring-context/src/main/java/org/springframework/cache/interceptor/CacheResolver.java
  4. 13
      spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/HeadersMethodArgumentResolver.java
  5. 6
      spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolverComposite.java
  6. 22
      spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java

31
spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheResolverAdapter.java vendored

@ -1,5 +1,20 @@ @@ -1,5 +1,20 @@
package org.springframework.cache.jcache.interceptor;
/*
* Copyright 2002-2018 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.cache.jcache.interceptor;
import java.util.Collection;
import java.util.Collections;
@ -23,17 +38,19 @@ class CacheResolverAdapter implements CacheResolver { @@ -23,17 +38,19 @@ class CacheResolverAdapter implements CacheResolver {
private final javax.cache.annotation.CacheResolver target;
/**
* Create a new instance with the JSR-107 cache resolver to invoke.
*/
public CacheResolverAdapter(javax.cache.annotation.CacheResolver target) {
Assert.notNull(target, "JSR-107 cache resolver must be set.");
Assert.notNull(target, "JSR-107 CacheResolver is required");
this.target = target;
}
/**
* Return the underlying {@link javax.cache.annotation.CacheResolver} that this
* instance is using.
* Return the underlying {@link javax.cache.annotation.CacheResolver}
* that this instance is using.
*/
protected javax.cache.annotation.CacheResolver getTarget() {
return target;
@ -45,8 +62,10 @@ class CacheResolverAdapter implements CacheResolver { @@ -45,8 +62,10 @@ class CacheResolverAdapter implements CacheResolver {
throw new IllegalStateException("Unexpected context " + context);
}
CacheInvocationContext<?> cacheInvocationContext = (CacheInvocationContext<?>) context;
javax.cache.Cache<Object, Object> cache = target.resolveCache(cacheInvocationContext);
Assert.notNull(cache, () -> "Cannot resolve cache for '" + context + "' using '" + target + "'");
javax.cache.Cache<Object, Object> cache = this.target.resolveCache(cacheInvocationContext);
if (cache == null) {
throw new IllegalStateException("Could not resolve cache for " + context + " using " + this.target);
}
return Collections.singleton(new JCacheCache(cache));
}

4
spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/CacheResolverAdapterTests.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -58,7 +58,7 @@ public class CacheResolverAdapterTests extends AbstractJCacheTests { @@ -58,7 +58,7 @@ public class CacheResolverAdapterTests extends AbstractJCacheTests {
DefaultCacheInvocationContext<?> dummyContext = createDummyContext();
CacheResolverAdapter adapter = new CacheResolverAdapter(getCacheResolver(dummyContext, null));
thrown.expect(IllegalArgumentException.class);
thrown.expect(IllegalStateException.class);
adapter.resolveCaches(dummyContext);
}

3
spring-context/src/main/java/org/springframework/cache/interceptor/CacheResolver.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@ -35,6 +35,7 @@ public interface CacheResolver { @@ -35,6 +35,7 @@ public interface CacheResolver {
* Return the cache(s) to use for the specified invocation.
* @param context the context of the particular invocation
* @return the cache(s) to use (never {@code null})
* @throws IllegalStateException if cache resolution failed
*/
Collection<? extends Cache> resolveCaches(CacheOperationInvocationContext<?> context);

13
spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/HeadersMethodArgumentResolver.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 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.
@ -26,7 +26,6 @@ import org.springframework.messaging.MessageHeaders; @@ -26,7 +26,6 @@ import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver;
import org.springframework.messaging.support.MessageHeaderAccessor;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
/**
@ -46,16 +45,13 @@ public class HeadersMethodArgumentResolver implements HandlerMethodArgumentResol @@ -46,16 +45,13 @@ public class HeadersMethodArgumentResolver implements HandlerMethodArgumentResol
public boolean supportsParameter(MethodParameter parameter) {
Class<?> paramType = parameter.getParameterType();
return ((parameter.hasParameterAnnotation(Headers.class) && Map.class.isAssignableFrom(paramType)) ||
MessageHeaders.class == paramType ||
MessageHeaderAccessor.class.isAssignableFrom(paramType));
MessageHeaders.class == paramType || MessageHeaderAccessor.class.isAssignableFrom(paramType));
}
@Override
@Nullable
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
Class<?> paramType = parameter.getParameterType();
if (Map.class.isAssignableFrom(paramType)) {
return message.getHeaders();
}
@ -70,7 +66,10 @@ public class HeadersMethodArgumentResolver implements HandlerMethodArgumentResol @@ -70,7 +66,10 @@ public class HeadersMethodArgumentResolver implements HandlerMethodArgumentResol
}
else {
Method method = ReflectionUtils.findMethod(paramType, "wrap", Message.class);
Assert.notNull(method, () -> "Cannot create accessor of type " + paramType + " for message " + message);
if (method == null) {
throw new IllegalStateException(
"Cannot create accessor of type " + paramType + " for message " + message);
}
return ReflectionUtils.invokeMethod(method, null, message);
}
}

6
spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolverComposite.java

@ -25,7 +25,6 @@ import java.util.concurrent.ConcurrentHashMap; @@ -25,7 +25,6 @@ import java.util.concurrent.ConcurrentHashMap;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.util.Assert;
/**
* Resolves method parameters by delegating to a list of registered
@ -110,9 +109,10 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu @@ -110,9 +109,10 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu
@Override
@Nullable
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
HandlerMethodArgumentResolver resolver = getArgumentResolver(parameter);
Assert.notNull(resolver, () -> "Unknown parameter type [" + parameter.getParameterType().getName() + "]");
if (resolver == null) {
throw new IllegalStateException("Unknown parameter type [" + parameter.getParameterType().getName() + "]");
}
return resolver.resolveArgument(parameter, message);
}

22
spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -579,10 +579,10 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi @@ -579,10 +579,10 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
XMLReader xmlReader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
for (int i = 0; i < resources.length; i++) {
Resource currentResource = resources[i];
Assert.notNull(currentResource, "Resource is null");
Assert.isTrue(currentResource.exists(), () -> "Resource " + currentResource + " does not exist");
InputSource inputSource = SaxResourceUtils.createInputSource(currentResource);
Resource resource = resources[i];
Assert.notNull(resource, "Resource is null");
Assert.isTrue(resource.exists(), () -> "Resource " + resource + " does not exist");
InputSource inputSource = SaxResourceUtils.createInputSource(resource);
schemaSources[i] = new SAXSource(xmlReader, inputSource);
}
SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);
@ -1060,12 +1060,12 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi @@ -1060,12 +1060,12 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
}
@Override
public InputStream getInputStream() throws IOException {
public InputStream getInputStream() {
return new ByteArrayInputStream(this.data, this.offset, this.length);
}
@Override
public OutputStream getOutputStream() throws IOException {
public OutputStream getOutputStream() {
throw new UnsupportedOperationException();
}
@ -1081,11 +1081,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi @@ -1081,11 +1081,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
}
private static final EntityResolver NO_OP_ENTITY_RESOLVER = new EntityResolver() {
@Override
public InputSource resolveEntity(String publicId, String systemId) {
return new InputSource(new StringReader(""));
}
};
private static final EntityResolver NO_OP_ENTITY_RESOLVER =
(publicId, systemId) -> new InputSource(new StringReader(""));
}

Loading…
Cancel
Save