KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > formview > State


1 package net.sourceforge.formview;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.List JavaDoc;
6
7 import org.apache.commons.collections.FastHashMap;
8
9 /**
10  * State composed by :
11  * <ul>
12  * <li><b>name</b> of state, like CREATE, UPDATE, READ,...</li>
13  * <li><b>behaviour</b> of state, like READ-WRITE, READ-ONLY, INVISIBLE,...
14  * Behaviour is used for each HTML element into DisplayerConfig.
15  * </li>
16  * </ul>
17  *
18  * @see net.sourceforge.formview.displayer.DisplayerConfig
19  * @version 1.0.0
20  * @author <a HREF="mailto:angelo.zerr@gmail.com">Angelo ZERR</a>
21  */

22 public class State {
23
24     private String JavaDoc name;
25     private String JavaDoc behaviour;
26     /**
27      * Map of <code>Field</code>s keyed on their property value.
28      */

29     protected FastHashMap hFields = null;
30     protected List JavaDoc lFields = null;
31     
32     public String JavaDoc getBehaviour() {
33         return behaviour;
34     }
35     public void setBehaviour(String JavaDoc behaviour) {
36         this.behaviour = behaviour;
37     }
38     public String JavaDoc getName() {
39         return name;
40     }
41     public void setName(String JavaDoc name) {
42         this.name = name;
43     }
44     /**
45      * Add a <code>Field</code> to the <code>Form</code>.
46      */

47     public void addField(FieldView f, Class JavaDoc updatedByClass, String JavaDoc updatedByMethodName) {
48         if (hFields == null)
49             hFields = new FastHashMap();
50         if (lFields == null)
51             lFields = new ArrayList JavaDoc();
52         f.setUpdatedByClass(updatedByClass);
53         f.setUpdatedByMethodName(updatedByMethodName);
54         this.lFields.add(f);
55         this.hFields.put(f.getProperty(), f);
56     }
57     
58     public void addField(FieldView f, Class JavaDoc updatedByClass) {
59         addField(f, updatedByClass, "");
60     }
61  
62     public void addField(FieldView f) {
63         addField(f, FormView.class);
64     }
65     
66     public FieldView getField(String JavaDoc property) {
67         if (hFields != null) {
68             return (FieldView)hFields.get(property);
69         }
70         return null;
71     }
72     
73     public List JavaDoc getFields() {
74         return lFields;
75     }
76
77     public Object JavaDoc clone() {
78         State stateCloned = new State();
79         stateCloned.setBehaviour(this.behaviour);
80         stateCloned.setName(this.name);
81         // Clone list of fields
82
if (lFields != null) {
83             for (Iterator JavaDoc iter = lFields.iterator(); iter.hasNext();) {
84                 FieldView field = (FieldView) iter.next();
85                 stateCloned.addField((FieldView)field.clone());
86                 
87             }
88         }
89         return stateCloned;
90         
91     }
92 }
93
Popular Tags