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,113 @@
|
|
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 Configuration
|
36
|
+
|
37
|
+
# This is the driver class for processing a series of directories, looking
|
38
|
+
# for configuration files. It relies on visitor objects to do the actual
|
39
|
+
# configuration processing--all this class does is recurse through the
|
40
|
+
# requested directories.
|
41
|
+
class Loader
|
42
|
+
|
43
|
+
# This is the array of search paths that the loader will descend.
|
44
|
+
attr_reader :search_paths
|
45
|
+
|
46
|
+
# This is the array of visitor objects that will be employed by this
|
47
|
+
# driver.
|
48
|
+
attr_reader :loaders
|
49
|
+
|
50
|
+
# Create a new Loader object that will search the given paths.
|
51
|
+
# Regardless, the 'copland/impl' directory will always be processed.
|
52
|
+
def initialize( search_paths=[] )
|
53
|
+
@search_paths = []
|
54
|
+
use_library "copland"
|
55
|
+
add_search_path *search_paths
|
56
|
+
@loaders = []
|
57
|
+
end
|
58
|
+
|
59
|
+
# Add new search paths to be searched.
|
60
|
+
def add_search_path( *paths )
|
61
|
+
@search_paths.concat( paths ).uniq!
|
62
|
+
end
|
63
|
+
|
64
|
+
# Add a new visitor loader to be used while processing directories.
|
65
|
+
def add_loader( loader )
|
66
|
+
@loaders.push loader
|
67
|
+
end
|
68
|
+
|
69
|
+
# Processes each search path in turn, and finishes by calling
|
70
|
+
# #finalize! on each of the visitors. The +options+ parameter is
|
71
|
+
# passed to each loader.
|
72
|
+
def load( options={} )
|
73
|
+
@search_paths.each { |path| load_path path, options }
|
74
|
+
@loaders.each { |loader| loader.finalize! }
|
75
|
+
end
|
76
|
+
|
77
|
+
# Processes a single path (recursively). Each loader gets a turn
|
78
|
+
# at the directory, and then any subdirectories are processed by
|
79
|
+
# recursively calling this method on that directory.
|
80
|
+
#
|
81
|
+
# If the given path does not exist, this does nothing.
|
82
|
+
def load_path( path, options )
|
83
|
+
return unless File.directory?( path )
|
84
|
+
|
85
|
+
@loaders.each do |loader|
|
86
|
+
options = loader.process_dir( path, options )
|
87
|
+
end
|
88
|
+
|
89
|
+
Dir.foreach( path ) do |entry|
|
90
|
+
next if entry == "." || entry == ".."
|
91
|
+
|
92
|
+
file_name = File.join( path, entry )
|
93
|
+
load_path( file_name, options ) if File.directory?( file_name )
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Adds the use of the given library to the registry that is being
|
98
|
+
# constructed. The +name+ parameter must be the string that would be
|
99
|
+
# +require+'d (i.e., "copland/lib"). That file must then (at least)
|
100
|
+
# add a value to the Copland::LIBRARIES hash: the key must be the
|
101
|
+
# library name (i.e., "copland/lib"), and the value must be an array
|
102
|
+
# of paths that should be searched for this library, for package
|
103
|
+
# descriptors.
|
104
|
+
def use_library( name )
|
105
|
+
require( name )
|
106
|
+
# add_search_path does a uniq! on the result, so we can always just
|
107
|
+
# add the whole thing in and not worry about duplication.
|
108
|
+
add_search_path *Copland::LIBRARIES[ name ]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,87 @@
|
|
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
|
+
require 'copland/configuration-point'
|
36
|
+
require 'copland/configuration/yaml/schema'
|
37
|
+
require 'copland/configuration/yaml/utils'
|
38
|
+
|
39
|
+
module Copland
|
40
|
+
module Configuration
|
41
|
+
module YAML
|
42
|
+
|
43
|
+
# This delegate is responsible for processing configuration points in a
|
44
|
+
# package descriptor.
|
45
|
+
class ConfigurationPointProcessor
|
46
|
+
include TypeValidator
|
47
|
+
|
48
|
+
# Creates a new ConfigurationPointProcessor that feeds into the given
|
49
|
+
# Package instance. The +options+ are used while processing each
|
50
|
+
# configuration point.
|
51
|
+
def initialize( package, options={} )
|
52
|
+
@package = package
|
53
|
+
@options = options
|
54
|
+
@schema = SchemaParser.new
|
55
|
+
end
|
56
|
+
|
57
|
+
# The list of recognized key values in a configuration point element.
|
58
|
+
VALID_KEYS = [ "description", "type", "schema" ]
|
59
|
+
|
60
|
+
# The list of required key values in a configuration point element.
|
61
|
+
REQUIRED_KEYS = [ "type" ]
|
62
|
+
|
63
|
+
# Create and return a new configuration point with the given name.
|
64
|
+
# Initialize it with the data in the +doc+ parameter (which must be a
|
65
|
+
# Hash).
|
66
|
+
def process( name, doc )
|
67
|
+
ensure_element_type "configuration-point", doc, Hash
|
68
|
+
validate_elements doc
|
69
|
+
|
70
|
+
factory = Copland::ClassFactory.instance
|
71
|
+
point = factory.get( Copland::ConfigurationPoint::POOL_NAME,
|
72
|
+
doc["type"], @package, name, @options )
|
73
|
+
|
74
|
+
point.description = doc["description"]
|
75
|
+
|
76
|
+
if doc['schema']
|
77
|
+
point.schema = @schema.process( point, doc['schema'] )
|
78
|
+
end
|
79
|
+
|
80
|
+
return point
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,134 @@
|
|
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
|
+
require 'copland/configuration/errors'
|
36
|
+
require 'copland/instantiator/abstract'
|
37
|
+
|
38
|
+
module Copland
|
39
|
+
module Configuration
|
40
|
+
module YAML
|
41
|
+
|
42
|
+
# This structure is used to represent individual values in an
|
43
|
+
# implementor's "construction parameters". It is basically used to
|
44
|
+
# remove the YAML-specific data structures, so that the core Copland
|
45
|
+
# routines become more YAML-agnostic.
|
46
|
+
ValueElement = Struct.new( :type_id, :value )
|
47
|
+
|
48
|
+
# This delegate is responsible for processing the 'implementor' token in
|
49
|
+
# a YAML stream.
|
50
|
+
class ImplementorProcessor
|
51
|
+
|
52
|
+
# Process the given implementor +definition+ and set the service
|
53
|
+
# point's instantiator to the resulting instantiator.
|
54
|
+
#
|
55
|
+
# If definition is a string, then the instantiator will be
|
56
|
+
# "simple", backed by the class given as the definition.
|
57
|
+
#
|
58
|
+
# If definition is a Hash, then the instantiator will be "complex",
|
59
|
+
# and will be described by the definition.
|
60
|
+
#
|
61
|
+
# Any other type is an error.
|
62
|
+
def process( point, definition )
|
63
|
+
case definition
|
64
|
+
when String
|
65
|
+
instantiator = "simple"
|
66
|
+
when Hash
|
67
|
+
instantiator = "complex"
|
68
|
+
deyamlize_hash point, definition
|
69
|
+
else
|
70
|
+
raise ParserError,
|
71
|
+
"'implementor' must be either a String or a Hash"
|
72
|
+
end
|
73
|
+
|
74
|
+
factory = Copland::ClassFactory.instance
|
75
|
+
point.instantiator = factory.get( Copland::Instantiator::POOL_NAME,
|
76
|
+
instantiator, point, definition )
|
77
|
+
end
|
78
|
+
|
79
|
+
# Converts the given hash from YAML-specific data structures to more
|
80
|
+
# general ValueElement-based data.
|
81
|
+
def deyamlize_hash( point, hash, path="" )
|
82
|
+
hash.each_pair do |key, value|
|
83
|
+
hash[ key ] = deyamlize_value( point, key, value, path )
|
84
|
+
end
|
85
|
+
end
|
86
|
+
private :deyamlize_hash
|
87
|
+
|
88
|
+
# Converts the given array from YAML-specific data structures to more
|
89
|
+
# general ValueElement-based data.
|
90
|
+
def deyamlize_array( point, array, path="" )
|
91
|
+
index = 0
|
92
|
+
return array.map do |v|
|
93
|
+
v = deyamlize_value point, index, v, path
|
94
|
+
index += 1
|
95
|
+
v
|
96
|
+
end
|
97
|
+
end
|
98
|
+
private :deyamlize_array
|
99
|
+
|
100
|
+
# Converts the given value from YAML-specific data structures to more
|
101
|
+
# general ValueElement-based data. The converted value is returned.
|
102
|
+
def deyamlize_value( point, key, value, path )
|
103
|
+
new_value = ValueElement.new "string", value
|
104
|
+
|
105
|
+
if value.is_a? Hash
|
106
|
+
new_value.type_id = "hash"
|
107
|
+
deyamlize_hash point, value, path + key.to_s + "/"
|
108
|
+
|
109
|
+
elsif value.is_a? Array
|
110
|
+
new_value.type_id = "array"
|
111
|
+
new_value.value = deyamlize_array point, value,
|
112
|
+
path + key.to_s + "/"
|
113
|
+
|
114
|
+
elsif value.is_a? Integer
|
115
|
+
new_value.type_id = "integer"
|
116
|
+
|
117
|
+
elsif value.is_a? Float
|
118
|
+
new_value.type_id = "real"
|
119
|
+
|
120
|
+
elsif value.respond_to?( :type_id ) && value.respond_to?( :value )
|
121
|
+
new_value.type_id = value.type_id
|
122
|
+
new_value.value = value.value
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
return new_value
|
127
|
+
end
|
128
|
+
private :deyamlize_value
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|
134
|
+
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
|
+
require 'copland/configuration/errors'
|
35
|
+
require 'copland/configuration/yaml/utils'
|
36
|
+
|
37
|
+
module Copland
|
38
|
+
module Configuration
|
39
|
+
module YAML
|
40
|
+
|
41
|
+
# Manages the processing of 'interceptor' elements from the parsed YAML
|
42
|
+
# stream.
|
43
|
+
class InterceptorProcessor
|
44
|
+
include TypeValidator
|
45
|
+
|
46
|
+
# Processes the given +definition+ (which must be a Hash), and adds
|
47
|
+
# the definition as a pending interceptor to the given service point
|
48
|
+
# (see ServicePoint#add_pending_interceptor).
|
49
|
+
def process( point, definition )
|
50
|
+
ensure_element_type "interceptor", definition, Hash
|
51
|
+
|
52
|
+
unless definition[ "service" ]
|
53
|
+
raise ParserError, "missing element: service"
|
54
|
+
end
|
55
|
+
|
56
|
+
point.add_pending_interceptor definition
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,56 @@
|
|
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/configuration/yaml/utils'
|
35
|
+
|
36
|
+
module Copland
|
37
|
+
module Configuration
|
38
|
+
module YAML
|
39
|
+
|
40
|
+
# This delegate is responsible for processing an element the 'listen-to'
|
41
|
+
# construct.
|
42
|
+
class ListenerProcessor
|
43
|
+
include TypeValidator
|
44
|
+
|
45
|
+
# Adds the given definition to the point as an event producer. (See
|
46
|
+
# ServicePoint::add_event_producer.)
|
47
|
+
def process( point, definition )
|
48
|
+
ensure_element_type "listen-to-element", definition, String
|
49
|
+
point.add_event_producer definition
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|