< prev index next >

test/jdk/jdk/jfr/event/metadata/TestDefaultConfigurations.java

Print this page




 155         for (SettingDescriptor s : cd.getSettingDescriptors()) {
 156             requiredSettings.add(s.getName());
 157         }
 158         return requiredSettings;
 159     }
 160 
 161     private static Document createDocument(String content) throws ParserConfigurationException, SAXException, IOException {
 162         DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
 163         DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
 164         Document doc = dBuilder.parse(new InputSource(new StringReader(content)));
 165         doc.getDocumentElement().normalize();
 166         // Don't want to add these settings to the jfc-files we ship since they
 167         // are not useful to configure. They are however needed to make the test
 168         // pass.
 169         insertSetting(doc, EventNames.ActiveSetting, "stackTrace", "false");
 170         insertSetting(doc, EventNames.ActiveSetting, "threshold", "0 ns");
 171         insertSetting(doc, EventNames.ActiveRecording, "stackTrace", "false");
 172         insertSetting(doc, EventNames.ActiveRecording, "threshold", "0 ns");
 173         insertSetting(doc, EventNames.JavaExceptionThrow, "threshold", "0 ns");
 174         insertSetting(doc, EventNames.JavaErrorThrow, "threshold", "0 ns");




 175         return doc;
 176     }
 177 
 178     private static void insertSetting(Document doc, String eventName, String settingName, String settingValue) {
 179         for (Element event : getChildElements(doc.getDocumentElement(), "event")) {
 180             Attr attribute = event.getAttributeNode("name");
 181             if (attribute != null) {
 182                 if (eventName.equals(attribute.getValue())) {
 183                     Element setting = doc.createElement("setting");
 184                     setting.setAttribute("name", settingName);
 185                     setting.setTextContent(settingValue);
 186                     event.appendChild(setting);
 187                 }
 188             }
 189         }
 190     }
 191 
 192     private static Collection<Element> getChildElements(Element parent, String name) {
 193         NodeList elementsByTagName = parent.getElementsByTagName(name);
 194         List<Element> elements = new ArrayList<>();


 155         for (SettingDescriptor s : cd.getSettingDescriptors()) {
 156             requiredSettings.add(s.getName());
 157         }
 158         return requiredSettings;
 159     }
 160 
 161     private static Document createDocument(String content) throws ParserConfigurationException, SAXException, IOException {
 162         DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
 163         DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
 164         Document doc = dBuilder.parse(new InputSource(new StringReader(content)));
 165         doc.getDocumentElement().normalize();
 166         // Don't want to add these settings to the jfc-files we ship since they
 167         // are not useful to configure. They are however needed to make the test
 168         // pass.
 169         insertSetting(doc, EventNames.ActiveSetting, "stackTrace", "false");
 170         insertSetting(doc, EventNames.ActiveSetting, "threshold", "0 ns");
 171         insertSetting(doc, EventNames.ActiveRecording, "stackTrace", "false");
 172         insertSetting(doc, EventNames.ActiveRecording, "threshold", "0 ns");
 173         insertSetting(doc, EventNames.JavaExceptionThrow, "threshold", "0 ns");
 174         insertSetting(doc, EventNames.JavaErrorThrow, "threshold", "0 ns");
 175         insertSetting(doc, EventNames.CertificateChain, "threshold", "0 ns");
 176         insertSetting(doc, EventNames.TLSHandshake, "threshold", "0 ns");
 177         insertSetting(doc, EventNames.SecurityProperty, "threshold", "0 ns");
 178         insertSetting(doc, EventNames.X509Certificate, "threshold", "0 ns");
 179         return doc;
 180     }
 181 
 182     private static void insertSetting(Document doc, String eventName, String settingName, String settingValue) {
 183         for (Element event : getChildElements(doc.getDocumentElement(), "event")) {
 184             Attr attribute = event.getAttributeNode("name");
 185             if (attribute != null) {
 186                 if (eventName.equals(attribute.getValue())) {
 187                     Element setting = doc.createElement("setting");
 188                     setting.setAttribute("name", settingName);
 189                     setting.setTextContent(settingValue);
 190                     event.appendChild(setting);
 191                 }
 192             }
 193         }
 194     }
 195 
 196     private static Collection<Element> getChildElements(Element parent, String name) {
 197         NodeList elementsByTagName = parent.getElementsByTagName(name);
 198         List<Element> elements = new ArrayList<>();
< prev index next >