refactor the save method so that it is available to all and null safe. also added a readResolve to handle when null properties are deserialized

This commit is contained in:
Stephen Connolly committed 2011-03-30 17:22:33 +01:00
1 parent cd083bf4ed
commit d8096f24e4
3 files changed
+18 -14

No files matched your search

@@ -91,13 +91,6 @@ public class ListView extends View implements Saveable {
this.owner = owner;
}
public void save() throws IOException {
// persistence is a part of the owner.
// due to the initialization timing issue, it can be null when this method is called.
if (owner!=null)
owner.save();
}
private Object readResolve() {
if(includeRegex!=null)
includePattern = Pattern.compile(includeRegex);
@@ -148,10 +148,6 @@ public class TreeView extends View implements ViewGroup {
// noop
}
public void save() throws IOException {
owner.save();
}
public void doCreateView( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException, FormException {
checkPermission(View.CREATE);
views.add(View.create(req,rsp,this));
+18 -3
View File
@@ -130,6 +130,13 @@ public abstract class View extends AbstractModelObject implements AccessControll
this.owner = owner;
}
private Object readResolve() {
if (properties == null) {
properties = new ArrayList<ViewProperty>();
}
return this;
}
/**
* Gets all the items in this collection in a read-only view.
*/
@@ -213,7 +220,15 @@ public abstract class View extends AbstractModelObject implements AccessControll
ps.add(p);
p.setView(this);
properties = ps;
owner.save();
save();
}
public void save() throws IOException {
// persistence is a part of the owner
// due to initialization timing issue, it can be null when this method is called
if (owner != null) {
owner.save();
}
}
/**
@@ -615,7 +630,7 @@ public abstract class View extends AbstractModelObject implements AccessControll
checkPermission(CONFIGURE);
description = req.getParameter("description");
owner.save();
save();
rsp.sendRedirect("."); // go to the top page
}
@@ -658,7 +673,7 @@ public abstract class View extends AbstractModelObject implements AccessControll
}
properties = props;
owner.save();
save();
rsp.sendRedirect2("../"+name);
}