Polishing

This commit is contained in:
Juergen Hoeller
2014-07-24 18:35:49 +02:00
parent fca72f6b65
commit 6e95b2613e
78 changed files with 467 additions and 463 deletions

View File

@@ -20,6 +20,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.w3c.dom.Element;
import org.springframework.beans.factory.config.TypedStringValue;
import org.springframework.beans.factory.parsing.ReaderContext;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@@ -37,7 +39,6 @@ import org.springframework.cache.interceptor.CacheableOperation;
import org.springframework.cache.interceptor.NameMatchCacheOperationSource;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
/**
* {@link org.springframework.beans.factory.xml.BeanDefinitionParser
@@ -74,7 +75,8 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
// Using attributes source.
List<RootBeanDefinition> attributeSourceDefinitions = parseDefinitionsSources(cacheDefs, parserContext);
builder.addPropertyValue("cacheOperationSources", attributeSourceDefinitions);
} else {
}
else {
// Assume annotations source.
builder.addPropertyValue("cacheOperationSources", new RootBeanDefinition(
AnnotationCacheOperationSource.class));
@@ -177,8 +179,6 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
/**
* Simple, reusable class used for overriding defaults.
*
* @author Costin Leau
*/
private static class Props {
@@ -190,7 +190,6 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
private String[] caches = null;
Props(Element root) {
String defaultCache = root.getAttribute("cache");
key = root.getAttribute("key");
@@ -202,7 +201,6 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
}
}
<T extends CacheOperation> T merge(Element element, ReaderContext readerCtx, T op) {
String cache = element.getAttribute("cache");
@@ -210,7 +208,8 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
String[] localCaches = caches;
if (StringUtils.hasText(cache)) {
localCaches = StringUtils.commaDelimitedListToStringArray(cache.trim());
} else {
}
else {
if (caches == null) {
readerCtx.error("No cache specified specified for " + element.getNodeName(), element);
}
@@ -224,16 +223,16 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
}
String merge(Element element, ReaderContext readerCtx) {
String m = element.getAttribute(METHOD_ATTRIBUTE);
if (StringUtils.hasText(m)) {
return m.trim();
}
String method = element.getAttribute(METHOD_ATTRIBUTE);
if (StringUtils.hasText(method)) {
return method;
return method.trim();
}
if (StringUtils.hasText(this.method)) {
return this.method;
}
readerCtx.error("No method specified for " + element.getNodeName(), element);
return null;
}
}
}

View File

@@ -13,13 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.format;
import java.lang.annotation.Annotation;
import java.util.Set;
/**
* A factory that creates formatters to format values of fields annotated with a particular {@link Annotation}.
* A factory that creates formatters to format values of fields annotated with a particular
* {@link Annotation}.
*
* <p>For example, a {@code DateTimeFormatAnnotationFormatterFactory} might create a formatter
* that formats {@code Date} values set on fields annotated with {@code @DateTimeFormat}.
@@ -36,8 +38,10 @@ public interface AnnotationFormatterFactory<A extends Annotation> {
Set<Class<?>> getFieldTypes();
/**
* Get the Printer to print the value of a field of {@code fieldType} annotated with {@code annotation}.
* If the type &lt;T&gt; the printer accepts is not assignable to {@code fieldType}, a coercion from {@code fieldType} to &lt;T&gt; will be attempted before the Printer is invoked.
* Get the Printer to print the value of a field of {@code fieldType} annotated with
* {@code annotation}.
* <p>If the type T the printer accepts is not assignable to {@code fieldType}, a
* coercion from {@code fieldType} to T will be attempted before the Printer is invoked.
* @param annotation the annotation instance
* @param fieldType the type of field that was annotated
* @return the printer
@@ -45,8 +49,10 @@ public interface AnnotationFormatterFactory<A extends Annotation> {
Printer<?> getPrinter(A annotation, Class<?> fieldType);
/**
* Get the Parser to parse a submitted value for a field of {@code fieldType} annotated with {@code annotation}.
* If the object the parser returns is not assignable to {@code fieldType}, a coercion to {@code fieldType} will be attempted before the field is set.
* Get the Parser to parse a submitted value for a field of {@code fieldType}
* annotated with {@code annotation}.
* <p>If the object the parser returns is not assignable to {@code fieldType},
* a coercion to {@code fieldType} will be attempted before the field is set.
* @param annotation the annotation instance
* @param fieldType the type of field that was annotated
* @return the parser

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* 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.
@@ -90,7 +90,7 @@ public class FormattingConversionService extends GenericConversionService
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void addFormatterForFieldAnnotation(AnnotationFormatterFactory annotationFormatterFactory) {
final Class<? extends Annotation> annotationType = (Class<? extends Annotation>)
Class<? extends Annotation> annotationType = (Class<? extends Annotation>)
GenericTypeResolver.resolveTypeArgument(annotationFormatterFactory.getClass(), AnnotationFormatterFactory.class);
if (annotationType == null) {
throw new IllegalArgumentException("Unable to extract parameterized Annotation type argument from AnnotationFormatterFactory [" +
@@ -100,7 +100,7 @@ public class FormattingConversionService extends GenericConversionService
((EmbeddedValueResolverAware) annotationFormatterFactory).setEmbeddedValueResolver(this.embeddedValueResolver);
}
Set<Class<?>> fieldTypes = annotationFormatterFactory.getFieldTypes();
for (final Class<?> fieldType : fieldTypes) {
for (Class<?> fieldType : fieldTypes) {
addConverter(new AnnotationPrinterConverter(annotationType, annotationFormatterFactory, fieldType));
addConverter(new AnnotationParserConverter(annotationType, annotationFormatterFactory, fieldType));
}
@@ -109,14 +109,14 @@ public class FormattingConversionService extends GenericConversionService
private static class PrinterConverter implements GenericConverter {
private Class<?> fieldType;
private final Class<?> fieldType;
private TypeDescriptor printerObjectType;
private final TypeDescriptor printerObjectType;
@SuppressWarnings("rawtypes")
private Printer printer;
private final Printer printer;
private ConversionService conversionService;
private final ConversionService conversionService;
public PrinterConverter(Class<?> fieldType, Printer<?> printer, ConversionService conversionService) {
this.fieldType = fieldType;
@@ -155,11 +155,11 @@ public class FormattingConversionService extends GenericConversionService
private static class ParserConverter implements GenericConverter {
private Class<?> fieldType;
private final Class<?> fieldType;
private Parser<?> parser;
private final Parser<?> parser;
private ConversionService conversionService;
private final ConversionService conversionService;
public ParserConverter(Class<?> fieldType, Parser<?> parser, ConversionService conversionService) {
this.fieldType = fieldType;
@@ -204,12 +204,12 @@ public class FormattingConversionService extends GenericConversionService
private class AnnotationPrinterConverter implements ConditionalGenericConverter {
private Class<? extends Annotation> annotationType;
private final Class<? extends Annotation> annotationType;
@SuppressWarnings("rawtypes")
private AnnotationFormatterFactory annotationFormatterFactory;
private final AnnotationFormatterFactory annotationFormatterFactory;
private Class<?> fieldType;
private final Class<?> fieldType;
public AnnotationPrinterConverter(Class<? extends Annotation> annotationType,
AnnotationFormatterFactory<?> annotationFormatterFactory, Class<?> fieldType) {
@@ -220,24 +220,24 @@ public class FormattingConversionService extends GenericConversionService
@Override
public Set<ConvertiblePair> getConvertibleTypes() {
return Collections.singleton(new ConvertiblePair(fieldType, String.class));
return Collections.singleton(new ConvertiblePair(this.fieldType, String.class));
}
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return sourceType.hasAnnotation(annotationType);
return sourceType.hasAnnotation(this.annotationType);
}
@Override
@SuppressWarnings("unchecked")
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
AnnotationConverterKey converterKey =
new AnnotationConverterKey(sourceType.getAnnotation(annotationType), sourceType.getObjectType());
new AnnotationConverterKey(sourceType.getAnnotation(this.annotationType), sourceType.getObjectType());
GenericConverter converter = cachedPrinters.get(converterKey);
if (converter == null) {
Printer<?> printer = annotationFormatterFactory.getPrinter(
Printer<?> printer = this.annotationFormatterFactory.getPrinter(
converterKey.getAnnotation(), converterKey.getFieldType());
converter = new PrinterConverter(fieldType, printer, FormattingConversionService.this);
converter = new PrinterConverter(this.fieldType, printer, FormattingConversionService.this);
cachedPrinters.put(converterKey, converter);
}
return converter.convert(source, sourceType, targetType);
@@ -245,20 +245,20 @@ public class FormattingConversionService extends GenericConversionService
@Override
public String toString() {
return "@" + annotationType.getName() + " " + fieldType.getName() + " -> " +
String.class.getName() + ": " + annotationFormatterFactory;
return "@" + this.annotationType.getName() + " " + this.fieldType.getName() + " -> " +
String.class.getName() + ": " + this.annotationFormatterFactory;
}
}
private class AnnotationParserConverter implements ConditionalGenericConverter {
private Class<? extends Annotation> annotationType;
private final Class<? extends Annotation> annotationType;
@SuppressWarnings("rawtypes")
private AnnotationFormatterFactory annotationFormatterFactory;
private final AnnotationFormatterFactory annotationFormatterFactory;
private Class<?> fieldType;
private final Class<?> fieldType;
public AnnotationParserConverter(Class<? extends Annotation> annotationType,
AnnotationFormatterFactory<?> annotationFormatterFactory, Class<?> fieldType) {
@@ -274,19 +274,19 @@ public class FormattingConversionService extends GenericConversionService
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return targetType.hasAnnotation(annotationType);
return targetType.hasAnnotation(this.annotationType);
}
@Override
@SuppressWarnings("unchecked")
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
AnnotationConverterKey converterKey =
new AnnotationConverterKey(targetType.getAnnotation(annotationType), targetType.getObjectType());
new AnnotationConverterKey(targetType.getAnnotation(this.annotationType), targetType.getObjectType());
GenericConverter converter = cachedParsers.get(converterKey);
if (converter == null) {
Parser<?> parser = annotationFormatterFactory.getParser(
Parser<?> parser = this.annotationFormatterFactory.getParser(
converterKey.getAnnotation(), converterKey.getFieldType());
converter = new ParserConverter(fieldType, parser, FormattingConversionService.this);
converter = new ParserConverter(this.fieldType, parser, FormattingConversionService.this);
cachedParsers.put(converterKey, converter);
}
return converter.convert(source, sourceType, targetType);
@@ -294,8 +294,8 @@ public class FormattingConversionService extends GenericConversionService
@Override
public String toString() {
return String.class.getName() + " -> @" + annotationType.getName() + " " +
fieldType.getName() + ": " + annotationFormatterFactory;
return String.class.getName() + " -> @" + this.annotationType.getName() + " " +
this.fieldType.getName() + ": " + this.annotationFormatterFactory;
}
}
@@ -312,25 +312,28 @@ public class FormattingConversionService extends GenericConversionService
}
public Annotation getAnnotation() {
return annotation;
return this.annotation;
}
public Class<?> getFieldType() {
return fieldType;
return this.fieldType;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof AnnotationConverterKey)) {
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof AnnotationConverterKey)) {
return false;
}
AnnotationConverterKey key = (AnnotationConverterKey) o;
return this.annotation.equals(key.annotation) && this.fieldType.equals(key.fieldType);
AnnotationConverterKey otherKey = (AnnotationConverterKey) other;
return (this.annotation.equals(otherKey.annotation) && this.fieldType.equals(otherKey.fieldType));
}
@Override
public int hashCode() {
return this.annotation.hashCode() + 29 * this.fieldType.hashCode();
return (this.annotation.hashCode() + 29 * this.fieldType.hashCode());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* 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.
@@ -39,32 +39,38 @@ class WebLogicClassPreProcessorAdapter implements InvocationHandler {
private final ClassLoader loader;
/**
* Creates a new {@link WebLogicClassPreProcessorAdapter}.
* @param transformer the {@link ClassFileTransformer} to be adapted (must
* not be {@code null})
* @param transformer the {@link ClassFileTransformer} to be adapted
* (must not be {@code null})
*/
public WebLogicClassPreProcessorAdapter(ClassFileTransformer transformer, ClassLoader loader) {
this.transformer = transformer;
this.loader = loader;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String name = method.getName();
if ("equals".equals(name)) {
return (Boolean.valueOf(proxy == args[0]));
} else if ("hashCode".equals(name)) {
return (proxy == args[0]);
}
else if ("hashCode".equals(name)) {
return hashCode();
} else if ("toString".equals(name)) {
}
else if ("toString".equals(name)) {
return toString();
} else if ("initialize".equals(name)) {
}
else if ("initialize".equals(name)) {
initialize((Hashtable<?, ?>) args[0]);
return null;
} else if ("preProcess".equals(name)) {
}
else if ("preProcess".equals(name)) {
return preProcess((String) args[0], (byte[]) args[1]);
} else {
}
else {
throw new IllegalArgumentException("Unknown method: " + method);
}
}
@@ -76,16 +82,15 @@ class WebLogicClassPreProcessorAdapter implements InvocationHandler {
try {
byte[] result = this.transformer.transform(this.loader, className, null, null, classBytes);
return (result != null ? result : classBytes);
} catch (IllegalClassFormatException ex) {
}
catch (IllegalClassFormatException ex) {
throw new IllegalStateException("Cannot transform due to illegal class format", ex);
}
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder(getClass().getName());
builder.append(" for transformer: ");
builder.append(this.transformer);
return builder.toString();
return getClass().getName() + " for transformer: " + this.transformer;
}
}

View File

@@ -149,7 +149,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac
@Override
public ManagedNotification[] getManagedNotifications(Class<?> clazz) throws InvalidMetadataException {
ManagedNotifications notificationsAnn = clazz.getAnnotation(ManagedNotifications.class);
if(notificationsAnn == null) {
if (notificationsAnn == null) {
return new ManagedNotification[0];
}
Annotation[] notifications = notificationsAnn.value();

View File

@@ -514,7 +514,7 @@ public abstract class AbstractReflectiveMBeanInfoAssembler extends AbstractMBean
MBeanParameterInfo[] info = new MBeanParameterInfo[paramNames.length];
Class<?>[] typeParameters = method.getParameterTypes();
for(int i = 0; i < info.length; i++) {
for (int i = 0; i < info.length; i++) {
info[i] = new MBeanParameterInfo(paramNames[i], typeParameters[i].getName(), paramNames[i]);
}

View File

@@ -153,7 +153,7 @@ public class MetadataMBeanInfoAssembler extends AbstractReflectiveMBeanInfoAssem
protected boolean includeOperation(Method method, String beanKey) {
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
if (pd != null) {
if(hasManagedAttribute(method)) {
if (hasManagedAttribute(method)) {
return true;
}
}
@@ -334,7 +334,7 @@ public class MetadataMBeanInfoAssembler extends AbstractReflectiveMBeanInfoAssem
*/
@Override
protected void populateAttributeDescriptor(Descriptor desc, Method getter, Method setter, String beanKey) {
if(getter != null && hasManagedMetric(getter)) {
if (getter != null && hasManagedMetric(getter)) {
populateMetricDescriptor(desc, this.attributeSource.getManagedMetric(getter));
}
else {
@@ -376,11 +376,11 @@ public class MetadataMBeanInfoAssembler extends AbstractReflectiveMBeanInfoAssem
desc.setField(FIELD_DISPLAY_NAME, metric.getDisplayName());
}
if(StringUtils.hasLength(metric.getUnit())) {
if (StringUtils.hasLength(metric.getUnit())) {
desc.setField(FIELD_UNITS, metric.getUnit());
}
if(StringUtils.hasLength(metric.getCategory())) {
if (StringUtils.hasLength(metric.getCategory())) {
desc.setField(FIELD_METRIC_CATEGORY, metric.getCategory());
}

View File

@@ -247,7 +247,7 @@ public class DefaultMessageCodesResolver implements MessageCodesResolver, Serial
public static String toDelimitedString(String... elements) {
StringBuilder rtn = new StringBuilder();
for (String element : elements) {
if(StringUtils.hasLength(element)) {
if (StringUtils.hasLength(element)) {
rtn.append(rtn.length() == 0 ? "" : CODE_SEPARATOR);
rtn.append(element);
}

View File

@@ -83,7 +83,7 @@ public class MethodValidationPostProcessor extends AbstractAdvisingBeanPostProce
* <p>Default is the default ValidatorFactory's default Validator.
*/
public void setValidator(Validator validator) {
if(validator instanceof LocalValidatorFactoryBean) {
if (validator instanceof LocalValidatorFactoryBean) {
this.validator = ((LocalValidatorFactoryBean) validator).getValidator();
}
else {