1 package com.jcorporate.expresso.services.controller; 2 3 66 67 import com.jcorporate.expresso.core.controller.ControllerException; 68 import com.jcorporate.expresso.core.controller.ControllerRequest; 69 import com.jcorporate.expresso.core.controller.ControllerResponse; 70 import com.jcorporate.expresso.core.controller.DBController; 71 import com.jcorporate.expresso.core.controller.Input; 72 import com.jcorporate.expresso.core.controller.State; 73 import com.jcorporate.expresso.core.controller.Transition; 74 import com.jcorporate.expresso.core.db.DBException; 75 import com.jcorporate.expresso.core.dbobj.DBObject; 76 import com.jcorporate.expresso.core.dbobj.Schema; 77 import com.jcorporate.expresso.core.dbobj.SchemaFactory; 78 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 79 import com.jcorporate.expresso.core.dbobj.ValidValue; 80 import com.jcorporate.expresso.services.controller.dbmaint.Add; 81 import com.jcorporate.expresso.services.controller.dbmaint.AddUpdate; 82 import com.jcorporate.expresso.services.controller.dbmaint.List; 83 import com.jcorporate.expresso.services.controller.dbmaint.Search; 84 import com.jcorporate.expresso.services.controller.dbmaint.SearchList; 85 import com.jcorporate.expresso.services.controller.dbmaint.Update; 86 import com.jcorporate.expresso.services.controller.dbmaint.UpdateDelete; 87 import com.jcorporate.expresso.services.controller.dbmaint.UpdateUpdate; 88 import com.jcorporate.expresso.services.controller.dbmaint.ViewBlob; 89 import com.jcorporate.expresso.services.dbobj.DBOtherMap; 90 import com.jcorporate.expresso.services.dbobj.SchemaList; 91 import org.apache.log4j.Logger; 92 93 import java.util.Enumeration ; 94 import java.util.Iterator ; 95 import java.util.Vector ; 96 97 98 116 public class DBMaint 117 extends DBController { 118 119 122 private static Logger log = Logger.getLogger(DBMaint.class); 123 public static final String UPDATE = "Update"; 124 public static final String LIST = "List"; 125 public static final String ADD = "Add"; 126 public static final String SEARCH = "Search"; 127 public static final String PROMPT = "prompt"; 128 129 132 public DBMaint() { 133 super(); 134 State prompt = new State(PROMPT, "Prompt to Select Schema"); 135 addState(prompt); 136 setInitialState("prompt"); 137 138 State selDBObj = new State("selDBObj", "Select Database Object"); 139 selDBObj.addRequiredParameter("SchemaClass"); 140 addState(selDBObj); 141 142 State add = new Add(ADD, "Prompt for New Record"); 143 addState(add); 144 145 State addUpdate = new AddUpdate("AddUpdate", "Save New Record"); 146 addState(addUpdate); 147 148 State list = new List(LIST, "List Records"); 149 addState(list); 150 151 State search = new Search(SEARCH, "Prompt for Search Criteria"); 152 addState(search); 153 154 State searchList = new SearchList("SearchList", 155 "Display records found by Search"); 156 addState(searchList); 157 158 State update = new Update(UPDATE, "Present Record for Update"); 159 addState(update); 160 161 State updateDelete = new UpdateDelete("UpdateDelete", "Delete Record"); 162 addState(updateDelete); 163 164 State updateUpdate = new UpdateUpdate("UpdateUpdate", "Update Record"); 165 addState(updateUpdate); 166 167 this.addState(new ViewBlob()); 168 169 170 this.setSchema(com.jcorporate.expresso.core.ExpressoSchema.class); 171 } 172 173 174 179 public String getTitle() { 180 return ("Database Maintenance"); 181 } 182 183 196 private void runPromptState(ControllerRequest request, ControllerResponse response) 197 throws ControllerException { 198 try { 199 Input chooseSchema = new Input(); 200 chooseSchema.setLabel("Choose Schema"); 201 chooseSchema.setName("SchemaClass"); 202 203 Vector v2 = new Vector (2); 204 v2.addElement(new ValidValue("com.jcorporate.expresso." + "core.ExpressoSchema", 205 "General")); 206 207 SchemaList sl = new SchemaList(SecuredDBObject.SYSTEM_ACCOUNT); 208 sl.setDataContext(request.getDataContext()); 209 210 SchemaList oneSchema = null; 211 212 for (Iterator e = sl.searchAndRetrieveList("Descrip").iterator(); 213 e.hasNext();) { 214 oneSchema = (SchemaList) e.next(); 215 v2.addElement(new ValidValue(oneSchema.getField("SchemaClass"), 216 oneSchema.getField("Descrip"))); 217 } 218 219 chooseSchema.setValidValues(v2); 220 response.addInput(chooseSchema); 221 222 Transition doDBObj = new Transition("Choose Database Object", 223 getClass().getName()); 224 doDBObj.setName("selDBObj"); 225 doDBObj.addParam(STATE_PARAM_KEY, "selDBObj"); 226 response.addTransition(doDBObj); 227 } catch (DBException de) { 228 throw new ControllerException(de.getMessage()); 229 } 230 } 231 232 233 241 private void runSelDBObjState(ControllerRequest request, ControllerResponse response) 242 throws ControllerException { 243 Input chooseDBobj = new Input(); 244 chooseDBobj.setLabel("Choose Database Object"); 245 chooseDBobj.setName("dbobj"); 246 247 Vector v2 = new Vector (); 248 249 try { 250 DBObject oneDBObject = null; 251 Schema mySchema = SchemaFactory.getInstance().getSchema(request.getParameter("SchemaClass")); 252 if (mySchema == null) { 253 throw new ControllerException("Error instantiating Schema: " + 254 request.getParameter("SchemaClass")); 255 } 256 257 for (Enumeration e = mySchema.getMembers(); e.hasMoreElements();) { 258 oneDBObject = (DBObject) e.nextElement(); 259 String descrip = oneDBObject.getMetaData().getDescription(request.getLocale()); 260 if (log.isDebugEnabled()) { 261 log.debug("Adding dataobject: " + descrip); 262 } 263 264 v2.addElement(new ValidValue(oneDBObject.getClass().getName(), 265 oneDBObject.getMetaData().getDescription(request.getLocale()))); 266 } 267 268 DBOtherMap otherDbobj = new DBOtherMap(SecuredDBObject.SYSTEM_ACCOUNT); 269 otherDbobj.setDataContext(request.getDataContext()); 270 271 } catch (DBException de) { 272 throw new ControllerException(de); 273 } 274 275 chooseDBobj.setValidValues(v2); 276 response.addInput(chooseDBobj); 277 response.addTransition(new Transition(ADD, this)); 278 response.addTransition(new Transition(LIST, this)); 279 response.addTransition(new Transition(SEARCH, this)); 280 } 281 282 } 283 | Popular Tags |