How the Finder can determine which application handles a particular file on MacOS X?
How the Finder can distinguish a bundle from a simple folder ? *
How the Finder can set the document's icon.
All these operations are handled by the MacOS X Launch Service. This service uses a database to record informations about all applications.
By example, when the finder copies an application on the hard drive from a distant volume or any other device, it populates the registry with the informations contained in the Content.plist file.
You can explore and modify the Launch Service database with a the little tool called lsregister located at path /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister.
(*) the finder examinates also the HFS+ bundle flag on a folder to detect a bundle. You can use the developer tool SetFile to switch on/off the flag