Thursday, August 23, 2012

How to retrieve arrayList object through SOAP?

After retrieving data from the Server side through SOAP.....you can store it in the Vector collection and the store it in the Class Object property........!!!!!!!!

Declare the List variables for storing the array object


private  List<String>  downloadList= new ArrayList<String>();
private  List<String>  usenameAttr = new ArrayList<String>();
private  List<String>  imageList = new ArrayList<String>();
private  List<String>  purposeList = new ArrayList<String>();

then create the List of class type for storing the value

List<GVDownlaodObjectEntity>  downloadGVObjectList= new ArrayList<GVDownlaodObjectEntity>();

Where GVDownlaodObjectEntity is a class below.........


package com.ags.entity;

public class GVDownlaodObjectEntity {


private String info="";

private String gvThumbnail="";

private String gvTitle="";

private String gvUserName="";

public String getGvUserName() {
return gvUserName;
}

public void setGvUserName(String gvUserName) {
this.gvUserName = gvUserName;
}

public String getInfo() {
return info;
}

public void setInfo(String info) {
this.info = info;
}

public String getGvThumbnail() {
return gvThumbnail;
}

public void setGvThumbnail(String gvThumbnail) {
this.gvThumbnail = gvThumbnail;
}

public String getGvTitle() {
return gvTitle;
}

public void setGvTitle(String gvTitle) {
this.gvTitle = gvTitle;
}


}



then retrieves the response and see how to get the data and store it in property....




Vector result = (Vector)envelope.getResponse();
System.out.println("result:"+ result.get(0));

for(int i = 0; i < ((SoapObject) result.get(0)).getPropertyCount(); i++) {
String  gvdownloadObject =  ((SoapObject) result.get(0)).getProperty(i).toString();
int firstIndex =gvdownloadObject.indexOf("{");
String newListGVObject = gvdownloadObject.substring(firstIndex+1, gvdownloadObject.length()-1);
System.out.println("NewGVObject["+i+"]:"+gvdownloadObject);
StringTokenizer str= new StringTokenizer(newListGVObject,";");
GVDownlaodObjectEntity gVDownlaodObjectEntity = new GVDownlaodObjectEntity();
while (str.hasMoreTokens()) {
String token = str.nextToken().trim();
System.out.println("Token:"+token);
 
if(token.compareToIgnoreCase("") != 0){
String gvDownloadTokens=token.substring(0,token.indexOf('='));
System.out.println("ObjectTokens:"+gvDownloadTokens);
if(gvDownloadTokens.compareToIgnoreCase("UserName") == 0){
gVDownlaodObjectEntity.setGvUserName(token.substring(token.indexOf('=')+1,token.length()));
}else if(gvDownloadTokens.compareToIgnoreCase("GvInfo") == 0){
gVDownlaodObjectEntity.setInfo(token.substring(token.indexOf('=')+1,token.length()));
}else if(gvDownloadTokens.compareToIgnoreCase("GvThumb") == 0){
gVDownlaodObjectEntity.setGvThumbnail(token.substring(token.indexOf('=')+1,token.length()));
}else if(gvDownloadTokens.compareToIgnoreCase("Id") == 0)
gVDownlaodObjectEntity.setGvId(token.substring(token.indexOf('=')+1,token.length()));
else if(gvDownloadTokens.compareToIgnoreCase("GvTitle") == 0){
gVDownlaodObjectEntity.setGvTitle(token.substring(token.indexOf('=')+1,token.length()));

downloadList.add(gVDownlaodObjectEntity.getGvTitle());
purposeList.add(gVDownlaodObjectEntity.getInfo());
usenameAttr.add(gVDownlaodObjectEntity.getGvUserName());
imageList.add(gVDownlaodObjectEntity.getGvThumbnail());

}
}


}
if(gVDownlaodObjectEntity != null)
downloadGVObjectList.add(gVDownlaodObjectEntity);
System.out.println("downloadGVObjectList size:"+downloadGVObjectList.size()+"|"+downloadGVObjectList.get(i).getGvThumbnail());
}

totalRecords=Integer.parseInt(((SoapObject) result.get(1)).toString());
System.out.println("total count from server:"+totalRecords);







No comments:

Post a Comment