# = Part
#
# A part encapsulates a service in the Framework. 
#
# code: 
# George Moschovitis  <gm@navel.gr>
#
# (c) 2004 Navel, all rights reserved.
# $Id: parts.rb 71 2004-10-18 10:50:22Z gmosx $

require "singleton"

require "n/l10n"

# gmosx, FIXME: safe is probably NOT needed!
$parts = N::SafeHash.new
$rewrites = N::SafeHash.new
$roles = N::SafeArray.new

module Kernel

	# Special require for part definitions.
	#
	def require_part(path)
		require("p/#{path}/part")
		for lc in $lc_use
			begin
				require("p/#{path}/#{lc}")
			rescue LoadError => e
				# Drink it!
				# $log.debug "No localization files for part '#{path}'" if $DBG
			end
		end
	end
	
	# Register a part
	#
	def register_part(part_class)
		part = part_class.instance()
		$parts[part.name] = part
		
		# gmosx: DOESNT work yet, we have to manage
		# the require order, perhaps DI/Copland can help
		# here?
		# auto require the parts this one depends
		# on. 
		#
		#for dep_part in part.dependencies
		#	require_part(dep_part)
		#end
			
		part.start()		
	end
	
end

# ----------------------------------------------------------------------

module N

# = Part
#
# A module of functionality in the framework
#
# = Design:
#
# Q: Part should include Entity to allow optional runtime 
# administration/customization ??
#
class Part
	include Singleton 
	
	# the (internal) name of this part
	attr_accessor :name
	# the tile of this part (intended for humans)
	attr_accessor :title
	# a description of the part
	attr_accessor :body
	# the version of this part
	attr_accessor :version
	# the vendor
	attr_accessor :vendor
	# url of the vendor's homepage.
	attr_accessor :vendor_url
	# an array of part names this part depends on. The named
	# parts are automatically required when requiring this part.
	attr_accessor :dependencies
	
	prop_accessor String, :path

	def initialize
		sitemap()
		rewrites()
		roles()
		prepared_statements()
	end
	
	# Install this part to the application. Called
	# by the application installation scripts. Typically
	# inserts bootstrap data in the database
	#
	def install
	end

	# Uninstall this part. Typically cleans up the
	# database.
	#	
	def unistall
	end

	#
	#	
	def start
	end
	
	#
	#
	def stop
	end

	# Define the pages this part introduces.
	#
	def sitemap
	end	

	# Define the rewrite rules for this part.
	#
	def rewrites
	end
	
	# Define the roles this part introduces.
	#
	def roles
	end

	# Define usefull prepared statements for this 
	# part   
	#
	def prepared_statements
	end

	#
	#
	def to_s
		@name
	end	
end

end # module

# Namespace for parts.
#
module P
end # module