00001 package clientswing.comunicationsystem; 00002 import clientswing.model.*; 00005 public class ComunicationSystem { 00007 XMLBuilder xmlBuilder; 00009 Gateway gateway; 00010 00017 public ComunicationSystem() 00018 throws Exception 00019 { 00020 00021 gateway = new SOAPGateway(); 00022 xmlBuilder = new XMLBuilder(); 00023 } 00026 public XResponse execute(XRequestLogin nickName ) 00027 throws Exception 00028 { 00029 00030 gateway.sendLogin(nickName); 00031 00032 return new XResponseMessage("Login successful for " + nickName.getNickName(),""); 00033 } 00036 public String execute() 00037 throws Exception 00038 { 00039 String logout; 00040 logout=gateway.logout(); 00041 return logout; 00042 } 00048 public XResponse execute(XRequestQuery xrequestQuery ) throws 00049 Exception{ 00050 00051 System.out.println("Executing query... "); 00052 System.out.println("Building XML... "); 00053 00054 String xml = xmlBuilder.build(xrequestQuery); 00055 00056 System.out.println("Sending query... "); 00057 String response = gateway.sendRequest(xml); 00058 System.out.println("\nResponse: \n\n" + response); 00059 XResponse xresponse = null; 00060 00061 00062 if (response!=null){ 00063 System.out.println("Starting parsing of response.."); 00064 xresponse = new XMLParser().parse(response); 00065 System.out.println("Parsing completed..."); 00066 } 00067 00068 return xresponse; 00069 } 00070 00071 public static void main(String[] argv){ 00072 XRequestQuery query = new XRequestQuery(); 00073 00074 query.setTableName("Pippo"); 00075 //query.setWhereClause("where","where"); 00076 query.addColumn(new Column("name")); 00077 00078 try { 00079 ComunicationSystem cs = new ComunicationSystem(); 00080 System.out.print( cs.execute(query) ); 00081 00082 } 00083 catch (Exception ex) { 00084 ex.printStackTrace(); 00085 } 00086 00087 } 00088 00089 }