Browse Source
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@453 50f2f4bb-b051-0410-bef5-90022cba6387pull/1/head
138 changed files with 2936 additions and 970 deletions
@ -0,0 +1,82 @@
@@ -0,0 +1,82 @@
|
||||
/* |
||||
* Copyright 2002-2007 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.beans; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @author Juergen Hoeller |
||||
* @since 21.08.2003 |
||||
*/ |
||||
public class DerivedTestBean extends TestBean implements Serializable { |
||||
|
||||
private String beanName; |
||||
|
||||
private boolean initialized; |
||||
|
||||
private boolean destroyed; |
||||
|
||||
|
||||
public DerivedTestBean() { |
||||
} |
||||
|
||||
public DerivedTestBean(String[] names) { |
||||
if (names == null || names.length < 2) { |
||||
throw new IllegalArgumentException("Invalid names array"); |
||||
} |
||||
setName(names[0]); |
||||
setBeanName(names[1]); |
||||
} |
||||
|
||||
public static DerivedTestBean create(String[] names) { |
||||
return new DerivedTestBean(names); |
||||
} |
||||
|
||||
|
||||
public void setBeanName(String beanName) { |
||||
if (this.beanName == null || beanName == null) { |
||||
this.beanName = beanName; |
||||
} |
||||
} |
||||
|
||||
public String getBeanName() { |
||||
return beanName; |
||||
} |
||||
|
||||
public void setSpouseRef(String name) { |
||||
setSpouse(new TestBean(name)); |
||||
} |
||||
|
||||
|
||||
public void initialize() { |
||||
this.initialized = true; |
||||
} |
||||
|
||||
public boolean wasInitialized() { |
||||
return initialized; |
||||
} |
||||
|
||||
|
||||
public void destroy() { |
||||
this.destroyed = true; |
||||
} |
||||
|
||||
public boolean wasDestroyed() { |
||||
return destroyed; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,135 @@
@@ -0,0 +1,135 @@
|
||||
/* |
||||
* Copyright 2002-2005 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.util.comparator; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
import java.util.Comparator; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
/** |
||||
* Unit tests for {@link PropertyComparator} |
||||
* |
||||
* @see org.springframework.beans.support.PropertyComparatorTests |
||||
* |
||||
* @author Keith Donald |
||||
* @author Chris Beams |
||||
*/ |
||||
public class ComparatorTests { |
||||
|
||||
@Test |
||||
public void testComparableComparator() { |
||||
Comparator<String> c = new ComparableComparator<String>(); |
||||
String s1 = "abc"; |
||||
String s2 = "cde"; |
||||
assertTrue(c.compare(s1, s2) < 0); |
||||
} |
||||
|
||||
@SuppressWarnings("unchecked") |
||||
@Test |
||||
public void testComparableComparatorIllegalArgs() { |
||||
Comparator c = new ComparableComparator(); |
||||
Object o1 = new Object(); |
||||
Object o2 = new Object(); |
||||
try { |
||||
c.compare(o1, o2); |
||||
} |
||||
catch (ClassCastException e) { |
||||
return; |
||||
} |
||||
fail("Comparator should have thrown a cce"); |
||||
} |
||||
|
||||
@Test |
||||
public void testBooleanComparatorTrueLow() { |
||||
Comparator<Boolean> c = BooleanComparator.TRUE_LOW; |
||||
assertTrue(c.compare(new Boolean(true), new Boolean(false)) < 0); |
||||
} |
||||
|
||||
@Test |
||||
public void testBooleanComparatorTrueHigh() { |
||||
Comparator<Boolean> c = BooleanComparator.TRUE_HIGH; |
||||
assertTrue(c.compare(new Boolean(true), new Boolean(false)) > 0); |
||||
assertTrue(c.compare(Boolean.TRUE, Boolean.TRUE) == 0); |
||||
} |
||||
|
||||
@SuppressWarnings("unchecked") |
||||
@Test |
||||
public void testNullSafeComparatorNullsLow() { |
||||
Comparator<String> c = NullSafeComparator.NULLS_LOW; |
||||
assertTrue(c.compare(null, "boo") < 0); |
||||
} |
||||
|
||||
@SuppressWarnings("unchecked") |
||||
@Test |
||||
public void testNullSafeComparatorNullsHigh() { |
||||
Comparator<String> c = NullSafeComparator.NULLS_HIGH; |
||||
assertTrue(c.compare(null, "boo") > 0); |
||||
assertTrue(c.compare(null, null) == 0); |
||||
} |
||||
|
||||
@Test |
||||
public void testCompoundComparatorEmpty() { |
||||
Comparator<String> c = new CompoundComparator<String>(); |
||||
try { |
||||
c.compare("foo", "bar"); |
||||
} |
||||
catch (IllegalStateException e) { |
||||
return; |
||||
} |
||||
fail("illegal state should've been thrown on empty list"); |
||||
} |
||||
|
||||
private static class Dog implements Comparable<Object> { |
||||
|
||||
private String nickName; |
||||
|
||||
private String firstName; |
||||
|
||||
private String lastName; |
||||
|
||||
public int compareTo(Object o) { |
||||
return nickName.compareTo(((Dog)o).nickName); |
||||
} |
||||
|
||||
public String getNickName() { |
||||
return nickName; |
||||
} |
||||
|
||||
public void setNickName(String nickName) { |
||||
this.nickName = nickName; |
||||
} |
||||
|
||||
public String getFirstName() { |
||||
return firstName; |
||||
} |
||||
|
||||
public void setFirstName(String firstName) { |
||||
this.firstName = firstName; |
||||
} |
||||
|
||||
public String getLastName() { |
||||
return lastName; |
||||
} |
||||
|
||||
public void setLastName(String lastName) { |
||||
this.lastName = lastName; |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -1 +0,0 @@
@@ -1 +0,0 @@
|
||||
typeMismatch=Field {0} did not have correct type |
||||
@ -1,2 +0,0 @@
@@ -1,2 +0,0 @@
|
||||
typeMismatch=Field {0} did not have correct type |
||||
age=Age |
||||
@ -1,2 +0,0 @@
@@ -1,2 +0,0 @@
|
||||
typeMismatch=Field {0} did not have correct type |
||||
person.age=Person Age |
||||
@ -1,461 +0,0 @@
@@ -1,461 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2007 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.web.servlet; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Locale; |
||||
|
||||
import javax.servlet.Servlet; |
||||
import javax.servlet.ServletConfig; |
||||
import javax.servlet.ServletException; |
||||
import javax.servlet.ServletRequest; |
||||
import javax.servlet.ServletResponse; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
import org.springframework.beans.BeansException; |
||||
import org.springframework.beans.MutablePropertyValues; |
||||
import org.springframework.beans.factory.config.RuntimeBeanReference; |
||||
import org.springframework.beans.factory.support.ManagedList; |
||||
import org.springframework.context.ApplicationEvent; |
||||
import org.springframework.context.ApplicationListener; |
||||
import org.springframework.context.i18n.LocaleContextHolder; |
||||
import org.springframework.context.support.ApplicationObjectSupport; |
||||
import org.springframework.core.Ordered; |
||||
import org.springframework.ui.ModelMap; |
||||
import org.springframework.web.bind.ServletRequestBindingException; |
||||
import org.springframework.web.context.WebApplicationContext; |
||||
import org.springframework.web.context.request.WebRequest; |
||||
import org.springframework.web.context.request.WebRequestInterceptor; |
||||
import org.springframework.web.context.support.RequestHandledEvent; |
||||
import org.springframework.web.context.support.StaticWebApplicationContext; |
||||
import org.springframework.web.multipart.MaxUploadSizeExceededException; |
||||
import org.springframework.web.multipart.MultipartException; |
||||
import org.springframework.web.multipart.MultipartHttpServletRequest; |
||||
import org.springframework.web.multipart.MultipartResolver; |
||||
import org.springframework.web.multipart.support.AbstractMultipartHttpServletRequest; |
||||
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver; |
||||
import org.springframework.web.servlet.handler.SimpleServletHandlerAdapter; |
||||
import org.springframework.web.servlet.handler.SimpleServletPostProcessor; |
||||
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; |
||||
import org.springframework.web.servlet.handler.UserRoleAuthorizationInterceptor; |
||||
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; |
||||
import org.springframework.web.servlet.i18n.SessionLocaleResolver; |
||||
import org.springframework.web.servlet.mvc.Controller; |
||||
import org.springframework.web.servlet.mvc.ParameterizableViewController; |
||||
import org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter; |
||||
import org.springframework.web.servlet.mvc.SimpleFormController; |
||||
import org.springframework.web.servlet.support.RequestContextUtils; |
||||
import org.springframework.web.servlet.theme.SessionThemeResolver; |
||||
import org.springframework.web.servlet.theme.ThemeChangeInterceptor; |
||||
import org.springframework.web.servlet.view.InternalResourceViewResolver; |
||||
import org.springframework.web.servlet.view.ResourceBundleViewResolver; |
||||
|
||||
/** |
||||
* @author Juergen Hoeller |
||||
* @since 21.05.2003 |
||||
*/ |
||||
public class ComplexWebApplicationContext extends StaticWebApplicationContext { |
||||
|
||||
public void refresh() throws BeansException { |
||||
registerSingleton(DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME, SessionLocaleResolver.class); |
||||
registerSingleton(DispatcherServlet.THEME_RESOLVER_BEAN_NAME, SessionThemeResolver.class); |
||||
|
||||
LocaleChangeInterceptor interceptor1 = new LocaleChangeInterceptor(); |
||||
LocaleChangeInterceptor interceptor2 = new LocaleChangeInterceptor(); |
||||
interceptor2.setParamName("locale2"); |
||||
ThemeChangeInterceptor interceptor3 = new ThemeChangeInterceptor(); |
||||
ThemeChangeInterceptor interceptor4 = new ThemeChangeInterceptor(); |
||||
interceptor4.setParamName("theme2"); |
||||
UserRoleAuthorizationInterceptor interceptor5 = new UserRoleAuthorizationInterceptor(); |
||||
interceptor5.setAuthorizedRoles(new String[] {"role1", "role2"}); |
||||
|
||||
List interceptors = new ArrayList(); |
||||
interceptors.add(interceptor5); |
||||
interceptors.add(interceptor1); |
||||
interceptors.add(interceptor2); |
||||
interceptors.add(interceptor3); |
||||
interceptors.add(interceptor4); |
||||
interceptors.add(new MyHandlerInterceptor1()); |
||||
interceptors.add(new MyHandlerInterceptor2()); |
||||
interceptors.add(new MyWebRequestInterceptor()); |
||||
|
||||
MutablePropertyValues pvs = new MutablePropertyValues(); |
||||
pvs.addPropertyValue( |
||||
"mappings", "/view.do=viewHandler\n/locale.do=localeHandler\nloc.do=anotherLocaleHandler"); |
||||
pvs.addPropertyValue("interceptors", interceptors); |
||||
registerSingleton("myUrlMapping1", SimpleUrlHandlerMapping.class, pvs); |
||||
|
||||
pvs = new MutablePropertyValues(); |
||||
pvs.addPropertyValue( |
||||
"mappings", "/form.do=localeHandler\n/unknown.do=unknownHandler\nservlet.do=myServlet"); |
||||
pvs.addPropertyValue("order", "2"); |
||||
registerSingleton("myUrlMapping2", SimpleUrlHandlerMapping.class, pvs); |
||||
|
||||
pvs = new MutablePropertyValues(); |
||||
pvs.addPropertyValue( |
||||
"mappings", "/form.do=formHandler\n/head.do=headController\n" + |
||||
"body.do=bodyController\n/noview*=noviewController\n/noview/simple*=noviewController"); |
||||
pvs.addPropertyValue("order", "1"); |
||||
registerSingleton("handlerMapping", SimpleUrlHandlerMapping.class, pvs); |
||||
|
||||
registerSingleton("myDummyAdapter", MyDummyAdapter.class); |
||||
registerSingleton("myHandlerAdapter", MyHandlerAdapter.class); |
||||
registerSingleton("standardHandlerAdapter", SimpleControllerHandlerAdapter.class); |
||||
registerSingleton("noviewController", NoViewController.class); |
||||
|
||||
pvs = new MutablePropertyValues(); |
||||
pvs.addPropertyValue("order", new Integer(0)); |
||||
pvs.addPropertyValue("basename", "org.springframework.web.servlet.complexviews"); |
||||
registerSingleton("viewResolver", ResourceBundleViewResolver.class, pvs); |
||||
|
||||
pvs = new MutablePropertyValues(); |
||||
pvs.addPropertyValue("suffix", ".jsp"); |
||||
registerSingleton("viewResolver2", InternalResourceViewResolver.class, pvs); |
||||
|
||||
pvs = new MutablePropertyValues(); |
||||
pvs.addPropertyValue("commandClass", "org.springframework.beans.TestBean"); |
||||
pvs.addPropertyValue("formView", "form"); |
||||
registerSingleton("formHandler", SimpleFormController.class, pvs); |
||||
|
||||
pvs = new MutablePropertyValues(); |
||||
pvs.addPropertyValue("viewName", "form"); |
||||
registerSingleton("viewHandler", ParameterizableViewController.class, pvs); |
||||
|
||||
registerSingleton("localeHandler", ComplexLocaleChecker.class); |
||||
registerSingleton("anotherLocaleHandler", ComplexLocaleChecker.class); |
||||
registerSingleton("unknownHandler", Object.class); |
||||
|
||||
registerSingleton("headController", HeadController.class); |
||||
registerSingleton("bodyController", BodyController.class); |
||||
|
||||
registerSingleton("servletPostProcessor", SimpleServletPostProcessor.class); |
||||
registerSingleton("handlerAdapter", SimpleServletHandlerAdapter.class); |
||||
registerSingleton("myServlet", MyServlet.class); |
||||
|
||||
pvs = new MutablePropertyValues(); |
||||
pvs.addPropertyValue("order", "1"); |
||||
pvs.addPropertyValue("exceptionMappings", |
||||
"java.lang.IllegalAccessException=failed2\n" + |
||||
"ServletRequestBindingException=failed3"); |
||||
pvs.addPropertyValue("defaultErrorView", "failed0"); |
||||
registerSingleton("exceptionResolver1", SimpleMappingExceptionResolver.class, pvs); |
||||
|
||||
pvs = new MutablePropertyValues(); |
||||
pvs.addPropertyValue("order", "0"); |
||||
pvs.addPropertyValue("exceptionMappings", "java.lang.Exception=failed1"); |
||||
List mappedHandlers = new ManagedList(); |
||||
mappedHandlers.add(new RuntimeBeanReference("anotherLocaleHandler")); |
||||
pvs.addPropertyValue("mappedHandlers", mappedHandlers); |
||||
pvs.addPropertyValue("defaultStatusCode", "500"); |
||||
pvs.addPropertyValue("defaultErrorView", "failed2"); |
||||
registerSingleton("handlerExceptionResolver", SimpleMappingExceptionResolver.class, pvs); |
||||
|
||||
registerSingleton("multipartResolver", MockMultipartResolver.class); |
||||
registerSingleton("testListener", TestApplicationListener.class); |
||||
|
||||
addMessage("test", Locale.ENGLISH, "test message"); |
||||
addMessage("test", Locale.CANADA, "Canadian & test message"); |
||||
|
||||
super.refresh(); |
||||
} |
||||
|
||||
|
||||
public static class HeadController implements Controller { |
||||
|
||||
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { |
||||
if ("HEAD".equals(request.getMethod())) { |
||||
response.setContentLength(5); |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
|
||||
public static class BodyController implements Controller { |
||||
|
||||
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { |
||||
response.getOutputStream().write("body".getBytes()); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
|
||||
public static class NoViewController implements Controller { |
||||
|
||||
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { |
||||
return new ModelAndView(); |
||||
} |
||||
} |
||||
|
||||
|
||||
public static class MyServlet implements Servlet { |
||||
|
||||
private ServletConfig servletConfig; |
||||
|
||||
public void init(ServletConfig servletConfig) throws ServletException { |
||||
this.servletConfig = servletConfig; |
||||
} |
||||
|
||||
public ServletConfig getServletConfig() { |
||||
return servletConfig; |
||||
} |
||||
|
||||
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException { |
||||
servletResponse.getOutputStream().write("body".getBytes()); |
||||
} |
||||
|
||||
public String getServletInfo() { |
||||
return null; |
||||
} |
||||
|
||||
public void destroy() { |
||||
this.servletConfig = null; |
||||
} |
||||
} |
||||
|
||||
|
||||
public static interface MyHandler { |
||||
|
||||
public void doSomething(HttpServletRequest request) throws ServletException, IllegalAccessException; |
||||
|
||||
public long lastModified(); |
||||
} |
||||
|
||||
|
||||
public static class MyHandlerAdapter extends ApplicationObjectSupport implements HandlerAdapter, Ordered { |
||||
|
||||
public int getOrder() { |
||||
return 99; |
||||
} |
||||
|
||||
public boolean supports(Object handler) { |
||||
return handler != null && MyHandler.class.isAssignableFrom(handler.getClass()); |
||||
} |
||||
|
||||
public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object delegate) |
||||
throws ServletException, IllegalAccessException { |
||||
((MyHandler) delegate).doSomething(request); |
||||
return null; |
||||
} |
||||
|
||||
public long getLastModified(HttpServletRequest request, Object delegate) { |
||||
return ((MyHandler) delegate).lastModified(); |
||||
} |
||||
} |
||||
|
||||
|
||||
public static class MyDummyAdapter extends ApplicationObjectSupport implements HandlerAdapter { |
||||
|
||||
public boolean supports(Object handler) { |
||||
return handler != null && MyHandler.class.isAssignableFrom(handler.getClass()); |
||||
} |
||||
|
||||
public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object delegate) |
||||
throws IOException, ServletException { |
||||
throw new ServletException("dummy"); |
||||
} |
||||
|
||||
public long getLastModified(HttpServletRequest request, Object delegate) { |
||||
return -1; |
||||
} |
||||
} |
||||
|
||||
|
||||
public static class MyHandlerInterceptor1 implements HandlerInterceptor { |
||||
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) |
||||
throws ServletException { |
||||
if (request.getAttribute("test2") != null) { |
||||
throw new ServletException("Wrong interceptor order"); |
||||
} |
||||
request.setAttribute("test1", "test1"); |
||||
request.setAttribute("test1x", "test1x"); |
||||
request.setAttribute("test1y", "test1y"); |
||||
return true; |
||||
} |
||||
|
||||
public void postHandle( |
||||
HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) |
||||
throws ServletException { |
||||
if (request.getAttribute("test2x") != null) { |
||||
throw new ServletException("Wrong interceptor order"); |
||||
} |
||||
if (!"test1x".equals(request.getAttribute("test1x"))) { |
||||
throw new ServletException("Incorrect request attribute"); |
||||
} |
||||
request.removeAttribute("test1x"); |
||||
} |
||||
|
||||
public void afterCompletion( |
||||
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) |
||||
throws ServletException { |
||||
if (request.getAttribute("test2y") != null) { |
||||
throw new ServletException("Wrong interceptor order"); |
||||
} |
||||
request.removeAttribute("test1y"); |
||||
} |
||||
} |
||||
|
||||
|
||||
public static class MyHandlerInterceptor2 implements HandlerInterceptor { |
||||
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) |
||||
throws ServletException { |
||||
if (request.getAttribute("test1x") == null) { |
||||
throw new ServletException("Wrong interceptor order"); |
||||
} |
||||
if (request.getParameter("abort") != null) { |
||||
return false; |
||||
} |
||||
request.setAttribute("test2", "test2"); |
||||
request.setAttribute("test2x", "test2x"); |
||||
request.setAttribute("test2y", "test2y"); |
||||
return true; |
||||
} |
||||
|
||||
public void postHandle( |
||||
HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) |
||||
throws ServletException { |
||||
if (request.getParameter("noView") != null) { |
||||
modelAndView.clear(); |
||||
} |
||||
if (request.getAttribute("test1x") == null) { |
||||
throw new ServletException("Wrong interceptor order"); |
||||
} |
||||
if (!"test2x".equals(request.getAttribute("test2x"))) { |
||||
throw new ServletException("Incorrect request attribute"); |
||||
} |
||||
request.removeAttribute("test2x"); |
||||
} |
||||
|
||||
public void afterCompletion( |
||||
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) |
||||
throws Exception { |
||||
if (request.getAttribute("test1y") == null) { |
||||
throw new ServletException("Wrong interceptor order"); |
||||
} |
||||
request.removeAttribute("test2y"); |
||||
} |
||||
} |
||||
|
||||
|
||||
public static class MyWebRequestInterceptor implements WebRequestInterceptor { |
||||
|
||||
public void preHandle(WebRequest request) throws Exception { |
||||
request.setAttribute("test3", "test3", WebRequest.SCOPE_REQUEST); |
||||
} |
||||
|
||||
public void postHandle(WebRequest request, ModelMap model) throws Exception { |
||||
request.setAttribute("test3x", "test3x", WebRequest.SCOPE_REQUEST); |
||||
} |
||||
|
||||
public void afterCompletion(WebRequest request, Exception ex) throws Exception { |
||||
request.setAttribute("test3y", "test3y", WebRequest.SCOPE_REQUEST); |
||||
} |
||||
} |
||||
|
||||
|
||||
public static class ComplexLocaleChecker implements MyHandler { |
||||
|
||||
public void doSomething(HttpServletRequest request) throws ServletException, IllegalAccessException { |
||||
WebApplicationContext wac = RequestContextUtils.getWebApplicationContext(request); |
||||
if (!(wac instanceof ComplexWebApplicationContext)) { |
||||
throw new ServletException("Incorrect WebApplicationContext"); |
||||
} |
||||
if (!(request instanceof MultipartHttpServletRequest)) { |
||||
throw new ServletException("Not in a MultipartHttpServletRequest"); |
||||
} |
||||
if (!(RequestContextUtils.getLocaleResolver(request) instanceof SessionLocaleResolver)) { |
||||
throw new ServletException("Incorrect LocaleResolver"); |
||||
} |
||||
if (!Locale.CANADA.equals(RequestContextUtils.getLocale(request))) { |
||||
throw new ServletException("Incorrect Locale"); |
||||
} |
||||
if (!Locale.CANADA.equals(LocaleContextHolder.getLocale())) { |
||||
throw new ServletException("Incorrect Locale"); |
||||
} |
||||
if (!(RequestContextUtils.getThemeResolver(request) instanceof SessionThemeResolver)) { |
||||
throw new ServletException("Incorrect ThemeResolver"); |
||||
} |
||||
if (!"theme".equals(RequestContextUtils.getThemeResolver(request).resolveThemeName(request))) { |
||||
throw new ServletException("Incorrect theme name"); |
||||
} |
||||
if (request.getParameter("fail") != null) { |
||||
throw new ModelAndViewDefiningException(new ModelAndView("failed1")); |
||||
} |
||||
if (request.getParameter("access") != null) { |
||||
throw new IllegalAccessException("illegal access"); |
||||
} |
||||
if (request.getParameter("servlet") != null) { |
||||
throw new ServletRequestBindingException("servlet"); |
||||
} |
||||
if (request.getParameter("exception") != null) { |
||||
throw new RuntimeException("servlet"); |
||||
} |
||||
} |
||||
|
||||
public long lastModified() { |
||||
return 99; |
||||
} |
||||
} |
||||
|
||||
|
||||
public static class MockMultipartResolver implements MultipartResolver { |
||||
|
||||
public boolean isMultipart(HttpServletRequest request) { |
||||
return true; |
||||
} |
||||
|
||||
public MultipartHttpServletRequest resolveMultipart(HttpServletRequest request) throws MultipartException { |
||||
if (request.getAttribute("fail") != null) { |
||||
throw new MaxUploadSizeExceededException(1000); |
||||
} |
||||
if (request instanceof MultipartHttpServletRequest) { |
||||
throw new IllegalStateException("Already a multipart request"); |
||||
} |
||||
if (request.getAttribute("resolved") != null) { |
||||
throw new IllegalStateException("Already resolved"); |
||||
} |
||||
request.setAttribute("resolved", Boolean.TRUE); |
||||
return new AbstractMultipartHttpServletRequest(request) { |
||||
}; |
||||
} |
||||
|
||||
public void cleanupMultipart(MultipartHttpServletRequest request) { |
||||
if (request.getAttribute("cleanedUp") != null) { |
||||
throw new IllegalStateException("Already cleaned up"); |
||||
} |
||||
request.setAttribute("cleanedUp", Boolean.TRUE); |
||||
} |
||||
} |
||||
|
||||
|
||||
public static class TestApplicationListener implements ApplicationListener { |
||||
|
||||
public int counter = 0; |
||||
|
||||
public void onApplicationEvent(ApplicationEvent event) { |
||||
if (event instanceof RequestHandledEvent) { |
||||
this.counter++; |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -1,118 +0,0 @@
@@ -1,118 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2005 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.web.servlet; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.Locale; |
||||
|
||||
import javax.servlet.ServletException; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
import org.springframework.beans.BeansException; |
||||
import org.springframework.beans.MutablePropertyValues; |
||||
import org.springframework.context.support.StaticMessageSource; |
||||
import org.springframework.ui.context.Theme; |
||||
import org.springframework.ui.context.ThemeSource; |
||||
import org.springframework.ui.context.support.SimpleTheme; |
||||
import org.springframework.ui.context.support.UiApplicationContextUtils; |
||||
import org.springframework.web.context.support.StaticWebApplicationContext; |
||||
import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; |
||||
import org.springframework.web.servlet.mvc.Controller; |
||||
import org.springframework.web.servlet.mvc.LastModified; |
||||
import org.springframework.web.servlet.mvc.SimpleFormController; |
||||
import org.springframework.web.servlet.support.RequestContextUtils; |
||||
import org.springframework.web.servlet.theme.AbstractThemeResolver; |
||||
import org.springframework.web.servlet.view.InternalResourceViewResolver; |
||||
import org.springframework.web.servlet.view.XmlViewResolver; |
||||
import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping; |
||||
|
||||
/** |
||||
* @author Juergen Hoeller |
||||
* @since 21.05.2003 |
||||
*/ |
||||
public class SimpleWebApplicationContext extends StaticWebApplicationContext { |
||||
|
||||
public void refresh() throws BeansException { |
||||
MutablePropertyValues pvs = new MutablePropertyValues(); |
||||
pvs.addPropertyValue("commandClass", "org.springframework.beans.TestBean"); |
||||
pvs.addPropertyValue("formView", "form"); |
||||
registerSingleton("/form.do", SimpleFormController.class, pvs); |
||||
|
||||
registerSingleton("/locale.do", LocaleChecker.class); |
||||
|
||||
addMessage("test", Locale.ENGLISH, "test message"); |
||||
addMessage("test", Locale.CANADA, "Canadian & test message"); |
||||
addMessage("testArgs", Locale.ENGLISH, "test {0} message {1}"); |
||||
addMessage("testArgsFormat", Locale.ENGLISH, "test {0} message {1,number,#.##} X"); |
||||
|
||||
registerSingleton(UiApplicationContextUtils.THEME_SOURCE_BEAN_NAME, DummyThemeSource.class); |
||||
|
||||
registerSingleton("handlerMapping", BeanNameUrlHandlerMapping.class); |
||||
registerSingleton("viewResolver", InternalResourceViewResolver.class); |
||||
|
||||
pvs = new MutablePropertyValues(); |
||||
pvs.addPropertyValue("location", "org/springframework/web/context/WEB-INF/sessionContext.xml"); |
||||
registerSingleton("viewResolver2", XmlViewResolver.class, pvs); |
||||
|
||||
super.refresh(); |
||||
} |
||||
|
||||
|
||||
public static class LocaleChecker implements Controller, LastModified { |
||||
|
||||
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) |
||||
throws ServletException, IOException { |
||||
if (!(RequestContextUtils.getWebApplicationContext(request) instanceof SimpleWebApplicationContext)) { |
||||
throw new ServletException("Incorrect WebApplicationContext"); |
||||
} |
||||
if (!(RequestContextUtils.getLocaleResolver(request) instanceof AcceptHeaderLocaleResolver)) { |
||||
throw new ServletException("Incorrect LocaleResolver"); |
||||
} |
||||
if (!Locale.CANADA.equals(RequestContextUtils.getLocale(request))) { |
||||
throw new ServletException("Incorrect Locale"); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public long getLastModified(HttpServletRequest request) { |
||||
return 98; |
||||
} |
||||
} |
||||
|
||||
|
||||
public static class DummyThemeSource implements ThemeSource { |
||||
|
||||
private StaticMessageSource messageSource; |
||||
|
||||
public DummyThemeSource() { |
||||
this.messageSource = new StaticMessageSource(); |
||||
this.messageSource.addMessage("themetest", Locale.ENGLISH, "theme test message"); |
||||
this.messageSource.addMessage("themetestArgs", Locale.ENGLISH, "theme test message {0}"); |
||||
} |
||||
|
||||
public Theme getTheme(String themeName) { |
||||
if (AbstractThemeResolver.ORIGINAL_DEFAULT_THEME_NAME.equals(themeName)) { |
||||
return new SimpleTheme(AbstractThemeResolver.ORIGINAL_DEFAULT_THEME_NAME, this.messageSource); |
||||
} |
||||
else { |
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,67 @@
@@ -0,0 +1,67 @@
|
||||
/* |
||||
* Copyright 2002-2007 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.mock.web; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.InputStream; |
||||
|
||||
import javax.servlet.ServletInputStream; |
||||
|
||||
import org.springframework.util.Assert; |
||||
|
||||
/** |
||||
* Delegating implementation of {@link javax.servlet.ServletInputStream}. |
||||
* |
||||
* <p>Used by {@link org.springframework.mock.web.MockHttpServletRequest}; typically not directly |
||||
* used for testing application controllers. |
||||
* |
||||
* @author Juergen Hoeller |
||||
* @since 1.0.2 |
||||
* @see org.springframework.mock.web.MockHttpServletRequest |
||||
*/ |
||||
public class DelegatingServletInputStream extends ServletInputStream { |
||||
|
||||
private final InputStream sourceStream; |
||||
|
||||
|
||||
/** |
||||
* Create a DelegatingServletInputStream for the given source stream. |
||||
* @param sourceStream the source stream (never <code>null</code>) |
||||
*/ |
||||
public DelegatingServletInputStream(InputStream sourceStream) { |
||||
Assert.notNull(sourceStream, "Source InputStream must not be null"); |
||||
this.sourceStream = sourceStream; |
||||
} |
||||
|
||||
/** |
||||
* Return the underlying source stream (never <code>null</code>). |
||||
*/ |
||||
public final InputStream getSourceStream() { |
||||
return this.sourceStream; |
||||
} |
||||
|
||||
|
||||
public int read() throws IOException { |
||||
return this.sourceStream.read(); |
||||
} |
||||
|
||||
public void close() throws IOException { |
||||
super.close(); |
||||
this.sourceStream.close(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
/* |
||||
* Copyright 2002-2007 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.beans; |
||||
|
||||
import org.springframework.core.enums.ShortCodedLabeledEnum; |
||||
|
||||
/** |
||||
* @author Rob Harrop |
||||
*/ |
||||
public class Colour extends ShortCodedLabeledEnum { |
||||
|
||||
public static final Colour RED = new Colour(0, "RED"); |
||||
public static final Colour BLUE = new Colour(1, "BLUE"); |
||||
public static final Colour GREEN = new Colour(2, "GREEN"); |
||||
public static final Colour PURPLE = new Colour(3, "PURPLE"); |
||||
|
||||
private Colour(int code, String label) { |
||||
super(code, label); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,85 @@
@@ -0,0 +1,85 @@
|
||||
/* |
||||
* Copyright 2002-2007 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.beans; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import org.springframework.beans.factory.BeanNameAware; |
||||
import org.springframework.beans.factory.DisposableBean; |
||||
|
||||
/** |
||||
* @author Juergen Hoeller |
||||
* @since 21.08.2003 |
||||
*/ |
||||
public class DerivedTestBean extends TestBean implements Serializable, BeanNameAware, DisposableBean { |
||||
|
||||
private String beanName; |
||||
|
||||
private boolean initialized; |
||||
|
||||
private boolean destroyed; |
||||
|
||||
|
||||
public DerivedTestBean() { |
||||
} |
||||
|
||||
public DerivedTestBean(String[] names) { |
||||
if (names == null || names.length < 2) { |
||||
throw new IllegalArgumentException("Invalid names array"); |
||||
} |
||||
setName(names[0]); |
||||
setBeanName(names[1]); |
||||
} |
||||
|
||||
public static DerivedTestBean create(String[] names) { |
||||
return new DerivedTestBean(names); |
||||
} |
||||
|
||||
|
||||
public void setBeanName(String beanName) { |
||||
if (this.beanName == null || beanName == null) { |
||||
this.beanName = beanName; |
||||
} |
||||
} |
||||
|
||||
public String getBeanName() { |
||||
return beanName; |
||||
} |
||||
|
||||
public void setSpouseRef(String name) { |
||||
setSpouse(new TestBean(name)); |
||||
} |
||||
|
||||
|
||||
public void initialize() { |
||||
this.initialized = true; |
||||
} |
||||
|
||||
public boolean wasInitialized() { |
||||
return initialized; |
||||
} |
||||
|
||||
|
||||
public void destroy() { |
||||
this.destroyed = true; |
||||
} |
||||
|
||||
public boolean wasDestroyed() { |
||||
return destroyed; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
/* |
||||
* Copyright 2002-2005 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.beans; |
||||
|
||||
public interface INestedTestBean { |
||||
|
||||
public String getCompany(); |
||||
|
||||
} |
||||
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
|
||||
/* |
||||
* Copyright 2002-2005 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.beans; |
||||
|
||||
public interface IOther { |
||||
|
||||
void absquatulate(); |
||||
|
||||
} |
||||
@ -0,0 +1,71 @@
@@ -0,0 +1,71 @@
|
||||
/* |
||||
* Copyright 2002-2007 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.beans; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
/** |
||||
* Interface used for {@link org.springframework.beans.TestBean}. |
||||
* |
||||
* <p>Two methods are the same as on Person, but if this |
||||
* extends person it breaks quite a few tests.. |
||||
* |
||||
* @author Rod Johnson |
||||
* @author Juergen Hoeller |
||||
*/ |
||||
public interface ITestBean { |
||||
|
||||
int getAge(); |
||||
|
||||
void setAge(int age); |
||||
|
||||
String getName(); |
||||
|
||||
void setName(String name); |
||||
|
||||
ITestBean getSpouse(); |
||||
|
||||
void setSpouse(ITestBean spouse); |
||||
|
||||
ITestBean[] getSpouses(); |
||||
|
||||
String[] getStringArray(); |
||||
|
||||
void setStringArray(String[] stringArray); |
||||
|
||||
/** |
||||
* Throws a given (non-null) exception. |
||||
*/ |
||||
void exceptional(Throwable t) throws Throwable; |
||||
|
||||
Object returnsThis(); |
||||
|
||||
INestedTestBean getDoctor(); |
||||
|
||||
INestedTestBean getLawyer(); |
||||
|
||||
IndexedTestBean getNestedIndexedBean(); |
||||
|
||||
/** |
||||
* Increment the age by one. |
||||
* @return the previous age |
||||
*/ |
||||
int haveBirthday(); |
||||
|
||||
void unreliableFileOperation() throws IOException; |
||||
|
||||
} |
||||
@ -0,0 +1,145 @@
@@ -0,0 +1,145 @@
|
||||
/* |
||||
* Copyright 2002-2006 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.beans; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Collection; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Set; |
||||
import java.util.SortedMap; |
||||
import java.util.SortedSet; |
||||
import java.util.TreeSet; |
||||
|
||||
/** |
||||
* @author Juergen Hoeller |
||||
* @since 11.11.2003 |
||||
*/ |
||||
public class IndexedTestBean { |
||||
|
||||
private TestBean[] array; |
||||
|
||||
private Collection collection; |
||||
|
||||
private List list; |
||||
|
||||
private Set set; |
||||
|
||||
private SortedSet sortedSet; |
||||
|
||||
private Map map; |
||||
|
||||
private SortedMap sortedMap; |
||||
|
||||
|
||||
public IndexedTestBean() { |
||||
this(true); |
||||
} |
||||
|
||||
public IndexedTestBean(boolean populate) { |
||||
if (populate) { |
||||
populate(); |
||||
} |
||||
} |
||||
|
||||
public void populate() { |
||||
TestBean tb0 = new TestBean("name0", 0); |
||||
TestBean tb1 = new TestBean("name1", 0); |
||||
TestBean tb2 = new TestBean("name2", 0); |
||||
TestBean tb3 = new TestBean("name3", 0); |
||||
TestBean tb4 = new TestBean("name4", 0); |
||||
TestBean tb5 = new TestBean("name5", 0); |
||||
TestBean tb6 = new TestBean("name6", 0); |
||||
TestBean tb7 = new TestBean("name7", 0); |
||||
TestBean tbX = new TestBean("nameX", 0); |
||||
TestBean tbY = new TestBean("nameY", 0); |
||||
this.array = new TestBean[] {tb0, tb1}; |
||||
this.list = new ArrayList(); |
||||
this.list.add(tb2); |
||||
this.list.add(tb3); |
||||
this.set = new TreeSet(); |
||||
this.set.add(tb6); |
||||
this.set.add(tb7); |
||||
this.map = new HashMap(); |
||||
this.map.put("key1", tb4); |
||||
this.map.put("key2", tb5); |
||||
this.map.put("key.3", tb5); |
||||
List list = new ArrayList(); |
||||
list.add(tbX); |
||||
list.add(tbY); |
||||
this.map.put("key4", list); |
||||
} |
||||
|
||||
|
||||
public TestBean[] getArray() { |
||||
return array; |
||||
} |
||||
|
||||
public void setArray(TestBean[] array) { |
||||
this.array = array; |
||||
} |
||||
|
||||
public Collection getCollection() { |
||||
return collection; |
||||
} |
||||
|
||||
public void setCollection(Collection collection) { |
||||
this.collection = collection; |
||||
} |
||||
|
||||
public List getList() { |
||||
return list; |
||||
} |
||||
|
||||
public void setList(List list) { |
||||
this.list = list; |
||||
} |
||||
|
||||
public Set getSet() { |
||||
return set; |
||||
} |
||||
|
||||
public void setSet(Set set) { |
||||
this.set = set; |
||||
} |
||||
|
||||
public SortedSet getSortedSet() { |
||||
return sortedSet; |
||||
} |
||||
|
||||
public void setSortedSet(SortedSet sortedSet) { |
||||
this.sortedSet = sortedSet; |
||||
} |
||||
|
||||
public Map getMap() { |
||||
return map; |
||||
} |
||||
|
||||
public void setMap(Map map) { |
||||
this.map = map; |
||||
} |
||||
|
||||
public SortedMap getSortedMap() { |
||||
return sortedMap; |
||||
} |
||||
|
||||
public void setSortedMap(SortedMap sortedMap) { |
||||
this.sortedMap = sortedMap; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
/* |
||||
* Copyright 2002-2005 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.beans; |
||||
|
||||
/** |
||||
* Simple nested test bean used for testing bean factories, AOP framework etc. |
||||
* |
||||
* @author Trevor D. Cook |
||||
* @since 30.09.2003 |
||||
*/ |
||||
public class NestedTestBean implements INestedTestBean { |
||||
|
||||
private String company = ""; |
||||
|
||||
public NestedTestBean() { |
||||
} |
||||
|
||||
public NestedTestBean(String company) { |
||||
setCompany(company); |
||||
} |
||||
|
||||
public void setCompany(String company) { |
||||
this.company = (company != null ? company : ""); |
||||
} |
||||
|
||||
public String getCompany() { |
||||
return company; |
||||
} |
||||
|
||||
public boolean equals(Object obj) { |
||||
if (!(obj instanceof NestedTestBean)) { |
||||
return false; |
||||
} |
||||
NestedTestBean ntb = (NestedTestBean) obj; |
||||
return this.company.equals(ntb.company); |
||||
} |
||||
|
||||
public int hashCode() { |
||||
return this.company.hashCode(); |
||||
} |
||||
|
||||
public String toString() { |
||||
return "NestedTestBean: " + this.company; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,437 @@
@@ -0,0 +1,437 @@
|
||||
/* |
||||
* Copyright 2002-2008 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.beans; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.ArrayList; |
||||
import java.util.Collection; |
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.HashSet; |
||||
import java.util.LinkedList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Properties; |
||||
import java.util.Set; |
||||
|
||||
import org.springframework.beans.factory.BeanFactory; |
||||
import org.springframework.beans.factory.BeanFactoryAware; |
||||
import org.springframework.beans.factory.BeanNameAware; |
||||
import org.springframework.util.ObjectUtils; |
||||
|
||||
/** |
||||
* Simple test bean used for testing bean factories, the AOP framework etc. |
||||
* |
||||
* @author Rod Johnson |
||||
* @author Juergen Hoeller |
||||
* @since 15 April 2001 |
||||
*/ |
||||
public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOther, Comparable { |
||||
|
||||
private String beanName; |
||||
|
||||
private String country; |
||||
|
||||
private BeanFactory beanFactory; |
||||
|
||||
private boolean postProcessed; |
||||
|
||||
private String name; |
||||
|
||||
private String sex; |
||||
|
||||
private int age; |
||||
|
||||
private boolean jedi; |
||||
|
||||
private ITestBean[] spouses; |
||||
|
||||
private String touchy; |
||||
|
||||
private String[] stringArray; |
||||
|
||||
private Integer[] someIntegerArray; |
||||
|
||||
private Date date = new Date(); |
||||
|
||||
private Float myFloat = new Float(0.0); |
||||
|
||||
private Collection friends = new LinkedList(); |
||||
|
||||
private Set someSet = new HashSet(); |
||||
|
||||
private Map someMap = new HashMap(); |
||||
|
||||
private List someList = new ArrayList(); |
||||
|
||||
private Properties someProperties = new Properties(); |
||||
|
||||
private INestedTestBean doctor = new NestedTestBean(); |
||||
|
||||
private INestedTestBean lawyer = new NestedTestBean(); |
||||
|
||||
private IndexedTestBean nestedIndexedBean; |
||||
|
||||
private boolean destroyed; |
||||
|
||||
private Number someNumber; |
||||
|
||||
private Colour favouriteColour; |
||||
|
||||
private Boolean someBoolean; |
||||
|
||||
private List otherColours; |
||||
|
||||
private List pets; |
||||
|
||||
|
||||
public TestBean() { |
||||
} |
||||
|
||||
public TestBean(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public TestBean(ITestBean spouse) { |
||||
this.spouses = new ITestBean[] {spouse}; |
||||
} |
||||
|
||||
public TestBean(String name, int age) { |
||||
this.name = name; |
||||
this.age = age; |
||||
} |
||||
|
||||
public TestBean(ITestBean spouse, Properties someProperties) { |
||||
this.spouses = new ITestBean[] {spouse}; |
||||
this.someProperties = someProperties; |
||||
} |
||||
|
||||
public TestBean(List someList) { |
||||
this.someList = someList; |
||||
} |
||||
|
||||
public TestBean(Set someSet) { |
||||
this.someSet = someSet; |
||||
} |
||||
|
||||
public TestBean(Map someMap) { |
||||
this.someMap = someMap; |
||||
} |
||||
|
||||
public TestBean(Properties someProperties) { |
||||
this.someProperties = someProperties; |
||||
} |
||||
|
||||
|
||||
public void setBeanName(String beanName) { |
||||
this.beanName = beanName; |
||||
} |
||||
|
||||
public String getBeanName() { |
||||
return beanName; |
||||
} |
||||
|
||||
public void setBeanFactory(BeanFactory beanFactory) { |
||||
this.beanFactory = beanFactory; |
||||
} |
||||
|
||||
public BeanFactory getBeanFactory() { |
||||
return beanFactory; |
||||
} |
||||
|
||||
public void setPostProcessed(boolean postProcessed) { |
||||
this.postProcessed = postProcessed; |
||||
} |
||||
|
||||
public boolean isPostProcessed() { |
||||
return postProcessed; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public String getSex() { |
||||
return sex; |
||||
} |
||||
|
||||
public void setSex(String sex) { |
||||
this.sex = sex; |
||||
if (this.name == null) { |
||||
this.name = sex; |
||||
} |
||||
} |
||||
|
||||
public int getAge() { |
||||
return age; |
||||
} |
||||
|
||||
public void setAge(int age) { |
||||
this.age = age; |
||||
} |
||||
|
||||
public boolean isJedi() { |
||||
return jedi; |
||||
} |
||||
|
||||
public void setJedi(boolean jedi) { |
||||
this.jedi = jedi; |
||||
} |
||||
|
||||
public ITestBean getSpouse() { |
||||
return (spouses != null ? spouses[0] : null); |
||||
} |
||||
|
||||
public void setSpouse(ITestBean spouse) { |
||||
this.spouses = new ITestBean[] {spouse}; |
||||
} |
||||
|
||||
public ITestBean[] getSpouses() { |
||||
return spouses; |
||||
} |
||||
|
||||
public String getTouchy() { |
||||
return touchy; |
||||
} |
||||
|
||||
public void setTouchy(String touchy) throws Exception { |
||||
if (touchy.indexOf('.') != -1) { |
||||
throw new Exception("Can't contain a ."); |
||||
} |
||||
if (touchy.indexOf(',') != -1) { |
||||
throw new NumberFormatException("Number format exception: contains a ,"); |
||||
} |
||||
this.touchy = touchy; |
||||
} |
||||
|
||||
public String getCountry() { |
||||
return country; |
||||
} |
||||
|
||||
public void setCountry(String country) { |
||||
this.country = country; |
||||
} |
||||
|
||||
public String[] getStringArray() { |
||||
return stringArray; |
||||
} |
||||
|
||||
public void setStringArray(String[] stringArray) { |
||||
this.stringArray = stringArray; |
||||
} |
||||
|
||||
public Integer[] getSomeIntegerArray() { |
||||
return someIntegerArray; |
||||
} |
||||
|
||||
public void setSomeIntegerArray(Integer[] someIntegerArray) { |
||||
this.someIntegerArray = someIntegerArray; |
||||
} |
||||
|
||||
public Date getDate() { |
||||
return date; |
||||
} |
||||
|
||||
public void setDate(Date date) { |
||||
this.date = date; |
||||
} |
||||
|
||||
public Float getMyFloat() { |
||||
return myFloat; |
||||
} |
||||
|
||||
public void setMyFloat(Float myFloat) { |
||||
this.myFloat = myFloat; |
||||
} |
||||
|
||||
public Collection getFriends() { |
||||
return friends; |
||||
} |
||||
|
||||
public void setFriends(Collection friends) { |
||||
this.friends = friends; |
||||
} |
||||
|
||||
public Set getSomeSet() { |
||||
return someSet; |
||||
} |
||||
|
||||
public void setSomeSet(Set someSet) { |
||||
this.someSet = someSet; |
||||
} |
||||
|
||||
public Map getSomeMap() { |
||||
return someMap; |
||||
} |
||||
|
||||
public void setSomeMap(Map someMap) { |
||||
this.someMap = someMap; |
||||
} |
||||
|
||||
public List getSomeList() { |
||||
return someList; |
||||
} |
||||
|
||||
public void setSomeList(List someList) { |
||||
this.someList = someList; |
||||
} |
||||
|
||||
public Properties getSomeProperties() { |
||||
return someProperties; |
||||
} |
||||
|
||||
public void setSomeProperties(Properties someProperties) { |
||||
this.someProperties = someProperties; |
||||
} |
||||
|
||||
public INestedTestBean getDoctor() { |
||||
return doctor; |
||||
} |
||||
|
||||
public void setDoctor(INestedTestBean doctor) { |
||||
this.doctor = doctor; |
||||
} |
||||
|
||||
public INestedTestBean getLawyer() { |
||||
return lawyer; |
||||
} |
||||
|
||||
public void setLawyer(INestedTestBean lawyer) { |
||||
this.lawyer = lawyer; |
||||
} |
||||
|
||||
public Number getSomeNumber() { |
||||
return someNumber; |
||||
} |
||||
|
||||
public void setSomeNumber(Number someNumber) { |
||||
this.someNumber = someNumber; |
||||
} |
||||
|
||||
public Colour getFavouriteColour() { |
||||
return favouriteColour; |
||||
} |
||||
|
||||
public void setFavouriteColour(Colour favouriteColour) { |
||||
this.favouriteColour = favouriteColour; |
||||
} |
||||
|
||||
public Boolean getSomeBoolean() { |
||||
return someBoolean; |
||||
} |
||||
|
||||
public void setSomeBoolean(Boolean someBoolean) { |
||||
this.someBoolean = someBoolean; |
||||
} |
||||
|
||||
public IndexedTestBean getNestedIndexedBean() { |
||||
return nestedIndexedBean; |
||||
} |
||||
|
||||
public void setNestedIndexedBean(IndexedTestBean nestedIndexedBean) { |
||||
this.nestedIndexedBean = nestedIndexedBean; |
||||
} |
||||
|
||||
public List getOtherColours() { |
||||
return otherColours; |
||||
} |
||||
|
||||
public void setOtherColours(List otherColours) { |
||||
this.otherColours = otherColours; |
||||
} |
||||
|
||||
public List getPets() { |
||||
return pets; |
||||
} |
||||
|
||||
public void setPets(List pets) { |
||||
this.pets = pets; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* @see org.springframework.beans.ITestBean#exceptional(Throwable) |
||||
*/ |
||||
public void exceptional(Throwable t) throws Throwable { |
||||
if (t != null) { |
||||
throw t; |
||||
} |
||||
} |
||||
|
||||
public void unreliableFileOperation() throws IOException { |
||||
throw new IOException(); |
||||
} |
||||
/** |
||||
* @see org.springframework.beans.ITestBean#returnsThis() |
||||
*/ |
||||
public Object returnsThis() { |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* @see org.springframework.beans.IOther#absquatulate() |
||||
*/ |
||||
public void absquatulate() { |
||||
} |
||||
|
||||
public int haveBirthday() { |
||||
return age++; |
||||
} |
||||
|
||||
|
||||
public void destroy() { |
||||
this.destroyed = true; |
||||
} |
||||
|
||||
public boolean wasDestroyed() { |
||||
return destroyed; |
||||
} |
||||
|
||||
|
||||
public boolean equals(Object other) { |
||||
if (this == other) { |
||||
return true; |
||||
} |
||||
if (other == null || !(other instanceof TestBean)) { |
||||
return false; |
||||
} |
||||
TestBean tb2 = (TestBean) other; |
||||
return (ObjectUtils.nullSafeEquals(this.name, tb2.name) && this.age == tb2.age); |
||||
} |
||||
|
||||
public int hashCode() { |
||||
return this.age; |
||||
} |
||||
|
||||
public int compareTo(Object other) { |
||||
if (this.name != null && other instanceof TestBean) { |
||||
return this.name.compareTo(((TestBean) other).getName()); |
||||
} |
||||
else { |
||||
return 1; |
||||
} |
||||
} |
||||
|
||||
public String toString() { |
||||
return this.name; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,172 @@
@@ -0,0 +1,172 @@
|
||||
/* |
||||
* Copyright 2002-2007 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.beans.factory; |
||||
|
||||
import org.springframework.beans.BeansException; |
||||
import org.springframework.beans.TestBean; |
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; |
||||
|
||||
/** |
||||
* Simple factory to allow testing of FactoryBean support in AbstractBeanFactory. |
||||
* Depending on whether its singleton property is set, it will return a singleton |
||||
* or a prototype instance. |
||||
* |
||||
* <p>Implements InitializingBean interface, so we can check that |
||||
* factories get this lifecycle callback if they want. |
||||
* |
||||
* @author Rod Johnson |
||||
* @since 10.03.2003 |
||||
*/ |
||||
public class DummyFactory |
||||
implements FactoryBean, BeanNameAware, BeanFactoryAware, InitializingBean, DisposableBean { |
||||
|
||||
public static final String SINGLETON_NAME = "Factory singleton"; |
||||
|
||||
private static boolean prototypeCreated; |
||||
|
||||
/** |
||||
* Clear static state. |
||||
*/ |
||||
public static void reset() { |
||||
prototypeCreated = false; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Default is for factories to return a singleton instance. |
||||
*/ |
||||
private boolean singleton = true; |
||||
|
||||
private String beanName; |
||||
|
||||
private AutowireCapableBeanFactory beanFactory; |
||||
|
||||
private boolean postProcessed; |
||||
|
||||
private boolean initialized; |
||||
|
||||
private TestBean testBean; |
||||
|
||||
private TestBean otherTestBean; |
||||
|
||||
|
||||
public DummyFactory() { |
||||
this.testBean = new TestBean(); |
||||
this.testBean.setName(SINGLETON_NAME); |
||||
this.testBean.setAge(25); |
||||
} |
||||
|
||||
/** |
||||
* Return if the bean managed by this factory is a singleton. |
||||
* @see FactoryBean#isSingleton() |
||||
*/ |
||||
public boolean isSingleton() { |
||||
return this.singleton; |
||||
} |
||||
|
||||
/** |
||||
* Set if the bean managed by this factory is a singleton. |
||||
*/ |
||||
public void setSingleton(boolean singleton) { |
||||
this.singleton = singleton; |
||||
} |
||||
|
||||
public void setBeanName(String beanName) { |
||||
this.beanName = beanName; |
||||
} |
||||
|
||||
public String getBeanName() { |
||||
return beanName; |
||||
} |
||||
|
||||
public void setBeanFactory(BeanFactory beanFactory) { |
||||
this.beanFactory = (AutowireCapableBeanFactory) beanFactory; |
||||
this.beanFactory.applyBeanPostProcessorsBeforeInitialization(this.testBean, this.beanName); |
||||
} |
||||
|
||||
public BeanFactory getBeanFactory() { |
||||
return beanFactory; |
||||
} |
||||
|
||||
public void setPostProcessed(boolean postProcessed) { |
||||
this.postProcessed = postProcessed; |
||||
} |
||||
|
||||
public boolean isPostProcessed() { |
||||
return postProcessed; |
||||
} |
||||
|
||||
public void setOtherTestBean(TestBean otherTestBean) { |
||||
this.otherTestBean = otherTestBean; |
||||
this.testBean.setSpouse(otherTestBean); |
||||
} |
||||
|
||||
public TestBean getOtherTestBean() { |
||||
return otherTestBean; |
||||
} |
||||
|
||||
public void afterPropertiesSet() { |
||||
if (initialized) { |
||||
throw new RuntimeException("Cannot call afterPropertiesSet twice on the one bean"); |
||||
} |
||||
this.initialized = true; |
||||
} |
||||
|
||||
/** |
||||
* Was this initialized by invocation of the |
||||
* afterPropertiesSet() method from the InitializingBean interface? |
||||
*/ |
||||
public boolean wasInitialized() { |
||||
return initialized; |
||||
} |
||||
|
||||
public static boolean wasPrototypeCreated() { |
||||
return prototypeCreated; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Return the managed object, supporting both singleton |
||||
* and prototype mode. |
||||
* @see FactoryBean#getObject() |
||||
*/ |
||||
public Object getObject() throws BeansException { |
||||
if (isSingleton()) { |
||||
return this.testBean; |
||||
} |
||||
else { |
||||
TestBean prototype = new TestBean("prototype created at " + System.currentTimeMillis(), 11); |
||||
if (this.beanFactory != null) { |
||||
this.beanFactory.applyBeanPostProcessorsBeforeInitialization(prototype, this.beanName); |
||||
} |
||||
prototypeCreated = true; |
||||
return prototype; |
||||
} |
||||
} |
||||
|
||||
public Class getObjectType() { |
||||
return TestBean.class; |
||||
} |
||||
|
||||
|
||||
public void destroy() { |
||||
if (this.testBean != null) { |
||||
this.testBean.setName(null); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,158 @@
@@ -0,0 +1,158 @@
|
||||
/* |
||||
* Copyright 2002-2007 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.beans.factory; |
||||
|
||||
import org.springframework.beans.BeansException; |
||||
import org.springframework.beans.factory.config.BeanPostProcessor; |
||||
|
||||
/** |
||||
* Simple test of BeanFactory initialization and lifecycle callbacks. |
||||
* |
||||
* @author Rod Johnson |
||||
* @author Colin Sampaleanu |
||||
* @since 12.03.2003 |
||||
*/ |
||||
public class LifecycleBean implements BeanNameAware, BeanFactoryAware, InitializingBean, DisposableBean { |
||||
|
||||
protected boolean initMethodDeclared = false; |
||||
|
||||
protected String beanName; |
||||
|
||||
protected BeanFactory owningFactory; |
||||
|
||||
protected boolean postProcessedBeforeInit; |
||||
|
||||
protected boolean inited; |
||||
|
||||
protected boolean initedViaDeclaredInitMethod; |
||||
|
||||
protected boolean postProcessedAfterInit; |
||||
|
||||
protected boolean destroyed; |
||||
|
||||
|
||||
public void setInitMethodDeclared(boolean initMethodDeclared) { |
||||
this.initMethodDeclared = initMethodDeclared; |
||||
} |
||||
|
||||
public boolean isInitMethodDeclared() { |
||||
return initMethodDeclared; |
||||
} |
||||
|
||||
public void setBeanName(String name) { |
||||
this.beanName = name; |
||||
} |
||||
|
||||
public String getBeanName() { |
||||
return beanName; |
||||
} |
||||
|
||||
public void setBeanFactory(BeanFactory beanFactory) { |
||||
this.owningFactory = beanFactory; |
||||
} |
||||
|
||||
public void postProcessBeforeInit() { |
||||
if (this.inited || this.initedViaDeclaredInitMethod) { |
||||
throw new RuntimeException("Factory called postProcessBeforeInit after afterPropertiesSet"); |
||||
} |
||||
if (this.postProcessedBeforeInit) { |
||||
throw new RuntimeException("Factory called postProcessBeforeInit twice"); |
||||
} |
||||
this.postProcessedBeforeInit = true; |
||||
} |
||||
|
||||
public void afterPropertiesSet() { |
||||
if (this.owningFactory == null) { |
||||
throw new RuntimeException("Factory didn't call setBeanFactory before afterPropertiesSet on lifecycle bean"); |
||||
} |
||||
if (!this.postProcessedBeforeInit) { |
||||
throw new RuntimeException("Factory didn't call postProcessBeforeInit before afterPropertiesSet on lifecycle bean"); |
||||
} |
||||
if (this.initedViaDeclaredInitMethod) { |
||||
throw new RuntimeException("Factory initialized via declared init method before initializing via afterPropertiesSet"); |
||||
} |
||||
if (this.inited) { |
||||
throw new RuntimeException("Factory called afterPropertiesSet twice"); |
||||
} |
||||
this.inited = true; |
||||
} |
||||
|
||||
public void declaredInitMethod() { |
||||
if (!this.inited) { |
||||
throw new RuntimeException("Factory didn't call afterPropertiesSet before declared init method"); |
||||
} |
||||
|
||||
if (this.initedViaDeclaredInitMethod) { |
||||
throw new RuntimeException("Factory called declared init method twice"); |
||||
} |
||||
this.initedViaDeclaredInitMethod = true; |
||||
} |
||||
|
||||
public void postProcessAfterInit() { |
||||
if (!this.inited) { |
||||
throw new RuntimeException("Factory called postProcessAfterInit before afterPropertiesSet"); |
||||
} |
||||
if (this.initMethodDeclared && !this.initedViaDeclaredInitMethod) { |
||||
throw new RuntimeException("Factory called postProcessAfterInit before calling declared init method"); |
||||
} |
||||
if (this.postProcessedAfterInit) { |
||||
throw new RuntimeException("Factory called postProcessAfterInit twice"); |
||||
} |
||||
this.postProcessedAfterInit = true; |
||||
} |
||||
|
||||
/** |
||||
* Dummy business method that will fail unless the factory |
||||
* managed the bean's lifecycle correctly |
||||
*/ |
||||
public void businessMethod() { |
||||
if (!this.inited || (this.initMethodDeclared && !this.initedViaDeclaredInitMethod) || |
||||
!this.postProcessedAfterInit) { |
||||
throw new RuntimeException("Factory didn't initialize lifecycle object correctly"); |
||||
} |
||||
} |
||||
|
||||
public void destroy() { |
||||
if (this.destroyed) { |
||||
throw new IllegalStateException("Already destroyed"); |
||||
} |
||||
this.destroyed = true; |
||||
} |
||||
|
||||
public boolean isDestroyed() { |
||||
return destroyed; |
||||
} |
||||
|
||||
|
||||
public static class PostProcessor implements BeanPostProcessor { |
||||
|
||||
public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException { |
||||
if (bean instanceof LifecycleBean) { |
||||
((LifecycleBean) bean).postProcessBeforeInit(); |
||||
} |
||||
return bean; |
||||
} |
||||
|
||||
public Object postProcessAfterInitialization(Object bean, String name) throws BeansException { |
||||
if (bean instanceof LifecycleBean) { |
||||
((LifecycleBean) bean).postProcessAfterInit(); |
||||
} |
||||
return bean; |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
/* |
||||
* Copyright 2002-2005 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.beans.factory; |
||||
|
||||
import org.springframework.beans.factory.InitializingBean; |
||||
|
||||
/** |
||||
* Simple test of BeanFactory initialization |
||||
* @author Rod Johnson |
||||
* @since 12.03.2003 |
||||
*/ |
||||
public class MustBeInitialized implements InitializingBean { |
||||
|
||||
private boolean inited; |
||||
|
||||
/** |
||||
* @see InitializingBean#afterPropertiesSet() |
||||
*/ |
||||
public void afterPropertiesSet() throws Exception { |
||||
this.inited = true; |
||||
} |
||||
|
||||
/** |
||||
* Dummy business method that will fail unless the factory |
||||
* managed the bean's lifecycle correctly |
||||
*/ |
||||
public void businessMethod() { |
||||
if (!this.inited) |
||||
throw new RuntimeException("Factory didn't call afterPropertiesSet() on MustBeInitialized object"); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
/* |
||||
* Copyright 2002-2005 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.context; |
||||
|
||||
import java.util.Locale; |
||||
|
||||
import org.springframework.context.ApplicationContext; |
||||
import org.springframework.context.ApplicationContextAware; |
||||
import org.springframework.context.ApplicationContextException; |
||||
import org.springframework.context.NoSuchMessageException; |
||||
|
||||
public class ACATester implements ApplicationContextAware { |
||||
|
||||
private ApplicationContext ac; |
||||
|
||||
public void setApplicationContext(ApplicationContext ctx) throws ApplicationContextException { |
||||
// check reinitialization
|
||||
if (this.ac != null) { |
||||
throw new IllegalStateException("Already initialized"); |
||||
} |
||||
|
||||
// check message source availability
|
||||
if (ctx != null) { |
||||
try { |
||||
ctx.getMessage("code1", null, Locale.getDefault()); |
||||
} |
||||
catch (NoSuchMessageException ex) { |
||||
// expected
|
||||
} |
||||
} |
||||
|
||||
this.ac = ctx; |
||||
} |
||||
|
||||
public ApplicationContext getApplicationContext() { |
||||
return ac; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
/* |
||||
* Copyright 2002-2007 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.context; |
||||
|
||||
import org.springframework.context.ApplicationContext; |
||||
import org.springframework.context.ApplicationContextAware; |
||||
|
||||
/** |
||||
* @author Juergen Hoeller |
||||
*/ |
||||
public class BeanThatBroadcasts implements ApplicationContextAware { |
||||
|
||||
public ApplicationContext applicationContext; |
||||
|
||||
public int receivedCount; |
||||
|
||||
|
||||
public void setApplicationContext(ApplicationContext applicationContext) { |
||||
this.applicationContext = applicationContext; |
||||
if (applicationContext.getDisplayName().indexOf("listener") != -1) { |
||||
applicationContext.getBean("listener"); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,61 @@
@@ -0,0 +1,61 @@
|
||||
/* |
||||
* Copyright 2002-2007 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.context; |
||||
|
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* A stub {@link ApplicationListener}. |
||||
* |
||||
* @author Thomas Risberg |
||||
* @author Juergen Hoeller |
||||
*/ |
||||
public class BeanThatListens implements ApplicationListener { |
||||
|
||||
private BeanThatBroadcasts beanThatBroadcasts; |
||||
|
||||
private int eventCount; |
||||
|
||||
|
||||
public BeanThatListens() { |
||||
} |
||||
|
||||
public BeanThatListens(BeanThatBroadcasts beanThatBroadcasts) { |
||||
this.beanThatBroadcasts = beanThatBroadcasts; |
||||
Map beans = beanThatBroadcasts.applicationContext.getBeansOfType(BeanThatListens.class); |
||||
if (!beans.isEmpty()) { |
||||
throw new IllegalStateException("Shouldn't have found any BeanThatListens instances"); |
||||
} |
||||
} |
||||
|
||||
|
||||
public void onApplicationEvent(ApplicationEvent event) { |
||||
eventCount++; |
||||
if (beanThatBroadcasts != null) { |
||||
beanThatBroadcasts.receivedCount++; |
||||
} |
||||
} |
||||
|
||||
public int getEventCount() { |
||||
return eventCount; |
||||
} |
||||
|
||||
public void zero() { |
||||
eventCount = 0; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
package org.springframework.context; |
||||
|
||||
|
||||
import org.springframework.beans.BeansException; |
||||
import org.springframework.beans.factory.BeanFactory; |
||||
import org.springframework.beans.factory.LifecycleBean; |
||||
|
||||
/** |
||||
* Simple bean to test ApplicationContext lifecycle methods for beans |
||||
* |
||||
* @author Colin Sampaleanu |
||||
* @since 03.07.2004 |
||||
*/ |
||||
public class LifecycleContextBean extends LifecycleBean implements ApplicationContextAware { |
||||
|
||||
protected ApplicationContext owningContext; |
||||
|
||||
public void setBeanFactory(BeanFactory beanFactory) { |
||||
super.setBeanFactory(beanFactory); |
||||
if (this.owningContext != null) |
||||
throw new RuntimeException("Factory called setBeanFactory after setApplicationContext"); |
||||
} |
||||
|
||||
public void afterPropertiesSet() { |
||||
super.afterPropertiesSet(); |
||||
if (this.owningContext == null) |
||||
throw new RuntimeException("Factory didn't call setAppliationContext before afterPropertiesSet on lifecycle bean"); |
||||
} |
||||
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { |
||||
if (this.owningFactory == null) |
||||
throw new RuntimeException("Factory called setApplicationContext before setBeanFactory"); |
||||
|
||||
this.owningContext = applicationContext; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
package org.springframework.context; |
||||
|
||||
import org.springframework.context.ApplicationEvent; |
||||
import org.springframework.context.ApplicationListener; |
||||
|
||||
/** |
||||
* Listener that maintains a global count of events. |
||||
* |
||||
* @author Rod Johnson |
||||
* @since January 21, 2001 |
||||
*/ |
||||
public class TestListener implements ApplicationListener { |
||||
|
||||
private int eventCount; |
||||
|
||||
public int getEventCount() { |
||||
return eventCount; |
||||
} |
||||
|
||||
public void zeroCounter() { |
||||
eventCount = 0; |
||||
} |
||||
|
||||
public void onApplicationEvent(ApplicationEvent e) { |
||||
++eventCount; |
||||
} |
||||
|
||||
} |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue