1 64 65 package com.jcorporate.expresso.services.controller.dbmaint; 66 67 import com.jcorporate.expresso.core.controller.Controller; 68 import com.jcorporate.expresso.core.controller.ControllerException; 69 import com.jcorporate.expresso.core.controller.Input; 70 import com.jcorporate.expresso.core.controller.Output; 71 import com.jcorporate.expresso.core.controller.Transition; 72 import com.jcorporate.expresso.core.dataobjects.DataObject; 73 import com.jcorporate.expresso.core.dataobjects.DataObjectMetaData; 74 import com.jcorporate.expresso.core.db.DBException; 75 import com.jcorporate.expresso.core.misc.Format; 76 import com.jcorporate.expresso.core.misc.StringUtil; 77 import com.jcorporate.expresso.core.security.User; 78 import com.jcorporate.expresso.core.security.UserInfo; 79 80 import java.util.Iterator ; 81 82 83 89 public abstract class GetBase 90 extends DynamicCmd { 91 public GetBase() { 92 } 93 94 98 public GetBase(String code, String descrip) { 99 super(code, descrip); 100 } 101 102 109 protected abstract void autoField(String oneFieldName) 110 throws DBException, ControllerException; 111 112 119 private void autoForm() 120 throws DBException, ControllerException { 121 String oneFieldName = null; 122 DataObject myDBObj = this.getDataObject(); 123 124 if (myDBObj == null) { 125 throw new DBException("Database object must be " + 126 "initialized before calling autoField"); 127 } 128 129 DataObjectMetaData metadata = myDBObj.getMetaData(); 130 showUserName(metadata.getDescription(this.getControllerRequest().getLocale())); 131 addOutput(new Output("title", metadata.getDescription(this.getControllerRequest().getLocale()))); 132 133 for (Iterator e = metadata.getFieldListArray().iterator(); e.hasNext();) { 134 oneFieldName = (String ) e.next(); 135 autoField(oneFieldName); 136 } 137 } 138 139 140 149 protected String displayValue(String fieldType, String fieldValue) 150 throws DBException { 151 try { 152 if (fieldType.equalsIgnoreCase("money")) { 153 if (!fieldValue.equals("")) { 154 return new Format("%-10.2f").form(new Double (fieldValue).doubleValue()); 155 } 156 } else { 157 return fieldValue; 158 } 159 } catch (NumberFormatException ne) { 160 throw new DBException("Number for field not in a " + 161 "valid numeric format:" + fieldValue + ":" + 162 ne.getMessage()); 163 } 164 165 return null; 166 } 167 168 169 178 protected void addLookupTransition(DataObjectMetaData metadata, 179 Input oneField, 180 String oneFieldName) throws DBException { 181 182 183 184 String lookupObjectName = StringUtil.notNull(metadata.getLookupObject(oneFieldName)); 185 186 String definitionName = StringUtil.notNull(metadata 187 .getFieldMetadata(oneFieldName).getLookupDefinition()); 188 189 if (!lookupObjectName.equals("")) { 190 boolean add = true; 191 if (com.jcorporate.expresso.core.security.User 196 .class.getName().equals(lookupObjectName)) { 197 User u = new User(); 198 UserInfo ui = u.getUserInfo(); 199 if (!(ui instanceof DataObject)) { 200 add = false; 201 } 202 } 203 204 if (add) { 205 Transition lookup = new Transition(); 206 lookup.setName("lookup"); 207 lookup.addParam("dbobj", lookupObjectName); 208 if (definitionName.length() > 0) { 209 lookup.addParam("definition", definitionName); 210 } 211 lookup.addParam(Controller.STATE_PARAM_KEY, "Search"); 212 lookup.setDescription("Look up Values"); 213 oneField.addNested(lookup); 214 } 215 } 216 } 217 218 227 protected void showForm() 228 throws DBException, ControllerException { 229 autoForm(); 230 showOptions(); 231 } 232 233 234 } 235 236 | Popular Tags |