From a32894ca313c8ad3ed3dedd0a7c77e897b0fad31 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Wed, 22 Dec 2010 10:23:34 +0000 Subject: [PATCH] Removed JDK 1.6 usage git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3830 50f2f4bb-b051-0410-bef5-90022cba6387 --- .../core/env/AbstractEnvironment.java | 22 ++++++--------- .../core/env/DefaultEnvironmentTests.java | 28 ++++++------------- ...tractRefreshableWebApplicationContext.java | 8 +++--- .../support/GenericWebApplicationContext.java | 6 ++-- .../support/StaticWebApplicationContext.java | 9 +++--- 5 files changed, 29 insertions(+), 44 deletions(-) diff --git a/org.springframework.core/src/main/java/org/springframework/core/env/AbstractEnvironment.java b/org.springframework.core/src/main/java/org/springframework/core/env/AbstractEnvironment.java index 1acc25c8662..216f6d53ed3 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/env/AbstractEnvironment.java +++ b/org.springframework.core/src/main/java/org/springframework/core/env/AbstractEnvironment.java @@ -5,7 +5,7 @@ * 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 + * 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, @@ -16,17 +16,9 @@ package org.springframework.core.env; -import static java.lang.String.format; -import static org.springframework.util.StringUtils.commaDelimitedListToSet; -import static org.springframework.util.StringUtils.trimAllWhitespace; -import static org.springframework.util.SystemPropertyUtils.PLACEHOLDER_PREFIX; -import static org.springframework.util.SystemPropertyUtils.PLACEHOLDER_SUFFIX; -import static org.springframework.util.SystemPropertyUtils.VALUE_SEPARATOR; - import java.security.AccessControlException; import java.util.Arrays; import java.util.Collections; -import java.util.Iterator; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.Map; @@ -36,12 +28,17 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.support.ConversionServiceFactory; import org.springframework.util.PropertyPlaceholderHelper; import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver; import org.springframework.util.StringUtils; +import static java.lang.String.*; +import static org.springframework.util.StringUtils.*; +import static org.springframework.util.SystemPropertyUtils.*; + /** * TODO SPR-7508: document @@ -78,7 +75,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { } public void addPropertySource(PropertySource propertySource) { - propertySources.push(propertySource); + propertySources.addFirst(propertySource); } public void addPropertySource(String name, Properties properties) { @@ -169,9 +166,8 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { public Properties asProperties() { // TODO SPR-7508: refactor, simplify. only handles map-based propertysources right now. Properties mergedProps = new Properties(); - Iterator> descendingIterator = getPropertySources().descendingIterator(); - while (descendingIterator.hasNext()) { - PropertySource propertySource = descendingIterator.next(); + for (int i = propertySources.size() -1; i >= 0; i--) { + PropertySource propertySource = propertySources.get(i); Object object = propertySource.getSource(); if (object instanceof Map) { for (Entry entry : ((Map)object).entrySet()) { diff --git a/org.springframework.core/src/test/java/org/springframework/core/env/DefaultEnvironmentTests.java b/org.springframework.core/src/test/java/org/springframework/core/env/DefaultEnvironmentTests.java index 0d233a15c8c..0ba3be26ec1 100644 --- a/org.springframework.core/src/test/java/org/springframework/core/env/DefaultEnvironmentTests.java +++ b/org.springframework.core/src/test/java/org/springframework/core/env/DefaultEnvironmentTests.java @@ -5,7 +5,7 @@ * 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 + * 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, @@ -16,23 +16,6 @@ package org.springframework.core.env; -import static java.lang.String.format; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.junit.matchers.JUnitMatchers.hasItem; -import static org.junit.matchers.JUnitMatchers.hasItems; -import static org.springframework.core.env.AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME; -import static org.springframework.core.env.AbstractEnvironment.DEFAULT_PROFILES_PROPERTY_NAME; -import static org.springframework.core.env.DefaultEnvironmentTests.CollectionMatchers.isEmpty; - import java.lang.reflect.Field; import java.security.AccessControlException; import java.security.Permission; @@ -50,6 +33,13 @@ import org.junit.Before; import org.junit.Test; import org.junit.internal.matchers.TypeSafeMatcher; +import static java.lang.String.format; +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; +import static org.junit.matchers.JUnitMatchers.*; +import static org.springframework.core.env.AbstractEnvironment.*; +import static org.springframework.core.env.DefaultEnvironmentTests.CollectionMatchers.*; + /** * Unit tests for {@link DefaultEnvironment}. * @@ -89,7 +79,7 @@ public class DefaultEnvironmentTests { // put 'system' at the front of the list LinkedList> propertySources = env.getPropertySources(); - propertySources.push(propertySources.remove(propertySources.indexOf(PropertySource.named("system")))); + propertySources.addFirst(propertySources.remove(propertySources.indexOf(PropertySource.named("system")))); // 'system' now has precedence assertThat(env.getProperty("foo"), equalTo("systemValue")); diff --git a/org.springframework.web/src/main/java/org/springframework/web/context/support/AbstractRefreshableWebApplicationContext.java b/org.springframework.web/src/main/java/org/springframework/web/context/support/AbstractRefreshableWebApplicationContext.java index 8cf8d01646e..9ba322b59c6 100644 --- a/org.springframework.web/src/main/java/org/springframework/web/context/support/AbstractRefreshableWebApplicationContext.java +++ b/org.springframework.web/src/main/java/org/springframework/web/context/support/AbstractRefreshableWebApplicationContext.java @@ -1,11 +1,11 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 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 + * 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, @@ -100,7 +100,7 @@ public abstract class AbstractRefreshableWebApplicationContext extends AbstractR public void setServletContext(ServletContext servletContext) { this.servletContext = servletContext; // TODO: SPR-7508 extract createEnvironment() method; do also in GWAC - this.getEnvironment().getPropertySources().push(new ServletContextPropertySource(this.servletContext)); + this.getEnvironment().getPropertySources().addFirst(new ServletContextPropertySource(this.servletContext)); } public ServletContext getServletContext() { @@ -113,7 +113,7 @@ public abstract class AbstractRefreshableWebApplicationContext extends AbstractR this.setServletContext(servletConfig.getServletContext()); } // TODO: SPR-7508 extract createEnvironment() method; do also in GWAC - this.getEnvironment().getPropertySources().push(new ServletConfigPropertySource(servletConfig)); + this.getEnvironment().getPropertySources().addFirst(new ServletConfigPropertySource(servletConfig)); } public ServletConfig getServletConfig() { diff --git a/org.springframework.web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java b/org.springframework.web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java index daf5b5805a0..4b301cd7666 100644 --- a/org.springframework.web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java +++ b/org.springframework.web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java @@ -1,11 +1,11 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 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 + * 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, @@ -160,7 +160,7 @@ public class GenericWebApplicationContext extends GenericApplicationContext @Override protected void onRefresh() { this.themeSource = UiApplicationContextUtils.initThemeSource(this); - this.getEnvironment().getPropertySources().push(new ServletContextPropertySource(servletContext)); + this.getEnvironment().getPropertySources().addFirst(new ServletContextPropertySource(servletContext)); } public Theme getTheme(String themeName) { diff --git a/org.springframework.web/src/main/java/org/springframework/web/context/support/StaticWebApplicationContext.java b/org.springframework.web/src/main/java/org/springframework/web/context/support/StaticWebApplicationContext.java index 60ff3d6655a..e3950645351 100644 --- a/org.springframework.web/src/main/java/org/springframework/web/context/support/StaticWebApplicationContext.java +++ b/org.springframework.web/src/main/java/org/springframework/web/context/support/StaticWebApplicationContext.java @@ -1,11 +1,11 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 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 + * 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, @@ -17,7 +17,6 @@ package org.springframework.web.context.support; import java.util.LinkedList; - import javax.servlet.ServletConfig; import javax.servlet.ServletContext; @@ -170,8 +169,8 @@ public class StaticWebApplicationContext extends StaticApplicationContext protected void onRefresh() { this.themeSource = UiApplicationContextUtils.initThemeSource(this); LinkedList> propertySources = this.getEnvironment().getPropertySources(); - propertySources.push(new ServletContextPropertySource(servletContext)); - propertySources.push(new ServletConfigPropertySource(servletConfig)); + propertySources.addFirst(new ServletContextPropertySource(servletContext)); + propertySources.addFirst(new ServletConfigPropertySource(servletConfig)); } public Theme getTheme(String themeName) {