Esempio n. 1
0
  private static void addAeonMicroSmartSwitch(ProductStore store) {

    store
        .select("/manufacturers[id=" + Integer.valueOf("0086") + "]")
        .then(
            new Callback<KObject[]>() {
              @Override
              public void on(KObject[] kObjects) {
                if (kObjects.length > 0) {
                  Manufacturer manufacturer = (Manufacturer) kObjects[0];
                  Product p2 = store.view().createProduct();
                  p2.setId(Integer.parseInt("1001", 16));
                  p2.setType(Integer.parseInt("0301", 16));
                  p2.setName("Roller Shutter 2");
                  manufacturer.addProducts(p2);
                }
              }
            });
  }
Esempio n. 2
0
 private static void load(ProductStore store) {
   String baseUrl = "http://open-zwave.googlecode.com/svn/trunk/config";
   try {
     URL url = new URL(baseUrl + "/manufacturer_specific.xml");
     URLConnection connection = url.openConnection();
     int fileLength = connection.getContentLength();
     if (fileLength == -1) {
       System.out.println("Invalide URL or file.");
       return;
     }
     XMLInputFactory inputFactory = XMLInputFactory.newInstance();
     InputStream input = connection.getInputStream();
     final XMLEventReader eventReader = inputFactory.createXMLEventReader(input);
     try {
       Manufacturer lastLoadedManufacturer =
           store.view().createManufacturer(); // void manufacturer
       while (eventReader.hasNext()) {
         XMLEvent event = eventReader.nextEvent();
         if (event.isStartElement()) {
           StartElement startElt = event.asStartElement();
           if (startElt.getName().getLocalPart().equals("Manufacturer")) {
             lastLoadedManufacturer = store.view().createManufacturer();
             Iterator<Attribute> attributes = startElt.getAttributes();
             while (attributes.hasNext()) {
               Attribute next = attributes.next();
               if (next.getName().toString().equals("id")) {
                 lastLoadedManufacturer.setId(Integer.parseInt(next.getValue(), 16));
               } else if (next.getName().toString().equals("name")) {
                 lastLoadedManufacturer.setName(next.getValue());
               }
             }
             store.addManufacturers(lastLoadedManufacturer);
           } else if (startElt.getName().getLocalPart().equals("Product")) {
             Product product = store.view().createProduct();
             Iterator<Attribute> attributes = startElt.getAttributes();
             while (attributes.hasNext()) {
               Attribute next = attributes.next();
               String attrName = next.getName().toString();
               if (attrName.equals("id")) {
                 product.setId(Integer.parseInt(next.getValue(), 16));
               } else if (attrName.equals("name")) {
                 product.setName(next.getValue());
               } else if (attrName.equals("type")) {
                 product.setType(Integer.parseInt(next.getValue(), 16));
               } else if (attrName.equals("config")) {
                 // Log.warn("Ignored Configuration file:" + next.getValue() + " for product " +
                 // product.getName());
                 parseConfiguration(baseUrl + "/" + next.getValue(), product);
               }
             }
             lastLoadedManufacturer.addProducts(product);
           }
         }
       }
       // Updates
       addAeonMicroSmartSwitch(store);
     } catch (XMLStreamException e1) {
       e1
           .printStackTrace(); // To change body of catch statement use File | Settings | File
                               // Templates.
     }
   } catch (MalformedURLException e1) {
     e1
         .printStackTrace(); // To change body of catch statement use File | Settings | File
                             // Templates.
   } catch (XMLStreamException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }