提交 365665f3 编写于 作者: K kohsuke

defining methods for persisting data.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@11315 71c3de6d-444a-0410-be80-ed276b4c234a
上级 5bdb38db
...@@ -14,9 +14,11 @@ import javax.servlet.ServletContext; ...@@ -14,9 +14,11 @@ import javax.servlet.ServletContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.File;
import java.net.URL; import java.net.URL;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import com.thoughtworks.xstream.XStream;
/** /**
* Base class of Hudson plugin. * Base class of Hudson plugin.
...@@ -143,4 +145,38 @@ public abstract class Plugin { ...@@ -143,4 +145,38 @@ public abstract class Plugin {
// use serveLocalizedFile to support automatic locale selection // use serveLocalizedFile to support automatic locale selection
rsp.serveLocalizedFile(req, new URL(wrapper.baseResourceURL,'.'+path)); rsp.serveLocalizedFile(req, new URL(wrapper.baseResourceURL,'.'+path));
} }
//
// Convenience methods for those plugins that persist configuration
//
/**
* Loads serializable fields of this instance from the persisted storage.
*
* <p>
* If there was no previously persisted state, this method is no-op.
*/
protected void load() throws IOException {
XmlFile xml = getConfigXml();
if(xml.exists())
xml.unmarshal(this);
}
/**
* Saves serializable fields of this instance to the persisted storage.
*/
protected void save() throws IOException {
getConfigXml().write(this);
}
/**
* Controls the file where {@link #load()} and {@link #save()}
* persists data.
*
* This method can be also overriden if the plugin wants to
* use a custom {@link XStream} instance to persist data.
*/
protected XmlFile getConfigXml() {
return new XmlFile(Hudson.XSTREAM,
new File(Hudson.getInstance().getRootDir(),wrapper.getShortName()+".xml"));
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册