copland 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/README +88 -0
- data/doc/manual-html/chapter-1.html +454 -0
- data/doc/manual-html/chapter-10.html +399 -0
- data/doc/manual-html/chapter-11.html +600 -0
- data/doc/manual-html/chapter-12.html +406 -0
- data/doc/manual-html/chapter-2.html +382 -0
- data/doc/manual-html/chapter-3.html +424 -0
- data/doc/manual-html/chapter-4.html +432 -0
- data/doc/manual-html/chapter-5.html +381 -0
- data/doc/manual-html/chapter-6.html +364 -0
- data/doc/manual-html/chapter-7.html +434 -0
- data/doc/manual-html/chapter-8.html +373 -0
- data/doc/manual-html/chapter-9.html +324 -0
- data/doc/manual-html/copland.png +0 -0
- data/doc/manual-html/index.html +331 -0
- data/doc/manual-html/manual.css +179 -0
- data/doc/manual-html/tutorial-1.html +407 -0
- data/doc/manual-html/tutorial-2.html +451 -0
- data/doc/manual-html/tutorial-3.html +484 -0
- data/doc/manual-html/tutorial-4.html +446 -0
- data/doc/manual-html/tutorial-5.html +520 -0
- data/doc/manual/chapter.erb +18 -0
- data/doc/manual/example.erb +18 -0
- data/doc/manual/img/copland.png +0 -0
- data/doc/manual/index.erb +30 -0
- data/doc/manual/manual.css +179 -0
- data/doc/manual/manual.rb +239 -0
- data/doc/manual/manual.yml +2643 -0
- data/doc/manual/page.erb +102 -0
- data/doc/manual/tutorial.erb +30 -0
- data/doc/packages/copland.html +764 -0
- data/doc/packages/copland.lib.html +439 -0
- data/doc/packages/copland.remote.html +2096 -0
- data/doc/packages/copland.webrick.html +925 -0
- data/doc/packages/index.html +49 -0
- data/doc/packages/packrat.css +125 -0
- data/examples/calc/calc.rb +47 -0
- data/examples/calc/package.yml +35 -0
- data/examples/calc/services.rb +74 -0
- data/examples/solitaire-cipher/README +11 -0
- data/examples/solitaire-cipher/Rakefile +57 -0
- data/examples/solitaire-cipher/bin/main.rb +14 -0
- data/examples/solitaire-cipher/lib/cipher.rb +230 -0
- data/examples/solitaire-cipher/lib/cli.rb +24 -0
- data/examples/solitaire-cipher/lib/package.yml +106 -0
- data/examples/solitaire-cipher/test/tc_deck.rb +30 -0
- data/examples/solitaire-cipher/test/tc_key-stream.rb +19 -0
- data/examples/solitaire-cipher/test/tc_keying-algorithms.rb +31 -0
- data/examples/solitaire-cipher/test/tc_solitaire-cipher.rb +66 -0
- data/examples/solitaire-cipher/test/tc_unkeyed-algorithm.rb +17 -0
- data/examples/solitaire-cipher/test/tests.rb +2 -0
- data/lib/copland.rb +56 -0
- data/lib/copland/class-factory.rb +95 -0
- data/lib/copland/configuration-point.rb +38 -0
- data/lib/copland/configuration-point/common.rb +203 -0
- data/lib/copland/configuration-point/errors.rb +44 -0
- data/lib/copland/configuration-point/list.rb +59 -0
- data/lib/copland/configuration-point/map.rb +59 -0
- data/lib/copland/configuration/errors.rb +43 -0
- data/lib/copland/configuration/loader.rb +113 -0
- data/lib/copland/configuration/yaml/configuration-point.rb +87 -0
- data/lib/copland/configuration/yaml/implementor.rb +134 -0
- data/lib/copland/configuration/yaml/interceptor.rb +63 -0
- data/lib/copland/configuration/yaml/listener.rb +56 -0
- data/lib/copland/configuration/yaml/loader.rb +122 -0
- data/lib/copland/configuration/yaml/package.rb +125 -0
- data/lib/copland/configuration/yaml/parser.rb +71 -0
- data/lib/copland/configuration/yaml/schema.rb +165 -0
- data/lib/copland/configuration/yaml/service-point.rb +116 -0
- data/lib/copland/configuration/yaml/utils.rb +82 -0
- data/lib/copland/default-schema-processor.rb +144 -0
- data/lib/copland/errors.rb +82 -0
- data/lib/copland/event-producer.rb +95 -0
- data/lib/copland/impl/builder-factory.rb +112 -0
- data/lib/copland/impl/copland-config.yml +1 -0
- data/lib/copland/impl/include-exclude.rb +140 -0
- data/lib/copland/impl/logging-interceptor.rb +106 -0
- data/lib/copland/impl/package.yml +217 -0
- data/lib/copland/impl/startup.rb +116 -0
- data/lib/copland/impl/symbol-source-manager.rb +131 -0
- data/lib/copland/impl/symbol-source.rb +63 -0
- data/lib/copland/instantiator.rb +38 -0
- data/lib/copland/instantiator/abstract.rb +91 -0
- data/lib/copland/instantiator/complex.rb +96 -0
- data/lib/copland/instantiator/identity.rb +58 -0
- data/lib/copland/instantiator/simple.rb +68 -0
- data/lib/copland/interceptor-chain.rb +166 -0
- data/lib/copland/interceptor.rb +139 -0
- data/lib/copland/log-factory.rb +206 -0
- data/lib/copland/models.rb +39 -0
- data/lib/copland/models/abstract.rb +78 -0
- data/lib/copland/models/prototype-deferred.rb +58 -0
- data/lib/copland/models/prototype.rb +58 -0
- data/lib/copland/models/proxy.rb +100 -0
- data/lib/copland/models/singleton-deferred.rb +59 -0
- data/lib/copland/models/singleton.rb +77 -0
- data/lib/copland/models/threaded.rb +65 -0
- data/lib/copland/ordering.rb +123 -0
- data/lib/copland/package.rb +246 -0
- data/lib/copland/registry.rb +368 -0
- data/lib/copland/schema.rb +206 -0
- data/lib/copland/service-point.rb +282 -0
- data/lib/copland/utils.rb +221 -0
- data/lib/copland/version.rb +47 -0
- data/test/conf-test/list-bad-key.yml +30 -0
- data/test/conf-test/list-bad-missing.yml +28 -0
- data/test/conf-test/list-bad-type.yml +28 -0
- data/test/conf-test/list-good.yml +29 -0
- data/test/conf-test/map-bad-key.yml +25 -0
- data/test/conf-test/map-bad-missing.yml +24 -0
- data/test/conf-test/map-bad-type.yml +23 -0
- data/test/conf-test/map-good.yml +25 -0
- data/test/configuration-point/package.yml +52 -0
- data/test/configuration/yaml/config/copland-config.yml +2 -0
- data/test/configuration/yaml/config/module.yml +2 -0
- data/test/configuration/yaml/config/subdir/copland-config.yml +2 -0
- data/test/configuration/yaml/config/subdir/package.yml +4 -0
- data/test/configuration/yaml/defaults/package.yml +5 -0
- data/test/configuration/yaml/defaults/subdir/package.yml +4 -0
- data/test/configuration/yaml/tc_config-loader.rb +86 -0
- data/test/configuration/yaml/tc_configuration-point-processor.rb +134 -0
- data/test/configuration/yaml/tc_implementor-processor.rb +104 -0
- data/test/configuration/yaml/tc_interceptor-processor.rb +85 -0
- data/test/configuration/yaml/tc_listener-processor.rb +69 -0
- data/test/configuration/yaml/tc_loader.rb +74 -0
- data/test/configuration/yaml/tc_package-processor.rb +120 -0
- data/test/configuration/yaml/tc_parser.rb +94 -0
- data/test/configuration/yaml/tc_schema-parser.rb +160 -0
- data/test/configuration/yaml/tc_service-point-processor.rb +104 -0
- data/test/configuration/yaml/tc_type-validator.rb +90 -0
- data/test/custom-logger.yml +3 -0
- data/test/impl/logging/package.yml +44 -0
- data/test/impl/logging/services.rb +84 -0
- data/test/impl/startup/package.yml +46 -0
- data/test/impl/startup/services.rb +47 -0
- data/test/impl/symbols/package.yml +24 -0
- data/test/impl/symbols/services.rb +38 -0
- data/test/impl/tc_builder-factory.rb +173 -0
- data/test/impl/tc_logging-interceptor.rb +148 -0
- data/test/impl/tc_startup.rb +59 -0
- data/test/impl/tc_symbol-sources.rb +61 -0
- data/test/logger.yml +6 -0
- data/test/mock.rb +201 -0
- data/test/schema/bad-package.yml +65 -0
- data/test/schema/package.yml +102 -0
- data/test/schema/services.rb +5 -0
- data/test/services/package.yml +79 -0
- data/test/services/simple.rb +87 -0
- data/test/tc_class-factory.rb +93 -0
- data/test/tc_complex-instantiator.rb +107 -0
- data/test/tc_configuration-point-contrib.rb +74 -0
- data/test/tc_configuration-point-schema.rb +122 -0
- data/test/tc_configuration-point.rb +91 -0
- data/test/tc_default-schema-processor.rb +297 -0
- data/test/tc_identity-instantiator.rb +61 -0
- data/test/tc_interceptors.rb +84 -0
- data/test/tc_logger.rb +131 -0
- data/test/tc_models.rb +176 -0
- data/test/tc_package.rb +165 -0
- data/test/tc_proxy.rb +65 -0
- data/test/tc_registry.rb +141 -0
- data/test/tc_schema.rb +78 -0
- data/test/tc_service-point.rb +178 -0
- data/test/tc_service.rb +70 -0
- data/test/tc_simple-instantiator.rb +61 -0
- data/test/tests.rb +93 -0
- data/tutorial/01/main.rb +7 -0
- data/tutorial/01/package.yml +8 -0
- data/tutorial/01/tutorial.rb +7 -0
- data/tutorial/02/main.rb +10 -0
- data/tutorial/02/package.yml +27 -0
- data/tutorial/02/tutorial.rb +46 -0
- data/tutorial/03/main.rb +24 -0
- data/tutorial/03/package.yml +29 -0
- data/tutorial/03/tutorial.rb +48 -0
- data/tutorial/04/main.rb +24 -0
- data/tutorial/04/package.yml +35 -0
- data/tutorial/04/tutorial.rb +48 -0
- data/tutorial/05/functions/package.yml +16 -0
- data/tutorial/05/functions/services.rb +15 -0
- data/tutorial/05/main.rb +10 -0
- data/tutorial/05/package.yml +35 -0
- data/tutorial/05/tutorial.rb +53 -0
- metadata +260 -0
@@ -0,0 +1,116 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions are met:
|
8
|
+
#
|
9
|
+
# * Redistributions of source code must retain the above copyright notice,
|
10
|
+
# this list of conditions and the following disclaimer.
|
11
|
+
#
|
12
|
+
# * Redistributions in binary form must reproduce the above copyright
|
13
|
+
# notice, this list of conditions and the following disclaimer in the
|
14
|
+
# documentation and/or other materials provided with the distribution.
|
15
|
+
#
|
16
|
+
# * The names of its contributors may not be used to endorse or promote
|
17
|
+
# products derived from this software without specific prior written
|
18
|
+
# permission.
|
19
|
+
#
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
23
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
24
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
25
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
# =============================================================================
|
32
|
+
#++
|
33
|
+
|
34
|
+
require 'copland/ordering'
|
35
|
+
|
36
|
+
module Copland
|
37
|
+
module Implementation
|
38
|
+
|
39
|
+
# This wraps a single service as a client to the Startup service.
|
40
|
+
# It provides the necessary #before? and #after? abstractions required
|
41
|
+
# by the Orderer module (which is used by Startup to order the
|
42
|
+
# clients before starting them).
|
43
|
+
class StartupClient
|
44
|
+
|
45
|
+
# The service point that is wrapped by this object.
|
46
|
+
attr_reader :point
|
47
|
+
|
48
|
+
# The array of names of service points that should start after this
|
49
|
+
# service point.
|
50
|
+
attr_reader :before
|
51
|
+
|
52
|
+
# The array of names of service points that should start before this
|
53
|
+
# service point.
|
54
|
+
attr_reader :after
|
55
|
+
|
56
|
+
# Instantiate a new client that wraps the given service point, and
|
57
|
+
# its before and after lists. These lists should be arrays of the
|
58
|
+
# <em>full names</em> of other services.
|
59
|
+
def initialize( point, before, after )
|
60
|
+
@point = point
|
61
|
+
@before = before
|
62
|
+
@after = after
|
63
|
+
end
|
64
|
+
|
65
|
+
# Returns +true+ if +self+ should be started before +e+.
|
66
|
+
def before?( e )
|
67
|
+
@before.include?( e.point.full_name ) ||
|
68
|
+
e.after.include?( point.full_name )
|
69
|
+
end
|
70
|
+
|
71
|
+
# Returns +true+ if +self+ should be after before +e+.
|
72
|
+
def after?( e )
|
73
|
+
@after.include?( e.point.full_name ) ||
|
74
|
+
e.before.include?( point.full_name )
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# This class is accessed via the singleton system service
|
79
|
+
# <tt>copland.Startup</tt>. It listens to the registry, and when it
|
80
|
+
# receives notification that the registry has been initialized, it will
|
81
|
+
# start all (enabled) services listed in the <tt>copland.Startup</tt>
|
82
|
+
# configuration point.
|
83
|
+
class Startup
|
84
|
+
|
85
|
+
# Setter for the clients collection
|
86
|
+
attr_writer :clients
|
87
|
+
|
88
|
+
# Setter for the instantiating registry
|
89
|
+
attr_writer :registry
|
90
|
+
|
91
|
+
# Invoked by Copland when the registry has been initialized. This allows
|
92
|
+
# the service to then instantiate each of its registered services in
|
93
|
+
# turn, in the order they were requested.
|
94
|
+
def start
|
95
|
+
list = []
|
96
|
+
@clients.each do |client|
|
97
|
+
enabled = client.fetch( 'enabled', true )
|
98
|
+
if enabled
|
99
|
+
service_name = client['service']
|
100
|
+
before = [ *( client['before'] || [] ) ]
|
101
|
+
after = [ *( client['after'] || [] ) ]
|
102
|
+
|
103
|
+
list << StartupClient.new(
|
104
|
+
@registry.service_point( service_name ),
|
105
|
+
before, after )
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
list = Orderer.order( list )
|
110
|
+
list.each { |client| client.point.instance }
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions are met:
|
8
|
+
#
|
9
|
+
# * Redistributions of source code must retain the above copyright notice,
|
10
|
+
# this list of conditions and the following disclaimer.
|
11
|
+
#
|
12
|
+
# * Redistributions in binary form must reproduce the above copyright
|
13
|
+
# notice, this list of conditions and the following disclaimer in the
|
14
|
+
# documentation and/or other materials provided with the distribution.
|
15
|
+
#
|
16
|
+
# * The names of its contributors may not be used to endorse or promote
|
17
|
+
# products derived from this software without specific prior written
|
18
|
+
# permission.
|
19
|
+
#
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
23
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
24
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
25
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
# =============================================================================
|
32
|
+
#++
|
33
|
+
|
34
|
+
require 'copland/ordering'
|
35
|
+
require 'copland/utils'
|
36
|
+
|
37
|
+
module Copland
|
38
|
+
module Implementation
|
39
|
+
|
40
|
+
# A utility class for representing a single symbol source definition.
|
41
|
+
# It is used only during the construction of a SymbolSourceManager class,
|
42
|
+
# when the ordering of the sources must be ascertained.
|
43
|
+
class SymbolSourceDefinition
|
44
|
+
|
45
|
+
# The name of the symbol source.
|
46
|
+
attr_accessor :name
|
47
|
+
|
48
|
+
# The symbol source itself, either a service a directly-instantiated
|
49
|
+
# object.
|
50
|
+
attr_accessor :source
|
51
|
+
|
52
|
+
# The array of sources that this source should be ordered before.
|
53
|
+
attr_accessor :before
|
54
|
+
|
55
|
+
# The array of sources that this source should be ordered after.
|
56
|
+
attr_accessor :after
|
57
|
+
|
58
|
+
# Create a new SymbolSourceDefinition from the given definition.
|
59
|
+
# The definition should match the schema for the SymbolSources
|
60
|
+
# configuration point, although no checking is done here.
|
61
|
+
def initialize( definition )
|
62
|
+
@name = definition[ 'name' ]
|
63
|
+
|
64
|
+
source = definition[ 'source' ]
|
65
|
+
if source.is_a?( String )
|
66
|
+
@source = Copland::get_class( source ).new
|
67
|
+
else
|
68
|
+
@source = source
|
69
|
+
end
|
70
|
+
|
71
|
+
@before = definition[ 'before' ] || []
|
72
|
+
@after = definition[ 'after' ] || []
|
73
|
+
end
|
74
|
+
|
75
|
+
# Return +true+ if the given source should be ordered after # +self+.
|
76
|
+
def before?( source )
|
77
|
+
@before.include?( source.name ) ||
|
78
|
+
source.after.include?( @name )
|
79
|
+
end
|
80
|
+
|
81
|
+
# Return +true+ if the given source should be ordered before # +self+.
|
82
|
+
def after?( source )
|
83
|
+
@after.include?( source.name ) ||
|
84
|
+
source.before.include?( @name )
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# The implementation of the SymbolSourceManager service. It forms the
|
89
|
+
# central repository of all symbols in Copland, and which clients may
|
90
|
+
# query the values of any defined symbols.
|
91
|
+
class SymbolSourceManager
|
92
|
+
|
93
|
+
# A unique value, used for identifying whether or not a value was found
|
94
|
+
# in a symbol source.
|
95
|
+
NOT_FOUND = Object.new
|
96
|
+
|
97
|
+
# Create a new SymbolSourceManager, using the given array of source
|
98
|
+
# definitions.
|
99
|
+
def initialize( sources )
|
100
|
+
@sources = sources.map { |entry| SymbolSourceDefinition.new( entry ) }
|
101
|
+
@sources = Copland::Orderer.order( @sources ).map { |v| v.source }
|
102
|
+
end
|
103
|
+
|
104
|
+
# Returns +true+ if the source contains a symbol with the given name.
|
105
|
+
def has_symbol?( name )
|
106
|
+
found = @sources.find { |source| source.has_symbol?( name ) }
|
107
|
+
return !found.nil?
|
108
|
+
end
|
109
|
+
|
110
|
+
# Returns the value of the given symbol, or the value of +default+ if no
|
111
|
+
# such symbol exists in source.
|
112
|
+
def lookup( name, default=nil )
|
113
|
+
@sources.each do |source|
|
114
|
+
value = source.lookup( name, NOT_FOUND )
|
115
|
+
if value != NOT_FOUND
|
116
|
+
return value
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
return default
|
121
|
+
end
|
122
|
+
|
123
|
+
# A convenience method that just delegates to #lookup.
|
124
|
+
def []( name )
|
125
|
+
lookup( name )
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions are met:
|
8
|
+
#
|
9
|
+
# * Redistributions of source code must retain the above copyright notice,
|
10
|
+
# this list of conditions and the following disclaimer.
|
11
|
+
#
|
12
|
+
# * Redistributions in binary form must reproduce the above copyright
|
13
|
+
# notice, this list of conditions and the following disclaimer in the
|
14
|
+
# documentation and/or other materials provided with the distribution.
|
15
|
+
#
|
16
|
+
# * The names of its contributors may not be used to endorse or promote
|
17
|
+
# products derived from this software without specific prior written
|
18
|
+
# permission.
|
19
|
+
#
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
23
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
24
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
25
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
# =============================================================================
|
32
|
+
#++
|
33
|
+
|
34
|
+
module Copland
|
35
|
+
module Implementation
|
36
|
+
|
37
|
+
# The default SymbolSource implementation, used by both the
|
38
|
+
# ApplicationDefaults and FactoryDefaults implementations.
|
39
|
+
class SymbolSource
|
40
|
+
|
41
|
+
# The map configuration point that backs this service.
|
42
|
+
attr_accessor :defaults
|
43
|
+
|
44
|
+
# Returns +true+ if the source contains a symbol with the given name.
|
45
|
+
def has_symbol?( name )
|
46
|
+
defaults.has_key?( name )
|
47
|
+
end
|
48
|
+
|
49
|
+
# Returns the value of the given symbol, or the value of +default+ if no
|
50
|
+
# such symbol exists in source.
|
51
|
+
def lookup( name, default=nil )
|
52
|
+
defaults.fetch( name, default )
|
53
|
+
end
|
54
|
+
|
55
|
+
# A convenience method that just delegates to #lookup.
|
56
|
+
def []( name )
|
57
|
+
lookup( name )
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions are met:
|
8
|
+
#
|
9
|
+
# * Redistributions of source code must retain the above copyright notice,
|
10
|
+
# this list of conditions and the following disclaimer.
|
11
|
+
#
|
12
|
+
# * Redistributions in binary form must reproduce the above copyright
|
13
|
+
# notice, this list of conditions and the following disclaimer in the
|
14
|
+
# documentation and/or other materials provided with the distribution.
|
15
|
+
#
|
16
|
+
# * The names of its contributors may not be used to endorse or promote
|
17
|
+
# products derived from this software without specific prior written
|
18
|
+
# permission.
|
19
|
+
#
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
23
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
24
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
25
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
# =============================================================================
|
32
|
+
#++
|
33
|
+
|
34
|
+
require 'copland/instantiator/abstract'
|
35
|
+
|
36
|
+
require 'copland/instantiator/simple'
|
37
|
+
require 'copland/instantiator/complex'
|
38
|
+
require 'copland/instantiator/identity'
|
@@ -0,0 +1,91 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions are met:
|
8
|
+
#
|
9
|
+
# * Redistributions of source code must retain the above copyright notice,
|
10
|
+
# this list of conditions and the following disclaimer.
|
11
|
+
#
|
12
|
+
# * Redistributions in binary form must reproduce the above copyright
|
13
|
+
# notice, this list of conditions and the following disclaimer in the
|
14
|
+
# documentation and/or other materials provided with the distribution.
|
15
|
+
#
|
16
|
+
# * The names of its contributors may not be used to endorse or promote
|
17
|
+
# products derived from this software without specific prior written
|
18
|
+
# permission.
|
19
|
+
#
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
23
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
24
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
25
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
# =============================================================================
|
32
|
+
#++
|
33
|
+
|
34
|
+
require 'copland/class-factory'
|
35
|
+
|
36
|
+
module Copland
|
37
|
+
module Instantiator
|
38
|
+
|
39
|
+
# The name of the ClassFactory pool associated with instantiators.
|
40
|
+
POOL_NAME = "instantiator"
|
41
|
+
|
42
|
+
begin
|
43
|
+
factory = Copland::ClassFactory.instance
|
44
|
+
factory.create_pool( POOL_NAME )
|
45
|
+
end
|
46
|
+
|
47
|
+
# The ancestor class of all instantiators. It provides functionality
|
48
|
+
# common to all instantiators.
|
49
|
+
class Abstract
|
50
|
+
|
51
|
+
# The service point that this instantiator is intended to, well,
|
52
|
+
# instantiate.
|
53
|
+
attr_reader :point
|
54
|
+
|
55
|
+
# The definition data for this instantiator. Each subclass may choose to
|
56
|
+
# interpret this property differently.
|
57
|
+
attr_reader :definition
|
58
|
+
|
59
|
+
# Create a new instantiator using the given service point and
|
60
|
+
# definition data.
|
61
|
+
def initialize( point, definition )
|
62
|
+
@point = point
|
63
|
+
@definition = definition
|
64
|
+
end
|
65
|
+
|
66
|
+
# Raises a NotImplementedError. Subclasses must override this
|
67
|
+
# method and provide functionality for instantiating a service point.
|
68
|
+
def instantiate
|
69
|
+
raise NotImplementedError
|
70
|
+
end
|
71
|
+
|
72
|
+
# Does nothing.
|
73
|
+
def validate!
|
74
|
+
end
|
75
|
+
|
76
|
+
# A convenience method for registering +self+ with the ClassFactory
|
77
|
+
# under the given name. This will also add a +name+ method to the
|
78
|
+
# class, which will return the value of the +name+ parameter.
|
79
|
+
def self.register_as( name )
|
80
|
+
class_eval <<-EOF
|
81
|
+
def name
|
82
|
+
#{name.inspect}
|
83
|
+
end
|
84
|
+
EOF
|
85
|
+
Copland::ClassFactory.instance.register( POOL_NAME, name, self )
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions are met:
|
8
|
+
#
|
9
|
+
# * Redistributions of source code must retain the above copyright notice,
|
10
|
+
# this list of conditions and the following disclaimer.
|
11
|
+
#
|
12
|
+
# * Redistributions in binary form must reproduce the above copyright
|
13
|
+
# notice, this list of conditions and the following disclaimer in the
|
14
|
+
# documentation and/or other materials provided with the distribution.
|
15
|
+
#
|
16
|
+
# * The names of its contributors may not be used to endorse or promote
|
17
|
+
# products derived from this software without specific prior written
|
18
|
+
# permission.
|
19
|
+
#
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
23
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
24
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
25
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
# =============================================================================
|
32
|
+
#++
|
33
|
+
|
34
|
+
require 'copland/errors'
|
35
|
+
require 'copland/instantiator/abstract'
|
36
|
+
|
37
|
+
module Copland
|
38
|
+
module Instantiator
|
39
|
+
|
40
|
+
# The Complex instantiator is a more sophisticated way of instantiating
|
41
|
+
# services. It provides for the wiring of dependencies into the new service
|
42
|
+
# "automatically" (based on specified dependencies). This instantiator is
|
43
|
+
# what allows Copland to claim support for "dependency injection."
|
44
|
+
class Complex < Abstract
|
45
|
+
|
46
|
+
register_as "complex"
|
47
|
+
|
48
|
+
# The hash of parameters to pass to the instantiating factory.
|
49
|
+
attr_reader :construction_parms
|
50
|
+
|
51
|
+
# The service point of the factory to use to instantiate the service.
|
52
|
+
attr_reader :factory_point
|
53
|
+
|
54
|
+
# Create a new Complex instantiator for the given service point, using
|
55
|
+
# the given +definition+ hash.
|
56
|
+
def initialize( point, definition )
|
57
|
+
super point, definition
|
58
|
+
|
59
|
+
@factory_id = definition[ "factory" ] || "copland.BuilderFactory"
|
60
|
+
@factory_id = @factory_id.value if @factory_id.respond_to?( :value )
|
61
|
+
|
62
|
+
@construction_parms = definition.dup
|
63
|
+
@construction_parms.delete "factory"
|
64
|
+
end
|
65
|
+
|
66
|
+
# Validates the parameters to this instantiator by running them through
|
67
|
+
# the schema of the associated factory service point (if any).
|
68
|
+
def validate!
|
69
|
+
@factory_point = point.find_service_point( @factory_id )
|
70
|
+
|
71
|
+
schema = @factory_point.schema
|
72
|
+
if schema.respond_to?( :validate )
|
73
|
+
schema.validate @factory_point, point, construction_parms
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Create a new instance of the service via the factory service. The
|
78
|
+
# constructor parameters are passed through the factory's schema
|
79
|
+
# (if any) before passing them to the factory's +create_instance+
|
80
|
+
# method.
|
81
|
+
def instantiate
|
82
|
+
@factory = @factory_point.instance unless @factory
|
83
|
+
|
84
|
+
parms = @construction_parms
|
85
|
+
schema = @factory_point.schema
|
86
|
+
if schema.respond_to?( :process )
|
87
|
+
parms = schema.process( @factory_point, point, parms )
|
88
|
+
end
|
89
|
+
|
90
|
+
@factory.create_instance( point, parms )
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|