Java源码示例:org.springframework.expression.MethodFilter
示例1
/**
* Verifies behavior requested in SPR-9621.
*/
@Test
public void customMethodFilter() {
StandardEvaluationContext context = new StandardEvaluationContext();
// Register a custom MethodResolver...
List<MethodResolver> customResolvers = new ArrayList<>();
customResolvers.add(new CustomMethodResolver());
context.setMethodResolvers(customResolvers);
// or simply...
// context.setMethodResolvers(new ArrayList<MethodResolver>());
// Register a custom MethodFilter...
MethodFilter filter = new CustomMethodFilter();
try {
context.registerMethodFilter(String.class, filter);
fail("should have failed");
}
catch (IllegalStateException ise) {
assertEquals(
"Method filter cannot be set as the reflective method resolver is not in use",
ise.getMessage());
}
}
示例2
/**
* Verifies behavior requested in SPR-9621.
*/
@Test
public void customMethodFilter() {
StandardEvaluationContext context = new StandardEvaluationContext();
// Register a custom MethodResolver...
List<MethodResolver> customResolvers = new ArrayList<>();
customResolvers.add(new CustomMethodResolver());
context.setMethodResolvers(customResolvers);
// or simply...
// context.setMethodResolvers(new ArrayList<MethodResolver>());
// Register a custom MethodFilter...
MethodFilter filter = new CustomMethodFilter();
try {
context.registerMethodFilter(String.class, filter);
fail("should have failed");
}
catch (IllegalStateException ise) {
assertEquals(
"Method filter cannot be set as the reflective method resolver is not in use",
ise.getMessage());
}
}
示例3
/**
* Verifies behavior requested in SPR-9621.
*/
@Test
public void customMethodFilter() throws Exception {
StandardEvaluationContext context = new StandardEvaluationContext();
// Register a custom MethodResolver...
List<MethodResolver> customResolvers = new ArrayList<MethodResolver>();
customResolvers.add(new CustomMethodResolver());
context.setMethodResolvers(customResolvers);
// or simply...
// context.setMethodResolvers(new ArrayList<MethodResolver>());
// Register a custom MethodFilter...
MethodFilter filter = new CustomMethodFilter();
try {
context.registerMethodFilter(String.class, filter);
fail("should have failed");
} catch (IllegalStateException ise) {
assertEquals(
"Method filter cannot be set as the reflective method resolver is not in use",
ise.getMessage());
}
}
示例4
/**
* Register a filter for methods on the given type.
* @param type the type to filter on
* @param filter the corresponding method filter,
* or {@code null} to clear any filter for the given type
*/
public void registerMethodFilter(Class<?> type, @Nullable MethodFilter filter) {
if (this.filters == null) {
this.filters = new HashMap<>();
}
if (filter != null) {
this.filters.put(type, filter);
}
else {
this.filters.remove(type);
}
}
示例5
/**
* Register a {@code MethodFilter} which will be called during method resolution
* for the specified type.
* <p>The {@code MethodFilter} may remove methods and/or sort the methods which
* will then be used by SpEL as the candidates to look through for a match.
* @param type the type for which the filter should be called
* @param filter a {@code MethodFilter}, or {@code null} to unregister a filter for the type
* @throws IllegalStateException if the {@link ReflectiveMethodResolver} is not in use
*/
public void registerMethodFilter(Class<?> type, MethodFilter filter) throws IllegalStateException {
initMethodResolvers();
ReflectiveMethodResolver resolver = this.reflectiveMethodResolver;
if (resolver == null) {
throw new IllegalStateException(
"Method filter cannot be set as the reflective method resolver is not in use");
}
resolver.registerMethodFilter(type, filter);
}
示例6
/**
* Register a filter for methods on the given type.
* @param type the type to filter on
* @param filter the corresponding method filter,
* or {@code null} to clear any filter for the given type
*/
public void registerMethodFilter(Class<?> type, @Nullable MethodFilter filter) {
if (this.filters == null) {
this.filters = new HashMap<>();
}
if (filter != null) {
this.filters.put(type, filter);
}
else {
this.filters.remove(type);
}
}
示例7
/**
* Register a {@code MethodFilter} which will be called during method resolution
* for the specified type.
* <p>The {@code MethodFilter} may remove methods and/or sort the methods which
* will then be used by SpEL as the candidates to look through for a match.
* @param type the type for which the filter should be called
* @param filter a {@code MethodFilter}, or {@code null} to unregister a filter for the type
* @throws IllegalStateException if the {@link ReflectiveMethodResolver} is not in use
*/
public void registerMethodFilter(Class<?> type, MethodFilter filter) throws IllegalStateException {
initMethodResolvers();
ReflectiveMethodResolver resolver = this.reflectiveMethodResolver;
if (resolver == null) {
throw new IllegalStateException(
"Method filter cannot be set as the reflective method resolver is not in use");
}
resolver.registerMethodFilter(type, filter);
}
示例8
public void registerMethodFilter(Class<?> type, MethodFilter filter) {
if (this.filters == null) {
this.filters = new HashMap<Class<?>, MethodFilter>();
}
if (filter != null) {
this.filters.put(type, filter);
}
else {
this.filters.remove(type);
}
}
示例9
/**
* Register a {@code MethodFilter} which will be called during method resolution
* for the specified type.
* <p>The {@code MethodFilter} may remove methods and/or sort the methods which
* will then be used by SpEL as the candidates to look through for a match.
* @param type the type for which the filter should be called
* @param filter a {@code MethodFilter}, or {@code null} to unregister a filter for the type
* @throws IllegalStateException if the {@link ReflectiveMethodResolver} is not in use
*/
public void registerMethodFilter(Class<?> type, MethodFilter filter) throws IllegalStateException {
ensureMethodResolversInitialized();
if (this.reflectiveMethodResolver != null) {
this.reflectiveMethodResolver.registerMethodFilter(type, filter);
}
else {
throw new IllegalStateException("Method filter cannot be set as the reflective method resolver is not in use");
}
}
示例10
public void registerMethodFilter(Class<?> type, MethodFilter filter) {
if (this.filters == null) {
this.filters = new HashMap<Class<?>, MethodFilter>();
}
if (filter != null) {
this.filters.put(type, filter);
}
else {
this.filters.remove(type);
}
}
示例11
/**
* Register a {@code MethodFilter} which will be called during method resolution
* for the specified type.
* <p>The {@code MethodFilter} may remove methods and/or sort the methods which
* will then be used by SpEL as the candidates to look through for a match.
* @param type the type for which the filter should be called
* @param filter a {@code MethodFilter}, or {@code null} to unregister a filter for the type
* @throws IllegalStateException if the {@link ReflectiveMethodResolver} is not in use
*/
public void registerMethodFilter(Class<?> type, MethodFilter filter) throws IllegalStateException {
ensureMethodResolversInitialized();
if (this.reflectiveMethodResolver != null) {
this.reflectiveMethodResolver.registerMethodFilter(type, filter);
}
else {
throw new IllegalStateException("Method filter cannot be set as the reflective method resolver is not in use");
}
}