Polishing
This commit is contained in:
parent
be2d915cc2
commit
72a5737ab9
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2013 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -29,17 +29,16 @@ import org.springframework.util.StringUtils;
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>pattern: regular expression for the fully-qualified method names to match.
|
* <li>pattern: regular expression for the fully-qualified method names to match.
|
||||||
* The exact regexp syntax will depend on the subclass (e.g. Perl5 regular expressions)
|
* The exact regexp syntax will depend on the subclass (e.g. Perl5 regular expressions)
|
||||||
* <li>patterns: alternative property taking a String array of patterns. The result will
|
* <li>patterns: alternative property taking a String array of patterns.
|
||||||
* be the union of these patterns.
|
* The result will be the union of these patterns.
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* <p>Note: the regular expressions must be a match. For example,
|
* <p>Note: the regular expressions must be a match. For example,
|
||||||
* {@code .*get.*} will match com.mycom.Foo.getBar().
|
* {@code .*get.*} will match com.mycom.Foo.getBar().
|
||||||
* {@code get.*} will not.
|
* {@code get.*} will not.
|
||||||
*
|
*
|
||||||
* <p>This base class is serializable. Subclasses should declare all fields transient
|
* <p>This base class is serializable. Subclasses should declare all fields transient;
|
||||||
* - the initPatternRepresentation method in this class will be invoked again on the
|
* the {@link #initPatternRepresentation} method will be invoked again on deserialization.
|
||||||
* client side on deserialization.
|
|
||||||
*
|
*
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
|
@ -51,10 +50,14 @@ import org.springframework.util.StringUtils;
|
||||||
public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPointcut
|
public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPointcut
|
||||||
implements Serializable {
|
implements Serializable {
|
||||||
|
|
||||||
/** Regular expressions to match */
|
/**
|
||||||
|
* Regular expressions to match.
|
||||||
|
*/
|
||||||
private String[] patterns = new String[0];
|
private String[] patterns = new String[0];
|
||||||
|
|
||||||
/** Regular expressions <strong>not</strong> to match */
|
/**
|
||||||
|
* Regular expressions <strong>not</strong> to match.
|
||||||
|
*/
|
||||||
private String[] excludedPatterns = new String[0];
|
private String[] excludedPatterns = new String[0];
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -64,15 +67,15 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo
|
||||||
* @see #setPatterns
|
* @see #setPatterns
|
||||||
*/
|
*/
|
||||||
public void setPattern(String pattern) {
|
public void setPattern(String pattern) {
|
||||||
setPatterns(new String[] {pattern});
|
setPatterns(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the regular expressions defining methods to match.
|
* Set the regular expressions defining methods to match.
|
||||||
* Matching will be the union of all these; if any match,
|
* Matching will be the union of all these; if any match, the pointcut matches.
|
||||||
* the pointcut matches.
|
* @see #setPattern
|
||||||
*/
|
*/
|
||||||
public void setPatterns(String[] patterns) {
|
public void setPatterns(String... patterns) {
|
||||||
Assert.notEmpty(patterns, "'patterns' must not be empty");
|
Assert.notEmpty(patterns, "'patterns' must not be empty");
|
||||||
this.patterns = new String[patterns.length];
|
this.patterns = new String[patterns.length];
|
||||||
for (int i = 0; i < patterns.length; i++) {
|
for (int i = 0; i < patterns.length; i++) {
|
||||||
|
|
@ -94,15 +97,15 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo
|
||||||
* @see #setExcludedPatterns
|
* @see #setExcludedPatterns
|
||||||
*/
|
*/
|
||||||
public void setExcludedPattern(String excludedPattern) {
|
public void setExcludedPattern(String excludedPattern) {
|
||||||
setExcludedPatterns(new String[] {excludedPattern});
|
setExcludedPatterns(excludedPattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the regular expressions defining methods to match for exclusion.
|
* Set the regular expressions defining methods to match for exclusion.
|
||||||
* Matching will be the union of all these; if any match,
|
* Matching will be the union of all these; if any match, the pointcut matches.
|
||||||
* the pointcut matches.
|
* @see #setExcludedPattern
|
||||||
*/
|
*/
|
||||||
public void setExcludedPatterns(String[] excludedPatterns) {
|
public void setExcludedPatterns(String... excludedPatterns) {
|
||||||
Assert.notEmpty(excludedPatterns, "'excludedPatterns' must not be empty");
|
Assert.notEmpty(excludedPatterns, "'excludedPatterns' must not be empty");
|
||||||
this.excludedPatterns = new String[excludedPatterns.length];
|
this.excludedPatterns = new String[excludedPatterns.length];
|
||||||
for (int i = 0; i < excludedPatterns.length; i++) {
|
for (int i = 0; i < excludedPatterns.length; i++) {
|
||||||
|
|
@ -124,7 +127,7 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo
|
||||||
* of the target class as well as against the method's declaring class,
|
* of the target class as well as against the method's declaring class,
|
||||||
* plus the name of the method.
|
* plus the name of the method.
|
||||||
*/
|
*/
|
||||||
public boolean matches(Method method, Class targetClass) {
|
public boolean matches(Method method, Class<?> targetClass) {
|
||||||
return ((targetClass != null && matchesPattern(targetClass.getName() + "." + method.getName())) ||
|
return ((targetClass != null && matchesPattern(targetClass.getName() + "." + method.getName())) ||
|
||||||
matchesPattern(method.getDeclaringClass().getName() + "." + method.getName()));
|
matchesPattern(method.getDeclaringClass().getName() + "." + method.getName()));
|
||||||
}
|
}
|
||||||
|
|
@ -172,18 +175,18 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo
|
||||||
protected abstract void initExcludedPatternRepresentation(String[] patterns) throws IllegalArgumentException;
|
protected abstract void initExcludedPatternRepresentation(String[] patterns) throws IllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does the pattern at the given index match this string?
|
* Does the pattern at the given index match the given String?
|
||||||
* @param pattern {@code String} pattern to match
|
* @param pattern the {@code String} pattern to match
|
||||||
* @param patternIndex index of pattern from 0
|
* @param patternIndex index of pattern (starting from 0)
|
||||||
* @return {@code true} if there is a match, else {@code false}.
|
* @return {@code true} if there is a match, {@code false} otherwise
|
||||||
*/
|
*/
|
||||||
protected abstract boolean matches(String pattern, int patternIndex);
|
protected abstract boolean matches(String pattern, int patternIndex);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does the exclusion pattern at the given index match this string?
|
* Does the exclusion pattern at the given index match the given String?
|
||||||
* @param pattern {@code String} pattern to match.
|
* @param pattern the {@code String} pattern to match
|
||||||
* @param patternIndex index of pattern starting from 0.
|
* @param patternIndex index of pattern (starting from 0)
|
||||||
* @return {@code true} if there is a match, else {@code false}.
|
* @return {@code true} if there is a match, {@code false} otherwise
|
||||||
*/
|
*/
|
||||||
protected abstract boolean matchesExclusion(String pattern, int patternIndex);
|
protected abstract boolean matchesExclusion(String pattern, int patternIndex);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2013 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -178,7 +178,6 @@ public class ComposablePointcut implements Pointcut, Serializable {
|
||||||
return this.methodMatcher;
|
return this.methodMatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
if (this == other) {
|
if (this == other) {
|
||||||
|
|
@ -187,7 +186,6 @@ public class ComposablePointcut implements Pointcut, Serializable {
|
||||||
if (!(other instanceof ComposablePointcut)) {
|
if (!(other instanceof ComposablePointcut)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ComposablePointcut that = (ComposablePointcut) other;
|
ComposablePointcut that = (ComposablePointcut) other;
|
||||||
return ObjectUtils.nullSafeEquals(that.classFilter, this.classFilter) &&
|
return ObjectUtils.nullSafeEquals(that.classFilter, this.classFilter) &&
|
||||||
ObjectUtils.nullSafeEquals(that.methodMatcher, this.methodMatcher);
|
ObjectUtils.nullSafeEquals(that.methodMatcher, this.methodMatcher);
|
||||||
|
|
@ -207,8 +205,7 @@ public class ComposablePointcut implements Pointcut, Serializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ComposablePointcut: ClassFilter [" + this.classFilter +
|
return "ComposablePointcut: " + this.classFilter + ", " +this.methodMatcher;
|
||||||
"], MethodMatcher [" + this.methodMatcher + "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ import org.springframework.util.Assert;
|
||||||
* <p>Example usage with
|
* <p>Example usage with
|
||||||
* {@link org.springframework.http.converter.json.MappingJackson2HttpMessageConverter}:
|
* {@link org.springframework.http.converter.json.MappingJackson2HttpMessageConverter}:
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre class="code">
|
||||||
* <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
|
* <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
|
||||||
* <property name="objectMapper">
|
* <property name="objectMapper">
|
||||||
* <bean class="org.springframework.web.context.support.Jackson2ObjectMapperFactoryBean"
|
* <bean class="org.springframework.web.context.support.Jackson2ObjectMapperFactoryBean"
|
||||||
|
|
@ -58,7 +58,7 @@ import org.springframework.util.Assert;
|
||||||
*
|
*
|
||||||
* <p>Example usage with MappingJackson2JsonView:
|
* <p>Example usage with MappingJackson2JsonView:
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre class="code">
|
||||||
* <bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">
|
* <bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">
|
||||||
* <property name="objectMapper">
|
* <property name="objectMapper">
|
||||||
* <bean class="org.springframework.web.context.support.Jackson2ObjectMapperFactoryBean"
|
* <bean class="org.springframework.web.context.support.Jackson2ObjectMapperFactoryBean"
|
||||||
|
|
@ -78,7 +78,7 @@ import org.springframework.util.Assert;
|
||||||
* options), you can still use the more general methods
|
* options), you can still use the more general methods
|
||||||
* {@link #setFeaturesToEnable(Object[])} and {@link #setFeaturesToDisable(Object[])}.
|
* {@link #setFeaturesToEnable(Object[])} and {@link #setFeaturesToDisable(Object[])}.
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre class="code">
|
||||||
* <bean class="org.springframework.web.context.support.Jackson2ObjectMapperFactoryBean">
|
* <bean class="org.springframework.web.context.support.Jackson2ObjectMapperFactoryBean">
|
||||||
* <property name="featuresToEnable">
|
* <property name="featuresToEnable">
|
||||||
* <array>
|
* <array>
|
||||||
|
|
@ -102,8 +102,6 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
|
||||||
|
|
||||||
private ObjectMapper objectMapper;
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
private Map<Object, Boolean> features = new HashMap<Object, Boolean>();
|
|
||||||
|
|
||||||
private DateFormat dateFormat;
|
private DateFormat dateFormat;
|
||||||
|
|
||||||
private AnnotationIntrospector annotationIntrospector;
|
private AnnotationIntrospector annotationIntrospector;
|
||||||
|
|
@ -112,6 +110,8 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
|
||||||
|
|
||||||
private final Map<Class<?>, JsonDeserializer<?>> deserializers = new LinkedHashMap<Class<?>, JsonDeserializer<?>>();
|
private final Map<Class<?>, JsonDeserializer<?>> deserializers = new LinkedHashMap<Class<?>, JsonDeserializer<?>>();
|
||||||
|
|
||||||
|
private final Map<Object, Boolean> features = new HashMap<Object, Boolean>();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the ObjectMapper instance to use. If not set, the ObjectMapper will
|
* Set the ObjectMapper instance to use. If not set, the ObjectMapper will
|
||||||
|
|
@ -142,8 +142,7 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the {@link AnnotationIntrospector} for both serialization and
|
* Set an {@link AnnotationIntrospector} for both serialization and deserialization.
|
||||||
* deserialization.
|
|
||||||
*/
|
*/
|
||||||
public void setAnnotationIntrospector(AnnotationIntrospector annotationIntrospector) {
|
public void setAnnotationIntrospector(AnnotationIntrospector annotationIntrospector) {
|
||||||
this.annotationIntrospector = annotationIntrospector;
|
this.annotationIntrospector = annotationIntrospector;
|
||||||
|
|
@ -257,6 +256,10 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
|
||||||
this.objectMapper.setDateFormat(this.dateFormat);
|
this.objectMapper.setDateFormat(this.dateFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.annotationIntrospector != null) {
|
||||||
|
this.objectMapper.setAnnotationIntrospector(this.annotationIntrospector);
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.serializers.isEmpty() || !this.deserializers.isEmpty()) {
|
if (!this.serializers.isEmpty() || !this.deserializers.isEmpty()) {
|
||||||
SimpleModule module = new SimpleModule();
|
SimpleModule module = new SimpleModule();
|
||||||
addSerializers(module);
|
addSerializers(module);
|
||||||
|
|
@ -264,10 +267,6 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
|
||||||
this.objectMapper.registerModule(module);
|
this.objectMapper.registerModule(module);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.annotationIntrospector != null) {
|
|
||||||
this.objectMapper.setAnnotationIntrospector(this.annotationIntrospector);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Object feature : this.features.keySet()) {
|
for (Object feature : this.features.keySet()) {
|
||||||
configureFeature(feature, this.features.get(feature));
|
configureFeature(feature, this.features.get(feature));
|
||||||
}
|
}
|
||||||
|
|
@ -304,7 +303,7 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
|
||||||
this.objectMapper.configure((MapperFeature) feature, enabled);
|
this.objectMapper.configure((MapperFeature) feature, enabled);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new FatalBeanException("Unknown feature class " + feature.getClass().getName());
|
throw new FatalBeanException("Unknown feature class: " + feature.getClass().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue