package coneclient; import org.us_vo.www.Registry; import org.us_vo.www.RegistrySoap; import org.us_vo.www.RegistryLocator; import org.us_vo.www.RegistrySoap; import org.us_vo.www.RegistryLocator; import org.us_vo.www.ArrayOfSimpleResource; import org.us_vo.www.SimpleResource; import java.net.URL; import java.util.StringTokenizer; import java.rmi.RemoteException; import javax.xml.rpc.ServiceException; public class FindConeSearch { /** * Connect to the NVO registry and retrieve Cone Search services * that match a particular query. */ public static SimpleResource[] search(String query) throws ServiceException, RemoteException { // get a registry service object Registry regService = new RegistryLocator(); // get an interface object that can accept our query. RegistrySoap regInterface = regService.getRegistrySoap(); // Combine our query with a constraint to return only Cone Searches. // The resulting query will look something like this: // // ServiceType like '%CONE%' and (Title like '%parallax%') // query = "ResourceType like '%CONE%' and (" + query + ")"; System.err.println("Query: " + query); // Now submit the query ArrayOfSimpleResource results = regInterface.queryRegistry(query); // return all of the results return results.getSimpleResource(); } public static void main(String[] args) { try { // concatonate all the input arguments into a single query // string StringBuffer in = new StringBuffer(); for(int i=0; i < args.length; i++) { if (args[i] != null) in.append(args[i]).append(' '); } String query = in.toString(); // submit our query SimpleResource[] cs = search(query); if (cs == null || cs.length == 0) { System.out.println("No matching Cone Search services found"); } else { // print out results for(int i=0; i < cs.length; i++) { System.out.println("Title: " + cs[i].getTitle()); System.out.println("Address: " + cs[i].getServiceURL()); System.out.println("====================================="); } } } catch (ServiceException ex) { System.err.println("failed to connect to Registry: " + ex.getMessage()); System.exit(1); } catch (RemoteException ex) { System.err.println("failed to process query: " + ex.getMessage()); System.exit(1); } catch (Exception ex) { System.err.println("Error: " + ex.getMessage()); ex.printStackTrace(); System.exit(1); } } public static String correctBaseURL(String url) { url = url.trim(); char lastChar = url.charAt(url.length()-1); boolean hasQM = url.indexOf('?') > 0; if (hasQM && lastChar != '?' && lastChar != '&') return url + '&'; else if (!hasQM) return url + '?'; else return url; } public static SimpleResource[] keywordSearch(String keywords) throws ServiceException, RemoteException { String query = ""; // String keyword; StringTokenizer st = new StringTokenizer(keywords); while (st.hasMoreTokens()) { keyword = st.nextToken(); // add in our constraints to the query } System.err.println("Registry query: " + query); // // submit our query return null; } }