serialize full Pattern objects
This commit is contained in:
@@ -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
|
||||
/** 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
|
||||
/**
|
||||
* 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
|
||||
@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
|
||||
", 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
/**
|
||||
* 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];
|
||||
|
||||
|
||||
/**
|
||||
@@ -58,6 +58,14 @@ public class JdkRegexpMethodPointcut extends AbstractRegexpMethodPointcut {
|
||||
this.compiledPatterns = compilePatterns(patterns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize exclusion {@link Pattern Patterns} from the supplied <code>String[]</code>.
|
||||
*/
|
||||
@Override
|
||||
protected void initExcludedPatternRepresentation(String[] excludedPatterns) throws PatternSyntaxException {
|
||||
this.compiledExclusionPatterns = compilePatterns(excludedPatterns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the {@link Pattern} at index <code>patternIndex</code>
|
||||
* matches the supplied candidate <code>String</code>.
|
||||
@@ -68,14 +76,6 @@ public class JdkRegexpMethodPointcut extends AbstractRegexpMethodPointcut {
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize exclusion {@link Pattern Patterns} from the supplied <code>String[]</code>.
|
||||
*/
|
||||
@Override
|
||||
protected void initExcludedPatternRepresentation(String[] excludedPatterns) throws IllegalArgumentException {
|
||||
this.compiledExclusionPatterns = compilePatterns(excludedPatterns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the exclusion {@link Pattern} at index <code>patternIndex</code>
|
||||
* matches the supplied candidate <code>String</code>.
|
||||
@@ -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]);
|
||||
|
||||
Reference in New Issue
Block a user