public Package parse(InputStream input) throws Exception { try { Element root = new SAXReader().read(input).getRootElement(); Package pk = parsePackage(root); Element consts = root.element("consts"); if (consts != null) { pk.setConsts(parseFields(consts.elements(), null, pk)); } pk.setEnums(parseEnums(root.element("enums"), pk)); pk.setObjects(parseObjects(root.element("objects"), pk)); pk.setServices(parseServices(root.element("services"), pk)); return pk; } finally { input.close(); } }
private Package parsePackage(Element el) { Package pk = new Package(); Map<String, String> nsMap = new HashMap<String, String>(4); for (Attribute attr : (List<Attribute>) el.attributes()) { String name = attr.getName(); String value = attr.getValue(); if ("name".equals(name)) { pk.setName(value); } else { nsMap.put(name, value); } } pk.setNamespaces(nsMap); pk.setId(pk.getNamespace("js")); parseDoc(el, pk); return pk; }