Browse Source

serialize full Pattern objects

conversation
Juergen Hoeller 16 years ago
parent
commit
9306d6dbaa
  1. 36
      org.springframework.aop/src/main/java/org/springframework/aop/support/AbstractRegexpMethodPointcut.java
  2. 25
      org.springframework.aop/src/main/java/org/springframework/aop/support/JdkRegexpMethodPointcut.java

36
org.springframework.aop/src/main/java/org/springframework/aop/support/AbstractRegexpMethodPointcut.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@ -55,7 +55,7 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo @@ -55,7 +55,7 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo
/** Regular expressions to match */
private String[] patterns = new String[0];
/** Regaular expressions <strong>not</strong> to match */
/** Regular expressions <strong>not</strong> to match */
private String[] excludedPatterns = new String[0];
@ -155,14 +155,22 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo @@ -155,14 +155,22 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo
/**
* Subclasses must implement this to initialize regexp pointcuts.
* Can be invoked multiple times.
* <p>This method will be invoked from the setPatterns method,
* <p>This method will be invoked from the {@link #setPatterns} method,
* and also on deserialization.
* @param patterns the patterns to initialize
* @throws IllegalArgumentException in case of an invalid pattern
*/
protected abstract void initPatternRepresentation(String[] patterns) throws IllegalArgumentException;
protected abstract void initExcludedPatternRepresentation(String[] excludedPatterns) throws IllegalArgumentException;
/**
* Subclasses must implement this to initialize regexp pointcuts.
* Can be invoked multiple times.
* <p>This method will be invoked from the {@link #setExcludedPatterns} method,
* and also on deserialization.
* @param patterns the patterns to initialize
* @throws IllegalArgumentException in case of an invalid pattern
*/
protected abstract void initExcludedPatternRepresentation(String[] patterns) throws IllegalArgumentException;
/**
* Does the pattern at the given index match this string?
@ -197,12 +205,10 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo @@ -197,12 +205,10 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo
@Override
public int hashCode() {
int result = 27;
for (int i = 0; i < this.patterns.length; i++) {
String pattern = this.patterns[i];
for (String pattern : this.patterns) {
result = 13 * result + pattern.hashCode();
}
for (int i = 0; i < this.excludedPatterns.length; i++) {
String excludedPattern = this.excludedPatterns[i];
for (String excludedPattern : this.excludedPatterns) {
result = 13 * result + excludedPattern.hashCode();
}
return result;
@ -214,18 +220,4 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo @@ -214,18 +220,4 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo
", excluded patterns " + ObjectUtils.nullSafeToString(this.excludedPatterns);
}
//---------------------------------------------------------------------
// Serialization support
//---------------------------------------------------------------------
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
// Rely on default serialization; just initialize state after deserialization.
ois.defaultReadObject();
// Ask subclass to reinitialize.
initPatternRepresentation(this.patterns);
initExcludedPatternRepresentation(this.excludedPatterns);
}
}

25
org.springframework.aop/src/main/java/org/springframework/aop/support/JdkRegexpMethodPointcut.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2009 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.
@ -42,12 +42,12 @@ public class JdkRegexpMethodPointcut extends AbstractRegexpMethodPointcut { @@ -42,12 +42,12 @@ public class JdkRegexpMethodPointcut extends AbstractRegexpMethodPointcut {
/**
* Compiled form of the patterns.
*/
private transient Pattern[] compiledPatterns = new Pattern[0];
private Pattern[] compiledPatterns = new Pattern[0];
/**
* Compiled form of the exclusion patterns.
*/
private transient Pattern[] compiledExclusionPatterns = new Pattern[0];
private Pattern[] compiledExclusionPatterns = new Pattern[0];
/**
@ -59,21 +59,21 @@ public class JdkRegexpMethodPointcut extends AbstractRegexpMethodPointcut { @@ -59,21 +59,21 @@ public class JdkRegexpMethodPointcut extends AbstractRegexpMethodPointcut {
}
/**
* Returns <code>true</code> if the {@link Pattern} at index <code>patternIndex</code>
* matches the supplied candidate <code>String</code>.
* Initialize exclusion {@link Pattern Patterns} from the supplied <code>String[]</code>.
*/
@Override
protected boolean matches(String pattern, int patternIndex) {
Matcher matcher = this.compiledPatterns[patternIndex].matcher(pattern);
return matcher.matches();
protected void initExcludedPatternRepresentation(String[] excludedPatterns) throws PatternSyntaxException {
this.compiledExclusionPatterns = compilePatterns(excludedPatterns);
}
/**
* Initialize exclusion {@link Pattern Patterns} from the supplied <code>String[]</code>.
* Returns <code>true</code> if the {@link Pattern} at index <code>patternIndex</code>
* matches the supplied candidate <code>String</code>.
*/
@Override
protected void initExcludedPatternRepresentation(String[] excludedPatterns) throws IllegalArgumentException {
this.compiledExclusionPatterns = compilePatterns(excludedPatterns);
protected boolean matches(String pattern, int patternIndex) {
Matcher matcher = this.compiledPatterns[patternIndex].matcher(pattern);
return matcher.matches();
}
/**
@ -86,11 +86,12 @@ public class JdkRegexpMethodPointcut extends AbstractRegexpMethodPointcut { @@ -86,11 +86,12 @@ public class JdkRegexpMethodPointcut extends AbstractRegexpMethodPointcut {
return matcher.matches();
}
/**
* Compiles the supplied <code>String[]</code> into an array of
* {@link Pattern} objects and returns that array.
*/
private Pattern[] compilePatterns(String[] source) {
private Pattern[] compilePatterns(String[] source) throws PatternSyntaxException {
Pattern[] destination = new Pattern[source.length];
for (int i = 0; i < source.length; i++) {
destination[i] = Pattern.compile(source[i]);

Loading…
Cancel
Save