⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 converter.java

📁 用Java实现的TCAP协议
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 *  Copyrights:
 *
 *  Copyright - 1999 Sun Microsystems, Inc. All rights reserved.
 *  901 San Antonio Road, Palo Alto, California 94043, U.S.A.
 *
 *  This product and related documentation are protected by copyright and
 *  distributed under licenses restricting its use, copying, distribution, and
 *  decompilation. No part of this product or related documentation may be
 *  reproduced in any form by any means without prior written authorization of
 *  Sun and its licensors, if any.
 *
 *  RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the United
 *  States Government is subject to the restrictions set forth in DFARS
 *  252.227-7013 (c)(1)(ii) and FAR 52.227-19.
 *
 *  The product described in this manual may be protected by one or more U.S.
 *  patents, foreign patents, or pending applications.
 *
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 *  Author:
 *
 *  AePONA Limited, Interpoint Building
 *  20-24 York Street, Belfast BT15 1AQ
 *  N. Ireland.
 *
 *
 *  Module Name   : JAIN TCAP RI
 *  File Name     : Converter.java
 *  Author        : Aidan Mc Gowan + Colm Hayden [Aepona]
 *                  Eugene Bell [AePONA]
 *  Approver      : Aepona JAIN Team
 *  Version       : 1.1
 *  Notes         :
 *
 * HISTORY
 * Version   Date      Author              Comments
 * 1.0     19/03/99   AMcG, CH             Initial version
 * 1.0d    15/8/2000  Eugene Bell          Final Public Release
 * 1.1     26/4/2001  Eugene Bell          Maintenance Release 1.1
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */
package com.aepona.jain.protocol.ss7.tcap;

import jain.ParameterNotSetException;
import jain.protocol.ss7.tcap.TcapConstants;
import jain.protocol.ss7.tcap.DialogueIndEvent;
import jain.protocol.ss7.tcap.ComponentIndEvent;
import jain.protocol.ss7.tcap.DialogueReqEvent;
import jain.protocol.ss7.tcap.ComponentReqEvent;
import jain.protocol.ss7.tcap.component.*;
import jain.protocol.ss7.tcap.dialogue.*;
import jain.protocol.ss7.SccpUserAddress;

 /**
  * Converts received ComponentRequest and DialogueRequest Events to Component and Dialogue
  * Indication Events.  Sets all Mandatory parameters of Indication Events to equalivalant values
  * of received Request Event.
  *
  * @version     1.1
  * @author      AePONA
  */
public class Converter{

  /**
  * Converts Component Request Events to Component Indication Events
  *
  * @param <var>requestComponent</var> the request component to be converted
  * @param <var>eventSource</var> the object to act as the event source for the
  * converted component
  * @param <var>lastComponent</var> indicates whether this is the last component being sent
  */
  protected static ComponentIndEvent reqToInd( ComponentReqEvent requestComponent,
                                            Object eventSource,
                                            boolean lastComponent){

    System.out.println("Converter : reqToInd(Component) : In Component convertor");

    // Generic ComponentIndication Event to be returned from this method.
    ComponentIndEvent componentIndication = null;

    // Checks the received component's primitive type.  Depending on primitive
    // type the appropriate parameters are set for each Component.
    switch(requestComponent.getPrimitiveType()) {

      // handles INVOKE components
      case TcapConstants.PRIMITIVE_INVOKE: {
        componentIndication = invokeReqToInd((InvokeReqEvent)requestComponent,
                                              eventSource,
                                              lastComponent);
        break;
      }

      // handles ERROR components
      case TcapConstants.PRIMITIVE_ERROR: {
        componentIndication = errorReqToInd((ErrorReqEvent)requestComponent,
                                            eventSource,
                                            lastComponent);
        break;
      }

      // handles REJECT components
      case TcapConstants.PRIMITIVE_REJECT: {
        componentIndication = rejectReqToInd((RejectReqEvent)requestComponent,
                                             eventSource,
                                             lastComponent);
        break;
      }

      // handles RESULT components
      case TcapConstants.PRIMITIVE_RESULT: {
        componentIndication = resultReqToInd((ResultReqEvent)requestComponent,
                                             eventSource,
                                             lastComponent);
        break;
      }
    }
    // return the new componentIndication to the object that invoked this method
    return (componentIndication);
  }

  /**
  * Converts Dialogue Request Events to Dialogue Indication Events
  *
  * @param <var>dialogueReq</var> the dialogue request to be converted
  * @param <var>eventSource</var> the object to act as the event source for the
  * converted dialogue
  * @param <var>componentsPresent</var> indicates whether there are any components
  * accompanying this Dialogue primitive
  */
  protected static DialogueIndEvent reqToInd(DialogueReqEvent dialogueReq,
                                             Object eventSource,
                                             boolean componentsPresent) {

    System.out.println("Converter : reqToInd(Dialogue) : In dialogue convertor");

    // Generic DialogueIndication Event to be returned from this method.
    DialogueIndEvent dialogueIndication = null;

    /**
    * Checks the received dialogues's primitive type.  Depending on primitive
    * type the appropriate parameters are set for each Dialogue.
    */
    switch(dialogueReq.getPrimitiveType()) {

      // Dialogue PRIMITIVE of type UNI
      case TcapConstants.PRIMITIVE_UNIDIRECTIONAL :{
        dialogueIndication = uniReqToInd((UnidirectionalReqEvent)dialogueReq,
                                         eventSource,
                                         componentsPresent);
        break;
      }

      // Dialogue PRIMITIVE of type BEGIN
      case TcapConstants.PRIMITIVE_BEGIN : {
        dialogueIndication = beginReqToInd((BeginReqEvent)dialogueReq,
                                           eventSource,
                                           componentsPresent);
        break;
      }

      // Dilaogue PRIMITIVE of type CONTINUE
      case TcapConstants.PRIMITIVE_CONTINUE : {
        dialogueIndication = continueReqToInd((ContinueReqEvent)dialogueReq,
                                              eventSource,
                                              componentsPresent);
        break;
      }

      // Dialogue PRIMITIVE of type END
      case TcapConstants.PRIMITIVE_END : {
        dialogueIndication = endReqToInd((EndReqEvent)dialogueReq,
                                         eventSource,
                                         componentsPresent);
        break;
      }

      // Dilaogue PRIMITIVE of type USER ABORT
      case TcapConstants.PRIMITIVE_USER_ABORT : {
        dialogueIndication = userAbortReqToInd((UserAbortReqEvent)dialogueReq,
                                               eventSource,
                                               componentsPresent);
        break;
      }
    }
    return(dialogueIndication);
  }

  /**
  * Converts an InvokeReqEvent to an InvokeIndEvent component with the specified Object
  * acting as the new Event source
  * @param <var>eventSource</var> the EventSource of the new Component indication
  * @param <var>lastComponent</var> indicates whether this is the last component being sent
  */
  private static InvokeIndEvent invokeReqToInd(InvokeReqEvent invokeRequest,
                                               Object eventSource,
                                               boolean lastComponent) {
    InvokeIndEvent invokeIndication = null;
    Operation operation = null;

    try {
      operation = invokeRequest.getOperation();
    } catch (ParameterNotSetException ex) {}

    invokeIndication = new InvokeIndEvent(eventSource, operation, lastComponent);
    invokeIndication.setLastInvokeEvent(invokeRequest.isLastInvokeEvent());

    try {
      invokeIndication.setDialogueId(invokeRequest.getDialogueId());
    } catch (ParameterNotSetException ex) {}

    try {
      invokeIndication.setInvokeId(invokeRequest.getInvokeId());
    } catch (ParameterNotSetException ex) {}

    try {
      invokeIndication.setParameters(invokeRequest.getParameters());
    } catch (ParameterNotSetException ex) {}

    return (invokeIndication);
  }

  /**
  * Converts an ErrorReqEvent to an ErrorIndEvent component with the specified Object
  * acting as the new Event source
  * @param <var>eventSource</var> the EventSource of the new Component indication
  * @param <var>lastComponent</var> indicates whether this is the last component being sent
  */
  private static ErrorIndEvent errorReqToInd(ErrorReqEvent errorRequest,
                                             Object eventSource,
                                             boolean lastComponent){
    ErrorIndEvent errorIndication = null;
    int did = 0;
    int errorType = 0;
    byte[] errorCode = null;

    try {
      did = errorRequest.getDialogueId();
    } catch (ParameterNotSetException ex) {}

    try {
      errorType = errorRequest.getErrorType();
    } catch (ParameterNotSetException ex) {}

    try {
      errorCode = errorRequest.getErrorCode();
    } catch (ParameterNotSetException ex) {}

    errorIndication = new ErrorIndEvent(eventSource,
                                        did,
                                        errorType,
                                        errorCode,
                                        lastComponent);

    try {
      errorIndication.setInvokeId(errorRequest.getInvokeId());
    } catch (ParameterNotSetException ex) {}

    try {
      errorIndication.setParameters(errorRequest.getParameters());
    } catch (ParameterNotSetException ex) {}

    return (errorIndication);
  }

  /**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -