KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > common > actions > ModelAction


1 package org.infoglue.cms.applications.common.actions;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Collection JavaDoc;
5
6 import org.infoglue.cms.entities.kernel.Persistent;
7 import org.infoglue.cms.exception.ConstraintException;
8
9 /**
10  * Base class to provide Actions with some common semantics for dealing with
11  * a specific domain object (model) and collections of domain objects (models).
12  *
13  * @author Frank Febbraro (frank@phase2technology.com)
14  */

15 public abstract class ModelAction extends InfoGlueAbstractAction
16 {
17     private Persistent model = createModel();
18     private Collection JavaDoc models = new ArrayList JavaDoc();
19
20     public Persistent getModel()
21     {
22         return model;
23     }
24
25     protected void setModel(Persistent o)
26     {
27         model = (o == null) ? createModel() : o;
28     }
29
30     public Collection JavaDoc getModels()
31     {
32         return models;
33     }
34
35     protected void setModels(Collection JavaDoc c)
36     {
37         models = (c == null) ? new ArrayList JavaDoc() : c;
38     }
39
40     /**
41      * Template method used by subclasses to provide a new instance of the model.
42      * @return a new PersistentObject
43      */

44     protected abstract Persistent createModel();
45
46     /**
47      * Perform the validation operation on the model
48      * @throws ConstraintException If a validation error exists
49      */

50     protected void validateModel() throws ConstraintException
51     {
52         getModel().validate().throwIfNotEmpty();
53     }
54
55     /**
56      * Default implementation for WebworkAbstractAction, subclasses shold feel free to override
57      */

58     protected String JavaDoc doExecute() throws Exception JavaDoc
59     {
60         return SUCCESS;
61     }
62
63     //-------------------------------------------------------------------------
64
// Override some methods to remove the reliance on anything HTTP.
65
// WebWork did a good job abstracting HTTP away, lets take advantage of it
66
//-------------------------------------------------------------------------
67

68 }
69
Popular Tags