- package poker;
- import org.kxml.Xml;
- import org.kxml.parser.XmlParser;
- import org.kxml.parser.ParseEvent;
- import javax.microedition.io.*;
- import java.io.*;
- import javax.microedition.lcdui.*;
- import java.util.*;
- /**
- * <p>Title: </p>
- * <p>Description: </p>
- * <p>Copyright: Copyright (c) 2004</p>
- * <p>Company: </p>
- * @author not attributable
- * @version 1.0
- */
- class GetServicData {
- static String url="";
- static List imList;
- static String[] imValue;
- static String[] imID;
- static Image ServerImage,RoomImage,TableImage;
- static int kind=0;
- static String value="";
- /* kind define
- * -------------
- * 1:ServerList
- * 2:RoomList
- * 3:TableList
- * 4:AuthenticationUser
- * 5:ifCanGetSeat
- *
- * Required
- * -------------
- * url
- * all kind of Image
- * kind
- *
- * return
- * -------------
- * imList use in serverlist,roomlist,tablelist
- * imValue use in serverlist
- * imID use in serverlist,roomlist,tablelist
- *
- */
- public static void connect() {
- HttpConnection hc = null;
- DataOutputStream dos=null;
- DataInputStream in = null;
- String s="";
- StringBuffer b = new StringBuffer();
- try {
- hc = (HttpConnection)Connector.open(url);
- hc.setRequestMethod("GET");
- in = hc.openDataInputStream();
- System.out.println("open stream ok!");
- int ch;
- while((ch = in.read()) != -1)
- {
- b.append((char) ch);
- }
- s=b.toString();
- //System.out.println("read from service:"+s);
- in.close();
- hc.close();
- }
- catch (Exception ioe) {
- Error.errCode=1;
- Error.errStr="Error when make a connection.";
- return;
- }
- parseUsingkXML( s );
- }
- private static void parseUsingkXML( String xml ){
- try {
- ByteArrayInputStream bin = new ByteArrayInputStream(xml.getBytes() );
- InputStreamReader in = new InputStreamReader( bin );
- XmlParser parser = new XmlParser( in );
- Vector items = new Vector();
- switch( kind ){
- case 1:
- Func.deleteList(imList);
- parsekXMLItemsForServerList( parser);
- break;
- case 2:
- Func.deleteList(imList);
- parsekXMLItemsForRoomList( parser);
- break;
- case 3:
- Func.deleteList(imList);
- parsekXMLItemsForTableList( parser );
- break;
- case 4:
- parsekXMLItemsForLogin( parser );
- break;
- case 5:
- parsekXMLForIfCanSit( parser );
- break;
- }
- return ;
- }
- catch( IOException e ){
- Error.errCode=1;
- Error.errStr="parse Xml error!";
- return;
- }
- }
- private static void parsekXMLItemsForServerList( XmlParser parser) throws IOException {
- boolean inItem0 = false;
- boolean inItem1 = false;
- boolean inItem2 = false;
- int ii=0;
- while( true ){
- ParseEvent event = parser.read();
- switch( event.getType() ){
- case Xml.START_TAG:
- if (event.getName().equals("ServerID")){
- inItem0=true;
- ii++;
- }
- if( event.getName().equals( "Name" ) ){
- inItem1 = true;
- }
- if ( event.getName().equals("IP")){
- inItem2=true;
- }
- break;
- case Xml.END_TAG:
- if (event.getName().equals("ServerID")){
- inItem0 = false;
- }
- if( event.getName().equals( "Name" ) ){
- inItem1 = false;
- }
- if( event.getName().equals( "IP" ) ){
- inItem2 = false;
- }
- break;
- case Xml.TEXT:
- String ss="";
- ss=event.getText();
- if (inItem2){
- imValue[ii]=ss;
- }
- if( inItem1 ){
- imList.append(ss,RoomImage);
- }
- if (inItem0){
- imID[ii]=ss;
- }
- break;
- case Xml.END_DOCUMENT:
- return;
- }
- }
- }
- private static void parsekXMLItemsForRoomList( XmlParser parser) throws IOException {
- boolean inItem0 = false;
- boolean inItem1 = false;
- boolean inItem2 = false;
- boolean inItem3 = false;
- boolean itemOver=false;
- String s0="";
- String ss="";
- int ii=0;
- while( true ){
- ParseEvent event = parser.read();
- switch( event.getType() ){
- case Xml.START_TAG:
- if (event.getName().equals("RoomID")){
- inItem0=true;
- ii++;
- itemOver=false;
- }
- if( event.getName().equals( "Name" ) ){
- inItem1 = true;
- }
- if ( event.getName().equals("MaxPlayerCount")){
- inItem2=true;
- }
- if ( event.getName().equals("CurrentPlayerCount")){
- inItem3=true;
- itemOver=true;
- }
- break;
- case Xml.END_TAG:
- if (event.getName().equals("RoomID")){
- inItem0 = false;
- }
- if( event.getName().equals( "Name" ) ){
- inItem1 = false;
- }
- if( event.getName().equals( "MaxPlayerCount" ) ){
- inItem2 = false;
- }
- if( event.getName().equals( "CurrentPlayerCount" ) ){
- inItem3 = false;
- }
- break;
- case Xml.TEXT:
- s0 = event.getText();
- if(itemOver){
- ss=ss+"/"+s0+")";
- imList.append(ss, RoomImage);
- //System.out.println(ss);
- ss="";
- }
- else{
- if (inItem2){ss=ss+" (";}
- if (inItem0){
- }else{ ss=ss+s0;}
- }
- if (inItem0) {
- imID[ii] = s0;
- }
- break;
- case Xml.END_DOCUMENT:
- return;
- }
- }
- }
- //----get table list
- private static void parsekXMLItemsForTableList( XmlParser parser) throws IOException {
- boolean inItem0 = false;
- boolean inItem1 = false;
- boolean inItem2 = false;
- boolean itemOver=false;
- String s0="";
- String ss="";
- int ii=0;
- while( true ){
- ParseEvent event = parser.read();
- switch( event.getType() ){
- case Xml.START_TAG:
- if (event.getName().equals("TableID")){
- inItem0=true;
- ii++;
- itemOver=false;
- }
- if( event.getName().equals( "Name" ) ){
- inItem1 = true;
- }
- if ( event.getName().equals("FreeSeatCount")){
- inItem2=true;
- itemOver=true;
- }
- break;
- case Xml.END_TAG:
- if (event.getName().equals("TableID")){
- inItem0 = false;
- }
- if( event.getName().equals( "Name" ) ){
- inItem1 = false;
- }
- if( event.getName().equals( "FreeSeatCount" ) ){
- inItem2 = false;
- }
- break;
- case Xml.TEXT:
- s0 = event.getText();
- if(itemOver){
- ss=ss+"(free:"+s0+")";
- imList.append(ss, TableImage);
- //System.out.println(ss);
- ss="";
- }
- else{
- if (inItem0){
- }else{ ss=ss+s0;}
- }
- if (inItem0) {
- imID[ii] = s0;
- }
- break;
- case Xml.END_DOCUMENT:
- return;
- }
- }
- }
- //---end table list
- // -- login
- private static void parsekXMLItemsForLogin( XmlParser parser) throws IOException {
- boolean inItem0 = false;
- while( true ){
- ParseEvent event = parser.read();
- switch( event.getType() ){
- case Xml.START_TAG:
- if (event.getName().equals("int")){
- inItem0=true;
- }
- break;
- case Xml.END_TAG:
- if (event.getName().equals("int")){
- inItem0 = false;
- }
- break;
- case Xml.TEXT:
- String ss="";
- ss=event.getText();
- if (inItem0){
- url=ss;
- //System.out.print("ss=");
- //System.out.println(url);
- }
- break;
- case Xml.END_DOCUMENT:
- return;
- }
- }
- }
- //--- end login
- //--- if can sit ----
- private static void parsekXMLForIfCanSit( XmlParser parser) throws IOException {
- boolean inItem0 = false;
- while( true ){
- ParseEvent event = parser.read();
- switch( event.getType() ){
- case Xml.START_TAG:
- if (event.getName().equals("int")){
- inItem0=true;
- }
- break;
- case Xml.END_TAG:
- if (event.getName().equals("int")){
- inItem0 = false;
- }
- break;
- case Xml.TEXT:
- String ss="";
- ss=event.getText();
- if (inItem0){
- url=ss;
- //System.out.print("ss=");
- //System.out.println(url);
- }
- break;
- case Xml.END_DOCUMENT:
- return;
- }
- }
- }
- //----end if can sit ----
- public static String getIfCanSit(){
- String result="";
- url = "http://"+GameInfo.ServerAddress
- + "/gameservice/infomationservice.asmx/GetIfCanSit?gameID="
- + GameInfo.GameID+"&roomID="+GameInfo.RoomID
- + "&tableID="+GameInfo.TableID
- + "&accountID="+GameInfo.Account;
- kind=5;
- connect();
- result=url;
- System.out.println("if can sit result="+result);
- return result;
- }
- public static void getSeat(){
- //return seatID in imID
- //return accountlist in imValue
- }
- }