102 |
103 |
104 |
--------------------------------------------------------------------------------
/build/test-results/test/TEST-org.springframework.core.ConstantsTests.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/build/test-results/test/binary/output.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learn_spring_1.0_toJava8/1e9432eebbdd09a3ec11cc313c2b19c8227403c8/build/test-results/test/binary/output.bin
--------------------------------------------------------------------------------
/build/test-results/test/binary/output.bin.idx:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/build/test-results/test/binary/results.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learn_spring_1.0_toJava8/1e9432eebbdd09a3ec11cc313c2b19c8227403c8/build/test-results/test/binary/results.bin
--------------------------------------------------------------------------------
/docs/image/overview.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learn_spring_1.0_toJava8/1e9432eebbdd09a3ec11cc313c2b19c8227403c8/docs/image/overview.gif
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learn_spring_1.0_toJava8/1e9432eebbdd09a3ec11cc313c2b19c8227403c8/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS='"-Xmx64m"'
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS="-Xmx64m"
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'springframework'
2 |
3 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/BeanUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans;
18 |
19 | import java.beans.PropertyDescriptor;
20 | import java.lang.reflect.Constructor;
21 | import java.lang.reflect.InvocationTargetException;
22 | import java.util.Arrays;
23 | import java.util.List;
24 |
25 | /**
26 | * Static convenience methods for JavaBeans, for instantiating beans,
27 | * copying bean properties, etc.
28 | *
29 | * 자바빈즈, 빈 인스턴스화, 빈 속성들을 복사하기 위한 정적 편리 메소드들.
30 | *
31 | *
Mainly for use within the framework, but to some degree also
32 | * useful for application classes.
33 | *
34 | * 주로 어플리케이션내에서 사용되지만, 어플리케이션 클래스들에서도 어느정도는 유용하기도합니다.
35 | *
36 | * @author Rod Johnson
37 | * @author Juergen Hoeller
38 | * @version $Id: BeanUtils.java,v 1.15 2004/03/18 02:46:12 trisberg Exp $
39 | */
40 | public abstract class BeanUtils {
41 |
42 | /**
43 | * Convenience method to instantiate a class using its no-arg constructor.
44 | * As this method doesn't try to load classes by name, it should avoid class-loading issues.
45 | * @param clazz class to instantiate
46 | * @return the new instance
47 | */
48 | public static Object instantiateClass(Class clazz) throws BeansException {
49 | try {
50 | return clazz.newInstance();
51 | }
52 | catch (InstantiationException ex) {
53 | throw new FatalBeanException("Could not instantiate class [" + clazz.getName() +
54 | "]; Is it an interface or an abstract class? Does it have a no-arg constructor?", ex);
55 | }
56 | catch (IllegalAccessException ex) {
57 | throw new FatalBeanException("Could not instantiate class [" + clazz.getName() +
58 | "]; has class definition changed? Is there a public no-arg constructor?", ex);
59 | }
60 | }
61 |
62 | /**
63 | * Convenience method to instantiate a class using the given constructor.
64 | * As this method doesn't try to load classes by name, it should avoid class-loading issues.
65 | * @param constructor constructor to instantiate
66 | * @return the new instance
67 | */
68 | public static Object instantiateClass(Constructor constructor, Object[] arguments) throws BeansException {
69 | try {
70 | return constructor.newInstance(arguments);
71 | }
72 | catch (IllegalArgumentException ex) {
73 | throw new FatalBeanException("Illegal arguments when trying to instantiate constructor: " + constructor, ex);
74 | }
75 | catch (InstantiationException ex) {
76 | throw new FatalBeanException("Could not instantiate class [" + constructor.getDeclaringClass().getName() +
77 | "]; is it an interface or an abstract class?", ex);
78 | }
79 | catch (IllegalAccessException ex) {
80 | throw new FatalBeanException("Could not instantiate class [" + constructor.getDeclaringClass().getName() +
81 | "]; has class definition changed? Is there a public constructor?", ex);
82 | }
83 | catch (InvocationTargetException ex) {
84 | throw new FatalBeanException("Could not instantiate class [" + constructor.getDeclaringClass().getName() +
85 | "]; constructor threw exception", ex.getTargetException());
86 | }
87 | }
88 |
89 | /**
90 | * Determine if the given type is assignable from the given value,
91 | * assuming setting by reflection. Considers primitive wrapper classes
92 | * as assignable to the corresponding primitive types.
93 | *
For example used in a bean factory's constructor resolution.
94 | * @param type the target type
95 | * @param value the value that should be assigned to the type
96 | * @return if the type is assignable from the value
97 | */
98 | public static boolean isAssignable(Class type, Object value) {
99 | return (type.isInstance(value) ||
100 | (!type.isPrimitive() && value == null) ||
101 | (type.equals(boolean.class) && value instanceof Boolean) ||
102 | (type.equals(byte.class) && value instanceof Byte) ||
103 | (type.equals(char.class) && value instanceof Character) ||
104 | (type.equals(short.class) && value instanceof Short) ||
105 | (type.equals(int.class) && value instanceof Integer) ||
106 | (type.equals(long.class) && value instanceof Long) ||
107 | (type.equals(float.class) && value instanceof Float) ||
108 | (type.equals(double.class) && value instanceof Double));
109 | }
110 |
111 | /**
112 | * Check if the given class represents a "simple" property,
113 | * i.e. a primitive, a String, a Class, or a corresponding array.
114 | * Used to determine properties to check for a "simple" dependency-check.
115 | * @see org.springframework.beans.factory.support.RootBeanDefinition#DEPENDENCY_CHECK_SIMPLE
116 | * @see org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#dependencyCheck
117 | */
118 | public static boolean isSimpleProperty(Class clazz) {
119 | return clazz.isPrimitive() || isPrimitiveArray(clazz) || isPrimitiveWrapperArray(clazz) ||
120 | clazz.equals(String.class) || clazz.equals(String[].class) ||
121 | clazz.equals(Class.class) || clazz.equals(Class[].class);
122 | }
123 |
124 | /**
125 | * Check if the given class represents a primitive array,
126 | * i.e. boolean, byte, char, short, int, long, float, or double.
127 | */
128 | public static boolean isPrimitiveArray(Class clazz) {
129 | return boolean[].class.equals(clazz) || byte[].class.equals(clazz) || char[].class.equals(clazz) ||
130 | short[].class.equals(clazz) || int[].class.equals(clazz) || long[].class.equals(clazz) ||
131 | float[].class.equals(clazz) || double[].class.equals(clazz);
132 | }
133 |
134 | /**
135 | * Check if the given class represents an array of primitive wrappers,
136 | * i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double.
137 | */
138 | public static boolean isPrimitiveWrapperArray(Class clazz) {
139 | return Boolean[].class.equals(clazz) || Byte[].class.equals(clazz) || Character[].class.equals(clazz) ||
140 | Short[].class.equals(clazz) || Integer[].class.equals(clazz) || Long[].class.equals(clazz) ||
141 | Float[].class.equals(clazz) || Double[].class.equals(clazz);
142 | }
143 |
144 | /**
145 | * Copy the property values of the given source bean into the target bean.
146 | * @param source source bean
147 | * @param target target bean
148 | * @throws IllegalArgumentException if the classes of source and target do not match
149 | */
150 | public static void copyProperties(Object source, Object target)
151 | throws IllegalArgumentException, BeansException {
152 | copyProperties(source, target, null);
153 | }
154 |
155 | /**
156 | * Copy the property values of the given source bean into the given target bean,
157 | * ignoring the given ignoreProperties.
158 | * @param source source bean
159 | * @param target target bean
160 | * @param ignoreProperties array of property names to ignore
161 | * @throws IllegalArgumentException if the classes of source and target do not match
162 | */
163 | public static void copyProperties(Object source, Object target, String[] ignoreProperties)
164 | throws IllegalArgumentException, BeansException {
165 | if (source == null || target == null || !source.getClass().isInstance(target)) {
166 | throw new IllegalArgumentException("Target must an instance of source");
167 | }
168 | List ignoreList = (ignoreProperties != null) ? Arrays.asList(ignoreProperties) : null;
169 | BeanWrapper sourceBw = new BeanWrapperImpl(source);
170 | BeanWrapper targetBw = new BeanWrapperImpl(target);
171 | MutablePropertyValues values = new MutablePropertyValues();
172 | for (int i = 0; i < sourceBw.getPropertyDescriptors().length; i++) {
173 | PropertyDescriptor sourceDesc = sourceBw.getPropertyDescriptors()[i];
174 | String name = sourceDesc.getName();
175 | PropertyDescriptor targetDesc = targetBw.getPropertyDescriptor(name);
176 | if (targetDesc.getWriteMethod() != null && targetDesc.getReadMethod() != null &&
177 | (ignoreProperties == null || (!ignoreList.contains(name)))) {
178 | values.addPropertyValue(new PropertyValue(name, sourceBw.getPropertyValue(name)));
179 | }
180 | }
181 | targetBw.setPropertyValues(values);
182 | }
183 |
184 | }
185 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/BeanWrapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans;
18 |
19 | import java.beans.PropertyDescriptor;
20 | import java.beans.PropertyEditor;
21 | import java.util.Map;
22 |
23 | /**
24 | * The central interface of Spring's low-level JavaBeans infrastructure.
25 | * Typically not directly used by application code but rather implicitly
26 | * via a BeanFactory or a DataBinder.
27 | *
28 | * 스프링 로우레벨 자바빈즈 인프라스트럭쳐의 핵심 인터페이스입니다.
29 | * 일반적으로 어플리케이션 코드에서 직접적으로 사용되지 않으며,
30 | * 암시적으로 BeanFactory 나 DataBinder 에서 사용됩니다.
31 | *
32 | *
To be implemented by classes that can manipulate Java beans.
33 | * Implementing classes have the ability to get and set property values
34 | * (individually or in bulk), get property descriptors and query the
35 | * readability and writability of properties.
36 | *
37 | * 클래스에 의해 구현됨으로써 자바빈즈를 생성할 수 있습니다.
38 | * 클래스를 구현하여 프로퍼티값을 겟,셋할 수 있고, 프로퍼티 설명자를 얻을 수 있으며,
39 | * 속성이 읽고 쓰기가 가능한지 질의할 수 있습니다.
40 | *
41 | *
This interface supports nested properties enabling the setting
42 | * of properties on subproperties to an unlimited depth.
43 | *
44 | * 이 인터페이스는 속성의 하위 속성을 설정함으로써 무한대의 깊이를 가질 수 있게하는
45 | * 중첩된 속성(nested properties)를 지원합니다.
46 | *
47 | *
If a property update causes an exception, a PropertyVetoException will be
48 | * thrown. Bulk updates continue after exceptions are encountered, throwing an
49 | * exception wrapping all exceptions encountered during the update.
50 | *
51 | * 프로퍼티 업데이트가 예외를 발생시키면 PropertyVetoException 이 던져지게 됩니다.
52 | * Bulk 업데이트는 예외가 던져진 이후에 업데이트 도중에 만난 모든 예외를 wrapping 한 예외를 던지게 됩니다.
53 | *
54 | *
BeanWrapper implementations can be used repeatedly, with their "target"
55 | * or wrapped object changed.
56 | *
57 | * @author Rod Johnson
58 | * @since 13 April 2001
59 | * @version $Id: BeanWrapper.java,v 1.12 2004/03/19 07:40:12 jhoeller Exp $
60 | * @see org.springframework.beans.factory.BeanFactory
61 | * @see org.springframework.validation.DataBinder
62 | */
63 | public interface BeanWrapper {
64 |
65 | /**
66 | * Path separator for nested properties.
67 | * Follows normal Java conventions: getFoo().getBar() would be "foo.bar".
68 | */
69 | String NESTED_PROPERTY_SEPARATOR = ".";
70 |
71 |
72 | /**
73 | * Change the wrapped object. Implementations are required
74 | * to allow the type of the wrapped object to change.
75 | * @param obj wrapped object that we are manipulating
76 | */
77 | void setWrappedInstance(Object obj) throws BeansException;
78 |
79 | /**
80 | * Return the bean wrapped by this object (cannot be null).
81 | * @return the bean wrapped by this object
82 | */
83 | Object getWrappedInstance();
84 |
85 | /**
86 | * Convenience method to return the class of the wrapped object.
87 | * @return the class of the wrapped object
88 | */
89 | Class getWrappedClass();
90 |
91 | /**
92 | * Register the given custom property editor for all properties of the
93 | * given type.
94 | * @param requiredType type of the property
95 | * @param propertyEditor editor to register
96 | */
97 | void registerCustomEditor(Class requiredType, PropertyEditor propertyEditor);
98 |
99 | /**
100 | * Register the given custom property editor for the given type and
101 | * property, or for all properties of the given type.
102 | * @param requiredType type of the property, can be null if a property is
103 | * given but should be specified in any case for consistency checking
104 | * @param propertyPath path of the property (name or nested path), or
105 | * null if registering an editor for all properties of the given type
106 | * @param propertyEditor editor to register
107 | */
108 | void registerCustomEditor(Class requiredType, String propertyPath, PropertyEditor propertyEditor);
109 |
110 | /**
111 | * Find a custom property editor for the given type and property.
112 | * @param requiredType type of the property, can be null if a property is
113 | * given but should be specified in any case for consistency checking
114 | * @param propertyPath path of the property (name or nested path), or
115 | * null if looking for an editor for all properties of the given type
116 | * @return the registered editor, or null if none
117 | */
118 | PropertyEditor findCustomEditor(Class requiredType, String propertyPath);
119 |
120 |
121 | /**
122 | * Get the value of a property.
123 | * @param propertyName name of the property to get the value of
124 | * @return the value of the property.
125 | * @throws FatalBeanException if there is no such property, if the property
126 | * isn't readable, or if the property getter throws an exception.
127 | */
128 | Object getPropertyValue(String propertyName) throws BeansException;
129 |
130 | /**
131 | * Set a property value. This method is provided for convenience only.
132 | * The setPropertyValue(PropertyValue) method is more powerful.
133 | * @param propertyName name of the property to set value of
134 | * @param value the new value
135 | */
136 | void setPropertyValue(String propertyName, Object value) throws BeansException;
137 |
138 | /**
139 | * Update a property value.
140 | * This is the preferred way to update an individual property.
141 | * @param pv object containing new property value
142 | */
143 | void setPropertyValue(PropertyValue pv) throws BeansException;
144 |
145 | /**
146 | * Perform a bulk update from a Map.
147 | *
Bulk updates from PropertyValues are more powerful: This method is
148 | * provided for convenience. Behaviour will be identical to that of
149 | * the setPropertyValues(PropertyValues) method.
150 | * @param map Map to take properties from. Contains property value objects,
151 | * keyed by property name
152 | */
153 | void setPropertyValues(Map map) throws BeansException;
154 |
155 | /**
156 | * The preferred way to perform a bulk update.
157 | *
Note that performing a bulk update differs from performing a single update,
158 | * in that an implementation of this class will continue to update properties
159 | * if a recoverable error (such as a vetoed property change or a type mismatch,
160 | * but not an invalid fieldname or the like) is encountered, throwing a
161 | * PropertyAccessExceptionsException containing all the individual errors.
162 | * This exception can be examined later to see all binding errors.
163 | * Properties that were successfully updated stay changed.
164 | *
Does not allow unknown fields.
165 | * Equivalent to setPropertyValues(pvs, false, null).
166 | * @param pvs PropertyValues to set on the target object
167 | */
168 | void setPropertyValues(PropertyValues pvs) throws BeansException;
169 |
170 | /**
171 | * Perform a bulk update with full control over behavior.
172 | * Note that performing a bulk update differs from performing a single update,
173 | * in that an implementation of this class will continue to update properties
174 | * if a recoverable error (such as a vetoed property change or a type mismatch,
175 | * but not an invalid fieldname or the like) is encountered, throwing a
176 | * PropertyAccessExceptionsException containing all the individual errors.
177 | * This exception can be examined later to see all binding errors.
178 | * Properties that were successfully updated stay changed.
179 | *
Does not allow unknown fields.
180 | * @param pvs PropertyValues to set on the target object
181 | * @param ignoreUnknown should we ignore unknown values (not found in the bean!?)
182 | */
183 | void setPropertyValues(PropertyValues pvs, boolean ignoreUnknown)
184 | throws BeansException;
185 |
186 |
187 | /**
188 | * Get the PropertyDescriptors identified on this object
189 | * (standard JavaBeans introspection).
190 | * @return the PropertyDescriptors identified on this object
191 | */
192 | PropertyDescriptor[] getPropertyDescriptors() throws BeansException;
193 |
194 | /**
195 | * Get the property descriptor for a particular property.
196 | * @param propertyName property to check status for
197 | * @return the property descriptor for a particular property
198 | * @throws FatalBeanException if there is no such property
199 | */
200 | PropertyDescriptor getPropertyDescriptor(String propertyName) throws BeansException;
201 |
202 | /**
203 | * Return whether this property is readable.
204 | * Returns false if the property doesn't exist.
205 | * @param propertyName property to check status for
206 | * @return whether this property is readable
207 | */
208 | boolean isReadableProperty(String propertyName);
209 |
210 | /**
211 | * Return whether this property is writable.
212 | * Returns false if the property doesn't exist.
213 | * @param propertyName property to check status for
214 | * @return whether this property is writable
215 | */
216 | boolean isWritableProperty(String propertyName);
217 |
218 | }
219 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/BeansException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans;
18 |
19 | import org.springframework.core.NestedRuntimeException;
20 |
21 | /**
22 | * Abstract superclass for all exceptions thrown in the beans package
23 | * and subpackages.
24 | *
25 | * 빈, 서브패키지에서의 던져지는 모든 예외들에 대한 추상클래스
26 | *
27 | *
28 | *
29 | *
Note that this is a runtime (unchecked) exception. Beans exceptions
30 | * are usually fatal; there is no reason for them to be checked.
31 | *
32 | * @author Rod Johnson
33 | */
34 | public abstract class BeansException extends NestedRuntimeException {
35 |
36 | /**
37 | * Constructs a BeansException with the specified message.
38 | * @param msg the detail message
39 | */
40 | public BeansException(String msg) {
41 | super(msg);
42 | }
43 |
44 | /**
45 | * Constructs a BeansException with the specified message
46 | * and root cause.
47 | * @param msg the detail message
48 | * @param ex the root cause
49 | */
50 | public BeansException(String msg, Throwable ex) {
51 | super(msg, ex);
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/CachedIntrospectionResults.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans;
18 |
19 | import org.apache.commons.logging.Log;
20 | import org.apache.commons.logging.LogFactory;
21 |
22 | import java.beans.BeanInfo;
23 | import java.beans.IntrospectionException;
24 | import java.beans.Introspector;
25 | import java.beans.PropertyDescriptor;
26 | import java.util.HashMap;
27 | import java.util.Map;
28 |
29 | /**
30 | * Class to cache PropertyDescriptor information for a Java class.
31 | * Package-visible; not for use by application code.
32 | *
33 | * 자바클래스를 위한 PropertyDescriptor 정보를 캐시하기 위한 클래스입니다.
34 | *
35 | *
Necessary as Introspector.getBeanInfo() in JDK 1.3 will return a new
36 | * deep copy of the BeanInfo every time we ask for it. We take the opportunity
37 | * to hash property descriptors by method name for fast lookup.
38 | *
39 | *
Information is cached statically, so we don't need to create new
40 | * objects of this class for every JavaBean we manipulate. Thus this class
41 | * implements the factory design pattern, using a private constructor
42 | * and a public static forClass() method to obtain instances.
43 | *
44 | * @author Rod Johnson
45 | * @since 05 May 2001
46 | * @version $Id: CachedIntrospectionResults.java,v 1.8 2004/03/19 07:40:13 jhoeller Exp $
47 | */
48 | final class CachedIntrospectionResults {
49 |
50 | private static final Log logger = LogFactory.getLog(CachedIntrospectionResults.class);
51 |
52 | /** Map keyed by class containing CachedIntrospectionResults */
53 | private static HashMap classCache = new HashMap();
54 |
55 | /**
56 | * We might use this from the EJB tier, so we don't want to use synchronization.
57 | * Object references are atomic, so we can live with doing the occasional
58 | * unnecessary lookup at startup only.
59 | */
60 | protected static CachedIntrospectionResults forClass(Class clazz) throws BeansException {
61 | Object results = classCache.get(clazz);
62 | if (results == null) {
63 | // can throw BeansException
64 | results = new CachedIntrospectionResults(clazz);
65 | classCache.put(clazz, results);
66 | }
67 | else {
68 | if (logger.isDebugEnabled()) {
69 | logger.debug("Using cached introspection results for class " + clazz.getName());
70 | }
71 | }
72 | return (CachedIntrospectionResults) results;
73 | }
74 |
75 |
76 | private BeanInfo beanInfo;
77 |
78 | /** Property descriptors keyed by property name */
79 | private Map propertyDescriptorMap;
80 |
81 | /**
82 | * Create new CachedIntrospectionResults instance fot the given class.
83 | */
84 | private CachedIntrospectionResults(Class clazz) throws FatalBeanException {
85 | try {
86 | logger.debug("Getting BeanInfo for class [" + clazz.getName() + "]");
87 | this.beanInfo = Introspector.getBeanInfo(clazz);
88 |
89 | logger.debug("Caching PropertyDescriptors for class [" + clazz.getName() + "]");
90 | this.propertyDescriptorMap = new HashMap();
91 | // This call is slow so we do it once
92 | PropertyDescriptor[] pds = this.beanInfo.getPropertyDescriptors();
93 | for (int i = 0; i < pds.length; i++) {
94 | logger.debug("Found property '" + pds[i].getName() + "' of type [" + pds[i].getPropertyType() +
95 | "]; editor=[" + pds[i].getPropertyEditorClass() + "]");
96 | this.propertyDescriptorMap.put(pds[i].getName(), pds[i]);
97 | }
98 | }
99 | catch (IntrospectionException ex) {
100 | throw new FatalBeanException("Cannot get BeanInfo for object of class [" + clazz.getName() + "]", ex);
101 | }
102 | }
103 |
104 | protected BeanInfo getBeanInfo() {
105 | return beanInfo;
106 | }
107 |
108 | protected Class getBeanClass() {
109 | return beanInfo.getBeanDescriptor().getBeanClass();
110 | }
111 |
112 | protected PropertyDescriptor getPropertyDescriptor(String propertyName) throws BeansException {
113 | PropertyDescriptor pd = (PropertyDescriptor) this.propertyDescriptorMap.get(propertyName);
114 | if (pd == null) {
115 | throw new FatalBeanException("No property '" + propertyName + "' in class [" + getBeanClass().getName() + "]", null);
116 | }
117 | return pd;
118 | }
119 |
120 | }
121 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/FatalBeanException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans;
18 |
19 | /**
20 | * Thrown on an unrecoverable problem encountered in the
21 | * beans packages or sub-packages, e.g. bad class or field.
22 | *
23 | * 빈/하위 패키지에서 나쁜 클래스나 필드같은 복구불가능한 문제에 직면했을 때 던져지는 예외
24 | *
25 | * @author Rod Johnson
26 | * @version $Revision: 1.4 $
27 | */
28 | public class FatalBeanException extends BeansException {
29 |
30 | /**
31 | * Constructs a FatalBeanException with the specified message.
32 | * @param msg the detail message
33 | */
34 | public FatalBeanException(String msg) {
35 | super(msg);
36 | }
37 |
38 | /**
39 | * Constructs a FatalBeanException with the specified message
40 | * and root cause.
41 | * @param msg the detail message
42 | * @param ex root cause
43 | */
44 | public FatalBeanException(String msg, Throwable ex) {
45 | super(msg, ex);
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/MethodInvocationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans;
18 |
19 | import java.beans.PropertyChangeEvent;
20 |
21 | /**
22 | * Thrown when a method getter or setter throws an exception,
23 | * analogous to an InvocationTargetException.
24 | * @author Rod Johnson
25 | * @version $Revision: 1.6 $
26 | */
27 | public class MethodInvocationException extends PropertyAccessException {
28 |
29 | /**
30 | * Constructor to use when an exception results from a PropertyChangeEvent.
31 | * @param ex Throwable raised by invoked method
32 | * @param propertyChangeEvent PropertyChangeEvent that resulted in an exception
33 | */
34 | public MethodInvocationException(Throwable ex, PropertyChangeEvent propertyChangeEvent) {
35 | super("Property '" + propertyChangeEvent.getPropertyName() + "' threw exception", propertyChangeEvent, ex);
36 | }
37 |
38 | public String getErrorCode() {
39 | return "methodInvocation";
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/MutablePropertyValues.java:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | * Copyright 2002-2004 the original author or authors.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.springframework.beans;
19 |
20 | import org.springframework.util.StringUtils;
21 |
22 | import java.util.*;
23 |
24 | /**
25 | * Default implementation of the PropertyValues interface.
26 | * Allows simple manipulation of properties, and provides constructors
27 | * to support deep copy and construction from a Map.
28 | *
29 | * PropertyValues 에 대한 기본 구현체로 properties 에 대한 단순한 생성과 맵으로부터의 구성 딥카피를 지원하기 위한 생성자의 제공을 허용합니다.
30 | *
31 | * @author Rod Johnson
32 | * @since 13 May 2001
33 | * @version $Id: MutablePropertyValues.java,v 1.6 2004/03/18 02:46:12 trisberg Exp $
34 | */
35 | public class MutablePropertyValues implements PropertyValues {
36 |
37 | /** List of PropertyValue objects */
38 | private List propertyValuesList;
39 |
40 | /**
41 | * Creates a new empty MutablePropertyValues object.
42 | * Property values can be added with the addPropertyValue methods.
43 | * @see #addPropertyValue(PropertyValue)
44 | * @see #addPropertyValue(String, Object)
45 | */
46 | public MutablePropertyValues() {
47 | this.propertyValuesList = new ArrayList(10);
48 | }
49 |
50 | /**
51 | * Deep copy constructor. Guarantees PropertyValue references
52 | * are independent, although it can't deep copy objects currently
53 | * referenced by individual PropertyValue objects
54 | */
55 | public MutablePropertyValues(PropertyValues other) {
56 | this();
57 | if (other != null) {
58 | PropertyValue[] pvs = other.getPropertyValues();
59 | this.propertyValuesList = new ArrayList(pvs.length);
60 | for (int i = 0; i < pvs.length; i++) {
61 | addPropertyValue(new PropertyValue(pvs[i].getName(), pvs[i].getValue()));
62 | }
63 | }
64 | }
65 |
66 | /**
67 | * Construct a new PropertyValues object from a Map.
68 | * @param map Map with property values keyed by property name,
69 | * which must be a String
70 | */
71 | public MutablePropertyValues(Map map) {
72 | Set keys = map.keySet();
73 | this.propertyValuesList = new ArrayList(keys.size());
74 | Iterator itr = keys.iterator();
75 | while (itr.hasNext()) {
76 | String key = (String) itr.next();
77 | addPropertyValue(new PropertyValue(key, map.get(key)));
78 | }
79 | }
80 |
81 | /**
82 | * Add a PropertyValue object, replacing any existing one
83 | * for the respective property.
84 | * @param pv PropertyValue object to add
85 | */
86 | public void addPropertyValue(PropertyValue pv) {
87 | for (int i = 0; i < this.propertyValuesList.size(); i++) {
88 | PropertyValue currentPv = (PropertyValue) this.propertyValuesList.get(i);
89 | if (currentPv.getName().equals(pv.getName())) {
90 | this.propertyValuesList.set(i, pv);
91 | return;
92 | }
93 | }
94 | this.propertyValuesList.add(pv);
95 | }
96 |
97 | /**
98 | * Overloaded version of addPropertyValue that takes
99 | * a property name and a property value.
100 | * @param propertyName name of the property
101 | * @param propertyValue value of the property
102 | * @see #addPropertyValue(PropertyValue)
103 | */
104 | public void addPropertyValue(String propertyName, Object propertyValue) {
105 | addPropertyValue(new PropertyValue(propertyName, propertyValue));
106 | }
107 |
108 | /**
109 | * Remove the given PropertyValue, if contained.
110 | * @param pv the PropertyValue to remove
111 | */
112 | public void removePropertyValue(PropertyValue pv) {
113 | this.propertyValuesList.remove(pv);
114 | }
115 |
116 | /**
117 | * Overloaded version of removePropertyValue that takes
118 | * a property name.
119 | * @param propertyName name of the property
120 | * @see #removePropertyValue(PropertyValue)
121 | */
122 | public void removePropertyValue(String propertyName) {
123 | removePropertyValue(getPropertyValue(propertyName));
124 | }
125 |
126 | /**
127 | * Modify a PropertyValue object held in this object.
128 | * Indexed from 0.
129 | */
130 | public void setPropertyValueAt(PropertyValue pv, int i) {
131 | this.propertyValuesList.set(i, pv);
132 | }
133 |
134 | public PropertyValue[] getPropertyValues() {
135 | return (PropertyValue[]) this.propertyValuesList.toArray(new PropertyValue[0]);
136 | }
137 |
138 | public PropertyValue getPropertyValue(String propertyName) {
139 | for (int i = 0; i < this.propertyValuesList.size(); i++) {
140 | PropertyValue pv = (PropertyValue) this.propertyValuesList.get(i);
141 | if (pv.getName().equals(propertyName)) {
142 | return pv;
143 | }
144 | }
145 | return null;
146 | }
147 |
148 | public boolean contains(String propertyName) {
149 | return getPropertyValue(propertyName) != null;
150 | }
151 |
152 | public PropertyValues changesSince(PropertyValues old) {
153 | MutablePropertyValues changes = new MutablePropertyValues();
154 | if (old == this)
155 | return changes;
156 |
157 | // For each property value in the new set
158 | for (int i = 0; i < this.propertyValuesList.size(); i++) {
159 | PropertyValue newPv = (PropertyValue) this.propertyValuesList.get(i);
160 | // If there wasn't an old one, add it
161 | PropertyValue pvOld = old.getPropertyValue(newPv.getName());
162 | if (pvOld == null) {
163 | changes.addPropertyValue(newPv);
164 | }
165 | else if (!pvOld.equals(newPv)) {
166 | // It's changed
167 | changes.addPropertyValue(newPv);
168 | }
169 | }
170 | return changes;
171 | }
172 |
173 | public String toString() {
174 | PropertyValue[] pvs = getPropertyValues();
175 | StringBuffer sb = new StringBuffer("MutablePropertyValues: length=" + pvs.length + "; ");
176 | sb.append(StringUtils.arrayToDelimitedString(pvs, ","));
177 | return sb.toString();
178 | }
179 |
180 | }
181 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/NotWritablePropertyException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans;
18 |
19 | /**
20 | * Exception thrown on an attempt to set the value of a property
21 | * that isn't writable, because there's no setter method.
22 | * @author Rod Johnson
23 | */
24 | public class NotWritablePropertyException extends BeansException {
25 |
26 | /**
27 | * Creates new NotWritablePropertyException.
28 | */
29 | public NotWritablePropertyException(String propertyName, Class beanClass) {
30 | super("Property '" + propertyName + "' is not writable in bean class [" + beanClass.getName() + "]");
31 | }
32 |
33 | /**
34 | * Creates new NotWritablePropertyException with a root cause.
35 | */
36 | public NotWritablePropertyException(String propertyName, Class beanClass, Throwable ex) {
37 | super("Property '" + propertyName + "' is not writable in bean class [" + beanClass.getName() + "]", ex);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/NullValueInNestedPathException.java:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | * Copyright 2002-2004 the original author or authors.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.springframework.beans;
19 |
20 | /**
21 | * Exception thrown when navigation of a valid nested property
22 | * path encounters a null pointer exception. For example,
23 | * navigating spouse.age fails because the spouse property of the
24 | * target object has a null value.
25 | * @author Rod Johnson
26 | */
27 | public class NullValueInNestedPathException extends FatalBeanException {
28 |
29 | private String property;
30 |
31 | private Class clazz;
32 |
33 | /**
34 | * Constructor for NullValueInNestedPathException.
35 | * @param clazz
36 | * @param propertyName
37 | */
38 | public NullValueInNestedPathException(Class clazz, String propertyName) {
39 | super("Value of nested property '" + propertyName + "' is null in " + clazz, null);
40 | this.property = propertyName;
41 | this.clazz = clazz;
42 | }
43 |
44 | /**
45 | * @return the name of the offending property
46 | */
47 | public String getPropertyName() {
48 | return property;
49 | }
50 |
51 | public Class getBeanClass() {
52 | return clazz;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/PropertyAccessException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans;
18 |
19 | import org.springframework.core.ErrorCoded;
20 |
21 | import java.beans.PropertyChangeEvent;
22 |
23 | /**
24 | * Superclass for exceptions related to a property access,
25 | * such as type mismatch or invocation target exception.
26 | * @author Rod Johnson
27 | * @version $Revision: 1.4 $
28 | */
29 | public abstract class PropertyAccessException extends BeansException implements ErrorCoded {
30 |
31 | private PropertyChangeEvent propertyChangeEvent;
32 |
33 | public PropertyAccessException(String msg, PropertyChangeEvent propertyChangeEvent) {
34 | super(msg);
35 | this.propertyChangeEvent = propertyChangeEvent;
36 | }
37 |
38 | public PropertyAccessException(String msg, PropertyChangeEvent propertyChangeEvent, Throwable ex) {
39 | super(msg, ex);
40 | this.propertyChangeEvent = propertyChangeEvent;
41 | }
42 |
43 | /**
44 | * Return the PropertyChangeEvent that resulted in the problem.
45 | */
46 | public PropertyChangeEvent getPropertyChangeEvent() {
47 | return propertyChangeEvent;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/PropertyAccessExceptionsException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans;
18 |
19 | import java.io.PrintStream;
20 | import java.io.PrintWriter;
21 |
22 | /**
23 | * Combined exception, composed of individual binding propertyAccessExceptions.
24 | * An object of this class is created at the beginning of the binding
25 | * process, and errors added to it as necessary.
26 | *
27 | *
The binding process continues when it encounters application-level
28 | * propertyAccessExceptions, applying those changes that can be applied and storing
29 | * rejected changes in an object of this class.
30 | *
31 | * @author Rod Johnson
32 | * @author Juergen Hoeller
33 | * @since 18 April 2001
34 | * @version $Id: PropertyAccessExceptionsException.java,v 1.5 2004/03/18 02:46:12 trisberg Exp $
35 | */
36 | public class PropertyAccessExceptionsException extends BeansException {
37 |
38 | /** BeanWrapper wrapping the target object for binding */
39 | private final BeanWrapper beanWrapper;
40 |
41 | /** List of PropertyAccessException objects */
42 | private final PropertyAccessException[] propertyAccessExceptions;
43 |
44 | /**
45 | * Create new empty PropertyAccessExceptionsException.
46 | * We'll add errors to it as we attempt to bind properties.
47 | */
48 | protected PropertyAccessExceptionsException(BeanWrapper beanWrapper,
49 | PropertyAccessException[] propertyAccessExceptions) {
50 | super("");
51 | this.beanWrapper = beanWrapper;
52 | this.propertyAccessExceptions = propertyAccessExceptions;
53 | }
54 |
55 | /**
56 | * Return the BeanWrapper that generated this exception.
57 | */
58 | public BeanWrapper getBeanWrapper() {
59 | return beanWrapper;
60 | }
61 |
62 | /**
63 | * Return the object we're binding to.
64 | */
65 | public Object getBindObject() {
66 | return this.beanWrapper.getWrappedInstance();
67 | }
68 |
69 | /**
70 | * If this returns 0, no errors were encountered during binding.
71 | */
72 | public int getExceptionCount() {
73 | return this.propertyAccessExceptions.length;
74 | }
75 |
76 | /**
77 | * Return an array of the propertyAccessExceptions stored in this object.
78 | * Will return the empty array (not null) if there were no errors.
79 | */
80 | public PropertyAccessException[] getPropertyAccessExceptions() {
81 | return this.propertyAccessExceptions;
82 | }
83 |
84 | /**
85 | * Return the exception for this field, or null if there isn't one.
86 | */
87 | public PropertyAccessException getPropertyAccessException(String propertyName) {
88 | for (int i = 0; i < this.propertyAccessExceptions.length; i++) {
89 | PropertyAccessException pae = this.propertyAccessExceptions[i];
90 | if (propertyName.equals(pae.getPropertyChangeEvent().getPropertyName())) {
91 | return pae;
92 | }
93 | }
94 | return null;
95 | }
96 |
97 | public String getMessage() {
98 | StringBuffer sb = new StringBuffer();
99 | sb.append(this.toString());
100 | sb.append("; nested propertyAccessExceptions are: ");
101 | for (int i = 0; i < this.propertyAccessExceptions.length; i++) {
102 | PropertyAccessException pae = this.propertyAccessExceptions[i];
103 | sb.append("[");
104 | sb.append(pae.getClass().getName());
105 | sb.append(": ");
106 | sb.append(pae.getMessage());
107 | sb.append(']');
108 | if (i < this.propertyAccessExceptions.length - 1) {
109 | sb.append(", ");
110 | }
111 | }
112 | return sb.toString();
113 | }
114 |
115 | public void printStackTrace(PrintStream ps) {
116 | ps.println(this);
117 | for (int i = 0; i < this.propertyAccessExceptions.length; i++) {
118 | PropertyAccessException pae = this.propertyAccessExceptions[i];
119 | pae.printStackTrace(ps);
120 | }
121 | }
122 |
123 | public void printStackTrace(PrintWriter pw) {
124 | pw.println(this);
125 | for (int i = 0; i < this.propertyAccessExceptions.length; i++) {
126 | PropertyAccessException pae = this.propertyAccessExceptions[i];
127 | pae.printStackTrace(pw);
128 | }
129 | }
130 |
131 | public String toString() {
132 | return "PropertyAccessExceptionsException (" + getExceptionCount() + " errors)";
133 | }
134 |
135 | }
136 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/PropertyValue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans;
18 |
19 | /**
20 | * Class to hold information and value for an individual property.
21 | * Using an object here, rather than just storing all properties in a
22 | * map keyed by property name, allows for more flexibility, and the
23 | * ability to handle indexed properties etc in a special way if necessary.
24 | *
25 | * 각각의 속성들에 대한 정보와 값을 가지기 위한 클래스
26 | * 단지 프로퍼티 이름에 의한 맵을 가지고서 모든 속성들을 저장하는 것보다, 여기서 오브젝트를 사용함으로써,
27 | * 만약 필요하다면 인덱싱된 속성들을 다룰 수 있는 능력과, 좀 더 많은 유연함을 가질 수 있을 것이다
28 | *
29 | *
Note that the value doesn't need to be the final required type:
30 | * A BeanWrapper implementation should handle any necessary conversion, as
31 | * this object doesn't know anything about the objects it will be applied to.
32 | *
33 | * @author Rod Johnson
34 | * @since 13 May 2001
35 | * @version $Id: PropertyValue.java,v 1.3 2004/03/18 02:46:12 trisberg Exp $
36 | */
37 | public class PropertyValue {
38 |
39 | /** Property name */
40 | private String name;
41 |
42 | /** Value of the property */
43 | private Object value;
44 |
45 | /**
46 | * Creates new PropertyValue.
47 | * @param name name of the property
48 | * @param value value of the property (possibly before type conversion)
49 | */
50 | public PropertyValue(String name, Object value) {
51 | if (name == null) {
52 | throw new IllegalArgumentException("Property name cannot be null");
53 | }
54 | this.name = name;
55 | this.value = value;
56 | }
57 |
58 | /**
59 | * Return the name of the property.
60 | * @return the name of the property
61 | */
62 | public String getName() {
63 | return name;
64 | }
65 |
66 | /**
67 | * Return the value of the property.
68 | *
Note that type conversion will not have occurred here.
69 | * It is the responsibility of the BeanWrapper implementation to
70 | * perform type conversion.
71 | * @return the value of the property
72 | */
73 | public Object getValue() {
74 | return value;
75 | }
76 |
77 | public String toString() {
78 | return "PropertyValue: name='" + name + "'; value=[" + value + "]";
79 | }
80 |
81 | public boolean equals(Object other) {
82 | if (this == other) {
83 | return true;
84 | }
85 | if (!(other instanceof PropertyValue)) {
86 | return false;
87 | }
88 | PropertyValue otherPv = (PropertyValue) other;
89 | return (this.name.equals(otherPv.name) &&
90 | ((this.value == null && otherPv.value == null) || this.value.equals(otherPv.value)));
91 | }
92 |
93 | public int hashCode() {
94 | return this.name.hashCode() * 29 + (this.value != null ? this.value.hashCode() : 0);
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/PropertyValues.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans;
18 |
19 | /**
20 | * Object containing 0 or more PropertyValues comprising one update.
21 | * 0 혹은 많은 PropertyValue 들을 간직하는 객체
22 | * @author Rod Johnson
23 | * @since 13 May 2001
24 | * @version $Id: PropertyValues.java,v 1.3 2004/03/18 02:46:12 trisberg Exp $
25 | */
26 | public interface PropertyValues {
27 |
28 | /**
29 | * Return an array of the PropertyValue objects held in this object.
30 | * @return an array of the PropertyValue objects held in this object.
31 | */
32 | PropertyValue[] getPropertyValues();
33 |
34 | /**
35 | * Return the property value with the given name.
36 | * @param propertyName name to search for
37 | * @return pv or null
38 | */
39 | PropertyValue getPropertyValue(String propertyName);
40 |
41 | /**
42 | * Is there a property value for this property?
43 | * @param propertyName name of the property we're interested in
44 | * @return whether there is a property value for this property
45 | */
46 | boolean contains(String propertyName);
47 |
48 | /**
49 | * Return the changes since the previous PropertyValues.
50 | * Subclasses should also override equals.
51 | * @param old old property values
52 | * @return PropertyValues updated or new properties.
53 | * Return the empty PropertyValues if there are no changes.
54 | */
55 | PropertyValues changesSince(PropertyValues old);
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/PropertyValuesEditor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans;
18 |
19 | import org.springframework.beans.MutablePropertyValues;
20 | import org.springframework.beans.propertyeditors.PropertiesEditor;
21 |
22 | import java.beans.PropertyEditorSupport;
23 | import java.util.Properties;
24 |
25 | /**
26 | * Editor for PropertyValues objects. Not
27 | * a GUI editor.
28 | *
29 | * PropertyValues 를 위한 에디터로 GUI 에디터가 아니다
30 | *
31 | * 이 에디터는 사용가능하기전에 JavaBeans API 과 등록이 되어져야한다.
32 | * 이 패키지의 에디터들은 BeanWrapperImpl 에 의해 등록되어진다
33 | *
34 | * NB: this editor must be registered with the JavaBeans API before it
35 | * will be available. Editors in this package are
36 | * registered by BeanWrapperImpl.
37 | * The required format is defined in java.util.Properties documentation.
38 | * Each property must be on a new line.
39 | *
40 | * The present implementation relies on a PropertiesEditor.
41 | * @author Rod Johnson
42 | */
43 | public class PropertyValuesEditor extends PropertyEditorSupport {
44 |
45 |
46 | /**
47 | * @see java.beans.PropertyEditor#setAsText(java.lang.String)
48 | */
49 | public void setAsText(String s) throws IllegalArgumentException {
50 | PropertiesEditor pe = new PropertiesEditor();
51 | pe.setAsText(s);
52 | Properties props = (Properties) pe.getValue();
53 | setValue(new MutablePropertyValues(props));
54 | }
55 |
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/README.md:
--------------------------------------------------------------------------------
1 | # beans 패키지
2 |
3 | 이 패키지는 자바빈을 생성하기 위한 인터페이스와 클래스들을 포함한다
4 | 다른 스프링 패키지들에서 가장 많이 사용하는 패키지일 것이다
5 |
6 | ---
7 |
8 | 하위패키지
9 | factory
10 | propertyeditors
11 | support
12 |
13 | ---
14 |
15 | - BeansException : 빈, 서브패키지에서의 던져지는 모든 예외들에 대한 추상클래스
16 | - BeanWrapper : 스프링 로우레벨 자바빈즈 인프라스트럭쳐의 핵심 인터페이스
17 | - BeanWrapperImpl : BeanWrapper 인터페이스의 의 기본구현체(중요)
18 | - FatalBeanException : 빈/하위 패키지에서 나쁜 클래스나 필드같은 복구불가능한 문제에 직면했을 때 던져지는 예외
19 | - MutablePropertyValues : PropertyValues 에 대한 기본 구현체로 properties 에 대한 단순한 생성과 맵으로부터의 구성 딥카피를 지원하기 위한 생성자의 제공을 허용합니다.
20 | - PropertyValue : 각각의 속성들에 대한 정보와 값을 가지기 위한 클래스
21 |
22 | - (I)PropertyValues : 0 혹은 많은 PropertyValue 들을 간직하는 객체
23 | - ProperyValuesEditor : PropertyValues 를 위한 에디터로 GUI 에디터가 아니다
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/TypeMismatchException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans;
18 |
19 | import java.beans.PropertyChangeEvent;
20 |
21 | /**
22 | * Exception thrown on a type mismatch when trying to set a property.
23 | * @author Rod Johnson
24 | * @author Juergen Hoeller
25 | * @version $Revision: 1.5 $
26 | */
27 | public class TypeMismatchException extends PropertyAccessException {
28 |
29 | public TypeMismatchException(PropertyChangeEvent propertyChangeEvent, Class requiredType) {
30 | super("Cannot convert property value of type [" +
31 | (propertyChangeEvent.getNewValue() != null ?
32 | propertyChangeEvent.getNewValue().getClass().getName() : null) +
33 | "] to required type [" + requiredType.getName() + "]" +
34 | (propertyChangeEvent.getPropertyName() != null ?
35 | " for property '" + propertyChangeEvent.getPropertyName() + "'" : ""),
36 | propertyChangeEvent);
37 | }
38 |
39 | public TypeMismatchException(PropertyChangeEvent propertyChangeEvent, Class requiredType, Throwable ex) {
40 | super("Failed to convert property value of type [" +
41 | (propertyChangeEvent.getNewValue() != null ?
42 | propertyChangeEvent.getNewValue().getClass().getName() : null) +
43 | "] to required type [" + requiredType.getName() + "]" +
44 | (propertyChangeEvent.getPropertyName() != null ?
45 | " for property '" + propertyChangeEvent.getPropertyName() + "'" : ""),
46 | propertyChangeEvent, ex);
47 | }
48 |
49 | public String getErrorCode() {
50 | return "typeMismatch";
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/package.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | This package contains interfaces and classes for manipulating Java beans.
5 | It is used by most other Spring packages.
6 |
7 |
A BeanWrapper object may be used to set and get bean properties,
8 | singly or in bulk.
9 |
10 |
The classes in this package are discussed in Chapter 11 of
11 | Expert One-On-One J2EE Design and Development
12 | by Rod Johnson (Wrox, 2002).
13 |
14 | 이 패키지는 자바빈을 생성하기 위한 인터페이스와 클래스들을 포함한다
15 | 다른 스프링 패키지들에서 가장 많이 사용하는 패키지일 것이다
16 |
17 | 하위패키지
18 | factory
19 | propertyeditors
20 | support
21 |
22 | =============================================================
23 |
24 | BeansException : 빈, 서브패키지에서의 던져지는 모든 예외들에 대한 추상클래스
25 | BeanWrapper : 스프링 로우레벨 자바빈즈 인프라스트럭쳐의 핵심 인터페이스
26 | BeanWrapperImpl : BeanWrapper 인터페이스의 의 기본구현체(중요)
27 | FatalBeanException : 빈/하위 패키지에서 나쁜 클래스나 필드같은 복구불가능한 문제에 직면했을 때 던져지는 예외
28 | MutablePropertyValues : PropertyValues 에 대한 기본 구현체로 properties 에 대한 단순한 생성과 맵으로부터의 구성 딥카피를 지원하기 위한 생성자의 제공을 허용합니다.
29 | PropertyValue : 각각의 속성들에 대한 정보와 값을 가지기 위한 클래스
30 | (I) PropertyValues : 0 혹은 많은 PropertyValue 들을 간직하는 객체
31 | ProperyValuesEditor : PropertyValues 를 위한 에디터로 GUI 에디터가 아니다
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/propertyeditors/ClassEditor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans.propertyeditors;
18 |
19 | import java.beans.PropertyEditorSupport;
20 |
21 | /**
22 | * Editor for java.lang.Class, to directly feed a Class property
23 | * instead of using a String class name property.
24 | * @author Juergen Hoeller
25 | * @since 13.05.2003
26 | * @see Class
27 | */
28 | public class ClassEditor extends PropertyEditorSupport {
29 |
30 | public void setAsText(String text) throws IllegalArgumentException {
31 | Class clazz = null;
32 | try {
33 | clazz = Class.forName(text, true, Thread.currentThread().getContextClassLoader());
34 | }
35 | catch (ClassNotFoundException ex) {
36 | throw new IllegalArgumentException("Invalid class name [" + text + "]: " + ex.getMessage());
37 | }
38 | setValue(clazz);
39 | }
40 |
41 | public String getAsText() {
42 | return ((Class) getValue()).getName();
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/propertyeditors/CustomBooleanEditor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans.propertyeditors;
18 |
19 | import java.beans.PropertyEditorSupport;
20 |
21 | /**
22 | * Property editor for Boolean properties.
23 | *
24 | *
This is not meant to be used as system PropertyEditor but rather as
25 | * locale-specific Boolean editor within custom controller code, to parse
26 | * UI-caused boolean strings into Boolean properties of beans, and
27 | * evaluate them in the UI form.
28 | *
29 | *
In web MVC code, this editor will typically be registered with
30 | * binder.registerCustomEditor calls in an implementation of
31 | * BaseCommandController's initBinder method.
32 | *
33 | * @author Juergen Hoeller
34 | * @since 10.06.2003
35 | * @see org.springframework.validation.DataBinder#registerCustomEditor
36 | * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder
37 | * @see org.springframework.web.bind.BindInitializer#initBinder
38 | */
39 | public class CustomBooleanEditor extends PropertyEditorSupport {
40 |
41 | private boolean allowEmpty;
42 |
43 | /**
44 | * Create a new instance.
45 | *
The allowEmpty parameter states if an empty String should
46 | * be allowed for parsing, i.e. get interpreted as null value.
47 | * Else, an IllegalArgumentException gets thrown in that case.
48 | * @param allowEmpty if empty strings should be allowed
49 | */
50 | public CustomBooleanEditor(boolean allowEmpty) {
51 | this.allowEmpty = allowEmpty;
52 | }
53 |
54 | public void setAsText(String text) throws IllegalArgumentException {
55 | if (this.allowEmpty && text.trim().equals("")) {
56 | setValue(null);
57 | }
58 | else if (text.equalsIgnoreCase("true")) {
59 | setValue(Boolean.TRUE);
60 | }
61 | else if (text.equalsIgnoreCase("false")) {
62 | setValue(Boolean.FALSE);
63 | }
64 | else
65 | throw new IllegalArgumentException("Invalid Boolean value [" + text + "]");
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/propertyeditors/CustomDateEditor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans.propertyeditors;
18 |
19 | import java.beans.PropertyEditorSupport;
20 | import java.text.DateFormat;
21 | import java.text.ParseException;
22 | import java.util.Date;
23 |
24 | /**
25 | * PropertyEditor for Date, supporting a custom DateFormat.
26 | *
27 | *
This is not meant to be used as system PropertyEditor but rather as
28 | * locale-specific date editor within custom controller code, to parse
29 | * user-entered date strings into Date properties of beans, and render
30 | * them in the UI form.
31 | *
32 | *
In web MVC code, this editor will typically be registered with
33 | * binder.registerCustomEditor calls in an implementation of
34 | * BaseCommandController's initBinder method.
35 | *
36 | * @author Juergen Hoeller
37 | * @since 28.04.2003
38 | * @see org.springframework.validation.DataBinder#registerCustomEditor
39 | * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder
40 | * @see org.springframework.web.bind.BindInitializer#initBinder
41 | */
42 | public class CustomDateEditor extends PropertyEditorSupport {
43 |
44 | private final DateFormat dateFormat;
45 |
46 | private final boolean allowEmpty;
47 |
48 | /**
49 | * Create a new instance, using the given DateFormat for
50 | * parsing and rendering.
51 | *
The allowEmpty parameter states if an empty String should
52 | * be allowed for parsing, i.e. get interpreted as null value.
53 | * Else, an IllegalArgumentException gets thrown in that case.
54 | * @param dateFormat DateFormat to use for parsing and rendering
55 | * @param allowEmpty if empty strings should be allowed
56 | */
57 | public CustomDateEditor(DateFormat dateFormat, boolean allowEmpty) {
58 | this.dateFormat = dateFormat;
59 | this.allowEmpty = allowEmpty;
60 | }
61 |
62 | /**
63 | * Parse the Date from the given text, using the specified DateFormat.
64 | */
65 | public void setAsText(String text) throws IllegalArgumentException {
66 | if (this.allowEmpty && text.trim().equals("")) {
67 | // treat empty String as null value
68 | setValue(null);
69 | }
70 | else {
71 | try {
72 | setValue(this.dateFormat.parse(text));
73 | }
74 | catch (ParseException ex) {
75 | throw new IllegalArgumentException("Could not parse date: " + ex.getMessage());
76 | }
77 | }
78 | }
79 |
80 | /**
81 | * Format the Date as String, using the specified DateFormat.
82 | */
83 | public String getAsText() {
84 | return this.dateFormat.format((Date) getValue());
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/propertyeditors/CustomNumberEditor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans.propertyeditors;
18 |
19 | import java.beans.PropertyEditorSupport;
20 | import java.math.BigDecimal;
21 | import java.math.BigInteger;
22 | import java.text.NumberFormat;
23 | import java.text.ParseException;
24 |
25 | /**
26 | * Property editor for any Number subclass like Integer, Long, Float, Double.
27 | * Uses a given NumberFormat for (locale-specific) parsing and rendering.
28 | *
29 | *
This is not meant to be used as system PropertyEditor but rather as
30 | * locale-specific number editor within custom controller code, to parse
31 | * user-entered number strings into Number properties of beans, and render
32 | * them in the UI form.
33 | *
34 | *
In web MVC code, this editor will typically be registered with
35 | * binder.registerCustomEditor calls in an implementation of
36 | * BaseCommandController's initBinder method.
37 | *
38 | * @author Juergen Hoeller
39 | * @since 06.06.2003
40 | * @see org.springframework.validation.DataBinder#registerCustomEditor
41 | * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder
42 | * @see org.springframework.web.bind.BindInitializer#initBinder
43 | */
44 | public class CustomNumberEditor extends PropertyEditorSupport {
45 |
46 | private Class numberClass;
47 |
48 | private NumberFormat numberFormat;
49 |
50 | private final boolean allowEmpty;
51 |
52 | /**
53 | * Create a new instance, using the given NumberFormat for
54 | * parsing and rendering.
55 | *
The allowEmpty parameter states if an empty String should
56 | * be allowed for parsing, i.e. get interpreted as null value.
57 | * Else, an IllegalArgumentException gets thrown in that case.
58 | * @param numberClass Number subclass to generate
59 | * @param numberFormat NumberFormat to use for parsing and rendering
60 | * @param allowEmpty if empty strings should be allowed
61 | * @throws IllegalArgumentException if an invalid numberClass has been specified
62 | */
63 | public CustomNumberEditor(Class numberClass, NumberFormat numberFormat, boolean allowEmpty)
64 | throws IllegalArgumentException {
65 | if (!Number.class.isAssignableFrom(numberClass)) {
66 | throw new IllegalArgumentException("Property class must be a subclass of Number");
67 | }
68 | this.numberClass = numberClass;
69 | this.numberFormat = numberFormat;
70 | this.allowEmpty = allowEmpty;
71 | }
72 |
73 | public void setAsText(String text) throws IllegalArgumentException {
74 | if (this.allowEmpty && text.trim().equals("")) {
75 | setValue(null);
76 | }
77 | else {
78 | try {
79 | Number number = this.numberFormat.parse(text);
80 | if (this.numberClass.isInstance(number)) {
81 | setValue(number);
82 | }
83 | else if (this.numberClass.equals(Short.class)) {
84 | setValue(new Short(number.shortValue()));
85 | }
86 | else if (this.numberClass.equals(Integer.class)) {
87 | setValue(new Integer(number.intValue()));
88 | }
89 | else if (this.numberClass.equals(Long.class)) {
90 | setValue(new Long(number.longValue()));
91 | }
92 | else if (this.numberClass.equals(BigInteger.class)) {
93 | setValue(BigInteger.valueOf(number.longValue()));
94 | }
95 | else if (this.numberClass.equals(Float.class)) {
96 | setValue(new Float(number.floatValue()));
97 | }
98 | else if (this.numberClass.equals(Double.class)) {
99 | setValue(new Double(number.doubleValue()));
100 | }
101 | else if (this.numberClass.equals(BigDecimal.class)) {
102 | setValue(new BigDecimal(Double.toString(number.doubleValue())));
103 | }
104 | else {
105 | throw new IllegalArgumentException("Cannot convert [" + text + "] to [" + this.numberClass + "]");
106 | }
107 | }
108 | catch (ParseException ex) {
109 | throw new IllegalArgumentException("Cannot parse number: " + ex.getMessage());
110 | }
111 | }
112 | }
113 |
114 | public String getAsText() {
115 | return this.numberFormat.format(getValue());
116 | }
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/propertyeditors/FileEditor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans.propertyeditors;
18 |
19 | import java.beans.PropertyEditorSupport;
20 | import java.io.File;
21 |
22 | /**
23 | * Editor for java.io.File, to directly feed a File property
24 | * instead of using a String file name property.
25 | * @author Juergen Hoeller
26 | * @since 09.12.2003
27 | * @see File
28 | */
29 | public class FileEditor extends PropertyEditorSupport {
30 |
31 | public void setAsText(String text) throws IllegalArgumentException {
32 | setValue(new File(text));
33 | }
34 |
35 | public String getAsText() {
36 | return ((File) getValue()).getAbsolutePath();
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/propertyeditors/LocaleEditor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans.propertyeditors;
18 |
19 | import org.springframework.util.StringUtils;
20 |
21 | import java.beans.PropertyEditorSupport;
22 | import java.util.Locale;
23 |
24 | /**
25 | * Editor for java.util.Locale, to directly feed a Locale property.
26 | * Expects the same syntax as Locale.toString, i.e. language + optionally
27 | * country + optionally variant, separated by "_" (e.g. "en", "en_US").
28 | * @author Juergen Hoeller
29 | * @since 26.05.2003
30 | */
31 | public class LocaleEditor extends PropertyEditorSupport {
32 |
33 | public void setAsText(String text) {
34 | String[] parts = StringUtils.delimitedListToStringArray(text, "_");
35 | String language = parts.length > 0 ? parts[0] : "";
36 | String country = parts.length > 1 ? parts[1] : "";
37 | String variant = parts.length > 2 ? parts[2] : "";
38 | setValue(language.length() > 0 ? new Locale(language, country, variant) : null);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/propertyeditors/PropertiesEditor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans.propertyeditors;
18 |
19 | import java.beans.PropertyEditorSupport;
20 | import java.io.ByteArrayInputStream;
21 | import java.io.IOException;
22 | import java.util.ArrayList;
23 | import java.util.Iterator;
24 | import java.util.List;
25 | import java.util.Properties;
26 |
27 | /**
28 | * Editor for java.util.Properties objects. Handles conversion from String
29 | * to Properties object.
30 | *
31 | * java.util.Properties 객체들을 위한 에디터로, 문자열에서 Properties 객체로의 전환을 다룹니다.
32 | *
33 | *
This editor must be registered before it will be available. Standard
34 | * editors in this package are automatically registered by BeanWrapperImpl.
35 | *
36 | *
The required format is defined in java.util.Properties documentation.
37 | * Each property must be on a new line.
38 | *
39 | * @author Rod Johnson
40 | * @version $Id: PropertiesEditor.java,v 1.5 2004/03/18 02:46:13 trisberg Exp $
41 | * @see org.springframework.beans.BeanWrapperImpl
42 | * @see java.util.Properties#load
43 | */
44 | public class PropertiesEditor extends PropertyEditorSupport {
45 |
46 | /**
47 | * Any of these characters, if they're first after whitespace or first
48 | * on a line, mean that the line is a comment and should be ignored.
49 | */
50 | public final static String COMMENT_MARKERS = "#!";
51 |
52 | public void setAsText(String text) throws IllegalArgumentException {
53 | if (text == null) {
54 | throw new IllegalArgumentException("Cannot set Properties to null");
55 | }
56 | Properties props = new Properties();
57 | try {
58 | props.load(new ByteArrayInputStream(text.getBytes()));
59 | dropComments(props);
60 | }
61 | catch (IOException ex) {
62 | // shouldn't happen
63 | throw new IllegalArgumentException("Failed to parse [" + text + "] into Properties");
64 | }
65 | setValue(props);
66 | }
67 |
68 | /**
69 | * Remove comment lines. We shouldn't need to do this, according to
70 | * java.util.Properties documentation, but if we don't we end up with
71 | * properties like "#this=is a comment" if we have whitespace before
72 | * the comment marker.
73 | */
74 | private void dropComments(Properties props) {
75 | Iterator keys = props.keySet().iterator();
76 | List commentKeys = new ArrayList();
77 | while (keys.hasNext()) {
78 | String key = (String) keys.next();
79 | // A comment line starts with one of our comment markers
80 | if (key.length() > 0 && COMMENT_MARKERS.indexOf(key.charAt(0)) != -1) {
81 | // We can't actually remove it as we'll get a
82 | // concurrent modification exception with the iterator
83 | commentKeys.add(key);
84 | }
85 | }
86 | for (Iterator it = commentKeys.iterator(); it.hasNext();) {
87 | String key = (String) it.next();
88 | props.remove(key);
89 | }
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/propertyeditors/README.md:
--------------------------------------------------------------------------------
1 | # beans/propertyeditors 패키지
2 |
3 | Properties editors 는 문자열 값을 java.util.Properties 같은 객체 타입으로 변환하기 위해 사용됩니다
4 | 몇몇개의 에디터들은 BeanWrapperImpl에 의해 자동으로 등록되어집니다
5 | CustomXxxEditor 클래스들은 특정 바인딩 프로세스들을 위하여 수동 등록으로 의도되어졌습니다.
6 |
7 | ---
8 |
9 | - PropertiesEditor : java.util.Properties 객체들을 위한 에디터로, 문자열에서 Properties 객체로의 전환을 다룹니다.
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/propertyeditors/StringArrayPropertyEditor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans.propertyeditors;
18 |
19 | import org.springframework.util.StringUtils;
20 |
21 | import java.beans.PropertyEditorSupport;
22 |
23 | /**
24 | * Properties editor for String[] type. Strings must be in CSV format.
25 | * This property editor is automatically registered by BeanWrapperImpl.
26 | * @author Rod Johnson
27 | * @see org.springframework.beans.BeanWrapperImpl
28 | */
29 | public class StringArrayPropertyEditor extends PropertyEditorSupport {
30 |
31 | public void setAsText(String s) throws IllegalArgumentException {
32 | String[] sa = StringUtils.commaDelimitedListToStringArray(s);
33 | setValue(sa);
34 | }
35 |
36 | public String getAsText() {
37 | String[] array = (String[]) this.getValue();
38 | return StringUtils.arrayToCommaDelimitedString(array);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/propertyeditors/StringTrimmerEditor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans.propertyeditors;
18 |
19 | import java.beans.PropertyEditorSupport;
20 |
21 | /**
22 | * Property editor that trims Strings.
23 | * Allows to transform an empty string into a null value.
24 | * Needs to be explictly registered, e.g. for command binding.
25 | * @author Juergen Hoeller
26 | * @see org.springframework.validation.DataBinder#registerCustomEditor
27 | * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder
28 | * @see org.springframework.web.bind.BindInitializer#initBinder
29 | */
30 | public class StringTrimmerEditor extends PropertyEditorSupport {
31 |
32 | private boolean emptyAsNull;
33 |
34 | /**
35 | * Create a new instance.
36 | * @param emptyAsNull whether to transform an empty string to null
37 | */
38 | public StringTrimmerEditor(boolean emptyAsNull) {
39 | this.emptyAsNull = emptyAsNull;
40 | }
41 |
42 | public void setAsText(String text) throws IllegalArgumentException {
43 | if (text == null) {
44 | setValue(null);
45 | }
46 | else {
47 | String value = text.trim();
48 | if (this.emptyAsNull && "".equals(value)) {
49 | setValue(null);
50 | }
51 | else {
52 | setValue(value);
53 | }
54 | }
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/propertyeditors/URLEditor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.beans.propertyeditors;
18 |
19 | import java.beans.PropertyEditorSupport;
20 | import java.net.MalformedURLException;
21 | import java.net.URL;
22 |
23 | /**
24 | * Editor for java.net.URL, to directly feed a URL property
25 | * instead of using a String property.
26 | * @author Juergen Hoeller
27 | * @since 15.12.2003
28 | */
29 | public class URLEditor extends PropertyEditorSupport {
30 |
31 | public void setAsText(String text) throws IllegalArgumentException {
32 | try {
33 | setValue(new URL(text));
34 | }
35 | catch (MalformedURLException ex) {
36 | throw new IllegalArgumentException("Malformed URL: " + ex.getMessage());
37 | }
38 | }
39 |
40 | public String getAsText() {
41 | return ((URL) getValue()).toExternalForm();
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/beans/propertyeditors/package.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Properties editors used to convert from String values to object
5 | types such as java.util.Properties.
6 |
7 |
Some of these editors are registered automatically by BeanWrapperImpl.
8 | "CustomXxxEditor" classes are intended for manual registration in
9 | specific binding processes, as they are localized or the like.
10 |
11 | Properties editors 는 문자열 값을 java.util.Properties 같은 객체 타입으로 변환하기 위해 사용됩니다
12 | 몇몇개의 에디터들은 BeanWrapperImpl에 의해 자동으로 등록되어집니다
13 | CustomXxxEditor 클래스들은 특정 바인딩 프로세스들을 위하여 수동 등록으로 의도되어졌습니다.
14 |
15 | ================================================================
16 |
17 | PropertiesEditor : java.util.Properties 객체들을 위한 에디터로, 문자열에서 Properties 객체로의 전환을 다룹니다.
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/core/ConstantException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.core;
18 |
19 | /**
20 | * Exception thrown when the Constants class is asked for an invalid
21 | * constant name.
22 | * @see org.springframework.core.Constants
23 | * @version $Id: ConstantException.java,v 1.2 2004/03/18 02:46:06 trisberg Exp $
24 | * @author Rod Johnson
25 | * @since 28-Apr-2003
26 | *
27 | * Constants 클래스가 유효하지 않은 상수 이름을 물어볼때 발생할 수 있는 예외
28 | */
29 | public class ConstantException extends IllegalArgumentException {
30 |
31 | /**
32 | * Thrown when an invalid constant name is requested.
33 | * @param clazz class containing the constant definitions
34 | * @param field invalid constant name
35 | * @param message description of the problem
36 | */
37 | public ConstantException(Class clazz, String field, String message) {
38 | super("Field '" + field + "' " + message + " in " + clazz);
39 | }
40 |
41 | /**
42 | * Thrown when an invalid constant value is looked up.
43 | * @param clazz class containing the constant definitions
44 | * @param namePrefix prefix of the searched constant names
45 | * @param value the looked up constant value
46 | */
47 | public ConstantException(Class clazz, String namePrefix, Object value) {
48 | super("No '" + namePrefix + "' field with value '" + value + "' found in " + clazz);
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/core/Constants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2004 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.core;
18 |
19 | import java.lang.reflect.Field;
20 | import java.lang.reflect.Modifier;
21 | import java.util.HashMap;
22 | import java.util.HashSet;
23 | import java.util.Iterator;
24 | import java.util.Map;
25 | import java.util.Set;
26 |
27 | /**
28 | * This class can be used to parse other classes containing constant definitions
29 | * in public static final members. The asXXXX() methods of this class allow these
30 | * constant values to be accessed via their string names.
31 | *
32 | *
Consider class Foo containing public final static int CONSTANT1 = 66;
33 | * An instance of this class wrapping Foo.class will return the
34 | * constant value of 66 from its asInt() method given the argument "CONSTANT1".
35 | *
36 | *
This class is ideal for use in PropertyEditors, enabling them to recognize
37 | * the same names as the constants themselves, and freeing them from
38 | * maintaining their own mapping.
39 | *
40 | * @version $Id: Constants.java,v 1.2 2004/03/18 02:46:06 trisberg Exp $
41 | * @author Rod Johnson
42 | * @author Juergen Hoeller
43 | * @since 16-Mar-2003
44 | *
45 | * 이 클래스는 다른 클래스들을 파싱하는데 사용될 수 있다.
46 | * 여기서 다른 클래스는 상수 정의를 public static final 필드로 정의한 것을 말한다.
47 | * asXXX 메서드는 이렇한 상수들을 문자열이름을 통해 접근할 수 있게 해준다.
48 | *
49 | */
50 | public class Constants {
51 |
52 | /** Map from String field name to object value */
53 | private final Map map = new HashMap();
54 |
55 | /** Class analyzed */
56 | private final Class clazz;
57 |
58 | /**
59 | * Create a new Constants converter class wrapping the given class.
60 | * All public static final variables will be exposed, whatever their type.
61 | * @param clazz class to analyze.
62 | */
63 | public Constants(Class clazz) {
64 | this.clazz = clazz;
65 | Field[] fields = clazz.getFields();
66 | for (int i = 0; i < fields.length; i++) {
67 | Field f = fields[i];
68 | if (Modifier.isFinal(f.getModifiers()) && Modifier.isStatic(f.getModifiers()) &&
69 | Modifier.isPublic(f.getModifiers())) {
70 | String name = f.getName();
71 | try {
72 | Object value = f.get(null);
73 | this.map.put(name, value);
74 | }
75 | catch (IllegalAccessException ex) {
76 | // just leave this field and continue
77 | }
78 | }
79 | }
80 | }
81 |
82 | /**
83 | * Return the number of constants exposed.
84 | * @return int the number of constants exposed
85 | */
86 | public int getSize() {
87 | return this.map.size();
88 | }
89 |
90 | /**
91 | * Return a constant value cast to a Number.
92 | * @param code name of the field
93 | * @return long value if successful
94 | * @see #asObject
95 | * @throws ConstantException if the field name wasn't found or
96 | * if the type wasn't compatible with Number
97 | */
98 | public Number asNumber(String code) throws ConstantException {
99 | Object o = asObject(code);
100 | if (!(o instanceof Number))
101 | throw new ConstantException(this.clazz, code, "not a Number");
102 | return (Number) o;
103 | }
104 |
105 | /**
106 | * Return a constant value as a String.
107 | * @param code name of the field
108 | * @return String string value if successful.
109 | * Works even if it's not a string (invokes toString()).
110 | * @see #asObject
111 | * @throws ConstantException if the field name wasn't found
112 | */
113 | public String asString(String code) throws ConstantException {
114 | return asObject(code).toString();
115 | }
116 |
117 | /**
118 | * Parse the given string (upper or lower case accepted) and return
119 | * the appropriate value if it's the name of a constant field in the
120 | * class we're analysing.
121 | * @throws ConstantException if there's no such field
122 | */
123 | public Object asObject(String code) throws ConstantException {
124 | code = code.toUpperCase();
125 | Object val = this.map.get(code);
126 | if (val == null) {
127 | throw new ConstantException(this.clazz, code, "not found");
128 | }
129 | return val;
130 | }
131 |
132 | /**
133 | * Return all values of the given group of constants.
134 | * @param namePrefix prefix of the constant names to search
135 | * @return the set of values
136 | */
137 | public Set