s2container 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Apache_Software_License_2.0.txt +202 -0
- data/ChangeLog +1 -0
- data/ChangeLog.ja +64 -0
- data/README +9 -0
- data/Rakefile +51 -0
- data/example/example01/example.rb +13 -0
- data/example/example01/run.rb +20 -0
- data/example/example02/example.rb +30 -0
- data/example/example02/run.rb +8 -0
- data/example/example03/example.rb +8 -0
- data/example/example03/run.rb +12 -0
- data/example/example04/example.rb +9 -0
- data/example/example04/run.rb +15 -0
- data/example/example05/example.rb +9 -0
- data/example/example05/run.rb +21 -0
- data/example/example06/example.rb +9 -0
- data/example/example06/run.rb +8 -0
- data/example/example07/example.rb +8 -0
- data/example/example07/run.rb +15 -0
- data/example/example08/example.rb +9 -0
- data/example/example08/run.rb +19 -0
- data/example/example09/example.rb +7 -0
- data/example/example09/run.rb +11 -0
- data/example/example10/example.rb +9 -0
- data/example/example10/run.rb +10 -0
- data/example/example11/example.rb +18 -0
- data/example/example11/run.rb +10 -0
- data/example/example12/example.rb +9 -0
- data/example/example12/run.rb +8 -0
- data/example/example13/example.rb +18 -0
- data/example/example13/example.sql +4 -0
- data/example/example13/run.rb +22 -0
- data/example/example13/sample.db +0 -0
- data/example/example14/example.db +0 -0
- data/example/example14/example.rb +57 -0
- data/example/example14/example.sql +50 -0
- data/example/example14/run1.rb +23 -0
- data/example/example14/run2.rb +28 -0
- data/example/example14/run3.rb +25 -0
- data/example/example14/run4.rb +23 -0
- data/example/example14/run5.rb +35 -0
- data/example/example15/example.rb +20 -0
- data/example/example15/run.rb +28 -0
- data/example/example16/example.rb +15 -0
- data/example/example16/run.rb +24 -0
- data/example/quickstart/quickstart1/quickstart.rb +10 -0
- data/example/quickstart/quickstart2/quickstart.rb +9 -0
- data/example/quickstart/quickstart3/quickstart.rb +9 -0
- data/example/quickstart/quickstart4/quickstart.rb +14 -0
- data/example/quickstart/quickstart5/quickstart.rb +21 -0
- data/example/quickstart/quickstart6/quickstart.rb +28 -0
- data/example/quickstart/quickstart7/quickstart.rb +18 -0
- data/lib/s2container.rb +25 -0
- data/lib/seasar/aop/aspect.rb +30 -0
- data/lib/seasar/aop/interceptor/trace-interceptor.rb +48 -0
- data/lib/seasar/aop/method-invocation.rb +57 -0
- data/lib/seasar/aop/pointcut.rb +53 -0
- data/lib/seasar/aop/s2aop-factory.rb +125 -0
- data/lib/seasar/aop.rb +29 -0
- data/lib/seasar/beans/abstract-property-desc.rb +59 -0
- data/lib/seasar/beans/attribute-accessor-desc.rb +60 -0
- data/lib/seasar/beans/bean-desc-factory.rb +68 -0
- data/lib/seasar/beans/bean-desc.rb +232 -0
- data/lib/seasar/beans/instance-variable-desc.rb +58 -0
- data/lib/seasar/beans.rb +29 -0
- data/lib/seasar/container/arg-def.rb +51 -0
- data/lib/seasar/container/aspect-def.rb +60 -0
- data/lib/seasar/container/aspect-info-def.rb +94 -0
- data/lib/seasar/container/assembler/abstract-assembler.rb +68 -0
- data/lib/seasar/container/assembler/auto-property-assembler.rb +57 -0
- data/lib/seasar/container/assembler/autobinding-auto-def.rb +55 -0
- data/lib/seasar/container/assembler/autobinding-def-factory.rb +57 -0
- data/lib/seasar/container/assembler/autobinding-none-def.rb +53 -0
- data/lib/seasar/container/assembler/manual-constructor-assembler.rb +67 -0
- data/lib/seasar/container/assembler/manual-property-assembler.rb +68 -0
- data/lib/seasar/container/autobinding-def.rb +36 -0
- data/lib/seasar/container/component-def.rb +229 -0
- data/lib/seasar/container/component-info-def.rb +117 -0
- data/lib/seasar/container/deployer/abstract-component-deployer.rb +47 -0
- data/lib/seasar/container/deployer/instance-def-factory.rb +56 -0
- data/lib/seasar/container/deployer/instance-outer-def.rb +44 -0
- data/lib/seasar/container/deployer/instance-prototype-def.rb +44 -0
- data/lib/seasar/container/deployer/instance-singleton-def.rb +42 -0
- data/lib/seasar/container/deployer/outer-component-deployer.rb +47 -0
- data/lib/seasar/container/deployer/prototype-component-deployer.rb +51 -0
- data/lib/seasar/container/deployer/singleton-component-deployer.rb +54 -0
- data/lib/seasar/container/exception/component-notfound-runtime-exception.rb +44 -0
- data/lib/seasar/container/exception/cyclic-reference-runtime-exception.rb +43 -0
- data/lib/seasar/container/exception/illegal-autobinding-def-runtime-exception.rb +43 -0
- data/lib/seasar/container/exception/illegal-instance-def-runtime-exception.rb +44 -0
- data/lib/seasar/container/exception/toomany-registration-runtime-exception.rb +46 -0
- data/lib/seasar/container/instance-def.rb +37 -0
- data/lib/seasar/container/outer-component-def.rb +34 -0
- data/lib/seasar/container/property-def.rb +43 -0
- data/lib/seasar/container/s2application-context.rb +447 -0
- data/lib/seasar/container/s2container-component-def.rb +41 -0
- data/lib/seasar/container/s2container.rb +308 -0
- data/lib/seasar/container/simple-component-def.rb +45 -0
- data/lib/seasar/container/toomany-registration-component-def.rb +69 -0
- data/lib/seasar/container.rb +143 -0
- data/lib/seasar/dbi/dbi-interceptor.rb +97 -0
- data/lib/seasar/dbi/paginate.rb +215 -0
- data/lib/seasar/dbi.rb +26 -0
- data/lib/seasar/exception/notyet-implemented-exception.rb +25 -0
- data/lib/seasar/exception/property-notfound-runtime-exception.rb +48 -0
- data/lib/seasar/exception/s2runtime-exception.rb +35 -0
- data/lib/seasar/exception/unsupported-operation-exception.rb +25 -0
- data/lib/seasar/exception.rb +27 -0
- data/lib/seasar/log/s2logger.rb +75 -0
- data/lib/seasar/log.rb +38 -0
- data/lib/seasar/util/class-util.rb +116 -0
- data/lib/seasar/util.rb +24 -0
- data/setup.rb +1585 -0
- data/test/seasar/aop/test_pointcut.rb +25 -0
- data/test/seasar/aop/test_s2aop_factory.rb +90 -0
- data/test/seasar/beans/test_bean-desc.rb +179 -0
- data/test/seasar/container/assembler/test_auto_property_assembler.rb +87 -0
- data/test/seasar/container/assembler/test_autobinding_def_factory.rb +22 -0
- data/test/seasar/container/assembler/test_manual_property_assembler.rb +59 -0
- data/test/seasar/container/assembler/test_manula_constructor_assembler.rb +59 -0
- data/test/seasar/container/assembler/test_proc_constructor_assembler.rb +61 -0
- data/test/seasar/container/deployer/test_instance_def_factory.rb +24 -0
- data/test/seasar/container/deployer/test_prototype-deployer.rb +25 -0
- data/test/seasar/container/deployer/test_singleton-component-deployer.rb +24 -0
- data/test/seasar/container/s2app_load_sample.rb +6 -0
- data/test/seasar/container/test_arg-def.rb +34 -0
- data/test/seasar/container/test_aspect-info-def.rb +85 -0
- data/test/seasar/container/test_component-def.rb +91 -0
- data/test/seasar/container/test_component-info-def.rb +88 -0
- data/test/seasar/container/test_s2application-context.rb +290 -0
- data/test/seasar/container/test_s2container.rb +268 -0
- data/test/seasar/dbi/test_paginate.rb +265 -0
- data/test/seasar/test_log.rb +20 -0
- data/test/seasar/test_util.rb +46 -0
- data/test/test-suite.rb +7 -0
- metadata +211 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#--
|
3
|
+
# +----------------------------------------------------------------------+
|
4
|
+
# | Copyright 2005-2008 the Seasar Foundation and the Others. |
|
5
|
+
# +----------------------------------------------------------------------+
|
6
|
+
# | Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
+
# | you may not use this file except in compliance with the License. |
|
8
|
+
# | You may obtain a copy of the License at |
|
9
|
+
# | |
|
10
|
+
# | http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
+
# | |
|
12
|
+
# | Unless required by applicable law or agreed to in writing, software |
|
13
|
+
# | distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
+
# | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
15
|
+
# | either express or implied. See the License for the specific language |
|
16
|
+
# | governing permissions and limitations under the License. |
|
17
|
+
# +----------------------------------------------------------------------+
|
18
|
+
#++
|
19
|
+
|
20
|
+
module Seasar
|
21
|
+
module Beans
|
22
|
+
# Publicな属性の定義を行うクラスです。
|
23
|
+
class InstanceVariableDesc < AbstractPropertyDesc
|
24
|
+
|
25
|
+
# InstanceVariableDescを構築します。
|
26
|
+
#
|
27
|
+
# - args
|
28
|
+
# 1. Symbol <em>prop_name</em>
|
29
|
+
#
|
30
|
+
def initialize(prop_name)
|
31
|
+
super
|
32
|
+
end
|
33
|
+
|
34
|
+
# プロパティ値をセットするメソッドです。
|
35
|
+
#
|
36
|
+
# - args
|
37
|
+
# 1. Object <em>instance</em>
|
38
|
+
# 2. mixed <em>value</em>
|
39
|
+
# - return
|
40
|
+
# - nil
|
41
|
+
#
|
42
|
+
def set_value(instance, value)
|
43
|
+
instance.instance_variable_set(@property_name, value)
|
44
|
+
end
|
45
|
+
|
46
|
+
# プロパティ値を返します。
|
47
|
+
#
|
48
|
+
# - args
|
49
|
+
# 1. Object <em>instance</em>
|
50
|
+
# - return
|
51
|
+
# - mixed
|
52
|
+
#
|
53
|
+
def get_value(instance)
|
54
|
+
return instance.instance_variable_get(@property_name)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/seasar/beans.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#--
|
3
|
+
# +----------------------------------------------------------------------+
|
4
|
+
# | Copyright 2005-2008 the Seasar Foundation and the Others. |
|
5
|
+
# +----------------------------------------------------------------------+
|
6
|
+
# | Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
+
# | you may not use this file except in compliance with the License. |
|
8
|
+
# | You may obtain a copy of the License at |
|
9
|
+
# | |
|
10
|
+
# | http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
+
# | |
|
12
|
+
# | Unless required by applicable law or agreed to in writing, software |
|
13
|
+
# | distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
+
# | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
15
|
+
# | either express or implied. See the License for the specific language |
|
16
|
+
# | governing permissions and limitations under the License. |
|
17
|
+
# +----------------------------------------------------------------------+
|
18
|
+
#++
|
19
|
+
|
20
|
+
module Seasar
|
21
|
+
module Beans
|
22
|
+
autoload :AbstractPropertyDesc, 'seasar/beans/abstract-property-desc'
|
23
|
+
autoload :InstanceVariableDesc, 'seasar/beans/instance-variable-desc'
|
24
|
+
autoload :AttributeAccessorDesc, 'seasar/beans/attribute-accessor-desc'
|
25
|
+
autoload :BeanDescFactory, 'seasar/beans/bean-desc-factory'
|
26
|
+
autoload :BeanDesc, 'seasar/beans/bean-desc'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#--
|
3
|
+
# +----------------------------------------------------------------------+
|
4
|
+
# | Copyright 2005-2008 the Seasar Foundation and the Others. |
|
5
|
+
# +----------------------------------------------------------------------+
|
6
|
+
# | Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
+
# | you may not use this file except in compliance with the License. |
|
8
|
+
# | You may obtain a copy of the License at |
|
9
|
+
# | |
|
10
|
+
# | http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
+
# | |
|
12
|
+
# | Unless required by applicable law or agreed to in writing, software |
|
13
|
+
# | distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
+
# | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
15
|
+
# | either express or implied. See the License for the specific language |
|
16
|
+
# | governing permissions and limitations under the License. |
|
17
|
+
# +----------------------------------------------------------------------+
|
18
|
+
#++
|
19
|
+
module Seasar
|
20
|
+
module Container
|
21
|
+
class ArgDef
|
22
|
+
|
23
|
+
# - args
|
24
|
+
# 1. Object <em>value</em>
|
25
|
+
#
|
26
|
+
def initialize(value = nil)
|
27
|
+
@value = value
|
28
|
+
@expressioin = nil
|
29
|
+
@child_component_def = nil
|
30
|
+
@container = nil
|
31
|
+
end
|
32
|
+
attr_accessor :container, :expression, :child_component_def, :value
|
33
|
+
|
34
|
+
#
|
35
|
+
# - args
|
36
|
+
# - none
|
37
|
+
# - return
|
38
|
+
# - Object
|
39
|
+
#
|
40
|
+
def value
|
41
|
+
if @child_component_def.is_a?(ComponentDef)
|
42
|
+
return @child_component_def.get_component
|
43
|
+
elsif @expression.is_a?(String)
|
44
|
+
return eval(@expression)
|
45
|
+
else
|
46
|
+
return @value
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#--
|
3
|
+
# +----------------------------------------------------------------------+
|
4
|
+
# | Copyright 2005-2008 the Seasar Foundation and the Others. |
|
5
|
+
# +----------------------------------------------------------------------+
|
6
|
+
# | Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
+
# | you may not use this file except in compliance with the License. |
|
8
|
+
# | You may obtain a copy of the License at |
|
9
|
+
# | |
|
10
|
+
# | http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
+
# | |
|
12
|
+
# | Unless required by applicable law or agreed to in writing, software |
|
13
|
+
# | distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
+
# | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
15
|
+
# | either express or implied. See the License for the specific language |
|
16
|
+
# | governing permissions and limitations under the License. |
|
17
|
+
# +----------------------------------------------------------------------+
|
18
|
+
#++
|
19
|
+
|
20
|
+
module Seasar
|
21
|
+
module Container
|
22
|
+
class AspectDef < ArgDef
|
23
|
+
|
24
|
+
# - args
|
25
|
+
# 1. Regexp <em>pointcut</em>
|
26
|
+
# 2. Object <em>interceptor</em>
|
27
|
+
# 3. Proc <em>procedure</em>
|
28
|
+
#
|
29
|
+
def initialize(pointcut, interceptor = nil, &procedure)
|
30
|
+
if interceptor.nil? and procedure
|
31
|
+
interceptor = procedure
|
32
|
+
end
|
33
|
+
super(interceptor)
|
34
|
+
@pointcut = Seasar::Aop::Pointcut.new(pointcut)
|
35
|
+
end
|
36
|
+
attr_accessor :pointcut
|
37
|
+
|
38
|
+
#
|
39
|
+
# - args
|
40
|
+
# - none
|
41
|
+
# - return
|
42
|
+
# - Seasar::Aop::Aspect
|
43
|
+
#
|
44
|
+
def aspect
|
45
|
+
return Seasar::Aop::Aspect.new(self.value, self.pointcut)
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# - args
|
50
|
+
# 1. Object <em>interceptor</em>
|
51
|
+
# - return
|
52
|
+
# - none
|
53
|
+
#
|
54
|
+
def value=(interceptor)
|
55
|
+
raise ArgumentError.new("call method not defined on [#{interceptor} (#{interceptor.class})].") if not interceptor.class.method_defined?(:call)
|
56
|
+
super
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#--
|
3
|
+
# +----------------------------------------------------------------------+
|
4
|
+
# | Copyright 2005-2008 the Seasar Foundation and the Others. |
|
5
|
+
# +----------------------------------------------------------------------+
|
6
|
+
# | Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
+
# | you may not use this file except in compliance with the License. |
|
8
|
+
# | You may obtain a copy of the License at |
|
9
|
+
# | |
|
10
|
+
# | http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
+
# | |
|
12
|
+
# | Unless required by applicable law or agreed to in writing, software |
|
13
|
+
# | distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
+
# | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
15
|
+
# | either express or implied. See the License for the specific language |
|
16
|
+
# | governing permissions and limitations under the License. |
|
17
|
+
# +----------------------------------------------------------------------+
|
18
|
+
#++
|
19
|
+
module Seasar
|
20
|
+
module Container
|
21
|
+
class AspectInfoDef
|
22
|
+
|
23
|
+
attr_accessor :interceptor, :pattern, :pointcut, :condition
|
24
|
+
|
25
|
+
# - args
|
26
|
+
# 1. Hash <em>options</em>
|
27
|
+
def initialize(options)
|
28
|
+
if options[:interceptor].nil?
|
29
|
+
raise ArgumentError.new("interceptor not specified.")
|
30
|
+
end
|
31
|
+
@interceptor = options[:interceptor]
|
32
|
+
|
33
|
+
if options[:pattern].nil?
|
34
|
+
@pattern = /interceptor/i
|
35
|
+
@condition = false
|
36
|
+
else
|
37
|
+
@pattern = options[:pattern]
|
38
|
+
@condition = options[:condition].nil? ? true : options[:condition]
|
39
|
+
end
|
40
|
+
|
41
|
+
@pointcut = options[:pointcut].nil? ? /.+/ : options[:pointcut]
|
42
|
+
|
43
|
+
self.setup_matcher
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# - args
|
48
|
+
# - none
|
49
|
+
# - return
|
50
|
+
# - none
|
51
|
+
#
|
52
|
+
def setup_matcher
|
53
|
+
case
|
54
|
+
when @pattern.is_a?(Regexp)
|
55
|
+
@matcher = lambda {|component_def|
|
56
|
+
result = false
|
57
|
+
if @pattern.match(component_def.component_name.to_s)
|
58
|
+
result = true
|
59
|
+
end
|
60
|
+
if @pattern.match(component_def.component_class.name)
|
61
|
+
result = true
|
62
|
+
end
|
63
|
+
result
|
64
|
+
}
|
65
|
+
when @pattern.is_a?(Class)
|
66
|
+
@matcher = lambda {|component_def| component_def.component_class == @pattern }
|
67
|
+
when @pattern.is_a?(Module)
|
68
|
+
@matcher = lambda {|component_def| component_def.component_class.name.match(/^#{@pattern.name}::/) }
|
69
|
+
when @pattern.is_a?(String)
|
70
|
+
@matcher = lambda {|component_def| @pattern == component_def.component_name or @pattern == component_def.component_class.name }
|
71
|
+
when @pattern.is_a?(Symbol)
|
72
|
+
@matcher = lambda {|component_def| @pattern == component_def.component_name or @pattern == component_def.component_class.name.to_sym }
|
73
|
+
else
|
74
|
+
raise ArgumentError.new("unsupported pattern class #{@pattern}")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# - args
|
80
|
+
# 1. Seasar::Container::ComponentDef <em>component_def</em>
|
81
|
+
# - return
|
82
|
+
# - Boolean
|
83
|
+
#
|
84
|
+
def applicable?(component_def)
|
85
|
+
result = @matcher.call(component_def)
|
86
|
+
if @condition
|
87
|
+
return result
|
88
|
+
else
|
89
|
+
return !result
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#--
|
3
|
+
# +----------------------------------------------------------------------+
|
4
|
+
# | Copyright 2005-2008 the Seasar Foundation and the Others. |
|
5
|
+
# +----------------------------------------------------------------------+
|
6
|
+
# | Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
+
# | you may not use this file except in compliance with the License. |
|
8
|
+
# | You may obtain a copy of the License at |
|
9
|
+
# | |
|
10
|
+
# | http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
+
# | |
|
12
|
+
# | Unless required by applicable law or agreed to in writing, software |
|
13
|
+
# | distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
+
# | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
15
|
+
# | either express or implied. See the License for the specific language |
|
16
|
+
# | governing permissions and limitations under the License. |
|
17
|
+
# +----------------------------------------------------------------------+
|
18
|
+
#++
|
19
|
+
|
20
|
+
module Seasar
|
21
|
+
module Container
|
22
|
+
module Assembler
|
23
|
+
# コンポーネントを構築する(アセンブルする)抽象クラスです。
|
24
|
+
class AbstractAssembler
|
25
|
+
|
26
|
+
# AbstractAssemblerを構築します。
|
27
|
+
# - args
|
28
|
+
# 1. Seasar::Container::ComponentDefSymbol <em>component_def</em>
|
29
|
+
def initialize(component_def)
|
30
|
+
@component_def = component_def
|
31
|
+
end
|
32
|
+
|
33
|
+
# AutoConstructorAssemblerとAutoPropertyAssemblerでタイプヒントされたコンポーネントを取得する際に
|
34
|
+
# 呼び出される。
|
35
|
+
# @param string component_key
|
36
|
+
# @param boolean is_array_acceptable
|
37
|
+
# @return mixed
|
38
|
+
#
|
39
|
+
# - args
|
40
|
+
# 1. String|Symbol <em>component_key</em>
|
41
|
+
# 2. Boolean <em>is_array_acceptable</em>
|
42
|
+
# - return
|
43
|
+
# - Object
|
44
|
+
#
|
45
|
+
def get_argument(component_key, is_array_acceptable = False)
|
46
|
+
value = nil
|
47
|
+
begin
|
48
|
+
s2logger.fatal(self){ 'aaa ' + component_key.to_s}
|
49
|
+
value = @component_def.container.get_component(component_key)
|
50
|
+
rescue Seasar::Container::Exception::TooManyRegistrationRuntimeException => e
|
51
|
+
if is_array_acceptable
|
52
|
+
child_component_defs = @component_def.container.get_component_def(component_key).component_defs
|
53
|
+
value = []
|
54
|
+
for child_component_def in child_component_defs
|
55
|
+
value << child_component_def.component
|
56
|
+
end
|
57
|
+
else
|
58
|
+
raise e
|
59
|
+
end
|
60
|
+
rescue Seasar::Container::Exception::ComponentNotFoundRuntimeException => e
|
61
|
+
s2logger.debug(self.class.name) {"no component found for key #{component_key}"}
|
62
|
+
end
|
63
|
+
return value
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#--
|
3
|
+
# +----------------------------------------------------------------------+
|
4
|
+
# | Copyright 2005-2008 the Seasar Foundation and the Others. |
|
5
|
+
# +----------------------------------------------------------------------+
|
6
|
+
# | Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
+
# | you may not use this file except in compliance with the License. |
|
8
|
+
# | You may obtain a copy of the License at |
|
9
|
+
# | |
|
10
|
+
# | http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
+
# | |
|
12
|
+
# | Unless required by applicable law or agreed to in writing, software |
|
13
|
+
# | distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
+
# | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
15
|
+
# | either express or implied. See the License for the specific language |
|
16
|
+
# | governing permissions and limitations under the License. |
|
17
|
+
# +----------------------------------------------------------------------+
|
18
|
+
#++
|
19
|
+
module Seasar
|
20
|
+
module Container
|
21
|
+
module Assembler
|
22
|
+
# 自動インジェクションでプロパティを設定するアセンブラです。
|
23
|
+
class AutoPropertyAssembler < ManualPropertyAssembler
|
24
|
+
|
25
|
+
# AutoPropertyAssemblerを構築します。
|
26
|
+
# @param Seasar::Container::ComponentDef component_def
|
27
|
+
# - args
|
28
|
+
# 1. Seasar::Container::ComponentDef <em>component_def</em>
|
29
|
+
def initialize(component_def)
|
30
|
+
super
|
31
|
+
end
|
32
|
+
|
33
|
+
# 自動プロパティインジェクションを実施します。
|
34
|
+
# @param instance component
|
35
|
+
# - args
|
36
|
+
# 1. Object <em>component</em>
|
37
|
+
# - return
|
38
|
+
# - none
|
39
|
+
#
|
40
|
+
def assemble(component)
|
41
|
+
super
|
42
|
+
bean_desc = Seasar::Beans::BeanDescFactory.get_bean_desc(component)
|
43
|
+
bean_desc.typehint_property_descs.each {|property_name, prop_desc|
|
44
|
+
if @component_def.has_property_def(prop_desc.property_name)
|
45
|
+
next
|
46
|
+
end
|
47
|
+
value = self.get_argument(prop_desc.typehint, prop_desc.array_acceptable)
|
48
|
+
if not value.nil?
|
49
|
+
prop_desc.set_value(component, value)
|
50
|
+
end
|
51
|
+
}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#--
|
3
|
+
# +----------------------------------------------------------------------+
|
4
|
+
# | Copyright 2005-2008 the Seasar Foundation and the Others. |
|
5
|
+
# +----------------------------------------------------------------------+
|
6
|
+
# | Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
+
# | you may not use this file except in compliance with the License. |
|
8
|
+
# | You may obtain a copy of the License at |
|
9
|
+
# | |
|
10
|
+
# | http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
+
# | |
|
12
|
+
# | Unless required by applicable law or agreed to in writing, software |
|
13
|
+
# | distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
+
# | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
15
|
+
# | either express or implied. See the License for the specific language |
|
16
|
+
# | governing permissions and limitations under the License. |
|
17
|
+
# +----------------------------------------------------------------------+
|
18
|
+
#++
|
19
|
+
module Seasar
|
20
|
+
module Container
|
21
|
+
module Assembler
|
22
|
+
# 自動バインディング設定のオートを表すクラスです。
|
23
|
+
class AutoBindingAutoDef < Seasar::Container::AutoBindingDef
|
24
|
+
# AutoBindingAutoDefを構築します。
|
25
|
+
# - args
|
26
|
+
# 1. Symbol <em>name</em>
|
27
|
+
def initialize(name)
|
28
|
+
@name = name
|
29
|
+
end
|
30
|
+
|
31
|
+
# AutoConstructorAssemblerを生成します。
|
32
|
+
#
|
33
|
+
# - args
|
34
|
+
# 1. Seasar::Container::ComponentDef <em>component_def</em>
|
35
|
+
# - return
|
36
|
+
# - Seasar::Container::Assembler::ManualConstructorAssembler
|
37
|
+
#
|
38
|
+
def create_constructor_assembler(component_def)
|
39
|
+
return ManualConstructorAssembler.new(component_def)
|
40
|
+
end
|
41
|
+
|
42
|
+
# AutoPropertyAssemblerを生成します。
|
43
|
+
# - args
|
44
|
+
# 1. Seasar::Container::ComponentDef <em>component_def</em>
|
45
|
+
# - return
|
46
|
+
# - Seasar::Container::Assembler::AutoPropertyAssembler
|
47
|
+
#
|
48
|
+
def create_property_assembler(component_def)
|
49
|
+
return AutoPropertyAssembler.new(component_def)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#--
|
3
|
+
# +----------------------------------------------------------------------+
|
4
|
+
# | Copyright 2005-2008 the Seasar Foundation and the Others. |
|
5
|
+
# +----------------------------------------------------------------------+
|
6
|
+
# | Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
+
# | you may not use this file except in compliance with the License. |
|
8
|
+
# | You may obtain a copy of the License at |
|
9
|
+
# | |
|
10
|
+
# | http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
+
# | |
|
12
|
+
# | Unless required by applicable law or agreed to in writing, software |
|
13
|
+
# | distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
+
# | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
15
|
+
# | either express or implied. See the License for the specific language |
|
16
|
+
# | governing permissions and limitations under the License. |
|
17
|
+
# +----------------------------------------------------------------------+
|
18
|
+
#++
|
19
|
+
module Seasar
|
20
|
+
module Container
|
21
|
+
module Assembler
|
22
|
+
|
23
|
+
# 自動バインディング設定を生成するファクトリクラスです。
|
24
|
+
class AutoBindingDefFactory
|
25
|
+
@@auto_binding_defs = {}
|
26
|
+
|
27
|
+
# 自動バインディング設定を追加します。
|
28
|
+
#
|
29
|
+
# - args
|
30
|
+
# 1. Seasar::Container::AutoBindingDef <em>auto_binding_def</em>
|
31
|
+
# - return
|
32
|
+
# - none
|
33
|
+
#
|
34
|
+
def AutoBindingDefFactory.add_autobinding_def(auto_binding_def)
|
35
|
+
@@auto_binding_defs[auto_binding_def.name] = auto_binding_def
|
36
|
+
end
|
37
|
+
|
38
|
+
# 自動バインディング設定を返します。
|
39
|
+
# - args
|
40
|
+
# 1. Symbol <em>name</em>
|
41
|
+
# - return
|
42
|
+
# - Seasar::Container::AutoBindingDef
|
43
|
+
#
|
44
|
+
def AutoBindingDefFactory.get_autobinding_def(name)
|
45
|
+
if not @@auto_binding_defs.key?(name)
|
46
|
+
raise Seasar::Container::Exception::IllegalAutoBindingDefRuntimeException.new(name)
|
47
|
+
end
|
48
|
+
return @@auto_binding_defs[name]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
#デフォルトの自動バインディング設定をファクトリクラスに登録します。
|
53
|
+
AutoBindingDefFactory.add_autobinding_def(AutoBindingAutoDef.new(Seasar::Container::AutoBindingDef::AUTO_NAME))
|
54
|
+
AutoBindingDefFactory.add_autobinding_def(AutoBindingNoneDef.new(Seasar::Container::AutoBindingDef::NONE_NAME))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#--
|
3
|
+
# +----------------------------------------------------------------------+
|
4
|
+
# | Copyright 2005-2008 the Seasar Foundation and the Others. |
|
5
|
+
# +----------------------------------------------------------------------+
|
6
|
+
# | Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
+
# | you may not use this file except in compliance with the License. |
|
8
|
+
# | You may obtain a copy of the License at |
|
9
|
+
# | |
|
10
|
+
# | http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
+
# | |
|
12
|
+
# | Unless required by applicable law or agreed to in writing, software |
|
13
|
+
# | distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
+
# | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
15
|
+
# | either express or implied. See the License for the specific language |
|
16
|
+
# | governing permissions and limitations under the License. |
|
17
|
+
# +----------------------------------------------------------------------+
|
18
|
+
#++
|
19
|
+
module Seasar
|
20
|
+
module Container
|
21
|
+
module Assembler
|
22
|
+
# 自動バインディング設定の設定無しを表すクラスです。
|
23
|
+
class AutoBindingNoneDef < Seasar::Container::AutoBindingDef
|
24
|
+
# AutoBindingNoneDefを構築します。
|
25
|
+
# - args
|
26
|
+
# 1. Symbol <em>name</em>
|
27
|
+
def initialize(name)
|
28
|
+
@name = name
|
29
|
+
end
|
30
|
+
|
31
|
+
# ManualConstructorAssemblerを生成します。
|
32
|
+
# - args
|
33
|
+
# 1. Seasar::Container::ComponentDef <em>component_def</em>
|
34
|
+
# - return
|
35
|
+
# - Seasar::Container::Assembler::ManualConstructorAssembler
|
36
|
+
#
|
37
|
+
def create_constructor_assembler(component_def)
|
38
|
+
return ManualConstructorAssembler.new(component_def)
|
39
|
+
end
|
40
|
+
|
41
|
+
# ManualPropertyAssemblerを生成します。
|
42
|
+
# - args
|
43
|
+
# 1. Seasar::Container::ComponentDef <em>component_def</em>
|
44
|
+
# - return
|
45
|
+
# - Seasar::Container::Assembler::ManualPropertyAssembler
|
46
|
+
#
|
47
|
+
def create_property_assembler(component_def)
|
48
|
+
return ManualPropertyAssembler.new(component_def)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#--
|
3
|
+
# +----------------------------------------------------------------------+
|
4
|
+
# | Copyright 2005-2008 the Seasar Foundation and the Others. |
|
5
|
+
# +----------------------------------------------------------------------+
|
6
|
+
# | Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
+
# | you may not use this file except in compliance with the License. |
|
8
|
+
# | You may obtain a copy of the License at |
|
9
|
+
# | |
|
10
|
+
# | http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
+
# | |
|
12
|
+
# | Unless required by applicable law or agreed to in writing, software |
|
13
|
+
# | distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
+
# | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
15
|
+
# | either express or implied. See the License for the specific language |
|
16
|
+
# | governing permissions and limitations under the License. |
|
17
|
+
# +----------------------------------------------------------------------+
|
18
|
+
#++
|
19
|
+
module Seasar
|
20
|
+
module Container
|
21
|
+
module Assembler
|
22
|
+
|
23
|
+
# コンストラクタをマニュアルインジェクションで構築するアセンブラです。
|
24
|
+
class ManualConstructorAssembler < AbstractAssembler
|
25
|
+
|
26
|
+
# ManualConstructorAssemblerを構築します。
|
27
|
+
# - args
|
28
|
+
# 1. Seasar::Container::ComponentDef <em>component_def</em>
|
29
|
+
def initialize(component_def)
|
30
|
+
super
|
31
|
+
end
|
32
|
+
|
33
|
+
# コンストラクタをマニュアルインジェクションで構築します。
|
34
|
+
# - args
|
35
|
+
# - none
|
36
|
+
# - return
|
37
|
+
# - none
|
38
|
+
def assemble
|
39
|
+
args = []
|
40
|
+
for arg_def in @component_def.get_arg_defs
|
41
|
+
args << arg_def.value
|
42
|
+
end
|
43
|
+
|
44
|
+
procedure = nil
|
45
|
+
if @component_def.onetime_proc.is_a?(Proc)
|
46
|
+
procedure = @component_def.onetime_proc
|
47
|
+
@component_def.onetime_proc = nil
|
48
|
+
elsif @component_def.procedure.is_a?(Proc)
|
49
|
+
procedure = @component_def.procedure
|
50
|
+
end
|
51
|
+
if procedure.nil?
|
52
|
+
return @component_def.get_concreate_class.new(*args)
|
53
|
+
elsif @component_def.component_class == Proc
|
54
|
+
return procedure
|
55
|
+
else
|
56
|
+
component = procedure.call(*args)
|
57
|
+
if component.is_a?(@component_def.component_class)
|
58
|
+
return component
|
59
|
+
else
|
60
|
+
raise TypeError.new("invalid instance found. #{@component_def.component_class.name} is expected, but was #{component.class.name}")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|