FileDocCategorySizeDatePackage
CBSTestServer.javaAPI DocphoneME MR2 API (J2ME)5867Wed May 02 18:00:32 BST 2007com.sun.tck.wma.cbs

CBSTestServer

public class CBSTestServer extends Object implements com.sun.wma.api.server.CBSServer
Implements CBSserver interface. This class will be used by the JDTS test harness to test CBS receive functionality.

Fields Summary
private CBSMessageConnection
cbsmess
private com.sun.tck.wma.MessageConnection
conn
private char
UCS_CHAR
private final String
CBS_SCHEME
The URL scheme for the CBS protocol.
Constructors Summary
public CBSTestServer()
Construct a new CBS test server.


               
      
Methods Summary
public voiddie()
CBS server terminates any active operations and frees up resources..

        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {
                System.err.println("Exception thrown by CBS Test server: " + e);
            }
        }
    
public voidinit()
Initialize CBS server.

        cbsmess = new CBSMessageConnection();
    
public voidsend(java.lang.String type, int segNum, java.lang.String address)
Send a CBS message.

param
type "gsm7", "ucs2", or "binary"
param
segNum Number of message segemnts
param
address CBS address for the message


        String urlFragment = address.substring(CBS_SCHEME.length());

        try {
            conn = cbsmess.openPrim(urlFragment);
        } catch (IOException ioe) {
            System.err.println("Exception thrown by CBS Test server: " + ioe);
        }

        int num = 0;

        if (type.equals("gsm7")) {
            TextMessage tmsg = (TextMessage)cbsmess.newMessage(MessageConnection.TEXT_MESSAGE, address);

            // construct the message
            switch (segNum){
                case 1:
                    num = 24;
                    break;
                case 2:
                    num = 26;
                    break;
                case 3:
                    num = 50;
		    break;
                case 4:
                    num = 74;
		    break;
                default:
                    num = 0;
            }

            String long_msg = "";;
            for (int i = 0; i < num; i++) {
                long_msg += "Hello "; // the string contains 6 chars
            }

            tmsg.setPayloadText(long_msg);
         
            try {
                conn.send(tmsg);
            } catch (Exception e) {
                System.err.println("Exception thrown by CBS Test server: " + e);
            }

        } else if (type.equals("ucs2")) {
            TextMessage tmsg = (TextMessage)cbsmess.newMessage(MessageConnection.TEXT_MESSAGE, address);

            // construct the message
            switch (segNum){
                case 1:
                    num = 60;
                    break;
                case 2:
                    num = 68;
		    break;
                case 3:
		    num = 128;
		    break;
                case 4:
                    num = 190;
		    break;
                default:
		    num = 0;
            }

            char[] ucs_chars = new char[num];
		
            for (int i = 0; i < num; i++) {
                ucs_chars[i] = UCS_CHAR; // char UCS_CHAR  = 0x00a4;
            }
            String long_msg = new String(ucs_chars);

            tmsg.setPayloadText(long_msg);

            try {
                conn.send(tmsg);
            } catch (Exception e) {
                System.err.println("Exception thrown by CBS Test server: " + e);
            }

        } else if (type.equals("binary")) {
            BinaryMessage bmsg = (BinaryMessage)cbsmess.newMessage(MessageConnection.BINARY_MESSAGE, address);

            // construct the message
            switch (segNum){
                case 1:
                    num = 130;
                    break;
                case 2:
                    num = 136;
                    break;
                case 3:
                    num = 260;
		    break;
                case 4:
                    num = 390;
		    break;
                default:
		    num = 0;
            }

            byte[] byte_msg = new byte[num];
            for (int i = 0; i < num; i++) {
                byte_msg[i] = (byte) i; // create a byte[]
            }

            bmsg.setPayloadData(byte_msg);

            try {
                conn.send(bmsg);
            } catch (Exception e) {
                System.err.println("Exception thrown by CBS Test server: " + e);
            }
        }