s2container 0.9.0 → 0.9.1
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/ChangeLog +14 -0
- data/Rakefile +2 -2
- data/example/example032/example.rb +10 -0
- data/example/example032/run.rb +21 -0
- data/example/example13/run.rb +16 -6
- data/example/example14/example.rb +16 -0
- data/example/example14/run6.rb +35 -0
- data/lib/s2container.rb +8 -0
- data/lib/seasar/aop.rb +5 -1
- data/lib/seasar/aop/interceptor/trace-interceptor.rb +0 -0
- data/lib/seasar/aop/s2aop-factory.rb +12 -10
- data/lib/seasar/aop/s2aop-factory186.rb +126 -0
- data/lib/seasar/container.rb +4 -8
- data/lib/seasar/dbi.rb +1 -0
- data/lib/seasar/dbi/tx-interceptor.rb +55 -0
- data/lib/seasar/log.rb +12 -6
- data/lib/seasar/log/factory/java-logger-factory.rb +52 -0
- data/lib/seasar/log/factory/ruby-logger-factory.rb +68 -0
- data/lib/seasar/log/jlogger.rb +102 -0
- data/lib/seasar/log/s2logger.rb +7 -32
- data/lib/seasar/util/class-util.rb +2 -0
- data/test/seasar/aop/test_s2aop_factory.rb +1 -0
- data/test/seasar/test_log.rb +18 -0
- metadata +11 -2
data/ChangeLog
CHANGED
@@ -1,7 +1,21 @@
|
|
1
1
|
|
2
|
+
2009-06-20 s2container-0.9.1
|
3
|
+
|
4
|
+
* modify: for JRuby.
|
5
|
+
* info: s2container-0.9.1 release.
|
6
|
+
|
7
|
+
2009-06-04 s2container-0.9.1
|
8
|
+
|
9
|
+
* add: add Seasar::DBI::TxInterceptor.
|
10
|
+
|
11
|
+
2009-05-06 s2container-0.9.1
|
12
|
+
|
13
|
+
* fix: s2aspect method.
|
14
|
+
|
2
15
|
2009-04-26 s2container-0.9.0
|
3
16
|
|
4
17
|
* add: destroy method to Seasar::Container::S2Container, Seasar::Container::ComponentDef.
|
18
|
+
* info: s2container-0.9.0 release.
|
5
19
|
|
6
20
|
2009-04-15 s2container-0.8.0
|
7
21
|
|
data/Rakefile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
RUBY_S2CONTAINER_VERSION = '0.9.
|
1
|
+
RUBY_S2CONTAINER_VERSION = '0.9.1'
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'rake'
|
@@ -18,7 +18,7 @@ end
|
|
18
18
|
|
19
19
|
spec = Gem::Specification.new do |s|
|
20
20
|
s.name = 's2container'
|
21
|
-
s.date = '2009-
|
21
|
+
s.date = '2009-06-20'
|
22
22
|
s.version = RUBY_S2CONTAINER_VERSION
|
23
23
|
s.authors = ['klove']
|
24
24
|
s.email = 'klovelion@gmail.com'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
$LOAD_PATH.unshift(File::expand_path(File::dirname(__FILE__)) + '/../../lib')
|
2
|
+
|
3
|
+
require 's2container'
|
4
|
+
require 'example'
|
5
|
+
|
6
|
+
component_info = s2component(:class => Example::Action) {
|
7
|
+
# constructor block
|
8
|
+
action = Example::Action.new
|
9
|
+
action.init
|
10
|
+
next action
|
11
|
+
}
|
12
|
+
|
13
|
+
component_info.destructor {|component|
|
14
|
+
# destructor block
|
15
|
+
component.quit
|
16
|
+
}
|
17
|
+
|
18
|
+
container = s2app.create
|
19
|
+
container.init # call constructor block
|
20
|
+
container.destroy # call destructor block
|
21
|
+
|
data/example/example13/run.rb
CHANGED
@@ -6,17 +6,27 @@ require 'dbi'
|
|
6
6
|
require 's2container'
|
7
7
|
require 'example'
|
8
8
|
|
9
|
-
s2comp(:class => DBI::DatabaseHandle, :name => :dbh, :autobinding => :none) {
|
10
|
-
|
9
|
+
component_info = s2comp(:class => DBI::DatabaseHandle, :name => :dbh, :autobinding => :none) {
|
10
|
+
s2logger.info(File.basename(__FILE__)){"Database handle connected."}
|
11
|
+
next DBI.connect("dbi:SQLite3:sample.db")
|
11
12
|
}
|
12
13
|
|
14
|
+
component_info.destructor {|dbh|
|
15
|
+
s2logger.info(File.basename(__FILE__)){"Database handle disconnected."}
|
16
|
+
dbh.disconnect
|
17
|
+
}
|
18
|
+
|
19
|
+
container = s2app.create
|
13
20
|
begin
|
14
|
-
|
15
|
-
|
16
|
-
s2logger.fatal(e.cause.class.name){"#{e.cause.message} #{e.cause.backtrace}"}
|
21
|
+
dao = container.get(Example::Dao)
|
22
|
+
dao.find_by_name('hoge')
|
17
23
|
rescue => e
|
18
24
|
s2logger.fatal(e.class.name){"#{e.message} #{e.backtrace}"}
|
19
25
|
ensure
|
20
|
-
|
26
|
+
begin
|
27
|
+
container.destroy
|
28
|
+
rescue => e
|
29
|
+
s2logger.error(self) {"destroy of s2container failed. #{e.message} #{e.backtrace}"}
|
30
|
+
end
|
21
31
|
end
|
22
32
|
|
@@ -54,4 +54,20 @@ module Example
|
|
54
54
|
class PrefectureDto < Seasar::DBI::Paginate
|
55
55
|
attr_accessor :name_like
|
56
56
|
end
|
57
|
+
|
58
|
+
class TxService
|
59
|
+
s2comp
|
60
|
+
s2aspect :interceptor => "dbi.tx"
|
61
|
+
attr_accessor :prefecture_dao
|
62
|
+
def execute
|
63
|
+
@prefecture_dao.insert(100, 'tx test1')
|
64
|
+
@prefecture_dao.insert(1, 'tx test2')
|
65
|
+
end
|
66
|
+
|
67
|
+
def execute2
|
68
|
+
@prefecture_dao.insert(200, 'tx test3')
|
69
|
+
return self.execute
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
57
73
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
$LOAD_PATH.unshift(File::expand_path(File::dirname(__FILE__)) + '/../../lib')
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'dbi'
|
5
|
+
|
6
|
+
require 's2container'
|
7
|
+
require 'seasar/dbi'
|
8
|
+
require 'example'
|
9
|
+
|
10
|
+
comp_info = s2comp(:class => DBI::DatabaseHandle, :namespace => "dbi", :autobinding => :none) {
|
11
|
+
DBI.connect("dbi:SQLite3:example.db")
|
12
|
+
}
|
13
|
+
|
14
|
+
comp_info.destructor {|dbh|
|
15
|
+
dbh.disconnect
|
16
|
+
}
|
17
|
+
|
18
|
+
container = s2app.create
|
19
|
+
begin
|
20
|
+
container[Example::TxService].execute
|
21
|
+
rescue => e
|
22
|
+
s2logger.fatal(e.class.name){"#{e.message}"}
|
23
|
+
ensure
|
24
|
+
container.destroy
|
25
|
+
end
|
26
|
+
|
27
|
+
container = s2app.create
|
28
|
+
begin
|
29
|
+
container[Example::TxService].execute2
|
30
|
+
rescue => e
|
31
|
+
s2logger.fatal(e.class.name){"#{e.message}"}
|
32
|
+
ensure
|
33
|
+
container.destroy
|
34
|
+
end
|
35
|
+
|
data/lib/s2container.rb
CHANGED
data/lib/seasar/aop.rb
CHANGED
@@ -23,7 +23,11 @@ module Seasar
|
|
23
23
|
autoload :Aspect, 'seasar/aop/aspect'
|
24
24
|
autoload :MethodInvocation, 'seasar/aop/method-invocation'
|
25
25
|
autoload :Pointcut, 'seasar/aop/pointcut'
|
26
|
-
|
26
|
+
if '1.8.6' < RUBY_VERSION
|
27
|
+
autoload :S2AopFactory, 'seasar/aop/s2aop-factory'
|
28
|
+
else
|
29
|
+
autoload :S2AopFactory, 'seasar/aop/s2aop-factory186'
|
30
|
+
end
|
27
31
|
end
|
28
32
|
end
|
29
33
|
|
File without changes
|
@@ -107,16 +107,18 @@ module Seasar
|
|
107
107
|
# - none
|
108
108
|
#
|
109
109
|
def weave_aspect(component_class, enhanced_class, method_name, interceptors)
|
110
|
-
enhanced_class.
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
110
|
+
enhanced_class.class_eval {|mod|
|
111
|
+
define_method(method_name) {|*args, &procedure|
|
112
|
+
invoker = MethodInvocation.new
|
113
|
+
invoker.method = component_class.instance_method(method_name).bind(self)
|
114
|
+
invoker.interceptors = interceptors
|
115
|
+
invoker.enhanced_class = enhanced_class
|
116
|
+
invoker.component_class = component_class
|
117
|
+
invoker.args = args
|
118
|
+
invoker.procedure = procedure
|
119
|
+
invoker.this = self
|
120
|
+
return invoker.proceed
|
121
|
+
}
|
120
122
|
}
|
121
123
|
end
|
122
124
|
end
|
@@ -0,0 +1,126 @@
|
|
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 "thread"
|
20
|
+
module Seasar
|
21
|
+
module Aop
|
22
|
+
|
23
|
+
# アスペクトを適用したクラスを生成するファクトリクラスです。
|
24
|
+
class S2AopFactory
|
25
|
+
@@index = 0
|
26
|
+
@@mutex = ::Mutex.new
|
27
|
+
|
28
|
+
class << self
|
29
|
+
|
30
|
+
#クラスにアスペクトを適用します。
|
31
|
+
#
|
32
|
+
# - args
|
33
|
+
# 1. Class <em>component_class</em>
|
34
|
+
# 2. Array <em>aspects</em>
|
35
|
+
# - return
|
36
|
+
# - Class
|
37
|
+
#
|
38
|
+
def create(component_class, aspects)
|
39
|
+
enhanced_class = S2AopFactory.generate_enhanced_class(component_class)
|
40
|
+
method_interceptors_map = S2AopFactory.creat_method_interceptors_map(component_class, aspects)
|
41
|
+
method_interceptors_map.each {|method_name, interceptors|
|
42
|
+
S2AopFactory.weave_aspect(component_class, enhanced_class, method_name, interceptors)
|
43
|
+
}
|
44
|
+
return enhanced_class
|
45
|
+
end
|
46
|
+
|
47
|
+
# 元のクラスを継承した新規クラスを返します。
|
48
|
+
# 新規クラスの名前には、「_EnhancedByS2Aop_###」が付加されます。
|
49
|
+
#
|
50
|
+
# - args
|
51
|
+
# 1. Class <em>component_class</em>
|
52
|
+
# - return
|
53
|
+
# - Class
|
54
|
+
#
|
55
|
+
def generate_enhanced_class(component_class)
|
56
|
+
#return Class.new(component_class)
|
57
|
+
consts = component_class.name.split(/::/)
|
58
|
+
enhanced_class_name = nil
|
59
|
+
@@mutex.synchronize {
|
60
|
+
enhanced_class_name = consts.pop + '_EnhancedByS2Aop_' + @@index.to_s
|
61
|
+
@@index += 1
|
62
|
+
}
|
63
|
+
if consts.size == 0
|
64
|
+
namespace = Object
|
65
|
+
else
|
66
|
+
namespace = eval(consts.join('::'))
|
67
|
+
end
|
68
|
+
clazz = Class.new(component_class)
|
69
|
+
# TODO: should throw exception? if contant has already defined in the namespace(module)
|
70
|
+
namespace.const_set(enhanced_class_name, clazz) unless namespace.const_defined?(enhanced_class_name)
|
71
|
+
return clazz
|
72
|
+
end
|
73
|
+
|
74
|
+
# クラスの各メソッドに適用するアスペクトを分類します。
|
75
|
+
#
|
76
|
+
# - args
|
77
|
+
# 1. Class <em>component_class</em>
|
78
|
+
# 2. Array <em>aspects</em>
|
79
|
+
# - return
|
80
|
+
# - Hash
|
81
|
+
#
|
82
|
+
def creat_method_interceptors_map(component_class, aspects)
|
83
|
+
methods = Seasar::Util::ClassUtil.get_aspectable_methods(component_class)
|
84
|
+
method_interceptors_map = {}
|
85
|
+
methods.each {|method_name|
|
86
|
+
interceptors = []
|
87
|
+
aspects.each {|aspect|
|
88
|
+
if aspect.pointcut.applicable?(method_name)
|
89
|
+
interceptors << aspect.interceptor
|
90
|
+
end
|
91
|
+
}
|
92
|
+
if 0 < interceptors.length
|
93
|
+
method_interceptors_map[method_name] = interceptors
|
94
|
+
end
|
95
|
+
}
|
96
|
+
return method_interceptors_map
|
97
|
+
end
|
98
|
+
|
99
|
+
# メソッドにアスペクトを織り込みます。(メソッドをinvokeクロージャで置き換えます)
|
100
|
+
#
|
101
|
+
# - args
|
102
|
+
# 1. Class <em>component_class</em>
|
103
|
+
# 2. Class <em>enhanced_class</em>
|
104
|
+
# 3. String|Symbol <em>method_name</em>
|
105
|
+
# 4. Array <em>interceptors</em>
|
106
|
+
# - return
|
107
|
+
# - none
|
108
|
+
#
|
109
|
+
def weave_aspect(component_class, enhanced_class, method_name, interceptors)
|
110
|
+
enhanced_class.class_eval {|mod|
|
111
|
+
define_method(method_name) {|*args|
|
112
|
+
invoker = MethodInvocation.new
|
113
|
+
invoker.method = component_class.instance_method(method_name).bind(self)
|
114
|
+
invoker.interceptors = interceptors
|
115
|
+
invoker.enhanced_class = enhanced_class
|
116
|
+
invoker.component_class = component_class
|
117
|
+
invoker.args = args
|
118
|
+
invoker.this = self
|
119
|
+
return invoker.proceed
|
120
|
+
}
|
121
|
+
}
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
data/lib/seasar/container.rb
CHANGED
@@ -65,20 +65,16 @@ alias s2comp s2component
|
|
65
65
|
# - nil
|
66
66
|
#
|
67
67
|
def s2aspect(option = {}, &procedure)
|
68
|
-
clazz =
|
69
|
-
if
|
68
|
+
clazz = option[:class]
|
69
|
+
if clazz.nil?
|
70
70
|
if self.class == Class
|
71
71
|
clazz = self
|
72
72
|
option[:static] = true
|
73
73
|
end
|
74
|
-
else
|
75
|
-
clazz = option[:class]
|
76
74
|
end
|
77
75
|
|
78
|
-
if option[:pattern].nil?
|
79
|
-
|
80
|
-
option[:pattern] = self.name
|
81
|
-
end
|
76
|
+
if option[:pattern].nil? && !clazz.nil?
|
77
|
+
option[:pattern] = clazz.name
|
82
78
|
end
|
83
79
|
return s2app.aspect(option, &procedure)
|
84
80
|
end
|
data/lib/seasar/dbi.rb
CHANGED
@@ -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 DBI
|
21
|
+
class TxInterceptor
|
22
|
+
s2comp :namespace => 'dbi', :name => 'tx', :default => true
|
23
|
+
|
24
|
+
# - args
|
25
|
+
# - none
|
26
|
+
#
|
27
|
+
def initialize
|
28
|
+
@dbh = :di, ::DBI::DatabaseHandle
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# - args
|
33
|
+
# 1. Seasar::Aop::MethodInvocation <em>invocation</em>
|
34
|
+
# - return
|
35
|
+
# - Object
|
36
|
+
#
|
37
|
+
def call(invocation)
|
38
|
+
result = nil
|
39
|
+
@dbh['AutoCommit'] = false
|
40
|
+
begin
|
41
|
+
result = invocation.proceed
|
42
|
+
@dbh.commit
|
43
|
+
rescue
|
44
|
+
s2logger.info(self.class.name){"doing rollback..."}
|
45
|
+
@dbh.rollback
|
46
|
+
s2logger.info(self.class.name){"rollback has occured."}
|
47
|
+
raise
|
48
|
+
ensure
|
49
|
+
@dbh['AutoCommit'] = true
|
50
|
+
end
|
51
|
+
return result
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/seasar/log.rb
CHANGED
@@ -19,20 +19,26 @@
|
|
19
19
|
|
20
20
|
#
|
21
21
|
# - args
|
22
|
-
#
|
22
|
+
# - none
|
23
23
|
# - return
|
24
24
|
# - Logger
|
25
25
|
#
|
26
|
-
def s2logger
|
27
|
-
if not logdev.nil?
|
28
|
-
Seasar::Log::S2Logger.set
|
29
|
-
Seasar::Log::S2Logger.logdev = logdev
|
30
|
-
end
|
26
|
+
def s2logger
|
31
27
|
return Seasar::Log::S2Logger.get
|
32
28
|
end
|
33
29
|
|
34
30
|
module Seasar
|
35
31
|
module Log
|
36
32
|
autoload :S2Logger, 'seasar/log/s2logger'
|
33
|
+
autoload :JLogger, 'seasar/log/jlogger'
|
34
|
+
module Factory
|
35
|
+
autoload :RubyLoggerFactory, 'seasar/log/factory/ruby-logger-factory'
|
36
|
+
autoload :JavaLoggerFactory, 'seasar/log/factory/java-logger-factory'
|
37
|
+
end
|
37
38
|
end
|
38
39
|
end
|
40
|
+
|
41
|
+
if defined? JRUBY_VERSION
|
42
|
+
Seasar::Log::S2Logger.factory = Seasar::Log::Factory::JavaLoggerFactory
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,52 @@
|
|
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 Log
|
21
|
+
module Factory
|
22
|
+
class JavaLoggerFactory
|
23
|
+
@@logger = nil
|
24
|
+
class << self
|
25
|
+
|
26
|
+
#
|
27
|
+
# - args
|
28
|
+
# - none
|
29
|
+
# - return
|
30
|
+
# - java.util.logging.Logger
|
31
|
+
#
|
32
|
+
def create
|
33
|
+
if @@logger.nil?
|
34
|
+
@@logger = Seasar::Log::JLogger.new
|
35
|
+
end
|
36
|
+
return @@logger
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# - args
|
41
|
+
# - none
|
42
|
+
# - return
|
43
|
+
# - none
|
44
|
+
#
|
45
|
+
def init
|
46
|
+
@@logger = nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
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
|
+
require "logger"
|
20
|
+
|
21
|
+
module Seasar
|
22
|
+
module Log
|
23
|
+
module Factory
|
24
|
+
class RubyLoggerFactory
|
25
|
+
@@logger = nil
|
26
|
+
@@logdev = STDERR
|
27
|
+
class << self
|
28
|
+
|
29
|
+
#
|
30
|
+
# - args
|
31
|
+
# - none
|
32
|
+
# - return
|
33
|
+
# - Logger
|
34
|
+
#
|
35
|
+
def create
|
36
|
+
if @@logger.nil?
|
37
|
+
@@logger = Logger.new(@@logdev)
|
38
|
+
@@logger.datetime_format = "%Y-%m-%d %H:%M:%S"
|
39
|
+
end
|
40
|
+
return @@logger
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# - args
|
45
|
+
# - none
|
46
|
+
# - return
|
47
|
+
# - none
|
48
|
+
#
|
49
|
+
def init
|
50
|
+
@@logger = nil
|
51
|
+
@@logdev = STDERR
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# - args
|
56
|
+
# 1. Object <em>logdev</em>
|
57
|
+
# - return
|
58
|
+
# - nil
|
59
|
+
#
|
60
|
+
def logdev=(logdev)
|
61
|
+
@@logdev = logdev
|
62
|
+
@@logger = nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,102 @@
|
|
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 "java"
|
20
|
+
#import 'java.util.logging.Logger'
|
21
|
+
module Seasar
|
22
|
+
module Log
|
23
|
+
class JLogger
|
24
|
+
|
25
|
+
#
|
26
|
+
# - args
|
27
|
+
# - 1. String <em>val</em>
|
28
|
+
# - return
|
29
|
+
# - java.util.logging.Logger
|
30
|
+
#
|
31
|
+
def instance(val = nil)
|
32
|
+
if val.nil?
|
33
|
+
return java.util.logging.Logger.global
|
34
|
+
else
|
35
|
+
return java.util.logging.Logger.getLogger(val.to_s.to_s)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
alias get instance
|
39
|
+
|
40
|
+
#
|
41
|
+
# - args
|
42
|
+
# - 1. String <em>val</em>
|
43
|
+
# - return
|
44
|
+
# - none
|
45
|
+
#
|
46
|
+
def debug(val = nil, &block)
|
47
|
+
self.fine(val, &block)
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# - args
|
52
|
+
# - 1. String <em>val</em>
|
53
|
+
# - return
|
54
|
+
# - none
|
55
|
+
#
|
56
|
+
def warn(val = nil, &block)
|
57
|
+
self.warning(val, &block)
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
# - args
|
62
|
+
# - 1. String <em>val</em>
|
63
|
+
# - return
|
64
|
+
# - none
|
65
|
+
#
|
66
|
+
def error(val = nil, &block)
|
67
|
+
self.severe(val, &block)
|
68
|
+
end
|
69
|
+
|
70
|
+
#
|
71
|
+
# - args
|
72
|
+
# - 1. String <em>val</em>
|
73
|
+
# - return
|
74
|
+
# - none
|
75
|
+
#
|
76
|
+
def fatal(val = nil, &block)
|
77
|
+
self.severe(val, &block)
|
78
|
+
end
|
79
|
+
|
80
|
+
#
|
81
|
+
# - args
|
82
|
+
# - 1. String <em>name</em>
|
83
|
+
# - 2. String <em>val</em>
|
84
|
+
# - return
|
85
|
+
# - none
|
86
|
+
#
|
87
|
+
def method_missing(name, val)
|
88
|
+
if block_given?
|
89
|
+
if val.nil?
|
90
|
+
java.util.logging.Logger.global.method(name).call(yield)
|
91
|
+
else
|
92
|
+
java.util.logging.Logger.getLogger(val.to_s).method(name).call(yield)
|
93
|
+
end
|
94
|
+
else
|
95
|
+
java.util.logging.Logger.global.method(name).call(val)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
|
data/lib/seasar/log/s2logger.rb
CHANGED
@@ -21,9 +21,8 @@ require "logger"
|
|
21
21
|
module Seasar
|
22
22
|
module Log
|
23
23
|
class S2Logger
|
24
|
-
@@logger = nil
|
25
|
-
@@logdev = STDERR
|
26
24
|
class << self
|
25
|
+
@@factory = Seasar::Log::Factory::RubyLoggerFactory
|
27
26
|
|
28
27
|
#
|
29
28
|
# - args
|
@@ -31,43 +30,19 @@ module Seasar
|
|
31
30
|
# - return
|
32
31
|
# - Logger
|
33
32
|
#
|
34
|
-
def
|
35
|
-
|
36
|
-
@@logger = Logger.new(@@logdev)
|
37
|
-
@@logger.datetime_format = "%Y-%m-%d %H:%M:%S"
|
38
|
-
end
|
39
|
-
return @@logger
|
33
|
+
def instance
|
34
|
+
@@factory.create
|
40
35
|
end
|
36
|
+
alias get instance
|
41
37
|
|
42
38
|
#
|
43
39
|
# - args
|
44
|
-
# 1.
|
40
|
+
# - 1. Seasar::Log::Factory <em>val</em>
|
45
41
|
# - 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
42
|
# - none
|
66
|
-
# - return
|
67
|
-
# - Logger
|
68
43
|
#
|
69
|
-
def
|
70
|
-
|
44
|
+
def factory=(val)
|
45
|
+
@@factory = val
|
71
46
|
end
|
72
47
|
end
|
73
48
|
end
|
data/test/seasar/test_log.rb
CHANGED
@@ -10,11 +10,29 @@ module Seasar
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_logging
|
13
|
+
return if defined? JRUBY_VERSION
|
13
14
|
#logger = s2logger('/tmp/a.log')
|
14
15
|
logger = s2logger
|
15
16
|
logger.level = Logger::DEBUG
|
16
17
|
s2logger.debug(self) {"debug level logging"}
|
17
18
|
end
|
19
|
+
|
20
|
+
def test_jlogger
|
21
|
+
return unless defined? JRUBY_VERSION
|
22
|
+
require 'lib/seasar/log/jlogger.rb'
|
23
|
+
require "java"
|
24
|
+
import 'java.util.logging.Level'
|
25
|
+
|
26
|
+
logger = Seasar::Log::JLogger.new
|
27
|
+
logger.finest("finest") {"finest"}
|
28
|
+
logger.finer("finer") {"finer"}
|
29
|
+
logger.debug("debug")
|
30
|
+
logger.info("info")
|
31
|
+
logger.warn("warn") {"warn"}
|
32
|
+
logger.error("error") {"error"}
|
33
|
+
logger.fatal("fatal") {"fatal"}
|
34
|
+
logger.config("config") {"config"}
|
35
|
+
end
|
18
36
|
end
|
19
37
|
end
|
20
38
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s2container
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- klove
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-06-20 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -68,7 +68,11 @@ files:
|
|
68
68
|
- lib/seasar/exception/notyet-implemented-exception.rb
|
69
69
|
- lib/seasar/exception/property-notfound-runtime-exception.rb
|
70
70
|
- lib/seasar/log/s2logger.rb
|
71
|
+
- lib/seasar/log/factory/ruby-logger-factory.rb
|
72
|
+
- lib/seasar/log/factory/java-logger-factory.rb
|
73
|
+
- lib/seasar/log/jlogger.rb
|
71
74
|
- lib/seasar/aop/interceptor/trace-interceptor.rb
|
75
|
+
- lib/seasar/aop/s2aop-factory186.rb
|
72
76
|
- lib/seasar/aop/method-invocation.rb
|
73
77
|
- lib/seasar/aop/pointcut.rb
|
74
78
|
- lib/seasar/aop/aspect.rb
|
@@ -80,6 +84,7 @@ files:
|
|
80
84
|
- lib/seasar/util/class-util.rb
|
81
85
|
- lib/seasar/container.rb
|
82
86
|
- lib/seasar/dbi/dbi-interceptor.rb
|
87
|
+
- lib/seasar/dbi/tx-interceptor.rb
|
83
88
|
- lib/seasar/dbi/paginate.rb
|
84
89
|
- lib/seasar/beans/instance-variable-desc.rb
|
85
90
|
- lib/seasar/beans/attribute-accessor-desc.rb
|
@@ -120,6 +125,7 @@ files:
|
|
120
125
|
- example/example08/example.rb
|
121
126
|
- example/example14
|
122
127
|
- example/example14/example.rb
|
128
|
+
- example/example14/run6.rb
|
123
129
|
- example/example14/run5.rb
|
124
130
|
- example/example14/run4.rb
|
125
131
|
- example/example14/run3.rb
|
@@ -133,6 +139,9 @@ files:
|
|
133
139
|
- example/example01
|
134
140
|
- example/example01/run.rb
|
135
141
|
- example/example01/example.rb
|
142
|
+
- example/example032
|
143
|
+
- example/example032/run.rb
|
144
|
+
- example/example032/example.rb
|
136
145
|
- example/example04
|
137
146
|
- example/example04/run.rb
|
138
147
|
- example/example04/example.rb
|