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.
Files changed (136) hide show
  1. data/Apache_Software_License_2.0.txt +202 -0
  2. data/ChangeLog +1 -0
  3. data/ChangeLog.ja +64 -0
  4. data/README +9 -0
  5. data/Rakefile +51 -0
  6. data/example/example01/example.rb +13 -0
  7. data/example/example01/run.rb +20 -0
  8. data/example/example02/example.rb +30 -0
  9. data/example/example02/run.rb +8 -0
  10. data/example/example03/example.rb +8 -0
  11. data/example/example03/run.rb +12 -0
  12. data/example/example04/example.rb +9 -0
  13. data/example/example04/run.rb +15 -0
  14. data/example/example05/example.rb +9 -0
  15. data/example/example05/run.rb +21 -0
  16. data/example/example06/example.rb +9 -0
  17. data/example/example06/run.rb +8 -0
  18. data/example/example07/example.rb +8 -0
  19. data/example/example07/run.rb +15 -0
  20. data/example/example08/example.rb +9 -0
  21. data/example/example08/run.rb +19 -0
  22. data/example/example09/example.rb +7 -0
  23. data/example/example09/run.rb +11 -0
  24. data/example/example10/example.rb +9 -0
  25. data/example/example10/run.rb +10 -0
  26. data/example/example11/example.rb +18 -0
  27. data/example/example11/run.rb +10 -0
  28. data/example/example12/example.rb +9 -0
  29. data/example/example12/run.rb +8 -0
  30. data/example/example13/example.rb +18 -0
  31. data/example/example13/example.sql +4 -0
  32. data/example/example13/run.rb +22 -0
  33. data/example/example13/sample.db +0 -0
  34. data/example/example14/example.db +0 -0
  35. data/example/example14/example.rb +57 -0
  36. data/example/example14/example.sql +50 -0
  37. data/example/example14/run1.rb +23 -0
  38. data/example/example14/run2.rb +28 -0
  39. data/example/example14/run3.rb +25 -0
  40. data/example/example14/run4.rb +23 -0
  41. data/example/example14/run5.rb +35 -0
  42. data/example/example15/example.rb +20 -0
  43. data/example/example15/run.rb +28 -0
  44. data/example/example16/example.rb +15 -0
  45. data/example/example16/run.rb +24 -0
  46. data/example/quickstart/quickstart1/quickstart.rb +10 -0
  47. data/example/quickstart/quickstart2/quickstart.rb +9 -0
  48. data/example/quickstart/quickstart3/quickstart.rb +9 -0
  49. data/example/quickstart/quickstart4/quickstart.rb +14 -0
  50. data/example/quickstart/quickstart5/quickstart.rb +21 -0
  51. data/example/quickstart/quickstart6/quickstart.rb +28 -0
  52. data/example/quickstart/quickstart7/quickstart.rb +18 -0
  53. data/lib/s2container.rb +25 -0
  54. data/lib/seasar/aop/aspect.rb +30 -0
  55. data/lib/seasar/aop/interceptor/trace-interceptor.rb +48 -0
  56. data/lib/seasar/aop/method-invocation.rb +57 -0
  57. data/lib/seasar/aop/pointcut.rb +53 -0
  58. data/lib/seasar/aop/s2aop-factory.rb +125 -0
  59. data/lib/seasar/aop.rb +29 -0
  60. data/lib/seasar/beans/abstract-property-desc.rb +59 -0
  61. data/lib/seasar/beans/attribute-accessor-desc.rb +60 -0
  62. data/lib/seasar/beans/bean-desc-factory.rb +68 -0
  63. data/lib/seasar/beans/bean-desc.rb +232 -0
  64. data/lib/seasar/beans/instance-variable-desc.rb +58 -0
  65. data/lib/seasar/beans.rb +29 -0
  66. data/lib/seasar/container/arg-def.rb +51 -0
  67. data/lib/seasar/container/aspect-def.rb +60 -0
  68. data/lib/seasar/container/aspect-info-def.rb +94 -0
  69. data/lib/seasar/container/assembler/abstract-assembler.rb +68 -0
  70. data/lib/seasar/container/assembler/auto-property-assembler.rb +57 -0
  71. data/lib/seasar/container/assembler/autobinding-auto-def.rb +55 -0
  72. data/lib/seasar/container/assembler/autobinding-def-factory.rb +57 -0
  73. data/lib/seasar/container/assembler/autobinding-none-def.rb +53 -0
  74. data/lib/seasar/container/assembler/manual-constructor-assembler.rb +67 -0
  75. data/lib/seasar/container/assembler/manual-property-assembler.rb +68 -0
  76. data/lib/seasar/container/autobinding-def.rb +36 -0
  77. data/lib/seasar/container/component-def.rb +229 -0
  78. data/lib/seasar/container/component-info-def.rb +117 -0
  79. data/lib/seasar/container/deployer/abstract-component-deployer.rb +47 -0
  80. data/lib/seasar/container/deployer/instance-def-factory.rb +56 -0
  81. data/lib/seasar/container/deployer/instance-outer-def.rb +44 -0
  82. data/lib/seasar/container/deployer/instance-prototype-def.rb +44 -0
  83. data/lib/seasar/container/deployer/instance-singleton-def.rb +42 -0
  84. data/lib/seasar/container/deployer/outer-component-deployer.rb +47 -0
  85. data/lib/seasar/container/deployer/prototype-component-deployer.rb +51 -0
  86. data/lib/seasar/container/deployer/singleton-component-deployer.rb +54 -0
  87. data/lib/seasar/container/exception/component-notfound-runtime-exception.rb +44 -0
  88. data/lib/seasar/container/exception/cyclic-reference-runtime-exception.rb +43 -0
  89. data/lib/seasar/container/exception/illegal-autobinding-def-runtime-exception.rb +43 -0
  90. data/lib/seasar/container/exception/illegal-instance-def-runtime-exception.rb +44 -0
  91. data/lib/seasar/container/exception/toomany-registration-runtime-exception.rb +46 -0
  92. data/lib/seasar/container/instance-def.rb +37 -0
  93. data/lib/seasar/container/outer-component-def.rb +34 -0
  94. data/lib/seasar/container/property-def.rb +43 -0
  95. data/lib/seasar/container/s2application-context.rb +447 -0
  96. data/lib/seasar/container/s2container-component-def.rb +41 -0
  97. data/lib/seasar/container/s2container.rb +308 -0
  98. data/lib/seasar/container/simple-component-def.rb +45 -0
  99. data/lib/seasar/container/toomany-registration-component-def.rb +69 -0
  100. data/lib/seasar/container.rb +143 -0
  101. data/lib/seasar/dbi/dbi-interceptor.rb +97 -0
  102. data/lib/seasar/dbi/paginate.rb +215 -0
  103. data/lib/seasar/dbi.rb +26 -0
  104. data/lib/seasar/exception/notyet-implemented-exception.rb +25 -0
  105. data/lib/seasar/exception/property-notfound-runtime-exception.rb +48 -0
  106. data/lib/seasar/exception/s2runtime-exception.rb +35 -0
  107. data/lib/seasar/exception/unsupported-operation-exception.rb +25 -0
  108. data/lib/seasar/exception.rb +27 -0
  109. data/lib/seasar/log/s2logger.rb +75 -0
  110. data/lib/seasar/log.rb +38 -0
  111. data/lib/seasar/util/class-util.rb +116 -0
  112. data/lib/seasar/util.rb +24 -0
  113. data/setup.rb +1585 -0
  114. data/test/seasar/aop/test_pointcut.rb +25 -0
  115. data/test/seasar/aop/test_s2aop_factory.rb +90 -0
  116. data/test/seasar/beans/test_bean-desc.rb +179 -0
  117. data/test/seasar/container/assembler/test_auto_property_assembler.rb +87 -0
  118. data/test/seasar/container/assembler/test_autobinding_def_factory.rb +22 -0
  119. data/test/seasar/container/assembler/test_manual_property_assembler.rb +59 -0
  120. data/test/seasar/container/assembler/test_manula_constructor_assembler.rb +59 -0
  121. data/test/seasar/container/assembler/test_proc_constructor_assembler.rb +61 -0
  122. data/test/seasar/container/deployer/test_instance_def_factory.rb +24 -0
  123. data/test/seasar/container/deployer/test_prototype-deployer.rb +25 -0
  124. data/test/seasar/container/deployer/test_singleton-component-deployer.rb +24 -0
  125. data/test/seasar/container/s2app_load_sample.rb +6 -0
  126. data/test/seasar/container/test_arg-def.rb +34 -0
  127. data/test/seasar/container/test_aspect-info-def.rb +85 -0
  128. data/test/seasar/container/test_component-def.rb +91 -0
  129. data/test/seasar/container/test_component-info-def.rb +88 -0
  130. data/test/seasar/container/test_s2application-context.rb +290 -0
  131. data/test/seasar/container/test_s2container.rb +268 -0
  132. data/test/seasar/dbi/test_paginate.rb +265 -0
  133. data/test/seasar/test_log.rb +20 -0
  134. data/test/seasar/test_util.rb +46 -0
  135. data/test/test-suite.rb +7 -0
  136. metadata +211 -0
@@ -0,0 +1,215 @@
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 DBI
22
+ class Paginate
23
+
24
+ # - args
25
+ # - none
26
+ #
27
+ def initialize
28
+ @offset = 0
29
+ @limit = 10
30
+ @page = 1
31
+ @window_size = 5
32
+ @total = nil
33
+ @data = nil
34
+ end
35
+ attr_accessor :page, :offset, :limit, :total
36
+
37
+ #
38
+ # - args
39
+ # 1. Array <em>data</em>
40
+ # - return
41
+ # - Integer
42
+ #
43
+ def data=(data)
44
+ @total = data.size
45
+ @data = data
46
+ return @total
47
+ end
48
+
49
+ #
50
+ # - args
51
+ # - none
52
+ # - return
53
+ # - Array
54
+ #
55
+ def data
56
+ if @offset + @limit < @total
57
+ len = @limit
58
+ else
59
+ len = @total - @offset
60
+ end
61
+ return @data[@offset, len]
62
+ end
63
+
64
+ #
65
+ # - args
66
+ # - none
67
+ # - return
68
+ # - Integer
69
+ #
70
+ def get_total_page
71
+ return (@total.to_f / @limit.to_f).ceil
72
+ end
73
+
74
+ #
75
+ # - args
76
+ # 1. Integer <em>page</em>
77
+ # - return
78
+ # - none
79
+ #
80
+ def page= (page)
81
+ if page < 1 or self.get_total_page < page
82
+ raise RangeError.new("#{page} is out of range 1-#{self.get_total_page}")
83
+ end
84
+ if @page < page
85
+ @offset = @offset + @limit * (page - @page)
86
+ elsif @page > page
87
+ @offset = @offset - @limit * (@page - page)
88
+ end
89
+ @page = page
90
+ end
91
+
92
+ #
93
+ # - args
94
+ # - none
95
+ # - return
96
+ # - none
97
+ #
98
+ def init_offset
99
+ @offset = 0
100
+ end
101
+
102
+ #
103
+ # - args
104
+ # - none
105
+ # - return
106
+ # - Integer
107
+ #
108
+ def total
109
+ if @total.nil?
110
+ raise 'total not set.'
111
+ end
112
+ return @total
113
+ end
114
+
115
+ #
116
+ # - args
117
+ # 1. Integer <em>size</em>
118
+ # - return
119
+ # - Integer
120
+ #
121
+ def window_size=(size)
122
+ size = 2 if size < 2
123
+ @window_size = size
124
+ end
125
+
126
+ #
127
+ # - args
128
+ # - none
129
+ # - return
130
+ # - none
131
+ #
132
+ def next
133
+ return if self.get_total_page == @page
134
+ @offset = @offset + @limit
135
+ @page += 1
136
+ end
137
+
138
+ #
139
+ # - args
140
+ # - none
141
+ # - return
142
+ # - Boolean
143
+ #
144
+ def next?
145
+ return @page < self.get_total_page
146
+ end
147
+
148
+ #
149
+ # - args
150
+ # - none
151
+ # - return
152
+ # - none
153
+ #
154
+ def prev
155
+ return if @page == 1
156
+ @page -= 1
157
+ @offset = @offset - @limit
158
+ end
159
+
160
+ #
161
+ # - args
162
+ # - none
163
+ # - return
164
+ # - Boolean
165
+ #
166
+ def prev?
167
+ return 1 < @page
168
+ end
169
+
170
+ #
171
+ # - args
172
+ # - none
173
+ # - return
174
+ # - Range
175
+ #
176
+ def page_range
177
+ total_page = self.get_total_page
178
+ if total_page <= @window_size
179
+ return 1..total_page
180
+ else
181
+ start = @page - (@window_size.to_f / 2.0).floor
182
+ if start < 1
183
+ return 1..@window_size
184
+ end
185
+ last = start + @window_size -1
186
+ if total_page < last
187
+ return (total_page - @window_size + 1) .. total_page
188
+ end
189
+ return start..last
190
+ end
191
+ end
192
+
193
+ #
194
+ # - args
195
+ # 1. Symbol <em>action</em>
196
+ # 2. Integer <em>index</em>
197
+ # - return
198
+ # - nil
199
+ #
200
+ def move(action, index = nil)
201
+ return if action.nil?
202
+ case action.to_sym
203
+ when :n, :next
204
+ self.next
205
+ when :p, :prev
206
+ self.prev
207
+ when :g, :goto
208
+ self.page = index.to_i
209
+ else
210
+ raise ArgumentError.new("invalid action [#{action}]")
211
+ end
212
+ end
213
+ end
214
+ end
215
+ end
data/lib/seasar/dbi.rb ADDED
@@ -0,0 +1,26 @@
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
+ require 'dbi'
21
+ require 'seasar/dbi/dbi-interceptor'
22
+ module Seasar
23
+ module DBI
24
+ autoload :Paginate, 'seasar/dbi/paginate'
25
+ end
26
+ end
@@ -0,0 +1,25 @@
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 Exception
22
+ class NotYetImplementedException < S2RuntimeException
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,48 @@
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 Exception
22
+ # プロパティが存在しない場合にスローされる例外です。
23
+ class PropertyNotFoundRuntimeException < S2RuntimeException
24
+
25
+ # PropertyNotFoundRuntimeExceptionを構築します。
26
+ #
27
+ # - args
28
+ # 1. Class <em>bean_class</em>
29
+ # 2. Symbol <em>attribute</em>
30
+ #
31
+ def initialize(bean_class, attribute)
32
+ @bean_class = bean_class
33
+ @attribute = attribute
34
+ end
35
+
36
+ # 文字列表現を返します。
37
+ #
38
+ # - args
39
+ # - none
40
+ # - return
41
+ # - String
42
+ #
43
+ def to_s
44
+ return "class : #{@bean_class}, attribute : #{@attribute}"
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,35 @@
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 Exception
22
+ # seasar用の例外です。
23
+ class S2RuntimeException < ::StandardError
24
+
25
+ # S2RuntimeExceptionを構築します。
26
+ #
27
+ # - args
28
+ # - none
29
+ #
30
+ def initialize
31
+ super
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,25 @@
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 Exception
22
+ class UnsupportedOperationException < S2RuntimeException
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,27 @@
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 Exception
22
+ autoload :S2RuntimeException, 'seasar/exception/s2runtime-exception'
23
+ autoload :PropertyNotFoundRuntimeException, 'seasar/exception/property-notfound-runtime-exception'
24
+ autoload :NotYetImplementedException, 'seasar/exception/notyet-implemented-exception'
25
+ autoload :UnsupportedOperationException, 'seasar/exception/unsupported-operation-exception'
26
+ end
27
+ end
@@ -0,0 +1,75 @@
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
+ require "logger"
20
+
21
+ module Seasar
22
+ module Log
23
+ class S2Logger
24
+ @@logger = nil
25
+ @@logdev = STDERR
26
+ class << self
27
+
28
+ #
29
+ # - args
30
+ # - none
31
+ # - return
32
+ # - Logger
33
+ #
34
+ def get
35
+ if @@logger.nil?
36
+ @@logger = Logger.new(@@logdev)
37
+ @@logger.datetime_format = "%Y-%m-%d %H:%M:%S"
38
+ end
39
+ return @@logger
40
+ end
41
+
42
+ #
43
+ # - args
44
+ # 1. Logger <em>logger</em>
45
+ # - return
46
+ # - nil
47
+ #
48
+ def set(logger = nil)
49
+ @@logger = logger
50
+ end
51
+
52
+ #
53
+ # - args
54
+ # 1. Object <em>logdev</em>
55
+ # - return
56
+ # - nil
57
+ #
58
+ def logdev=(logdev)
59
+ @@logdev = logdev
60
+ @@logger = nil
61
+ end
62
+
63
+ #
64
+ # - args
65
+ # - none
66
+ # - return
67
+ # - Logger
68
+ #
69
+ def logger
70
+ return @@logger
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
data/lib/seasar/log.rb ADDED
@@ -0,0 +1,38 @@
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
+ #
21
+ # - args
22
+ # 1. IO _logdev_
23
+ # - return
24
+ # - Logger
25
+ #
26
+ def s2logger(logdev = nil)
27
+ if not logdev.nil?
28
+ Seasar::Log::S2Logger.set
29
+ Seasar::Log::S2Logger.logdev = logdev
30
+ end
31
+ return Seasar::Log::S2Logger.get
32
+ end
33
+
34
+ module Seasar
35
+ module Log
36
+ autoload :S2Logger, 'seasar/log/s2logger'
37
+ end
38
+ end
@@ -0,0 +1,116 @@
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 Util
22
+
23
+ # クラスに関するユーティリティクラスです。
24
+ class ClassUtil
25
+ class << self
26
+ # 値がメソッドではない属性を返します。属性名が「_」ではじまる属性は無視されます。
27
+ #
28
+ # - args
29
+ # 1. Class <em>target</em>
30
+ # - return
31
+ # - Array
32
+ #
33
+ def get_instance_attributes(target)
34
+ attributes = {}
35
+ target.instance_variables.each {|name|
36
+ next if name[1, 1] == "_"
37
+ next if name[-1, 1] == "_"
38
+ attributes[name.to_sym] = target.instance_variable_get(name)
39
+ }
40
+ return attributes
41
+ end
42
+
43
+ #
44
+ # - args
45
+ # 1. Class <em>target</em>
46
+ # - return
47
+ # - Array
48
+ #
49
+ def get_accessor_attributes(target)
50
+ #method_names = (target.public_methods - Object.public_methods).map {|method_name| method_name.to_s}
51
+ method_names = target.public_methods(false).map {|method_name| method_name.to_s}
52
+ attributes = []
53
+ method_names.each {|name|
54
+ next if name.match(/^==+$/)
55
+ if name.match(/^(.+)=$/) && method_names.member?($1)
56
+ attributes << "@#{$1}".to_sym
57
+ end
58
+ }
59
+ return attributes
60
+ end
61
+
62
+ #
63
+ # - args
64
+ # 1. Class <em>clazz</em>
65
+ # - return
66
+ # - Array
67
+ #
68
+ def get_aspectable_methods(clazz)
69
+ #methods = clazz.instance_methods - Kernel.instance_methods - Object.instance_methods
70
+ methods = clazz.instance_methods - Kernel.instance_methods
71
+ return methods
72
+ =begin
73
+ result = []
74
+ methods.each {|method_name|
75
+ next if method_name[0, 1] == "_"
76
+ next if method_name[-1, 1] == "_"
77
+ next if method_name[-1, 1] == "?"
78
+ result << method_name
79
+ }
80
+ return result
81
+ =end
82
+ end
83
+
84
+ #
85
+ # When Class name is 'AbcDef', return 'abc_def'
86
+ #
87
+ # - args
88
+ # 1. Class _clazz_
89
+ # - return
90
+ # - Symbol
91
+ #
92
+ def ub_name(clazz)
93
+ name = clazz.name.split(/::/).last
94
+ name.gsub!(/([A-Z]+)/) { '_' + $1 }
95
+ return name[1..name.length].downcase.to_sym
96
+ end
97
+
98
+ #
99
+ # return the module name.
100
+ # When Class name is 'A::B::C', return 'A::B'
101
+ # When Class name is 'A', return ''
102
+ #
103
+ # - args
104
+ # 1. Class _clazz_
105
+ # - return
106
+ # - String
107
+ #
108
+ def module_name(clazz)
109
+ return '' unless clazz.name.match(/::/)
110
+ return clazz.name.sub(/::\w+$/, '')
111
+ end
112
+
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,24 @@
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 Util
22
+ autoload :ClassUtil, 'seasar/util/class-util'
23
+ end
24
+ end