Generate alerts_types.xml document along with other xml docs.

This commit is contained in:
alena 2011-01-25 10:35:59 -08:00
parent a705b104e7
commit e256285b05
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,20 @@
package com.cloud.api.doc;
public class Alert {
private String type;
private int value;
public Alert(String type, int value) {
this.type = type;
this.value = value;
}
public String getType() {
return type;
}
public int getValue() {
return value;
}
}

View File

@ -41,6 +41,7 @@ import java.util.zip.ZipOutputStream;
import org.apache.log4j.Logger;
import com.cloud.alert.AlertManager;
import com.cloud.api.BaseAsyncCmd;
import com.cloud.api.BaseAsyncCreateCmd;
import com.cloud.api.BaseCmd;
@ -200,6 +201,9 @@ public class ApiXmlDocWriter {
regularUser.close();
regularUserSorted.close();
//write alerttypes to xml
writeAlertTypes(xmlDocDir);
//gzip directory with xml doc
//zipDir(dirName + "xmldoc.zip", xmlDocDir);
@ -401,6 +405,25 @@ public class ApiXmlDocWriter {
}
private static void writeAlertTypes(String dirName) {
XStream xs = new XStream();
xs.alias("alert", Alert.class);
try {
ObjectOutputStream out = xs.createObjectOutputStream(new FileWriter(dirName + "/alert_types.xml"), "alerts");
for(Field f : AlertManager.class.getFields()){
String name = f.getName().substring(11);
Alert alert = new Alert(name, f.getInt(null));
out.writeObject(alert);
}
out.close();
} catch (IOException e) {
s_logger.error("Failed to create output stream to write an alert types ", e);
} catch (IllegalAccessException e) {
s_logger.error("Failed to read alert fields ", e);
}
}
private static class LinkedProperties extends Properties {
private final LinkedList<Object> keys = new LinkedList<Object>();