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

📄 getdata.java

📁 移动商务平台
💻 JAVA
字号:
/**
 *
 ******************************************
 ***  to Kristy,SUN YAT-SEN UNIVERSITY  *** 
 ******************************************  
 *
 *mTrade.java
 *Create on November,2003
 *Company:LeftBank
 *
 *@author Ben,XIDIAN UNIVERSITY
 *@version 0.1
 *
 */
 
 
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.DataInputStream;
import javax.microedition.io.HttpConnection;
import javax.microedition.io.Connector;

import org.kxml.*;
import org.kxml.parser.*;

import java.util.Vector;

/**
 *this class downloads information of Merchandises.
 *it opens a URL and calls a ASP which queries the database and generates XML Data
 */
public class GetData
{
      String url = "http://localhost/m-trade/asp/show.asp";
      DataInputStream ins = null;
      ParseEvent event;
      AbstractXmlParser parser;
      Vector itembrand,itemquantity,itemprice;


      public GetData()
      {

  	    try
  	    {	
  	  	 ins = Connector.openDataInputStream(url);
  		 parser = new XmlParser(new InputStreamReader(ins));
                        
 	    }
 	    catch(IOException ex)
  	    {
  	  	 System.out.println("GetData construction Error.");
  	    }	
  		
  	    itembrand = new Vector();
  	    itemquantity = new Vector();
  	    itemprice = new Vector();
      }//end constructor 
 	

      void parseData()
      {
  	    boolean foundbrand = false;
  	    boolean foundquan = false;
  	    boolean foundprice = false;
  	    do
  	    {
                  try
 		  {
			event = parser.read ();
			
			//theck the start tag of the Xml data
			if(event.getType()==Xml.START_TAG)
			{
  			      StartTag stag = (StartTag)event;
                              String name = stag.getName();
 					
                              if(name.equals("out_brand"))
   	  		      {
 		   	            foundbrand = true;
 		  	      }
			      else if(name.equals("out_quan"))
			           {	
 					 foundquan = true;
 		     	           }
 			           if(name.equals("out_price"))
 			           {	
 				         foundprice = true;
 			           }
 			}//end if Xml.START_TAG 
  		        
  		        //if there is the Text found ,save it
  		        if(event.getType()== Xml.TEXT)
 			{
  			      TextEvent tevent = (TextEvent)event;
  			      String content = tevent.getText();
                                    
                              if(foundbrand)
  			      {
  			           itembrand.addElement(content);
  			           foundbrand = false;
  			      }
  			      else if(foundquan)
  			           {
 			                 itemquantity.addElement(content);
  			                 foundquan = false;
  			           }
  			           if(foundprice)
  			           {
  			                 itemprice.addElement(content);
  			                 foundprice = false;
  			           }
  			}//end if Xml.TEXT
 		  }//end try
 		  catch(IOException ex)
  		  {	
  		        System.out.println("Transfer Error");
  		  }
            }//end do 
            while (!(event instanceof EndDocument));	
      }//end parseData			
      
      void releaseMeromery()
      {
       	    ins = null;
       	    parser = null;
       	    itembrand = null;
       	    itemquantity = null;
       	    itemprice = null;
      }
       
 	       
      
      Vector returnBrand()
      {
      	    return itembrand;
      }
      
      Vector returnStock()
      {
      	    return itemquantity;
      }
 	        
      Vector returnPrice()
      {
      	    return itemprice;
      }
}//end GetData

⌨️ 快捷键说明

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