## Component Loaders

Brendan Eich <brendan@mozilla.org>
John Bandauer <jband@netscape.com>
Mike McCabe <mccabe@netscape.com>
Mike Shaver <shaver@mozilla.org>
Suresh Duddi <dp@netscape.com>

### Scope of document

- Component Developers
- Clients of XPCOM (for information only)

### Why Component Loaders

Currently XPCOM requires all component to be packaged in DLLs and uses the dynamic loading mechanism available with each platform to accomplish instantiation of component. This method doesn't blend well with say components written in java or javascript and packaged different from a DLL. Hence the proposal for Component Loaders.

### Component Loaders

XPCOM in its simplest form can be viewed as creating instances of objects given a CONTRACTID or ClassID. How it does this instantiation is specific to XPCOM and opaque to clients of XPCOM.

Internally XPCOM maps the passed in CONTRACTID to a CID and then the CID maps into a DLL name. XPCOM loads the DLL assuming the dynamic loading mechanism to create a factory. Then, asks the factory to create a particular instance. Here are roughly the steps involved:

1. CreateInstance(..., CONTRACTID,...)
2. Map CONTRACTID to CID
3. Map CID to DLL
4. factory = Dynamically Load DLL to create Factory
5. Use Factory to create object instance

The proposal for Component Loaders is to get XPCOM to delegate the loading to a component loader:

- CreateInstance(..., CONTRACTID,...)
- Map CONTRACTID to CID
- Map CID to ComponentType
- If ComponentType is DLL

- factory = Dynamically Load DLL to create Factory

- else

- ComponentLoaderServiceCONTRACTID = "@mozilla.org/xpcom/component-loader;1?type=" + ComponentType *
- loaderInstance = GetService(..., ComponentLoaderServiceCONTRACTID,...)
- factory = loaderInstance->CreateFactory(..., componentLocation,...)

- Use Factory to create object instance

#### Format of ComponentType

ComponentType is assumed to be mimetype.

#### Component Registration

Registration of components in DLLs wont change. ComponentType of DLL is assumed here. To facilitate registration of components with specifc component types, the component manager will provide the following API:

`RegisterComponentWithType(const nsCID &aClass,`
`const char *aClassName,`
`const char *aContractID,`
`const char *aComponentType,`
`const char *aComponentLocation,`
`PRBool aReplace,`
`PRBool aPersist);`

#### Component Loader Service Registration

Since the loader is just another component with a special contractid, there is no special registration of the component loader. Component Loaders use either the RegisterComponent() api if they are a DLL (most common) or use RegisterComponentWithType() api if they are themselves of a particular type (very rare).

### Autoregistration of non DLL Components and Component Loaders

<Need to figure this out>

* ContractID syntax might change

Last Modified: 1 Aug 1999 Suresh Duddi <dp@netscape.com>