import java.lang.reflect.*; import java.net.URL; import org.apache.axis.types.*; import gw.*; public class Set { public static double TIMEOUT = 2.0; private GWPort proxy; Set(String gateway) { try { URL portURL = new URL("http://restsoap:AIIT@" + gateway + "/gw/soap"); GWServiceLocator locator = new GWServiceLocator(); proxy = locator.getGWPort(portURL); } catch (Exception e) { e.printStackTrace(); System.exit(2); } } // For attributes whose type is unsigned int, short, byte public void set(String name, UnsignedInt value, String addr) { GW__Attribute_Result[] results; Method m; Object o; try { GW__Attribute reqValue = new GW__Attribute(); reqValue.setName(name); Object[] args = new Object[1]; args[0] = value; Class[] valueClasses = new Class[1]; valueClasses[0] = Class.forName("org.apache.axis.types.UnsignedInt"); m = reqValue.getClass().getMethod("set" + name, valueClasses); m.invoke(reqValue, args); results = proxy.attributesSet(name, addr, TIMEOUT, "*", reqValue); for (int i = 0; i < results.length; i++) { GW__Attribute repValue = results[i].getValue(); m = repValue.getClass().getMethod("get" + name, (Class[])null); o = m.invoke(repValue, (Object[])null); System.out.println("Mote " + results[i].getAddr() + ": " + name + " value is " + o); } } catch (Exception e) { e.printStackTrace(); System.exit(2); } } public static void main(String [] args) { String usage = "Usage: java Set gateway attrName attrValue [mote]"; if (args.length != 3 && args.length != 4) { System.out.println(usage); System.exit(3); } String gateway = args[0]; String attrName = args[1]; UnsignedInt attrValue = new UnsignedInt(args[2]); String mote; if (args.length == 3) mote = "ffffffffffffffff"; else mote = args[3]; Set set = new Set(gateway); set.set(attrName, attrValue, mote); } }