ホーム > デベロッパ > J2ME / MIDP プログラミング > 実機に載せよう

第4回:実機に載せよう(ダウンサイズ)

001: //package com.s_cradle.improve.client;
002: 
003: import java.io.*;
004: //import com.s_cradle.improve.Constants;
005: import javax.microedition.lcdui.Alert;
006: 
007: /**
008:  * Copyright (C) 2003 Sophia Cradle, Inc.
009:  *
010:  * ポーリングが後に続くタスクを行うクラスです。
011:  * オペレーションのadd, remove, set, sendを発行します。
012:  *
013:  * @author Masaru Yoshimura
014:  */
015: public class F/*FollowedByPollingTask*/ extends Z/*Task*/ {
016:     //downsize 定数展開
017:     /*
018:     private static final String SET_STATUS = String.valueOf(
                                                           Constants.ITEM_INDEX_STATUS);
019:     private static final String STATUS_LOGOFF = String.valueOf(
                                                               Constants.STATUS_LOGOFF);
020: 
021:     private static final String TYPE_MESSAGE = String.valueOf(
                                                         Constants.MESSAGE_TYPE_NORMAL);
022:     private static final String WARNING_CONNECT_MESSAGE =
                                                       "前回の通信処理が失敗しました。";
023:     private static final String WARNING_SERVER_MESSAGE =
                                                              "サーバがエラーを返しました。";
024:     */
025: 
026:     private static final String[][] account/*ITEMS*/ = new String[][]{
027:         new String[]{
028:         "account"/*Constants.PARAMETER_ACCOUNT*/,"password"/*
                                                          Constants.PARAMETER_PASSWORD*/,
029:         "target"/*Constants.PARAMETER_TARGET*/
030:         },
031:         new String[]{
032:         "account"/*Constants.PARAMETER_ACCOUNT*/,"password"/*
                                                          Constants.PARAMETER_PASSWORD*/,
033:         "target"/*Constants.PARAMETER_TARGET*/
034:         },
035:         new String[]{
036:         "account"/*Constants.PARAMETER_ACCOUNT*/,"password"/*
                                                          Constants.PARAMETER_PASSWORD*/,
037:         "item"/*Constants.PARAMETER_ITEM*/,"content"/*Constants.PARAMETER_CONTENT*/
038:         },
039:         new String[]{
040:         "account"/*Constants.PARAMETER_ACCOUNT*/,"password"/*
                                                         Constants.PARAMETER_PASSWORD*/,
041:         "target"/*Constants.PARAMETER_TARGET*/,
042:         "type"/*Constants. PARAMETER_TYPE*/,"content"/*Constants.PARAMETER_CONTENT*/
043:         },
044:     };
045: 
046:     /*
047:     public static final int FBPT_ADD = 0;
048:     public static final int FBPT_REMOVE = 1;
049:     public static final int FBPT_SET = 2;
050:     public static final int FBPT_SEND = 3;
051:     */
052: 
053:     private static final int[] password/*TASK*/ = new int[]{
054:         2,3,4,5/*TASK_ADD,TASK_REMOVE,TASK_SET,TASK_SEND*/
055:     };
056: 
057: 
058:     /**
059:      * コンストラクタ。それぞれのオペレーションの値を引数にとります。
060:      */
061:     public F/*FollowedByPollingTask*/(int task, String[] strs1) {
062:         this.A/*parameterNames*/ = account/*ITEMS*/[task];
063:         this.E/*task*/ = password/*TASK*/[task];
064:         switch(task){
065:             case 0/*FBPT_ADD*/:
066:             case 1/*FBPT_REMOVE*/:
067:                 if( strs1.length == 1 ){
068:                     this.B/*parameterValues*/ = new String[]{D/*strs*/[0]/*
                                           account*/,D/*strs*/[1]/*password*/,strs1[0]};
069:                 }
070:                 break;
071:             case 2/*FBPT_SET*/:
072:                 if( strs1.length == 2 ){
073:                     this.B/*parameterValues*/ = new String[]{D/*strs*/[0]/*
                                            account*/,D/*strs*/[1]/*password*/,strs1[0],
074:                         strs1[1]};
075:                 }
076:                 break;
077:             case 3/*FBPT_SEND*/:
078:                 if( strs1.length == 3 ){
079:                     this.B/*parameterValues*/ = new String[]{D/*
                                 strs*/[0]/*account*/,D/*strs*/[1]/*password*/,strs1[0],
080:                         strs1[1],strs1[2]};
081:                 }
082:                 break;
083:         }
084:         if(this.A/*parameterNames*/ == null){
085:             throw new IllegalArgumentException("
                                       number of argument names and values not match!");
086:         }
087: 
088:         //status = 0/*STATUS_NOT_YET*/;
089:     }
090: 
091:     /**
092:      * 失敗時の処理
093:      */
094:     protected void Z/*processFailed*/() {
095:         System.out.println("f");
096:         Alert alert = new Alert("サーバがエラーを返しました。"/*WARNING_SERVER_MESSAGE*/);
097:         alert.setTimeout(Alert.FOREVER);
098:         I/*ImproveMIDlet*/.Code/*setCurrent*/(alert, I/*
                                                ImproveMIDlet*/.StackMap/*getCurrent*/());
099:     }
100: 
101:     /**
102:      * Throwableが投げられた時の処理
103:      */
104:     protected void I/*processThrowable*/(){
105:         System.out.println("t");
106:         Alert alert = new Alert(
                            "前回の通信処理が失敗しました。"/*WARNING_CONNECT_MESSAGE*/);
107:         for(int i=0;i<B/*parameterValues*/.length;i++){
108:             System.out.println(i+":"+B/*parameterValues*/[i]);
109:         }
110:         System.out.println();
111:         alert.setTimeout(Alert.FOREVER);
112:         I/*ImproveMIDlet*/.Code/*setCurrent*/(
                                     alert, I/*ImproveMIDlet*/.StackMap/*getCurrent*/());
113:     }
114: 
115:     /**
116:      * 返値を読んだ後の処理
117:      */
118:     protected void Code/*processAfterReturnValue*/(int result, DataInputStream input)
119:             throws java.io.IOException {
120:         if( E/*task*/ == 4/*TASK_SET*/ && B/*parameterValues*/[2].equals(
                           String.valueOf(4/*Constants.ITEM_INDEX_STATUS*/)/*SET_STATUS*/)
121:             && B/*parameterValues*/[3].equals(String.valueOf(
                                        0/*Constants.STATUS_LOGOFF*/)/*STATUS_LOGOFF*/) ){
122:             I/*ImproveMIDlet*/.I/*midlet*/.notifyDestroyed();
123:         }
124: 
125:         Z/*Task*/ t = Z/*getTask*/(6/*Task.TASK_POLLING*/,null);
126:         if( E/*task*/ == 5/*TASK_SEND*/ ){
127:             N/*PollingTask*/ pt = (N/*PollingTask*/)t;
128:            t.Code/*addOwnMessage*/(B/*parameterValues*/[2],B/*parameterValues*/[4]);
129:         }
130:         t.StackMap/*schedule*/(0);
131:     }
132: }