Skip to content

Commit 1239595

Browse files
committed
Polishing
1 parent 4428c34 commit 1239595

File tree

14 files changed

+159
-122
lines changed

14 files changed

+159
-122
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/config/PlaceholderConfigurerSupport.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,33 +30,33 @@
3030
*
3131
* <p>The default placeholder syntax follows the Ant / Log4J / JSP EL style:
3232
*
33-
*<pre class="code">${...}</pre>
33+
* <pre class="code">${...}</pre>
3434
*
3535
* Example XML bean definition:
3636
*
37-
*<pre class="code">{@code
38-
*<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"/>
39-
* <property name="driverClassName" value="}${driver}{@code "/>
40-
* <property name="url" value="jdbc:}${dbname}{@code "/>
41-
*</bean>
42-
*}</pre>
37+
* <pre class="code">
38+
* <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"/>
39+
* <property name="driverClassName" value="${driver}"/>
40+
* <property name="url" value="jdbc:${dbname}"/>
41+
* </bean>
42+
* </pre>
4343
*
4444
* Example properties file:
4545
*
46-
* <pre class="code"> driver=com.mysql.jdbc.Driver
46+
* <pre class="code">driver=com.mysql.jdbc.Driver
4747
* dbname=mysql:mydb</pre>
4848
*
4949
* Annotated bean definitions may take advantage of property replacement using
5050
* the {@link org.springframework.beans.factory.annotation.Value @Value} annotation:
5151
*
52-
*<pre class="code">@Value("${person.age}")</pre>
52+
* <pre class="code">@Value("${person.age}")</pre>
5353
*
5454
* Implementations check simple property values, lists, maps, props, and bean names
5555
* in bean references. Furthermore, placeholder values can also cross-reference
5656
* other placeholders, like:
5757
*
58-
*<pre class="code">rootPath=myrootdir
59-
*subPath=${rootPath}/subdir</pre>
58+
* <pre class="code">rootPath=myrootdir
59+
* subPath=${rootPath}/subdir</pre>
6060
*
6161
* In contrast to {@link PropertyOverrideConfigurer}, subclasses of this type allow
6262
* filling in of explicit placeholders in bean definitions.
@@ -75,9 +75,9 @@
7575
*
7676
* <p>Example XML property with default value:
7777
*
78-
*<pre class="code">{@code
79-
* <property name="url" value="jdbc:}${dbname:defaultdb}{@code "/>
80-
*}</pre>
78+
* <pre class="code">
79+
* <property name="url" value="jdbc:${dbname:defaultdb}"/>
80+
* </pre>
8181
*
8282
* @author Chris Beams
8383
* @author Juergen Hoeller
@@ -107,14 +107,14 @@ public abstract class PlaceholderConfigurerSupport extends PropertyResourceConfi
107107
/** Defaults to {@value #DEFAULT_VALUE_SEPARATOR} */
108108
protected String valueSeparator = DEFAULT_VALUE_SEPARATOR;
109109

110-
protected boolean ignoreUnresolvablePlaceholders = false;
111-
112110
protected String nullValue;
113111

114-
private BeanFactory beanFactory;
112+
protected boolean ignoreUnresolvablePlaceholders = false;
115113

116114
private String beanName;
117115

116+
private BeanFactory beanFactory;
117+
118118

119119
/**
120120
* Set the prefix that a placeholder string starts with.
@@ -143,13 +143,13 @@ public void setValueSeparator(String valueSeparator) {
143143
}
144144

145145
/**
146-
* Set a value that should be treated as {@code null} when
147-
* resolved as a placeholder value: e.g. "" (empty String) or "null".
146+
* Set a value that should be treated as {@code null} when resolved
147+
* as a placeholder value: e.g. "" (empty String) or "null".
148148
* <p>Note that this will only apply to full property values,
149149
* not to parts of concatenated values.
150150
* <p>By default, no such null value is defined. This means that
151-
* there is no way to express {@code null} as a property
152-
* value unless you explicitly map a corresponding value here.
151+
* there is no way to express {@code null} as a property value
152+
* unless you explicitly map a corresponding value here.
153153
*/
154154
public void setNullValue(String nullValue) {
155155
this.nullValue = nullValue;

spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCacheManager.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@
2424

2525
import org.springframework.cache.Cache;
2626
import org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager;
27-
import org.springframework.util.Assert;
2827

2928
/**
3029
* CacheManager backed by an EhCache {@link net.sf.ehcache.CacheManager}.
@@ -81,8 +80,10 @@ public void afterPropertiesSet() {
8180
@Override
8281
protected Collection<Cache> loadCaches() {
8382
Status status = getCacheManager().getStatus();
84-
Assert.isTrue(Status.STATUS_ALIVE.equals(status),
85-
"An 'alive' EhCache CacheManager is required - current cache is " + status.toString());
83+
if (!Status.STATUS_ALIVE.equals(status)) {
84+
throw new IllegalStateException(
85+
"An 'alive' EhCache CacheManager is required - current cache is " + status.toString());
86+
}
8687

8788
String[] names = getCacheManager().getCacheNames();
8889
Collection<Cache> caches = new LinkedHashSet<Cache>(names.length);
@@ -94,8 +95,7 @@ protected Collection<Cache> loadCaches() {
9495

9596
@Override
9697
protected Cache getMissingCache(String name) {
97-
// check the EhCache cache again
98-
// (in case the cache was added at runtime)
98+
// Check the EhCache cache again (in case the cache was added at runtime)
9999
Ehcache ehcache = getCacheManager().getEhcache(name);
100100
if (ehcache != null) {
101101
return new EhCacheCache(ehcache);

spring-context-support/src/test/java/org/springframework/cache/ehcache/EhCacheCacheManagerTests.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,9 +30,12 @@
3030
public class EhCacheCacheManagerTests extends AbstractTransactionSupportingCacheManagerTests<EhCacheCacheManager> {
3131

3232
private CacheManager nativeCacheManager;
33+
3334
private EhCacheCacheManager cacheManager;
35+
3436
private EhCacheCacheManager transactionalCacheManager;
3537

38+
3639
@Before
3740
public void setup() {
3841
nativeCacheManager = new CacheManager(new Configuration().name("EhCacheCacheManagerTests")
@@ -58,7 +61,8 @@ public void tearDown() {
5861
protected EhCacheCacheManager getCacheManager(boolean transactionAware) {
5962
if (transactionAware) {
6063
return transactionalCacheManager;
61-
} else {
64+
}
65+
else {
6266
return cacheManager;
6367
}
6468
}
@@ -77,4 +81,5 @@ protected void addNativeCache(String cacheName) {
7781
protected void removeNativeCache(String cacheName) {
7882
nativeCacheManager.removeCache(cacheName);
7983
}
84+
8085
}

spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheCacheManagerTests.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,9 +33,12 @@
3333
public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheManagerTests<JCacheCacheManager> {
3434

3535
private CacheManagerMock cacheManagerMock;
36+
3637
private JCacheCacheManager cacheManager;
38+
3739
private JCacheCacheManager transactionalCacheManager;
3840

41+
3942
@Before
4043
public void setupOnce() {
4144
cacheManagerMock = new CacheManagerMock();
@@ -55,7 +58,8 @@ public void setupOnce() {
5558
protected JCacheCacheManager getCacheManager(boolean transactionAware) {
5659
if (transactionAware) {
5760
return transactionalCacheManager;
58-
} else {
61+
}
62+
else {
5963
return cacheManager;
6064
}
6165
}
@@ -75,9 +79,11 @@ protected void removeNativeCache(String cacheName) {
7579
cacheManagerMock.removeCache(cacheName);
7680
}
7781

82+
7883
private static class CacheManagerMock {
7984

8085
private final List<String> cacheNames;
86+
8187
private final CacheManager cacheManager;
8288

8389
private CacheManagerMock() {
@@ -103,4 +109,5 @@ public void removeCache(String name) {
103109
given(cacheManager.getCache(name)).willReturn(null);
104110
}
105111
}
112+
106113
}

spring-context-support/src/test/java/org/springframework/cache/transaction/AbstractTransactionSupportingCacheManagerTests.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,11 +42,10 @@ public abstract class AbstractTransactionSupportingCacheManagerTests<T extends C
4242

4343
/**
4444
* Returns the {@link CacheManager} to use.
45-
*
4645
* @param transactionAware if the requested cache manager should be aware
4746
* of the transaction
4847
* @return the cache manager to use
49-
* @see org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager#setTransactionAware(boolean)
48+
* @see org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager#setTransactionAware
5049
*/
5150
protected abstract T getCacheManager(boolean transactionAware);
5251

@@ -65,6 +64,7 @@ public abstract class AbstractTransactionSupportingCacheManagerTests<T extends C
6564
*/
6665
protected abstract void removeNativeCache(String cacheName);
6766

67+
6868
@Test
6969
public void getOnExistingCache() {
7070
assertThat(getCacheManager(false).getCache(CACHE_NAME), is(instanceOf(getCacheType())));
@@ -77,10 +77,10 @@ public void getOnNewCache() {
7777
addNativeCache(cacheName);
7878
assertFalse(cacheManager.getCacheNames().contains(cacheName));
7979
try {
80-
assertThat(cacheManager.getCache(cacheName),
81-
is(instanceOf(getCacheType())));
80+
assertThat(cacheManager.getCache(cacheName), is(instanceOf(getCacheType())));
8281
assertTrue(cacheManager.getCacheNames().contains(cacheName));
83-
} finally {
82+
}
83+
finally {
8484
removeNativeCache(cacheName);
8585
}
8686
}
@@ -109,8 +109,10 @@ public void getTransactionalOnNewCache() {
109109
assertThat(cacheManager.getCache(cacheName),
110110
is(instanceOf(TransactionAwareCacheDecorator.class)));
111111
assertTrue(cacheManager.getCacheNames().contains(cacheName));
112-
} finally {
112+
}
113+
finally {
113114
removeNativeCache(cacheName);
114115
}
115116
}
117+
116118
}

spring-context/src/main/java/org/springframework/cache/support/AbstractCacheManager.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,7 +40,7 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing
4040

4141
private final ConcurrentMap<String, Cache> cacheMap = new ConcurrentHashMap<String, Cache>(16);
4242

43-
private Set<String> cacheNames = new LinkedHashSet<String>(16);
43+
private final Set<String> cacheNames = new LinkedHashSet<String>(16);
4444

4545

4646
// Early cache initialization on startup
@@ -96,6 +96,16 @@ protected final void addCache(Cache cache) {
9696
this.cacheNames.add(cache.getName());
9797
}
9898

99+
/**
100+
* Check for a registered cache of the given name.
101+
* In contrast to {@link #getCache(String)}, this method does not trigger
102+
* the lazy creation of missing caches via {@link #getMissingCache(String)}.
103+
* @param name the cache identifier (must not be {@code null})
104+
* @return the associated Cache instance, or {@code null} if none found
105+
* @since 4.1
106+
* @see #getCache(String)
107+
* @see #getMissingCache(String)
108+
*/
99109
protected final Cache lookupCache(String name) {
100110
return this.cacheMap.get(name);
101111
}
@@ -120,6 +130,7 @@ protected Cache decorateCache(Cache cache) {
120130
* @param name the name of the cache to retrieve
121131
* @return the missing cache or {@code null} if no such cache exists or could be
122132
* created
133+
* @since 4.1
123134
* @see #getCache(String)
124135
*/
125136
protected Cache getMissingCache(String name) {

spring-context/src/main/java/org/springframework/scripting/ScriptEvaluator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@ public interface ScriptEvaluator {
4444
* Evaluate the given script with the given arguments.
4545
* @param script the ScriptSource for the script to evaluate
4646
* @param arguments the key-value pairs to expose to the script,
47-
* typically as script variables. May be {@code null}.
47+
* typically as script variables (may be {@code null} or empty)
4848
* @return the return value of the script, if any
4949
* @throws ScriptCompilationException if the evaluator failed to read,
5050
* compile or evaluate the script

0 commit comments

Comments
 (0)