@Test void testCreateNetworkManagerWirelessInterface() { String objectPath = "/"; String busName = "org.freedesktop.NetworkManager.Device.Wireless"; boolean ignoreDtd = true; Logger logger = LoggerFactory.getLogger(InterfaceCodeGenerator.class); if (!StringUtils.isBlank(busName)) { String introspectionData = FileIoUtil.readFileToString("src/test/resources/CreateInterface/networkmanager/org.freedesktop.NetworkManager.Device.Wireless.xml"); InterfaceCodeGenerator ci2 = new InterfaceCodeGenerator(introspectionData, objectPath, busName); try { Map<File, String> analyze = ci2.analyze(ignoreDtd); assertEquals(1, analyze.size()); String clzContent = analyze.get(analyze.keySet().iterator().next()); assertTrue(clzContent.contains("@" + DBusInterfaceName.class.getSimpleName() + "(\"" + busName + "\")")); assertFalse(clzContent.contains("this._properties")); assertFalse(clzContent.contains("this._path")); assertFalse(clzContent.contains("this._interfaceName")); } catch (Exception _ex) { logger.error("Error while analyzing introspection data", _ex); } } }
public Map<File, String> analyze(boolean _ignoreDtd) throws Exception { if (_ignoreDtd) { docFac.setValidating(false); docFac.setNamespaceAware(true); docFac.setFeature("http: docFac.setFeature("http: docFac.setFeature("http: docFac.setFeature("http: } DocumentBuilder builder = docFac.newDocumentBuilder(); Document document = builder.parse(new InputSource(new StringReader(introspectionData))); Element root = document.getDocumentElement(); if (!StringUtil.isBlank(nodeName) && !StringUtil.isBlank(root.getAttribute("name"))) { if (!nodeName.equals(root.getAttribute("name"))) { logger.error("Retrieved node '{}' does not match requested node name '{}'!", root.getAttribute("name"), nodeName); return null; } } List<Element> interfaceElements = convertToElementList(root.getChildNodes()); Map<File, String> filesAndContents = new LinkedHashMap<>(); for (Element ife : interfaceElements) { if (!StringUtil.isBlank(busName) && ife.getAttribute("name").startsWith(busName)) { filesAndContents.putAll(extractAll(ife)); continue; } filesAndContents.putAll(extractAll(ife)); } return filesAndContents; }
InterfaceCodeGenerator { public Map<File, String> analyze(boolean _ignoreDtd) throws Exception { if (_ignoreDtd) { docFac.setValidating(false); docFac.setNamespaceAware(true); docFac.setFeature("http: docFac.setFeature("http: docFac.setFeature("http: docFac.setFeature("http: } DocumentBuilder builder = docFac.newDocumentBuilder(); Document document = builder.parse(new InputSource(new StringReader(introspectionData))); Element root = document.getDocumentElement(); if (!StringUtil.isBlank(nodeName) && !StringUtil.isBlank(root.getAttribute("name"))) { if (!nodeName.equals(root.getAttribute("name"))) { logger.error("Retrieved node '{}' does not match requested node name '{}'!", root.getAttribute("name"), nodeName); return null; } } List<Element> interfaceElements = convertToElementList(root.getChildNodes()); Map<File, String> filesAndContents = new LinkedHashMap<>(); for (Element ife : interfaceElements) { if (!StringUtil.isBlank(busName) && ife.getAttribute("name").startsWith(busName)) { filesAndContents.putAll(extractAll(ife)); continue; } filesAndContents.putAll(extractAll(ife)); } return filesAndContents; } }
InterfaceCodeGenerator { public Map<File, String> analyze(boolean _ignoreDtd) throws Exception { if (_ignoreDtd) { docFac.setValidating(false); docFac.setNamespaceAware(true); docFac.setFeature("http: docFac.setFeature("http: docFac.setFeature("http: docFac.setFeature("http: } DocumentBuilder builder = docFac.newDocumentBuilder(); Document document = builder.parse(new InputSource(new StringReader(introspectionData))); Element root = document.getDocumentElement(); if (!StringUtil.isBlank(nodeName) && !StringUtil.isBlank(root.getAttribute("name"))) { if (!nodeName.equals(root.getAttribute("name"))) { logger.error("Retrieved node '{}' does not match requested node name '{}'!", root.getAttribute("name"), nodeName); return null; } } List<Element> interfaceElements = convertToElementList(root.getChildNodes()); Map<File, String> filesAndContents = new LinkedHashMap<>(); for (Element ife : interfaceElements) { if (!StringUtil.isBlank(busName) && ife.getAttribute("name").startsWith(busName)) { filesAndContents.putAll(extractAll(ife)); continue; } filesAndContents.putAll(extractAll(ife)); } return filesAndContents; } InterfaceCodeGenerator(String _introspectionData, String _objectPath, String _busName); }
InterfaceCodeGenerator { public Map<File, String> analyze(boolean _ignoreDtd) throws Exception { if (_ignoreDtd) { docFac.setValidating(false); docFac.setNamespaceAware(true); docFac.setFeature("http: docFac.setFeature("http: docFac.setFeature("http: docFac.setFeature("http: } DocumentBuilder builder = docFac.newDocumentBuilder(); Document document = builder.parse(new InputSource(new StringReader(introspectionData))); Element root = document.getDocumentElement(); if (!StringUtil.isBlank(nodeName) && !StringUtil.isBlank(root.getAttribute("name"))) { if (!nodeName.equals(root.getAttribute("name"))) { logger.error("Retrieved node '{}' does not match requested node name '{}'!", root.getAttribute("name"), nodeName); return null; } } List<Element> interfaceElements = convertToElementList(root.getChildNodes()); Map<File, String> filesAndContents = new LinkedHashMap<>(); for (Element ife : interfaceElements) { if (!StringUtil.isBlank(busName) && ife.getAttribute("name").startsWith(busName)) { filesAndContents.putAll(extractAll(ife)); continue; } filesAndContents.putAll(extractAll(ife)); } return filesAndContents; } InterfaceCodeGenerator(String _introspectionData, String _objectPath, String _busName); Map<File, String> analyze(boolean _ignoreDtd); static void main(String[] args); }
InterfaceCodeGenerator { public Map<File, String> analyze(boolean _ignoreDtd) throws Exception { if (_ignoreDtd) { docFac.setValidating(false); docFac.setNamespaceAware(true); docFac.setFeature("http: docFac.setFeature("http: docFac.setFeature("http: docFac.setFeature("http: } DocumentBuilder builder = docFac.newDocumentBuilder(); Document document = builder.parse(new InputSource(new StringReader(introspectionData))); Element root = document.getDocumentElement(); if (!StringUtil.isBlank(nodeName) && !StringUtil.isBlank(root.getAttribute("name"))) { if (!nodeName.equals(root.getAttribute("name"))) { logger.error("Retrieved node '{}' does not match requested node name '{}'!", root.getAttribute("name"), nodeName); return null; } } List<Element> interfaceElements = convertToElementList(root.getChildNodes()); Map<File, String> filesAndContents = new LinkedHashMap<>(); for (Element ife : interfaceElements) { if (!StringUtil.isBlank(busName) && ife.getAttribute("name").startsWith(busName)) { filesAndContents.putAll(extractAll(ife)); continue; } filesAndContents.putAll(extractAll(ife)); } return filesAndContents; } InterfaceCodeGenerator(String _introspectionData, String _objectPath, String _busName); Map<File, String> analyze(boolean _ignoreDtd); static void main(String[] args);  }