#-- # ============================================================================= # Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu) # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # * The names of its contributors may not be used to endorse or promote # products derived from this software without specific prior written # permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # ============================================================================= #++ require 'copland/errors' require 'copland/package' require 'copland/configuration/yaml/service-point' require 'copland/configuration/yaml/configuration-point' require 'copland/configuration/yaml/utils' module Copland module Configuration module YAML # This delegate is responsible for processing a package descriptor # into a Registry instance. class PackageProcessor include TypeValidator # Creates a new PackageProcessor that feeds into the given Registry # instance. def initialize( registry, loader ) @registry = registry @loader = loader end # The list of recognized key values in a package descriptor. VALID_KEYS = [ "id", "description", "service-points", "configuration-points", "contributions", "require" ] # The list of required key values in a package descriptor. REQUIRED_KEYS = [ "id" ] # Process the package descriptor +doc+ into the active Registry # instance. The +options+ parameter is used when processing service # and configuration points within this package descriptor. # The new Package instance is added directly to the registry. def process( doc, options={} ) ensure_element_type "package definition", doc, Hash validate_elements doc package = Package.new( @registry, doc["id"] ) @registry.add_package package doc.each_pair do |key, value| case key when "id" # already discovered and handled above when "description" package.description = value when "service-points" ensure_element_type "service-points", value, Hash processor = ServicePointProcessor.new( package, options ) value.each_pair do |name, definition| point = processor.process name, definition package.add_service_point point end when "configuration-points" ensure_element_type "configuration-points", value, Hash processor = ConfigurationPointProcessor.new( package, options ) value.each_pair do |name, definition| point = processor.process name, definition package.add_configuration_point point end when "contributions" ensure_element_type "contributions", value, Hash value.each_pair do |name, value| package.add_pending_contribution name, value end when "require" ensure_element_type "require", value, Array value.each do |name| @loader.use_library name end else raise CoplandBug, "[BUG] invalid element discovered too late:" + key.inspect end end end end end end end