-
Notifications
You must be signed in to change notification settings - Fork 951
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix and test for GRAILS-9044 FilterConfig.methodMissing gets called f…
…or every invocation when calling a method with several arguments Fix and test for GRAILS-9050 Grails Filters's helper methods are shared between all Filters classes
- Loading branch information
Showing
4 changed files
with
254 additions
and
27 deletions.
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
...rs/src/main/groovy/org/codehaus/groovy/grails/plugins/web/filters/DelegateMetaMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package org.codehaus.groovy.grails.plugins.web.filters; | ||
|
||
import groovy.lang.MetaMethod; | ||
|
||
import org.codehaus.groovy.reflection.CachedClass; | ||
|
||
/** | ||
* MetaMethod implementation that delegates to real MetaMethod implementation | ||
* | ||
* This can be used to efficiently proxy a metamethod from another metaClass in methodMissing. | ||
* An example can be found in FilterConfig's methodMissing . | ||
* | ||
* Without this class it's hard to implement efficient methodMissing "caching" supporting methods with multiple signatures (same method name, different set of arguments). | ||
* | ||
* This class could be moved to org.codehaus.groovy.grails.commons.metaclass for reuse. | ||
* | ||
* @author Lari Hotari | ||
* | ||
*/ | ||
@SuppressWarnings("rawtypes") | ||
class DelegateMetaMethod extends MetaMethod { | ||
static interface DelegateMetaMethodTargetStrategy { | ||
public Object getTargetInstance(Object instance); | ||
} | ||
|
||
private MetaMethod delegateMethod; | ||
private DelegateMetaMethodTargetStrategy targetStrategy; | ||
|
||
public DelegateMetaMethod(MetaMethod delegateMethod, DelegateMetaMethodTargetStrategy targetStrategy) { | ||
this.delegateMethod=delegateMethod; | ||
this.targetStrategy=targetStrategy; | ||
} | ||
|
||
public int getModifiers() { | ||
return delegateMethod.getModifiers(); | ||
} | ||
|
||
public String getName() { | ||
return delegateMethod.getName(); | ||
} | ||
|
||
public Class getReturnType() { | ||
return delegateMethod.getReturnType(); | ||
} | ||
|
||
public Object invoke(Object object, Object[] arguments) { | ||
return delegateMethod.invoke(targetStrategy.getTargetInstance(object), arguments); | ||
} | ||
|
||
public void checkParameters(Class[] arguments) { | ||
delegateMethod.checkParameters(arguments); | ||
} | ||
|
||
public CachedClass[] getParameterTypes() { | ||
return delegateMethod.getParameterTypes(); | ||
} | ||
|
||
public boolean isMethod(MetaMethod method) { | ||
return delegateMethod.isMethod(method); | ||
} | ||
|
||
public Class[] getNativeParameterTypes() { | ||
return delegateMethod.getNativeParameterTypes(); | ||
} | ||
|
||
public boolean isVargsMethod(Object[] arguments) { | ||
return delegateMethod.isVargsMethod(arguments); | ||
} | ||
|
||
public String toString() { | ||
return delegateMethod.toString(); | ||
} | ||
|
||
public boolean equals(Object obj) { | ||
return delegateMethod.equals(obj); | ||
} | ||
|
||
public Object clone() { | ||
return delegateMethod.clone(); | ||
} | ||
|
||
public boolean isStatic() { | ||
return delegateMethod.isStatic(); | ||
} | ||
|
||
public boolean isAbstract() { | ||
return delegateMethod.isAbstract(); | ||
} | ||
|
||
public Object[] correctArguments(Object[] argumentArray) { | ||
return delegateMethod.correctArguments(argumentArray); | ||
} | ||
|
||
public boolean isCacheable() { | ||
return delegateMethod.isCacheable(); | ||
} | ||
|
||
public String getDescriptor() { | ||
return delegateMethod.getDescriptor(); | ||
} | ||
|
||
public String getSignature() { | ||
return delegateMethod.getSignature(); | ||
} | ||
|
||
public String getMopName() { | ||
return delegateMethod.getMopName(); | ||
} | ||
|
||
public Object doMethodInvoke(Object object, Object[] argumentArray) { | ||
return delegateMethod.doMethodInvoke(targetStrategy.getTargetInstance(object), argumentArray); | ||
} | ||
|
||
public boolean isValidMethod(Class[] arguments) { | ||
return delegateMethod.isValidMethod(arguments); | ||
} | ||
|
||
public boolean isValidExactMethod(Object[] args) { | ||
return delegateMethod.isValidExactMethod(args); | ||
} | ||
|
||
public boolean isValidExactMethod(Class[] args) { | ||
return delegateMethod.isValidExactMethod(args); | ||
} | ||
|
||
public boolean isValidMethod(Object[] arguments) { | ||
return delegateMethod.isValidMethod(arguments); | ||
} | ||
|
||
public CachedClass getDeclaringClass() { | ||
return delegateMethod.getDeclaringClass(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...ehaus/groovy/grails/plugins/web/filters/FilterConfigDelegateMetaMethodTargetStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.codehaus.groovy.grails.plugins.web.filters; | ||
|
||
import org.codehaus.groovy.grails.plugins.web.filters.DelegateMetaMethod.DelegateMetaMethodTargetStrategy; | ||
|
||
class FilterConfigDelegateMetaMethodTargetStrategy implements DelegateMetaMethodTargetStrategy{ | ||
public static final FilterConfigDelegateMetaMethodTargetStrategy instance=new FilterConfigDelegateMetaMethodTargetStrategy(); | ||
|
||
public Object getTargetInstance(Object instance) { | ||
return ((FilterConfig)instance).getFiltersDefinition(); | ||
} | ||
} |
Oops, something went wrong.