0 Replies Latest reply on May 27, 2009 6:20 PM by Matt Kohanek

    almost have richfaces tree working, just need a little more

    Matt Kohanek Novice

      This is basically what I need to do:

      1) Call Web service and get the xml
      2) Use simpleXML to parse XML into objects
      3) loop through objects and add to TreeNode data; attribute.

      I have a bunch of loose code that does much of this, but it is missing something and Im having trouble filling in the gaps.

      So I have this class which is how I call the web service and get the data:

      public DeviceCollection readXML(InputStream xml) throws Exception {
       Serializer serializer = new Persister();
      
       DeviceCollection deviceCollection = null;
       deviceCollection = serializer.read(DeviceCollection.class, xml);
       xml.close();
       return deviceCollection;
       }


      I also have a Device class:

      @Root
      public class Device {
       static String devicesUrl = "http://webc-apps.ni.com/measure/1.01/devices";
      
       LinkedList device = new LinkedList();
      
       @Element(required=false)
       private String deviceId;
      
       @Element(required=false)
       private String name;
      
       @ElementMap(entry = "property", key = "name", attribute = true, inline = true, required=true, data=false, empty=true)
       private Map<String, String> properties;
      
       public String getDeviceId() {
       return deviceId;
       }
      
       public void setDeviceId(String deviceId) {
       this.deviceId = deviceId;
       }
      
       public String getName() {
       return name;
       }
      
       public void setName(String name) {
       this.name = name;
       }
      
       public Map<String, String> getProperties() {
       return properties;
       }
      
       public void setProperties(Map<String, String> properties) {
       this.properties = properties;
       }
      
      }


      and a device Collection class:

      package deviceContainer;
      
      import org.apache.commons.httpclient.HttpClient;
      import org.apache.commons.httpclient.HttpStatus;
      import org.apache.commons.httpclient.methods.GetMethod;
      import org.simpleframework.xml.*;
      
      import java.util.Collection;
      
      @Root
      public class DeviceCollection {
      
       static String devicesUrl = "http://webc-apps.ni.com/measure/1.01/devices";
      
       @ElementList(inline = true)
       private Collection<Device> devices;
      
       //get devices
       public Collection<Device> getDevices() {
       return devices;
       }
      
       //set devices
       public void setDevices(Collection<Device> devices) {
       this.devices = devices;
       }
      
      }


      Then I have my Temp class, which I am trying to use to bind the data from the DeviceColelction to TreeNode data;

      public class Temp {
      
      
       public static void updateNode() throws IOException, Exception {
      
      
       XMLTreeDataBuilderTest node = new XMLTreeDataBuilderTest();
       DeviceCollectionXMLAO access = new DeviceCollectionXMLAO();
       DeviceCollection deviceCollection = access.readXML(method.getResponseBodyAsStream());
      
      
       node.setData(deviceCollection.get(0));
       node.setData((TreeNode) deviceCollection.getDevices());
      
       for (Device device : deviceCollection.getDevices()) {
       device.getDeviceId();
       }
      
      
       }


      Now I know all my classes except for this last Temp class are fine. I know I need to follow the steps I listed above, but Im just not sure where Im missing what I need to do. Im needing to send the stream of data to the access object in the Temp class. Right now method is underlined and says it cannot be resolved. I'm not sure what exactly method is coming from. I know it is something to do with the httpclient GetMethod which pulls the data from a website, and then this is being sent to the access object, and this is what deviceCollection is being set to. So then I will need to use the deviceCollection object to build my tree.

      I know this is quite a lot to go over, but really the only class that needs adjustment is that last class, Temp