Skip to content

Commit 4ac4630

Browse files
committed
Polishing
1 parent 29b40b9 commit 4ac4630

File tree

4 files changed

+59
-55
lines changed

4 files changed

+59
-55
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseBuilder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 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,7 @@
2424
* A builder that provides a convenient API for constructing an embedded database.
2525
*
2626
* <p>Usage example:
27-
* <pre>
27+
* <pre class="code">
2828
* EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
2929
* EmbeddedDatabase db = builder.setType(H2).addScript("schema.sql").addScript("data.sql").build();
3030
* db.shutdown();
@@ -44,6 +44,7 @@ public class EmbeddedDatabaseBuilder {
4444

4545
private final ResourceLoader resourceLoader;
4646

47+
4748
/**
4849
* Create a new embedded database builder.
4950
*/
@@ -62,6 +63,7 @@ public EmbeddedDatabaseBuilder(ResourceLoader resourceLoader) {
6263
this.resourceLoader = resourceLoader;
6364
}
6465

66+
6567
/**
6668
* Set the name of the embedded database.
6769
* <p>Defaults to "testdb" if not called.

spring-tx/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -32,7 +32,7 @@
3232
import org.springframework.util.Assert;
3333

3434
/**
35-
* Central helper that manages resources and transaction synchronizations per thread.
35+
* Central delegate that manages resources and transaction synchronizations per thread.
3636
* To be used by resource management code but not by typical application code.
3737
*
3838
* <p>Supports one resource per key without overwriting, that is, a resource needs
@@ -284,7 +284,7 @@ public static void initSynchronization() throws IllegalStateException {
284284
* @see org.springframework.core.Ordered
285285
*/
286286
public static void registerSynchronization(TransactionSynchronization synchronization)
287-
throws IllegalStateException {
287+
throws IllegalStateException {
288288

289289
Assert.notNull(synchronization, "TransactionSynchronization must not be null");
290290
if (!isSynchronizationActive()) {

spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -21,6 +21,7 @@
2121

2222
import org.apache.commons.logging.Log;
2323
import org.apache.commons.logging.LogFactory;
24+
2425
import org.springframework.beans.factory.BeanFactory;
2526
import org.springframework.core.BridgeMethodResolver;
2627
import org.springframework.core.MethodParameter;
@@ -29,15 +30,13 @@
2930
import org.springframework.util.ClassUtils;
3031

3132
/**
32-
* Encapsulates information about a bean method consisting of a
33-
* {@linkplain #getMethod() method} and a {@linkplain #getBean() bean}. Provides
34-
* convenient access to method parameters, the method return value, method
35-
* annotations.
33+
* Encapsulates information about a handler method consisting of a {@linkplain #getMethod() method}
34+
* and a {@linkplain #getBean() bean}. Provides convenient access to method parameters,
35+
* method return value, method annotations.
3636
*
37-
* <p>The class may be created with a bean instance or with a bean name (e.g. lazy
38-
* bean, prototype bean). Use {@link #createWithResolvedBean()} to obtain an
39-
* {@link HandlerMethod} instance with a bean instance initialized through the
40-
* bean factory.
37+
* <p>The class may be created with a bean instance or with a bean name (e.g. lazy-init bean,
38+
* prototype bean). Use {@link #createWithResolvedBean()} to obtain a {@link HandlerMethod}
39+
* instance with a bean instance resolved through the associated {@link BeanFactory}.
4140
*
4241
* @author Arjen Poutsma
4342
* @author Rossen Stoyanchev
@@ -50,48 +49,39 @@ public class HandlerMethod {
5049

5150
private final Object bean;
5251

53-
private final Method method;
54-
5552
private final BeanFactory beanFactory;
5653

57-
private final MethodParameter[] parameters;
54+
private final Method method;
5855

5956
private final Method bridgedMethod;
6057

58+
private final MethodParameter[] parameters;
59+
6160

6261
/**
6362
* Create an instance from a bean instance and a method.
6463
*/
6564
public HandlerMethod(Object bean, Method method) {
66-
Assert.notNull(bean, "bean is required");
67-
Assert.notNull(method, "method is required");
65+
Assert.notNull(bean, "Bean is required");
66+
Assert.notNull(method, "Method is required");
6867
this.bean = bean;
6968
this.beanFactory = null;
7069
this.method = method;
7170
this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
7271
this.parameters = initMethodParameters();
7372
}
7473

75-
private MethodParameter[] initMethodParameters() {
76-
int count = this.bridgedMethod.getParameterTypes().length;
77-
MethodParameter[] result = new MethodParameter[count];
78-
for (int i = 0; i < count; i++) {
79-
result[i] = new HandlerMethodParameter(i);
80-
}
81-
return result;
82-
}
83-
8474
/**
8575
* Create an instance from a bean instance, method name, and parameter types.
8676
* @throws NoSuchMethodException when the method cannot be found
8777
*/
8878
public HandlerMethod(Object bean, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException {
89-
Assert.notNull(bean, "bean is required");
90-
Assert.notNull(methodName, "method is required");
79+
Assert.notNull(bean, "Bean is required");
80+
Assert.notNull(methodName, "Method name is required");
9181
this.bean = bean;
9282
this.beanFactory = null;
9383
this.method = bean.getClass().getMethod(methodName, parameterTypes);
94-
this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
84+
this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(this.method);
9585
this.parameters = initMethodParameters();
9686
}
9787

@@ -101,11 +91,11 @@ public HandlerMethod(Object bean, String methodName, Class<?>... parameterTypes)
10191
* re-create the {@code HandlerMethod} with an initialized the bean.
10292
*/
10393
public HandlerMethod(String beanName, BeanFactory beanFactory, Method method) {
104-
Assert.hasText(beanName, "beanName is required");
105-
Assert.notNull(beanFactory, "beanFactory is required");
106-
Assert.notNull(method, "method is required");
94+
Assert.hasText(beanName, "Bean name is required");
95+
Assert.notNull(beanFactory, "BeanFactory is required");
96+
Assert.notNull(method, "Method is required");
10797
Assert.isTrue(beanFactory.containsBean(beanName),
108-
"Bean factory [" + beanFactory + "] does not contain bean [" + beanName + "]");
98+
"BeanFactory [" + beanFactory + "] does not contain bean [" + beanName + "]");
10999
this.bean = beanName;
110100
this.beanFactory = beanFactory;
111101
this.method = method;
@@ -129,15 +119,25 @@ protected HandlerMethod(HandlerMethod handlerMethod) {
129119
* Re-create HandlerMethod with the resolved handler.
130120
*/
131121
private HandlerMethod(HandlerMethod handlerMethod, Object handler) {
132-
Assert.notNull(handlerMethod, "handlerMethod is required");
133-
Assert.notNull(handler, "handler is required");
122+
Assert.notNull(handlerMethod, "HandlerMethod is required");
123+
Assert.notNull(handler, "Handler object is required");
134124
this.bean = handler;
135125
this.beanFactory = handlerMethod.beanFactory;
136126
this.method = handlerMethod.method;
137127
this.bridgedMethod = handlerMethod.bridgedMethod;
138128
this.parameters = handlerMethod.parameters;
139129
}
140130

131+
132+
private MethodParameter[] initMethodParameters() {
133+
int count = this.bridgedMethod.getParameterTypes().length;
134+
MethodParameter[] result = new MethodParameter[count];
135+
for (int i = 0; i < count; i++) {
136+
result[i] = new HandlerMethodParameter(i);
137+
}
138+
return result;
139+
}
140+
141141
/**
142142
* Returns the bean for this handler method.
143143
*/
@@ -157,9 +157,8 @@ public Method getMethod() {
157157
* Note that if the bean type is a CGLIB-generated class, the original, user-defined class is returned.
158158
*/
159159
public Class<?> getBeanType() {
160-
Class<?> clazz = (this.bean instanceof String)
161-
? this.beanFactory.getType((String) this.bean) : this.bean.getClass();
162-
160+
Class<?> clazz = (this.bean instanceof String ?
161+
this.beanFactory.getType((String) this.bean) : this.bean.getClass());
163162
return ClassUtils.getUserClass(clazz);
164163
}
165164

@@ -223,33 +222,34 @@ public HandlerMethod createWithResolvedBean() {
223222
}
224223

225224
@Override
226-
public boolean equals(Object o) {
227-
if (this == o) {
225+
public boolean equals(Object obj) {
226+
if (this == obj) {
228227
return true;
229228
}
230-
if (o != null && o instanceof HandlerMethod) {
231-
HandlerMethod other = (HandlerMethod) o;
232-
return this.bean.equals(other.bean) && this.method.equals(other.method);
229+
if (obj != null && obj instanceof HandlerMethod) {
230+
HandlerMethod other = (HandlerMethod) obj;
231+
return (this.bean.equals(other.bean) && this.method.equals(other.method));
233232
}
234233
return false;
235234
}
236235

237236
@Override
238237
public int hashCode() {
239-
return 31 * this.bean.hashCode() + this.method.hashCode();
238+
return this.bean.hashCode() * 31 + this.method.hashCode();
240239
}
241240

242241
@Override
243242
public String toString() {
244-
return method.toGenericString();
243+
return this.method.toGenericString();
245244
}
246245

246+
247247
/**
248248
* A MethodParameter with HandlerMethod-specific behavior.
249249
*/
250250
private class HandlerMethodParameter extends MethodParameter {
251251

252-
protected HandlerMethodParameter(int index) {
252+
public HandlerMethodParameter(int index) {
253253
super(HandlerMethod.this.bridgedMethod, index);
254254
}
255255

@@ -264,6 +264,7 @@ public <T extends Annotation> T getMethodAnnotation(Class<T> annotationType) {
264264
}
265265
}
266266

267+
267268
/**
268269
* A MethodParameter for a HandlerMethod return type based on an actual return value.
269270
*/
@@ -278,7 +279,7 @@ public ReturnValueMethodParameter(Object returnValue) {
278279

279280
@Override
280281
public Class<?> getParameterType() {
281-
return (this.returnValue != null) ? this.returnValue.getClass() : super.getParameterType();
282+
return (this.returnValue != null ? this.returnValue.getClass() : super.getParameterType());
282283
}
283284
}
284285

spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java

Lines changed: 7 additions & 6 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-2014 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.
@@ -74,6 +74,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
7474
/** Whether or not the view should add path variables in the model */
7575
private boolean exposePathVariables = true;
7676

77+
7778
/**
7879
* Set the view's name. Helpful for traceability.
7980
* <p>Framework code must call this when constructing views.
@@ -242,9 +243,10 @@ public void setExposePathVariables(boolean exposePathVariables) {
242243
* Returns the value of the flag indicating whether path variables should be added to the model or not.
243244
*/
244245
public boolean isExposePathVariables() {
245-
return exposePathVariables;
246+
return this.exposePathVariables;
246247
}
247248

249+
248250
/**
249251
* Prepares the view given the specified model, merging it with static
250252
* attributes and a RequestContext attribute, if necessary.
@@ -258,7 +260,6 @@ public void render(Map<String, ?> model, HttpServletRequest request, HttpServlet
258260
}
259261

260262
Map<String, Object> mergedModel = createMergedOutputModel(model, request, response);
261-
262263
prepareResponse(request, response);
263264
renderMergedOutputModel(mergedModel, request, response);
264265
}
@@ -268,11 +269,11 @@ public void render(Map<String, ?> model, HttpServletRequest request, HttpServlet
268269
* Dynamic values take precedence over static attributes.
269270
*/
270271
protected Map<String, Object> createMergedOutputModel(Map<String, ?> model, HttpServletRequest request,
271-
272272
HttpServletResponse response) {
273+
273274
@SuppressWarnings("unchecked")
274-
Map<String, Object> pathVars = this.exposePathVariables ?
275-
(Map<String, Object>) request.getAttribute(View.PATH_VARIABLES) : null;
275+
Map<String, Object> pathVars = (this.exposePathVariables ?
276+
(Map<String, Object>) request.getAttribute(View.PATH_VARIABLES) : null);
276277

277278
// Consolidate static and dynamic model attributes.
278279
int size = this.staticAttributes.size();

0 commit comments

Comments
 (0)