6 1 Create your Custom Service

LANSA Integrator

6.1 Create your Custom Service

Your custom service needs to implement the JSMService interface.

Your development environment needs to have access to jsm.jar, jsmservice.jar and jsmutil.jar.

Create and compile your custom service.

Put your custom service class in the package directory below the classes directory.

 

/jsm/instance/classes/com/lansa/jsm/userdefined/XYZService.class

 

Add an entry to service.properties in the system directory.

 

service.XYZService=com.lansa.jsm.userdefined.XYZService

 

Note: Standard LANSA Integrator licences that permit the use of user-defined services, require that the custom service class package name uses the com.lansa.jsm.userdefined. prefix. Unless you make special licencing arrangements, your custom services must use this naming convention.

Create a properties file called XYZService.properties in the properties directory.

 

#!<studio-project id="20050606-115520" name="XYZ_Project">

# XYZService resource ( Default )

message.001=XYZService successfully loaded

message.002=XYZService successfully unloaded

message.003=Command is not supported :

#!</studio-project>

 

 

Sample LANSA function

 

USE BUILTIN(JSM_OPEN) TO_GET(#JSMSTS #JSMMSG)

USE BUILTIN(JSM_COMMAND) WITH_ARGS(SERVICE_LOAD(XYZSERVICE) TRACE(*YES)) TO_GET(#JSMSTS #JSMMSG)

USE BUILTIN(JSM_COMMAND) WITH_ARGS(SERVICE_UNLOAD) TO_GET(#JSMSTS #JSMMSG)

USE BUILTIN(JSM_CLOSE) TO_GET(#JSMSTS #JSMMSG)

 

 

Sample XYZService code

 

package com.lansa.jsm.userdefined ;

 

import java.io.* ;

import java.net.* ;

import java.util.* ;

 

import com.lansa.jsm.* ;

 

public final class XYZService implements JSMService

{

    private JSMTrace m_trace = null ;

    private JSMResource m_serviceResource = null ;

 

    public XYZService ()

    {

        if ( !JSMManager.isLicenced ( this ) )

        {

            throw new IllegalArgumentException ( "Class is not licenced : " + this.getClass().getName() ) ;

        }

    }

 

    public final void service ( JSMContainer container )

    {

        m_trace = container.getServiceTrace () ;

 

        m_serviceResource = container.getServiceResource () ;

    }

 

    public final JSMResponse command ( JSMCommand command ) throws JSMException

    {

        try

        {

            if ( m_trace != null )

            {

                m_trace.print ( command ) ;

            }

 

            JSMResponse response = runCommand ( command ) ;

 

            if ( m_trace != null )

            {

                m_trace.print ( command, response ) ;

            }

 

            return response ;

        }

        catch ( Throwable t )

        {

            if ( m_trace != null )

            {

                m_trace.print ( command, t ) ;

            }

 

            return new JSMResponse ( t ) ;

        }

    }

 

    private final JSMResponse runCommand ( JSMCommand command ) throws Exception

    {

        if ( command.equals ( JSMCommand.SERVICE_LOAD ) )

        {

            return commandLOAD ( command ) ;

        }

 

        if ( command.equals ( JSMCommand.SERVICE_UNLOAD ) )

        {

            return commandUNLOAD ( command ) ;

        }

 

        if ( command.equals ( "SEND" ) )

        {

            return commandSEND ( command ) ;

        }

 

        return new JSMResponse ( JSMResponse.ERROR, m_serviceResource.getResource ( "message.003" ) + " " + command.getCommand () ) ;

    }

 

    private final JSMResponse commandLOAD ( JSMCommand command ) throws Exception

    {

        return new JSMResponse ( m_serviceResource.getResource ( "message.001" ) ) ;

    }

 

    private final JSMResponse commandUNLOAD ( JSMCommand command ) throws Exception

    {

        return new JSMResponse ( m_serviceResource.getResource ( "message.002" ) ) ;

    }

 

    private final JSMResponse commandSEND ( JSMCommand command ) throws Exception

    {

        return new JSMResponse ( "" ) ;

    }

}