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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -29,17 +29,16 @@ import org.springframework.util.StringUtils;
|
|||
* <ul>
|
||||
* <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)
|
||||
* <li>patterns: alternative property taking a String array of patterns. The result will
|
||||
* be the union of these patterns.
|
||||
* <li>patterns: alternative property taking a String array of patterns.
|
||||
* The result will be the union of these patterns.
|
||||
* </ul>
|
||||
*
|
||||
* <p>Note: the regular expressions must be a match. For example,
|
||||
* {@code .*get.*} will match com.mycom.Foo.getBar().
|
||||
* {@code get.*} will not.
|
||||
*
|
||||
* <p>This base class is serializable. Subclasses should declare all fields transient
|
||||
* - the initPatternRepresentation method in this class will be invoked again on the
|
||||
* client side on deserialization.
|
||||
* <p>This base class is serializable. Subclasses should declare all fields transient;
|
||||
* the {@link #initPatternRepresentation} method will be invoked again on deserialization.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
|
|
@ -51,10 +50,14 @@ import org.springframework.util.StringUtils;
|
|||
public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPointcut
|
||||
implements Serializable {
|
||||
|
||||
/** Regular expressions to match */
|
||||
/**
|
||||
* Regular expressions to match.
|
||||
*/
|
||||
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];
|
||||
|
||||
|
||||
|
|
@ -64,15 +67,15 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo
|
|||
* @see #setPatterns
|
||||
*/
|
||||
public void setPattern(String pattern) {
|
||||
setPatterns(new String[] {pattern});
|
||||
setPatterns(pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the regular expressions defining methods to match.
|
||||
* Matching will be the union of all these; if any match,
|
||||
* the pointcut matches.
|
||||
* Matching will be the union of all these; if any match, the pointcut matches.
|
||||
* @see #setPattern
|
||||
*/
|
||||
public void setPatterns(String[] patterns) {
|
||||
public void setPatterns(String... patterns) {
|
||||
Assert.notEmpty(patterns, "'patterns' must not be empty");
|
||||
this.patterns = new String[patterns.length];
|
||||
for (int i = 0; i < patterns.length; i++) {
|
||||
|
|
@ -94,15 +97,15 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo
|
|||
* @see #setExcludedPatterns
|
||||
*/
|
||||
public void setExcludedPattern(String excludedPattern) {
|
||||
setExcludedPatterns(new String[] {excludedPattern});
|
||||
setExcludedPatterns(excludedPattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the regular expressions defining methods to match for exclusion.
|
||||
* Matching will be the union of all these; if any match,
|
||||
* the pointcut matches.
|
||||
* Matching will be the union of all these; if any match, the pointcut matches.
|
||||
* @see #setExcludedPattern
|
||||
*/
|
||||
public void setExcludedPatterns(String[] excludedPatterns) {
|
||||
public void setExcludedPatterns(String... excludedPatterns) {
|
||||
Assert.notEmpty(excludedPatterns, "'excludedPatterns' must not be empty");
|
||||
this.excludedPatterns = new String[excludedPatterns.length];
|
||||
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,
|
||||
* 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())) ||
|
||||
matchesPattern(method.getDeclaringClass().getName() + "." + method.getName()));
|
||||
}
|
||||
|
|
@ -172,18 +175,18 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo
|
|||
protected abstract void initExcludedPatternRepresentation(String[] patterns) throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Does the pattern at the given index match this string?
|
||||
* @param pattern {@code String} pattern to match
|
||||
* @param patternIndex index of pattern from 0
|
||||
* @return {@code true} if there is a match, else {@code false}.
|
||||
* Does the pattern at the given index match the given String?
|
||||
* @param pattern the {@code String} pattern to match
|
||||
* @param patternIndex index of pattern (starting from 0)
|
||||
* @return {@code true} if there is a match, {@code false} otherwise
|
||||
*/
|
||||
protected abstract boolean matches(String pattern, int patternIndex);
|
||||
|
||||
/**
|
||||
* Does the exclusion pattern at the given index match this string?
|
||||
* @param pattern {@code String} pattern to match.
|
||||
* @param patternIndex index of pattern starting from 0.
|
||||
* @return {@code true} if there is a match, else {@code false}.
|
||||
* Does the exclusion pattern at the given index match the given String?
|
||||
* @param pattern the {@code String} pattern to match
|
||||
* @param patternIndex index of pattern (starting from 0)
|
||||
* @return {@code true} if there is a match, {@code false} otherwise
|
||||
*/
|
||||
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");
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
|
|
@ -187,7 +186,6 @@ public class ComposablePointcut implements Pointcut, Serializable {
|
|||
if (!(other instanceof ComposablePointcut)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ComposablePointcut that = (ComposablePointcut) other;
|
||||
return ObjectUtils.nullSafeEquals(that.classFilter, this.classFilter) &&
|
||||
ObjectUtils.nullSafeEquals(that.methodMatcher, this.methodMatcher);
|
||||
|
|
@ -207,8 +205,7 @@ public class ComposablePointcut implements Pointcut, Serializable {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ComposablePointcut: ClassFilter [" + this.classFilter +
|
||||
"], MethodMatcher [" + this.methodMatcher + "]";
|
||||
return "ComposablePointcut: " + this.classFilter + ", " +this.methodMatcher;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ import org.springframework.util.Assert;
|
|||
* <p>Example usage with
|
||||
* {@link org.springframework.http.converter.json.MappingJackson2HttpMessageConverter}:
|
||||
*
|
||||
* <pre>
|
||||
* <pre class="code">
|
||||
* <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
|
||||
* <property name="objectMapper">
|
||||
* <bean class="org.springframework.web.context.support.Jackson2ObjectMapperFactoryBean"
|
||||
|
|
@ -58,7 +58,7 @@ import org.springframework.util.Assert;
|
|||
*
|
||||
* <p>Example usage with MappingJackson2JsonView:
|
||||
*
|
||||
* <pre>
|
||||
* <pre class="code">
|
||||
* <bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">
|
||||
* <property name="objectMapper">
|
||||
* <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
|
||||
* {@link #setFeaturesToEnable(Object[])} and {@link #setFeaturesToDisable(Object[])}.
|
||||
*
|
||||
* <pre>
|
||||
* <pre class="code">
|
||||
* <bean class="org.springframework.web.context.support.Jackson2ObjectMapperFactoryBean">
|
||||
* <property name="featuresToEnable">
|
||||
* <array>
|
||||
|
|
@ -102,8 +102,6 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
|
|||
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
private Map<Object, Boolean> features = new HashMap<Object, Boolean>();
|
||||
|
||||
private DateFormat dateFormat;
|
||||
|
||||
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<Object, Boolean> features = new HashMap<Object, Boolean>();
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* deserialization.
|
||||
* Set an {@link AnnotationIntrospector} for both serialization and deserialization.
|
||||
*/
|
||||
public void setAnnotationIntrospector(AnnotationIntrospector annotationIntrospector) {
|
||||
this.annotationIntrospector = annotationIntrospector;
|
||||
|
|
@ -257,6 +256,10 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
|
|||
this.objectMapper.setDateFormat(this.dateFormat);
|
||||
}
|
||||
|
||||
if (this.annotationIntrospector != null) {
|
||||
this.objectMapper.setAnnotationIntrospector(this.annotationIntrospector);
|
||||
}
|
||||
|
||||
if (!this.serializers.isEmpty() || !this.deserializers.isEmpty()) {
|
||||
SimpleModule module = new SimpleModule();
|
||||
addSerializers(module);
|
||||
|
|
@ -264,10 +267,6 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
|
|||
this.objectMapper.registerModule(module);
|
||||
}
|
||||
|
||||
if (this.annotationIntrospector != null) {
|
||||
this.objectMapper.setAnnotationIntrospector(this.annotationIntrospector);
|
||||
}
|
||||
|
||||
for (Object feature : this.features.keySet()) {
|
||||
configureFeature(feature, this.features.get(feature));
|
||||
}
|
||||
|
|
@ -304,7 +303,7 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
|
|||
this.objectMapper.configure((MapperFeature) feature, enabled);
|
||||
}
|
||||
else {
|
||||
throw new FatalBeanException("Unknown feature class " + feature.getClass().getName());
|
||||
throw new FatalBeanException("Unknown feature class: " + feature.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue