/home/projects/magnet/reference/core/protocolHandlerDef

protocolHandlerDef

Overview

The <protocolHandlerDef> element can be used to extend the functionality of Magnet by adding a new protocol on top of the built-on file and http ones. For example, if you want to be able to retrieve resources from an FTP server using a <path> element you need to do two things. First, implement the ProtocolHandlerIF interface according to the contract it specifies, on top of FTP. Once this class is coded you need to tell Magnet how to associate the new protocol scheme to the class you just wrote. To perform the association between the protocol scheme and the class that provides the handling of the protocol you configure a so-called "protocol handler definition".

Attributes

Name Description Required Interpolation
type Defines the name of the protocol for which we provide a handler. yes yes
classname The name of the class that implements the interface ProtocolHandlerIF interface and provides the handling of that protocol. yes yes

Rendering Operations

When a <protocolHandlerDef> element is rendered, it performs the following operations in order:

  1. Resolves the type and classname attributes (using variable interpolation).
  2. Adds the new protocol handler definition to the central handler factory used by Magnet.

Examples

This example creates a new protocol handler for the FTP protocol. The association defines that the class com.mycorp.magnet.FtpProtocolHandler will be used everytime the ftp protocol is used.

<magnet xmlns:magnet="http://schemas.sapia-oss.org/magnet/"
        name="ProtocolHandlerDefExample1"
        description="This is a first example.">
...
    <protocolHandlerDef
            type="ftp"
            classname="com.mycorp.magnet.FtpProtocolHandler" />
...
</magnet>