6.1 カスタム・サービスの作成

カスタム・サービスでは、JSMServiceインターフェースを実装する必要があります。
お使いの開発環境からjsm.jar、jsmservice.jar、jsmutil.jarにアクセスできるようにしてください。
カスタム・サービスを作成してコンパイルします。
カスタム・サービス・クラスを、クラス・ディレクトリの下のパッケージ・ディレクトリに入れます。
/jsm/instance/classes/com/lansa/jsm/userdefined/XYZService.class
 
システム・ディレクトリのservice.propertiesにエントリーを追加します。
service.XYZService=com.lansa.jsm.userdefined.XYZService
 
注意:ユーザー定義サービスの使用を許可する標準 LANSA Integrator ライセンスの場合、カスタム・サービス・クラスのパッケージ名で接頭辞 com.lansa.jsm.userdefined. を使用する必要があります。特別なライセンス調整を行わない限り、カスタム・サービスではこの命名規則を使用してください。
XYZService.propertiesというプロパティ・ファイルをプロパティ・ディレクトリに作成します。
#!<studio-project id="20050606-115520" name="XYZ_Project">

  1. XYZService resource ( Default )
    message.001=XYZService successfully loaded
    message.002=XYZService successfully unloaded
    message.003=Command is not supported :
    #!</studio-project>
     
    LANSAファンクションのサンプル
    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)
     
    XYZServiceコードのサンプル
    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 ( "" ) ;
        }
    }