Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ApplicationContextBinder |
|
| 0.0;0 |
1 | /* | |
2 | * Copyright 2004-2008 the Seasar Foundation and the Others. | |
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, | |
13 | * either express or implied. See the License for the specific language | |
14 | * governing permissions and limitations under the License. | |
15 | */ | |
16 | package org.seasar.uruma.binding.context; | |
17 | ||
18 | import java.util.List; | |
19 | ||
20 | import org.seasar.framework.beans.PropertyDesc; | |
21 | import org.seasar.uruma.context.ApplicationContext; | |
22 | import org.seasar.uruma.core.UrumaMessageCodes; | |
23 | import org.seasar.uruma.log.UrumaLogger; | |
24 | ||
25 | /** | |
26 | * 任意のオブジェクトと {@link ApplicationContext} の間でバインディングを行うためのクラスです。<br /> | |
27 | * | |
28 | * @author y-komori | |
29 | */ | |
30 | public class ApplicationContextBinder { | |
31 | 4 | private static final UrumaLogger logger = UrumaLogger |
32 | .getLogger(ApplicationContextBinder.class); | |
33 | ||
34 | 0 | private ApplicationContextBinder() { |
35 | ||
36 | 0 | } |
37 | ||
38 | /** | |
39 | * プロパティから {@link ApplicationContext} へ値をバインドします。<br /> | |
40 | * 対象となるプロパティは、<code>defs</code> で指定される {@link ApplicationContextDef} | |
41 | * のリストです。<br /> | |
42 | * | |
43 | * @param target | |
44 | * ターゲットオブジェクト | |
45 | * @param defs | |
46 | * {@link ApplicationContextDef} のリスト | |
47 | * @param context | |
48 | * {@link ApplicationContext} オブジェクト | |
49 | */ | |
50 | public static void exportObjects(final Object target, | |
51 | final List<ApplicationContextDef> defs, | |
52 | final ApplicationContext context) { | |
53 | 112 | for (ApplicationContextDef def : defs) { |
54 | 0 | PropertyDesc pd = def.getPropertyDesc(); |
55 | 0 | String name = def.getName(); |
56 | 0 | Object value = pd.getValue(target); |
57 | ||
58 | 0 | if (logger.isDebugEnabled()) { |
59 | 0 | logger.log(UrumaMessageCodes.EXPORT_APPLICATION_CONTEXT, |
60 | UrumaLogger.getObjectDescription(target), pd | |
61 | .getPropertyName(), name, value); | |
62 | } | |
63 | 0 | context.setValue(name, value); |
64 | 0 | } |
65 | 112 | } |
66 | ||
67 | /** | |
68 | * {@link ApplicationContext} からプロパティへ値をバインドします。<br /> | |
69 | * 対象となるプロパティは、<code>defs</code> で指定される {@link ApplicationContextDef} | |
70 | * のリストです。<br /> | |
71 | * | |
72 | * @param target | |
73 | * ターゲットオブジェクト | |
74 | * @param defs | |
75 | * {@link ApplicationContextDef} のリスト | |
76 | * @param context | |
77 | * {@link ApplicationContext} オブジェクト | |
78 | */ | |
79 | public static void importObjects(final Object target, | |
80 | final List<ApplicationContextDef> defs, | |
81 | final ApplicationContext context) { | |
82 | 224 | for (ApplicationContextDef def : defs) { |
83 | 0 | PropertyDesc pd = def.getPropertyDesc(); |
84 | 0 | String name = def.getName(); |
85 | 0 | Object value = context.getValue(name); |
86 | ||
87 | 0 | if (logger.isDebugEnabled()) { |
88 | 0 | logger.log(UrumaMessageCodes.IMPORT_APPLICATION_CONTEXT, |
89 | UrumaLogger.getObjectDescription(target), pd | |
90 | .getPropertyName(), name, value); | |
91 | } | |
92 | ||
93 | 0 | pd.setValue(target, value); |
94 | 0 | } |
95 | 224 | } |
96 | } |