public int getIndex(TreeNode node) { XMLTreeNode n = (XMLTreeNode) node; int index = xml.getChildren().indexOf(n.xml); int count = xml.getChildren().size(); for (int i = 0; i < count; i++) { if (xml.getChildren().get(i).getName().equals(n.xml.getName())) { index = i; break; } } System.out.println("index of " + n.xml.getName() + " :: " + index); return index; }
public static APICall fromElemet(Element e) { APICall c = new APICall(); c.classname = e.getChildText("class"); c.methodname = e.getChildText("method"); Vector<Element> params = e.getChildren("param"); if (params == null || params.size() == 0) { c.paramTypes = null; c.params = null; } else { int pCount = params.size(); c.paramTypes = new Class[pCount]; c.params = new Object[pCount]; for (int i = 0; i < pCount; i++) { Element ep = params.get(i); String pUse = ep.getAttribute("use"); if (pUse != null) { // replace with parameter c.paramTypes[i] = String.class; c.params[i] = "${" + pUse + "}"; c.placeHolder.put(i, pUse); } else { String pType = ep.getAttribute("type"); String value = ep.getText(); if (value == null) value = ""; if (pType.equalsIgnoreCase("int")) { c.paramTypes[i] = Integer.TYPE; c.params[i] = Integer.parseInt(value); } else if (pType.equalsIgnoreCase("byte")) { c.paramTypes[i] = Byte.TYPE; c.params[i] = Byte.parseByte(value); } else if (pType.equalsIgnoreCase("long")) { c.paramTypes[i] = Long.TYPE; c.params[i] = Long.parseLong(value); } else if (pType.equalsIgnoreCase("double")) { c.paramTypes[i] = Double.TYPE; c.params[i] = Double.parseDouble(value); } else if (pType.equalsIgnoreCase("float")) { c.paramTypes[i] = Float.TYPE; c.params[i] = Float.parseFloat(value); } else if (pType.equalsIgnoreCase("file")) { c.paramTypes[i] = File.class; c.params[i] = new File(value); } else { // use String for no type or anything else c.paramTypes[i] = String.class; c.params[i] = value; } } } } return c; }
public boolean isLeaf() { if (xml.getChildren().size() == 0) return true; return false; }
public int getChildCount() { return xml.getChildren().size(); }
public TreeNode getChildAt(int childIndex) { if (isLeaf()) return null; return new XMLTreeNode(this, tree, xml.getChildren().get(childIndex)); }