import java.util.Hashtable; import lava.net.common.UNL; import lava.net.common.Value; import lava.net.psyc.PSYCMessageCenter; import lava.net.psyc.PSYCDeliveryException; /** * **/ public class PSYCDeliver { /** * **/ public void send(String[] args) { int uniPos = -1; int methodPos = -1; int bodyPos = -1; Hashtable vars = null; for(int i = 0;i < args.length;++i) { if(args[i].charAt(0) != '-') { // UNL, method or body if(uniPos < 0) uniPos = i; else if(methodPos < 0) methodPos = i; else if(bodyPos < 0) bodyPos = i; } else { // Variable int index = args[i].indexOf('='); if(index < 0) index = args[i].length(); if(index < 2) continue; String name = args[i].substring(1,index); String value; try { value = args[i].substring(index + 1,args[i].length()); } catch(StringIndexOutOfBoundsException e) { value = null; } if(vars == null) vars = new Hashtable(); vars.put(name,new Value(value)); } } if(uniPos < 0 || methodPos < 0) { System.out.println("Use arguments: []"); System.exit(0); } PSYCMessageCenter center = new PSYCMessageCenter(null,false); try { center.send(new UNL(args[uniPos]),args[methodPos],// bodyPos < 0 ? null : args[bodyPos],vars); } catch(PSYCDeliveryException e) { System.err.println("error: " + e.getMessage()); } // Don't ask me why, but sometimes, it doesn't flush buffers right. // Seems to be a java problem ... so let's wait a little bit to // get it a chance to do everything right. try { synchronized(this) { wait(1000); } } catch(InterruptedException e) { System.out.println("could not wait"); } // IMPORTANT! // if the close() s not there, some buffers maybe don't get flushed center.close(); } /** * **/ public final static void main(String[] args) { PSYCDeliver d = new PSYCDeliver(); d.send(args); } }