-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use SimpleEvaluationContext in AbstractMvcView
Issue: SWF-1722
- Loading branch information
1 parent
13d36e5
commit 962cb67
Showing
8 changed files
with
297 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...g/src/main/java/org/springframework/binding/expression/spel/EvaluationContextFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2002-2018 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.binding.expression.spel; | ||
|
||
import org.springframework.expression.EvaluationContext; | ||
|
||
/** | ||
* Factory to create the {@link EvaluationContext} for a given root Object. | ||
* | ||
* @author Rossen Stoyanchev | ||
* @since 2.4.8 | ||
*/ | ||
public interface EvaluationContextFactory { | ||
|
||
/** | ||
* Create an {@link EvaluationContext} for the given root object. | ||
* @param rootObject the root object | ||
* @return the created context instance | ||
*/ | ||
EvaluationContext createContext(Object rootObject); | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
...main/java/org/springframework/binding/expression/spel/SimpleEvaluationContextFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2002-2018 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.binding.expression.spel; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.binding.convert.ConversionService; | ||
import org.springframework.expression.EvaluationContext; | ||
import org.springframework.expression.PropertyAccessor; | ||
import org.springframework.expression.spel.support.DataBindingPropertyAccessor; | ||
import org.springframework.expression.spel.support.SimpleEvaluationContext; | ||
|
||
/** | ||
* Creates {@link SimpleEvaluationContext}, for use with data binding. | ||
* | ||
* @author Rossen Stoyanchev | ||
* @since 2.4.8 | ||
*/ | ||
public class SimpleEvaluationContextFactory implements EvaluationContextFactory { | ||
|
||
private static final PropertyAccessor dataBindingPropertyAccessor = | ||
DataBindingPropertyAccessor.forReadWriteAccess(); | ||
|
||
|
||
private final List<PropertyAccessor> propertyAccessors; | ||
|
||
private final ConversionService conversionService; | ||
|
||
|
||
public SimpleEvaluationContextFactory(List<PropertyAccessor> propertyAccessors, | ||
ConversionService conversionService) { | ||
|
||
this.propertyAccessors = propertyAccessors; | ||
this.conversionService = conversionService; | ||
} | ||
|
||
|
||
@Override | ||
public EvaluationContext createContext(Object rootObject) { | ||
return SimpleEvaluationContext | ||
.forPropertyAccessors(getAccessorsArray()) | ||
.withConversionService(conversionService.getDelegateConversionService()) | ||
.withRootObject(rootObject) | ||
.build(); | ||
} | ||
|
||
private PropertyAccessor[] getAccessorsArray() { | ||
int length = propertyAccessors.size() + 1; | ||
PropertyAccessor[] result = propertyAccessors.toArray(new PropertyAccessor[length]); | ||
result[length - 1] = dataBindingPropertyAccessor; | ||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.