/* Rajarshi Guha * 10/03/2005 * * * Updated 01/03/2006 - Synced with latest CDK. Added usage message * * Based on code written by Marty Hall */ import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.encoding.XMLType; import org.apache.axis.AxisFault; import javax.xml.namespace.QName; import javax.xml.rpc.ParameterMode; public class CDKsimaClient { private Call call; private QName qn; private boolean requestError; private String requestErrorMessage; // Initialize the Axis setup public CDKsimaClient(String host) { String endpoint = "http://localhost:8080/axis/services/CDKsima"; if (host != null) { endpoint = host; } try { Service service = new Service(); call = (Call) service.createCall(); call.setTargetEndpointAddress( new java.net.URL(endpoint) ); } catch (Throwable t) { handleError("CDKsimaClient (constructor) had an Exception.",t); } } // Return true in an error was found public boolean error() { return requestError; } // Return the error message public String getErrorText() { String msg; if (requestError) { msg = requestErrorMessage; } else { msg = ""; } return msg; } public double getSim(String[] mols, int l, int d) { try { call.removeAllParameters(); call.setOperationName( "getSim" ); call.addParameter( "mols", XMLType.SOAP_ARRAY, ParameterMode.IN); call.addParameter( "length", XMLType.XSD_INTEGER, ParameterMode.IN); call.addParameter( "depth", XMLType.XSD_INTEGER, ParameterMode.IN); call.setReturnType( XMLType.SOAP_ARRAY ); Object[] ret = (Object[]) call.invoke( new Object[] { mols, new Integer(l), new Integer(d) }); if (ret == null) { System.out.println("Error in SOAP call"); } System.out.println("CDKsimaClient got result : "); int nmol = mols.length; for (int i = 0; i < nmol; i++) { String s = ""; for (int j = 0; j < nmol; j++) { s = s + ((Double)ret[i*nmol+j]).doubleValue()+" "; } System.out.println(s); } return 0.0; } catch (Throwable t) { handleError("CDKsimaClient (getSim) had an Exception.",t); return (-1.0); } } // Set error flags, print stack trace public void handleError(String text, Throwable t) { requestError = true; requestErrorMessage = t.toString(); System.out.println(text); System.out.println(t); t.printStackTrace(); return; } // Test program public static void main(String [] args) { String host = null; if (args.length == 1) { host = args[0]; } System.out.println("Will calculate the similarity matrix for the following"); System.out.println("molecules: \"CCC\", \"CCCC\", \"CCC\", \"CCOC\"\n\nIf the program does not run you can specify an alternate\nhost on the command line\n"); String[] mols = { "CCC", "CCCC", "CCC", "CCOC" }; CDKsimaClient sr = new CDKsimaClient(host); sr.getSim(mols, 1024, 6); System.out.println("\n\nWill calculate the similarity matrix for the following"); System.out.println("molecules: \"CCCC\", \"CCOCC\", \"CCCC\", \nIf the program does not run you can specify an alternate\nhost on the command line\n"); mols = new String[] { "CCCC", "CCOCC", "CCCC" }; sr = new CDKsimaClient(host); sr.getSim(mols, 1024, 6); } }