View Javadoc

1   package com.sri.emo.dbobj;
2   
3   import com.jcorporate.expresso.core.db.DBConnection;
4   import com.jcorporate.expresso.core.db.DBException;
5   import com.jcorporate.expresso.core.dbobj.DBField;
6   import com.jcorporate.expresso.core.dbobj.ValidValue;
7   import com.jcorporate.expresso.core.security.ReadOnlyUser;
8   import org.apache.log4j.Logger;
9   
10  import java.util.Vector;
11  
12  /***
13   * This is a collection of attributes for a particular wizard step.  If you
14   * add attributes, you need to modify the getValidValues() function as well
15   * since this class enforces just what kind of attributes you can use.
16   */
17  public class StepAttributes extends com.jcorporate.expresso.core.dbobj.SecuredDBObject {
18  
19      /***
20  	 * 
21  	 */
22  	private static final long serialVersionUID = 1L;
23  
24  	/***
25       * Attribute Constant Supported for 'text style'.
26       */
27      public static final String ATTRIBUTE_TEXT_STYLE = "TextStyle";
28  
29      /***
30       * Attribute Constant Supported for 'model field'.
31       */
32      public static final String ATTRIBUTE_MODEL_FIELD = "ModelField";
33  
34      /***
35       * Attribute Constant Supported for 'model'.
36       */
37      public static final String ATTRIBUTE_MODEL = "Model";
38  
39      /***
40       * the ID of the instance, when step is of type 'attribute of instance'
41       */
42      public static final String ATTRIBUTE_INSTANCE_ID = "InstanceId";
43  
44      /***
45       * the ID of the Part, when step is of type 'attribute of instance'
46       */
47      public static final String ATTRIBUTE_INSTANCE_FIELD = "InstanceField";
48  
49  
50      /***
51       * Attribute Constant supported for 'Custom Picklist Id'
52       */
53      public static final String ATTRIBUTE_PICKLIST_ID = "PickListId";
54  
55      /***
56       * DBObject table name
57       */
58      public static final String TABLE_NAME = "StepAttributes";
59  
60      /***
61       * The log4j logger instance for this class type.  Send all logging output
62       * to this variable
63       */
64      private static final transient Logger log = Logger.getLogger(StepAttributes.class);
65  
66      /***
67       * Public constant for access to field
68       * "Item ID"
69       */
70      public static final String FLD_ID = "SettingId";
71  
72      /***
73       * Public constant for access to field
74       * "Wizard Step ID"
75       */
76      public static final String FLD_STEPID = "StepId";
77  
78      /***
79       * Public constant for access to field
80       * "Attribute Key"
81       */
82      public static final String FLD_ATTRIBUTEKEY = "AttributeKey";
83  
84      /***
85       * Public constant for access to field
86       * "Attribute Value"
87       */
88      public static final String FLD_ATTRIBUTEVALUE = "AttributeValue";
89  
90  
91      /***
92       * Valid value constant for text type attribute.
93       */
94      public static final String TEXT_VV_SINGLELINE = "1";
95  
96      /***
97       * Valid value constant for text type atttribute for multiline entry.
98       */
99      public static final String TEXT_VV_MULTILINE = "2";
100 
101     /***
102      * Creates an instance of StepAttributes.  Call setRequestingUid() and setDataContext()
103      * before using.
104      *
105      * @throws DBException upon initialization exception.
106      * @see com.jcorporate.expresso.core.dbobj.SecuredDBObject#SecuredDBObject
107      */
108     public StepAttributes() throws DBException {
109         super();
110     }
111 
112 
113     /***
114      * Creates an instance of StepAttributes that uses an already grabbed DBConnection
115      * object.  This is for use inside transactions.  <p>Example: <code><pre>
116      * DBConnection oneConnection = DBConnectionPool.getInstance("default").getConnection();
117      * oneConnection.setAutoCommit(false);
118      * StepAttributes myObj = new StepAttributes(oneConnection);
119      * //Set fields here....
120      * myObj.add();
121      * myObj.clear();
122      * //more set fields
123      * myObj.add();
124      * //Commit the transaction
125      * oneConnection.commit();
126      * oneConnection.release();
127      * </pre></code>
128      * </p>
129      *
130      * @param dbConnection com.jcorporate.expresso.core.db.DBConnection
131      * @throws DBException upon construction error
132      */
133     public StepAttributes(DBConnection dbConnection) throws DBException {
134         super(dbConnection);
135     }
136 
137     /* StepAttributes(DBConnection) */
138 
139     /***
140      * <p/>
141      * Constructor that sets a connection as the object is created - typically
142      * this is used when a particular DBConnection is required for the purposes of
143      * maintaining a database transaction. If a specific connection is not used,
144      * there is no way to use commit() and rollback() in the event of failure, as a
145      * different DBConnection might be used for each phase of the transaction.
146      * Critial sections should therefore explicity request a DBConnection from the
147      * connection pool and pass it to each of the DB objects in that section.
148      * </p>
149      * <p>This constructor is neceesary to work with otherDBMap and transaction
150      * capabilities</p>
151      *
152      * @param dbConnection    The DBConnection to utilize
153      * @param securityContext The data context that contains the setup (and
154      *                        security) tables for this object
155      * @throws DBException upon initialization error
156      */
157     public StepAttributes(DBConnection dbConnection, String securityContext) throws DBException {
158         super(dbConnection, securityContext);
159     }
160 
161     /***
162      * Constructor for security setup.
163      *
164      * @param userSecurity ReadOnlyUser security context.
165      * @throws DBException upon construction error.
166      */
167     public StepAttributes(final ReadOnlyUser userSecurity) throws DBException {
168         super(userSecurity);
169     }
170 
171     /***
172      * Retrieve the attribute key field.
173      *
174      * @return String may be empty string if attribute doesn't exist.
175      * @throws DBException upon error.
176      */
177     public String getAttributeKey() throws DBException {
178         return getField(FLD_ATTRIBUTEKEY);
179     }
180 
181     /***
182      * Retrieve the attribute value field.
183      *
184      * @return String may be empty string if attribute doesn't exist.
185      * @throws DBException upon error.
186      */
187     public String getAttributeValue() throws DBException {
188         return getField(FLD_ATTRIBUTEVALUE);
189     }
190 
191     /***
192      * One time intiialization of all the field types.  Set all specifications
193      * here such as field names, table name, friendly name of the data object,
194      * characterset, etc.
195      *
196      * @throws DBException upon error
197      * @todo fill this function out to use your dbobject.
198      */
199     protected void setupFields() throws DBException {
200         if (log.isDebugEnabled()) {
201             log.debug("Initializing field members");
202         }
203 
204         super.setupFields();
205 
206         setTargetTable(TABLE_NAME);
207         setDescription("Wizard Step Attributes");
208         setCharset("ISO-8859-1");
209 
210         addField(FLD_ID, "auto-inc", 0, false, "Item ID");
211         addKey(FLD_ID);
212 
213         addField(FLD_STEPID, DBField.INTEGER_TYPE, 0, false, "Wizard Step ID");
214 
215         addField(FLD_ATTRIBUTEKEY, DBField.VARCHAR_TYPE, 254, false, "Attribute Key");
216         setMultiValued(FLD_ATTRIBUTEKEY);
217 
218         addField(FLD_ATTRIBUTEVALUE, DBField.VARCHAR_TYPE, 254, true, "Attribute Value");
219 
220         //addIndex statements
221         addIndex("EmoWizStep_Attr", FLD_STEPID + "," + FLD_ATTRIBUTEKEY, true);
222 
223     }
224 
225     /***
226      * Retrieves the attributes allowable.
227      *
228      * @param fieldName String
229      * @return Vector of valid value objects.
230      * @throws DBException upon error.
231      */
232     public synchronized Vector getValidValues(String fieldName) throws DBException {
233         if (FLD_ATTRIBUTEKEY.equals(fieldName)) {
234             Vector vv = new Vector(6);
235             vv.add(new ValidValue(ATTRIBUTE_TEXT_STYLE, ATTRIBUTE_TEXT_STYLE));
236             vv.add(new ValidValue(ATTRIBUTE_MODEL_FIELD, ATTRIBUTE_MODEL_FIELD));
237             vv.add(new ValidValue(ATTRIBUTE_MODEL, ATTRIBUTE_MODEL));
238             vv.add(new ValidValue(ATTRIBUTE_INSTANCE_ID, ATTRIBUTE_INSTANCE_ID));
239             vv.add(new ValidValue(ATTRIBUTE_INSTANCE_FIELD, ATTRIBUTE_INSTANCE_FIELD));
240             vv.add(new ValidValue(ATTRIBUTE_PICKLIST_ID, ATTRIBUTE_PICKLIST_ID));
241 
242             return vv;
243         } else {
244             return super.getValidValues(fieldName);
245         }
246     }
247 
248     public void setStepId(String id) throws DBException {
249         setField(FLD_STEPID, id);
250     }
251 }