Polishing
This commit is contained in:
parent
86fc2dd556
commit
42db41e007
|
|
@ -59,8 +59,8 @@ public abstract class SpringFactoriesLoader {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the factory implementations of the given type from the default location, using
|
* Load the factory implementations of the given type from the default location,
|
||||||
* the given class loader.
|
* using the given class loader.
|
||||||
* <p>The returned factories are ordered in accordance with the {@link OrderComparator}.
|
* <p>The returned factories are ordered in accordance with the {@link OrderComparator}.
|
||||||
* @param factoryClass the interface or abstract class representing the factory
|
* @param factoryClass the interface or abstract class representing the factory
|
||||||
* @param classLoader the ClassLoader to use for loading (can be {@code null} to use the default)
|
* @param classLoader the ClassLoader to use for loading (can be {@code null} to use the default)
|
||||||
|
|
|
||||||
|
|
@ -53,20 +53,21 @@ import org.springframework.expression.spel.SpelMessage;
|
||||||
*/
|
*/
|
||||||
public class ReflectiveMethodResolver implements MethodResolver {
|
public class ReflectiveMethodResolver implements MethodResolver {
|
||||||
|
|
||||||
private Map<Class<?>, MethodFilter> filters = null;
|
|
||||||
|
|
||||||
// Using distance will ensure a more accurate match is discovered,
|
// Using distance will ensure a more accurate match is discovered,
|
||||||
// more closely following the Java rules.
|
// more closely following the Java rules.
|
||||||
private boolean useDistance = false;
|
private final boolean useDistance;
|
||||||
|
|
||||||
|
private Map<Class<?>, MethodFilter> filters;
|
||||||
|
|
||||||
|
|
||||||
public ReflectiveMethodResolver() {
|
public ReflectiveMethodResolver() {
|
||||||
|
this.useDistance = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructors allows the ReflectiveMethodResolver to be configured such that it will
|
* This constructors allows the ReflectiveMethodResolver to be configured such that it will
|
||||||
* use a distance computation to check which is the better of two close matches (when there
|
* use a distance computation to check which is the better of two close matches (when there
|
||||||
* are multiple matches). Using the distance computation is intended to ensure matches
|
* are multiple matches). Using the distance computation is intended to ensure matches
|
||||||
* are more closely representative of what a Java compiler would do when taking into
|
* are more closely representative of what a Java compiler would do when taking into
|
||||||
* account boxing/unboxing and whether the method candidates are declared to handle a
|
* account boxing/unboxing and whether the method candidates are declared to handle a
|
||||||
* supertype of the type (of the argument) being passed in.
|
* supertype of the type (of the argument) being passed in.
|
||||||
|
|
@ -77,6 +78,19 @@ public class ReflectiveMethodResolver implements MethodResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Locate a method on a type. There are three kinds of match that might occur:
|
* Locate a method on a type. There are three kinds of match that might occur:
|
||||||
* <ol>
|
* <ol>
|
||||||
|
|
@ -187,18 +201,6 @@ public class ReflectiveMethodResolver implements MethodResolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerMethodFilter(Class<?> type, MethodFilter filter) {
|
|
||||||
if (this.filters == null) {
|
|
||||||
this.filters = new HashMap<Class<?>, MethodFilter>();
|
|
||||||
}
|
|
||||||
if (filter == null) {
|
|
||||||
this.filters.remove(type);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.filters.put(type,filter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Method[] getMethods(Class<?> type, Object targetObject) {
|
private Method[] getMethods(Class<?> type, Object targetObject) {
|
||||||
if (targetObject instanceof Class) {
|
if (targetObject instanceof Class) {
|
||||||
Set<Method> methods = new HashSet<Method>();
|
Set<Method> methods = new HashSet<Method>();
|
||||||
|
|
|
||||||
|
|
@ -57,10 +57,10 @@ import org.springframework.orm.jpa.JpaDialect;
|
||||||
*/
|
*/
|
||||||
public class HibernateJpaVendorAdapter extends AbstractJpaVendorAdapter {
|
public class HibernateJpaVendorAdapter extends AbstractJpaVendorAdapter {
|
||||||
|
|
||||||
private final PersistenceProvider persistenceProvider;
|
|
||||||
|
|
||||||
private final JpaDialect jpaDialect = new HibernateJpaDialect();
|
private final JpaDialect jpaDialect = new HibernateJpaDialect();
|
||||||
|
|
||||||
|
private final PersistenceProvider persistenceProvider;
|
||||||
|
|
||||||
private final Class<? extends EntityManagerFactory> entityManagerFactoryInterface;
|
private final Class<? extends EntityManagerFactory> entityManagerFactoryInterface;
|
||||||
|
|
||||||
private final Class<? extends EntityManager> entityManagerInterface;
|
private final Class<? extends EntityManager> entityManagerInterface;
|
||||||
|
|
|
||||||
|
|
@ -45,10 +45,9 @@ import org.springframework.web.context.request.SessionScope;
|
||||||
import org.springframework.web.context.request.WebRequest;
|
import org.springframework.web.context.request.WebRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience methods for retrieving the root
|
* Convenience methods for retrieving the root {@link WebApplicationContext} for
|
||||||
* {@link org.springframework.web.context.WebApplicationContext} for a given
|
* a given {@link ServletContext}. This is useful for programmatically accessing
|
||||||
* {@code ServletContext}. This is useful for programmatically accessing a
|
* a Spring application context from within custom web views or MVC actions.
|
||||||
* Spring application context from within custom web views or MVC actions.
|
|
||||||
*
|
*
|
||||||
* <p>Note that there are more convenient ways of accessing the root context for
|
* <p>Note that there are more convenient ways of accessing the root context for
|
||||||
* many web frameworks, either part of Spring or available as an external library.
|
* many web frameworks, either part of Spring or available as an external library.
|
||||||
|
|
@ -232,6 +231,7 @@ public abstract class WebApplicationContextUtils {
|
||||||
*/
|
*/
|
||||||
public static void initServletPropertySources(
|
public static void initServletPropertySources(
|
||||||
MutablePropertySources propertySources, ServletContext servletContext) {
|
MutablePropertySources propertySources, ServletContext servletContext) {
|
||||||
|
|
||||||
initServletPropertySources(propertySources, servletContext, null);
|
initServletPropertySources(propertySources, servletContext, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -21,7 +21,6 @@ import java.util.Collections;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.portlet.PortletConfig;
|
import javax.portlet.PortletConfig;
|
||||||
import javax.portlet.PortletContext;
|
import javax.portlet.PortletContext;
|
||||||
import javax.portlet.PortletRequest;
|
import javax.portlet.PortletRequest;
|
||||||
|
|
@ -42,9 +41,9 @@ import org.springframework.web.context.request.WebRequest;
|
||||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience methods for retrieving the root WebApplicationContext for a given
|
* Convenience methods for retrieving the root {@link WebApplicationContext} for
|
||||||
* PortletContext. This is e.g. useful for accessing a Spring context from
|
* a given {@link PortletContext}. This is useful for programmatically accessing
|
||||||
* within custom Portlet implementations.
|
* a Spring application context from within custom Portlet implementations.
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author John A. Lewis
|
* @author John A. Lewis
|
||||||
|
|
@ -98,7 +97,7 @@ public abstract class PortletApplicationContextUtils {
|
||||||
* @see org.springframework.web.context.WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
|
* @see org.springframework.web.context.WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
|
||||||
*/
|
*/
|
||||||
public static ApplicationContext getRequiredWebApplicationContext(PortletContext pc)
|
public static ApplicationContext getRequiredWebApplicationContext(PortletContext pc)
|
||||||
throws IllegalStateException {
|
throws IllegalStateException {
|
||||||
|
|
||||||
ApplicationContext wac = getWebApplicationContext(pc);
|
ApplicationContext wac = getWebApplicationContext(pc);
|
||||||
if (wac == null) {
|
if (wac == null) {
|
||||||
|
|
@ -211,15 +210,15 @@ public abstract class PortletApplicationContextUtils {
|
||||||
*/
|
*/
|
||||||
public static void initPortletPropertySources(MutablePropertySources propertySources, ServletContext servletContext,
|
public static void initPortletPropertySources(MutablePropertySources propertySources, ServletContext servletContext,
|
||||||
PortletContext portletContext, PortletConfig portletConfig) {
|
PortletContext portletContext, PortletConfig portletConfig) {
|
||||||
Assert.notNull(propertySources, "propertySources must not be null");
|
|
||||||
|
|
||||||
|
Assert.notNull(propertySources, "propertySources must not be null");
|
||||||
WebApplicationContextUtils.initServletPropertySources(propertySources, servletContext);
|
WebApplicationContextUtils.initServletPropertySources(propertySources, servletContext);
|
||||||
|
|
||||||
if(portletContext != null && propertySources.contains(StandardPortletEnvironment.PORTLET_CONTEXT_PROPERTY_SOURCE_NAME)) {
|
if (portletContext != null && propertySources.contains(StandardPortletEnvironment.PORTLET_CONTEXT_PROPERTY_SOURCE_NAME)) {
|
||||||
propertySources.replace(StandardPortletEnvironment.PORTLET_CONTEXT_PROPERTY_SOURCE_NAME,
|
propertySources.replace(StandardPortletEnvironment.PORTLET_CONTEXT_PROPERTY_SOURCE_NAME,
|
||||||
new PortletContextPropertySource(StandardPortletEnvironment.PORTLET_CONTEXT_PROPERTY_SOURCE_NAME, portletContext));
|
new PortletContextPropertySource(StandardPortletEnvironment.PORTLET_CONTEXT_PROPERTY_SOURCE_NAME, portletContext));
|
||||||
}
|
}
|
||||||
if(portletConfig != null && propertySources.contains(StandardPortletEnvironment.PORTLET_CONFIG_PROPERTY_SOURCE_NAME)) {
|
if (portletConfig != null && propertySources.contains(StandardPortletEnvironment.PORTLET_CONFIG_PROPERTY_SOURCE_NAME)) {
|
||||||
propertySources.replace(StandardPortletEnvironment.PORTLET_CONFIG_PROPERTY_SOURCE_NAME,
|
propertySources.replace(StandardPortletEnvironment.PORTLET_CONFIG_PROPERTY_SOURCE_NAME,
|
||||||
new PortletConfigPropertySource(StandardPortletEnvironment.PORTLET_CONFIG_PROPERTY_SOURCE_NAME, portletConfig));
|
new PortletConfigPropertySource(StandardPortletEnvironment.PORTLET_CONFIG_PROPERTY_SOURCE_NAME, portletConfig));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue