package client; import net.ivoa.SkyNode.*; import net.ivoa.www.xml.ADQL.v0_7_4.*; import fr.u_strasbg.vizier.xml.VOTable_1_1_xsd.*; public class PlanClient { public static void main(String [] args) throws Exception { String node = "Abell"; String addr = "http://localhost:8080/axis/services/SkyNodeSoap"; int ind =0; if (args.length > ind) node = args[ind++]; if (args.length > ind) addr = args[ind++]; testService(node,addr); } public static void testService(String node,String addr) throws Exception { System.out.println("Testing "+ addr); java.net.URL url = new java.net.URL(addr); java.lang.String testTable = ""; java.lang.String testColumn = ""; net.ivoa.SkyNode.SkyNodeLocator adilSrv = new net.ivoa.SkyNode.SkyNodeLocator(); net.ivoa.SkyNode.SkyNodeSoap soap = adilSrv.getSkyNodeSoap(url); System.out.println("Testing tables() method"); net.ivoa.SkyNode.ArrayOfMetaTable tNames = soap.tables(); net.ivoa.SkyNode.MetaTable [] tb = tNames.getMetaTable(); net.ivoa.SkyNode.MetaTable table = tb[0]; String t = table.getName(); System.out.println("Table Name: " + t); System.out.println("Table Description: " + table.getDescription()); System.out.println("Number of Rows: " + table.getRows()); net.ivoa.SkyNode.ArrayOfMetaColumn cNames = soap.columns(t); net.ivoa.SkyNode.MetaColumn[] col = cNames.getMetaColumn(); String c = col[0].getName(); testTable = t; testColumn = c; String u = col[0].getUCD(); System.out.println("Column { " + c + " } + UCD{ "+ u+" }"); // SQL Query: select top 5 a.testColumn from testTable a //Create a Select object and fill it SelectType selectType = new SelectType(); SelectionLimitType restrict = new SelectionLimitType(); restrict.setTop(new org.apache.axis.types.UnsignedInt(5)); selectType.setRestrict(restrict); SelectionListType sl = new SelectionListType(); //Columns ColumnReferenceType[] cr = new ColumnReferenceType[1]; ColumnReferenceType cr0 = new ColumnReferenceType(); cr0.setTable("a"); cr0.setName(testColumn); cr[0] = cr0; sl.setItem(cr); selectType.setSelectionList(sl); // From Clause FromType from = new FromType(); ArchiveTableType[] tabArr = new ArchiveTableType[1]; ArchiveTableType arcTable = new ArchiveTableType(); arcTable.setName(testTable); arcTable.setAlias("a"); arcTable.setArchive(node); tabArr[0] = arcTable; from.setTable(tabArr); selectType.setFrom(from); // put it in a plan ExecPlan plan = new ExecPlan(); // initialize array of plan elements ArrayOfPlanElement planElmArr = new ArrayOfPlanElement(); //initialize the plan element PlanElement planElem = new PlanElement(); // set statement to PlanElement planElem.setStatement(selectType); ArrayOfString arrOfStr = new ArrayOfString(); arrOfStr.setString(new String[]{"http://localhost:8080/axis/services/SkyNodeSoap"}); planElem.setHosts(arrOfStr); planElem.setSigma(100); planElem.setTarget(node); // set PlanElement to ArrayOfPlanElement planElmArr.setPlanElement(new PlanElement[]{planElem}); // set ArrayOfPlanElement to ExecPlan plan.setFormat("VOTABLE"); plan.setPlanId(1); plan.setPortalURL("http://dev.openskyquery.net/Sky/SkyPortal/PortalJobs.asmx"); plan.setUploadTableAlias("up"); plan.setUploadTableName("#upload"); plan.setPlanElements(planElmArr); System.out.println("About to execute Plan..."); System.out.println("Perform the Query: 'SELECT TOP 5 a." + testColumn + " FROM " + testTable + " a"); net.ivoa.SkyNode.VOData vod = soap.executePlan(plan); output(vod); } public static void output(net.ivoa.SkyNode.VOData vod) { // Test for ErrorData being returned if (vod instanceof net.ivoa.SkyNode.ErrorData) { net.ivoa.SkyNode.ErrorData err = (net.ivoa.SkyNode.ErrorData)vod; System.out.println("Error: " + err.getError()); } else if (vod instanceof net.ivoa.SkyNode.VOTableData ){ // VOTableData returned net.ivoa.SkyNode.VOTableData votd = (net.ivoa.SkyNode.VOTableData)vod; VOTABLE vot = votd.getVOTABLE(); // Output info about the VOTABLE System.out.println("Output is a VOTABLE"); RESOURCE resource = vot.getRESOURCE(0); TABLE table = resource.getTABLE(0); FIELD[] fields = table.getFIELD(); int cols = fields.length; TR [] tr = table.getDATA().getTABLEDATA().getTR(); System.out.println("Data: " ); for (int j = 1; j <= cols; j++) { System.out.print(table.getFIELD(j-1).getName() + (j < cols ? "\t\t" : "\n")); } for (int j = 1; j <= cols; j++) { System.out.print("----------" + (j < cols ? "\t" : "\n")); } if (null == tr ) { // no rows System.out.println(" No rows returned"); } else { for (int i = 1; i <= tr.length; i++) { TR myRow = tr[i-1]; TD[] row = myRow.getTD(); for (int j = 1; j <= cols; j++) { System.out.print(row[j-1] + (j < cols ? "\t" : "\n")); } } } } } }