incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spo...@apache.org
Subject svn commit: r893358 - /incubator/kato/trunk/org.apache.kato/kato.api.vm/src/main/java/javax/tools/diagnostics/vm/spi/delegates/XMLDumpWriter.java
Date Wed, 23 Dec 2009 00:03:16 GMT
Author: spoole
Date: Wed Dec 23 00:03:15 2009
New Revision: 893358

URL: http://svn.apache.org/viewvc?rev=893358&view=rev
Log:
added the start of a write to xml style pure java dump. This is intended to make the current
dummy dump more useful

Added:
    incubator/kato/trunk/org.apache.kato/kato.api.vm/src/main/java/javax/tools/diagnostics/vm/spi/delegates/XMLDumpWriter.java

Added: incubator/kato/trunk/org.apache.kato/kato.api.vm/src/main/java/javax/tools/diagnostics/vm/spi/delegates/XMLDumpWriter.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.api.vm/src/main/java/javax/tools/diagnostics/vm/spi/delegates/XMLDumpWriter.java?rev=893358&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.api.vm/src/main/java/javax/tools/diagnostics/vm/spi/delegates/XMLDumpWriter.java
(added)
+++ incubator/kato/trunk/org.apache.kato/kato.api.vm/src/main/java/javax/tools/diagnostics/vm/spi/delegates/XMLDumpWriter.java
Wed Dec 23 00:03:15 2009
@@ -0,0 +1,141 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package javax.tools.diagnostics.vm.spi.delegates;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.lang.management.ManagementFactory;
+import java.lang.management.OperatingSystemMXBean;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+public class XMLDumpWriter {
+	
+	private DocumentBuilder builder=null;
+	
+	public XMLDumpWriter() {
+		DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
+		try {
+			 builder=factory.newDocumentBuilder();
+		} catch (ParserConfigurationException e) {
+			e.printStackTrace();
+		}
+	}
+	
+	public void write(File output) throws IOException {
+	
+		FileWriter fw=new FileWriter(output);
+		write(fw);
+		fw.close();
+	}
+
+	public  void write(Writer writer) throws IOException {
+		if(writer instanceof PrintWriter==false) {
+			writer=new PrintWriter(writer);
+		}
+		writeDump((PrintWriter)writer);
+		
+		
+	}
+
+	private void writeDump(PrintWriter out) {
+		
+		// write dump header
+		writeHeader(out);
+		
+		// write system properties
+		writeSystemProperties(out);
+		writeSystemEnvironmentProperties(out);
+	    
+		out.print("<mbean-info>");
+		OperatingSystemMXBean osmb=ManagementFactory.getOperatingSystemMXBean();
+		writeOSMXBean(out,osmb);
+		out.print("</mbean-info>");
+		// write dump trailer
+		writeTrailer(out);
+		
+	}
+
+	private void writeOSMXBean(PrintWriter out, OperatingSystemMXBean osmb) {
+		out.print("<"+osmb.getClass().getCanonicalName()+">");
+		
+		out.print("</"+osmb.getClass().getCanonicalName()+">");
+		
+	}
+
+	private void writeSystemEnvironmentProperties(PrintWriter out) {
+		Map<String,String> p=System.getenv();
+		int count=p.size();
+		out.print("<environment-variables size=\""+count+"\">");
+		writeMap(out, p);
+		out.print("</environment-variables>");
+		
+	}
+
+	private void writeMap(PrintWriter out, Map<String, String> p) {
+		for(String key:p.keySet()) {
+		
+			out.print("<entry>");
+			Object value=p.get(key);
+			 
+			if(key==null) {
+				out.print("<key isnull=\"true\"></key>");
+			}
+			else {
+				out.print("<key>"+escape(key.toString())+"</key>");
+			}
+			if(value==null) {
+				out.print("<value isnull=\"true\"></value>");
+			}
+			else {
+				out.print("<value>"+escape(value.toString())+"</value>");
+			}
+			out.print("</entry>");
+		}
+	}
+
+	private void writeSystemProperties(PrintWriter out) {
+		
+		Map p=System.getProperties();
+		int count=p.size();
+		out.print("<system-properties size=\""+count+"\">");
+		writeMap(out,p);
+		out.print("</system-properties>");
+	}
+
+	private String escape(String data) {
+		
+		return data; // FIXME - do it properly !
+	}
+
+	private void writeTrailer(PrintWriter out) {
+		out.print("</kato>");
+		
+	}
+
+	private void writeHeader(PrintWriter out) {
+		out.print("<kato>");
+		
+	}
+	
+	
+}



Mime
View raw message