Java Reference
In-Depth Information
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
switch (node.getNodeName()) {
case "PRODUCTID":
product = createProduct(Integer.parseInt(node.getTextContent()));
break;
case "QUANTITY":
quantity = Integer.parseInt(node.getTextContent());
break;
case "COST":
cost = Double.parseDouble(node.getTextContent());
// This is the last line, commit our item to the list
item = new Item(invoice, product, quantity, cost);
items.add(item);
break;
default:
break;
}
}
return items;
}
private static int[] getCollectionIds(Resource resource) {
Document document = client.getResourceCollection(resource);
NodeList elements = document.getElementsByTagName(resource.name());
int[] ids = new int[elements.getLength()];
for (int i = 0; i < ids.length; i++) {
ids[i] = Integer.parseInt(((Element) elements.item(i)).getTextContent());
}
return ids;
}
private static String getEl(Document document, String n) {
return document.getElementsByTagName(n).item(0).getTextContent();
}
}
Finally, you can create a RestClientProgram class to test what you've built:
package com.thomasbayer.sqlrest;
public class RestClientProgram {
public static void main(String[] args) {
int[] customerIds = ObjectFactory.getCustomerIds();
System.out.println("----------- Collection test -----------");
System.out.println("First three customer ids: " +
customerIds[0] + ", " +
customerIds[1] + ", " +
customerIds[2]);
Search WWH ::




Custom Search