indexing
	namespace: "candidate"
	cluster: "fso"
	description: "Represent a file system object."
	original_author: "Justin Finnerty"
	original_date: "July 2005"
	current_date: "$Date: 2005/09/28 13:38:36 $"
	current_author: "$Author: finnerty $"
	revision: "$Revision: 2.3 $"
	-- $Log: fso_prop_factory.ge,v $
	-- Revision 2.3  2005/09/28 13:38:36  finnerty
	-- Updated to work with ISE
	--
	-- Revision 2.2  2005/09/05 02:35:01  finnerty
	-- Updated to conform to cursors/containers in the GOBO library and
	-- test programs compile with SE and VE.
	--
	-- Revision 2.1  2005/09/02 08:08:21  finnerty
	-- Renamed *.e to *.ge for gepp
	--
	-- Revision 2.0  2005/08/26 23:30:22  finnerty
	-- == alpha version ==
	--
	-- Revision 1.4  2005/08/24 23:32:16  finnerty
	-- Added "default_create" as one of the creation methods.
	--
	-- Revision 1.3  2005/08/24 23:25:29  finnerty
	-- Made public methods to replace FILE_TOOLS for testing file existance.
	--
	-- Revision 1.2  2005/08/24 12:01:54  finnerty
	-- Improved detection of "system_notation".
	--
	-- Revision 1.1  2005/08/21 11:54:39  finnerty
	-- *** empty log message ***
	--
	--
   --
class FSO_PROP_FACTORY
	-- Provide a queriable inteface to a file system object.

#ifdef SE
insert
#else
inherit
#endif
   KL_SHARED_FILE_SYSTEM

creation {ANY}
	make_root
			
feature {NONE}
	-- Creation methods restricted as valid during creation only.
	make_root (a_filename: STRING) is
			-- Create the root node of a tree.
		require
			Name_required: a_filename /= Void and not a_filename.is_empty
		do
#ifdef SE
			m_name := a_filename.twin
#else
			!!m_name.make_from_string (a_filename)
#endif
			reset_properties
		ensure			
			Has_properties: properties /= Void
		end
feature {ANY}
	-- Status report
	exists: BOOLEAN is
			-- Is there a corresponding file system object?
		require
			Has_properties: properties /= Void
			Valid_name: name /= Void
		do
			Result := properties.exists
		ensure
			-- Result implies `path' is a real file system object
		end

feature {ANY}
	-- File handling
	frozen test_path (a_path: STRING): BOOLEAN is
			-- Test if `a_path' exists, no change to internal object. 
			-- This uses the lstat method so will return true for 
			-- dangling symlinks.
		do
			Result := m_factory.new (a_path).exists
		end

	frozen test_path_join (a_path, a_sub_path: STRING): BOOLEAN is
			-- Test if `a_sub_path' joined to `a_path' exists, no change
			-- to internal object. This uses the lstat method so will
			-- return true for dangling symlinks.
		local
			l_path: STRING
		do
#ifdef SE
			l_path := a_path.twin
#else
			!!l_path.make_from_string (a_path)
#endif
			to_file_path_with (l_path, a_sub_path)
			Result := m_factory.new (l_path).exists
		end

feature {ANY}
	-- Path handling
	frozen to_file_path_with (a_path, a_leaf: STRING) is
			-- Append system's directory separator and `a_leaf' to `a_path'.
		require
			No_empty_path: a_path /= Void and not a_path.is_empty
								a_leaf /= Void and not a_leaf.is_empty
		do
			-- Add two part of path together.
			a_path.copy (file_system.pathname( a_path, a_leaf ))
		ensure
			-- a_path.is_empty implies invalid path
		end

feature {ANY}
	-- Access
	properties: FSO_PROPERTIES
			-- Properties of the real file system object.  This is set by
			-- default, reset by calling `reset_properties'.

	path, name: STRING is
			-- File name of file system object.
		do
#ifdef SE
			Result := m_name.twin
#else
			!!Result.make_from_string (m_name)
#endif
		end


feature {ANY}
	-- Procedures
	set_name (a_new_name: STRING) is
			-- Change name of FSO
		require
			-- a_new_name is a valid file path name
			Valid_file_name: is_valid_path (a_new_name)
		do
			m_name.copy (a_new_name)
		end

	reset_properties is
			-- Fetch properties for the current path from the file
			-- system.
		do
			properties := m_factory.new (path)
		end
	
feature {NONE}
	-- Implementation
	m_factory: FACTORY_ARG [STRING, FSO_PROPERTIES] is
			-- Factory for FSO_PROPERTIES
		once
			-- Use POSIX factory
			!POSIX_FSO_PROP!Result.make
		end
feature {ANY}
	-- Status Report		
	frozen is_valid_path (a_new_name: STRING): BOOLEAN is
			-- Check path syntax
		do
			Result := file_system.is_relative_pathname (a_new_name) or else
			file_system.is_absolute_pathname (a_new_name)
		end

feature {NONE}
	-- Private attributes
	m_name: STRING
			-- The name of the real file system object

invariant	
	Valid_name: m_name /= Void and not m_name.is_empty
				
end -- class FSO_PROP_FACTORY
