1 64 65 package com.jcorporate.expresso.services.dbobj; 66 67 import com.jcorporate.expresso.core.controller.Controller; 68 import com.jcorporate.expresso.core.db.DBException; 69 import com.jcorporate.expresso.core.dbobj.RequestContext; 70 import com.jcorporate.expresso.core.servlet.StdServlet; 71 72 73 81 public class ControllerSecurity 82 extends SecurityDBObject { 83 84 87 public static final String CONTROLLER_CLASS = "ControllerClass"; 88 public static final String GROUP_NAME = "GroupName"; 89 public static final String STATES = "States"; 90 91 92 95 public static final String ANY_STATE_WILDCARD = "*"; 96 97 100 public ControllerSecurity() 101 throws DBException { 102 super(); 103 } 104 105 106 111 public ControllerSecurity(int uid) 112 throws DBException { 113 super(uid); 114 } 115 116 122 public ControllerSecurity(RequestContext request) 123 throws DBException { 124 super(request); 125 } 126 127 131 public void add() 132 throws DBException { 133 if (getField(STATES).equals("")) { 134 setField(STATES, ANY_STATE_WILDCARD); 135 } 136 137 super.add(); 138 } 139 140 141 147 public String getField(String fieldName) 148 throws DBException { 149 if (fieldName.equals("ControllerDescrip")) { 150 StdServlet serv; 151 Controller con; 152 153 try { 154 Class c = Class.forName(getField(CONTROLLER_CLASS)); 155 Object o = c.newInstance(); 156 157 if (o instanceof Controller) { 158 con = (Controller) o; 159 160 return con.getTitle(); 161 } else if (o instanceof StdServlet) { 162 serv = (StdServlet) o; 163 164 return serv.getTitle(); 165 } else { 166 return ("Unknown"); 167 } 168 } catch (ClassNotFoundException cn) { 169 return ("Controller/Servlet object " + 170 getField(CONTROLLER_CLASS) + " not found"); 171 } catch (InstantiationException ie) { 172 return ("Controller object " + 173 getField(CONTROLLER_CLASS) + 174 " cannot be instantiated"); 175 } catch (IllegalAccessException iae) { 176 return ("Illegal access loading Controller object"); 177 } 178 } 179 180 181 return super.getField(fieldName); 182 } 183 184 185 188 public void setupFields() 189 throws DBException { 190 setTargetTable("CONTROLLERSECURITY"); 191 setDescription("DBcontrollerSecurity"); 192 setCharset("ISO-8859-1"); 193 addField(CONTROLLER_CLASS, "char", 128, false, "controllerClass"); 194 addVirtualField("ControllerDescrip", "varchar", 80, 195 "controllerDescription"); 196 addField(GROUP_NAME, "char", 10, false, "group"); 197 addField(STATES, "text", 0, false, "allowedStates"); 198 setStringFilter(CONTROLLER_CLASS, "stripFilter"); 199 setStringFilter(GROUP_NAME, "stripFilter"); 200 setStringFilter(STATES, "rawFilter"); 201 addKey(CONTROLLER_CLASS); 202 addKey(GROUP_NAME); 203 setMultiValued(GROUP_NAME); 204 setLookupObject(GROUP_NAME, UserGroup.class.getName()); 205 } 206 207 208 214 public void setField(String fieldName, String fieldValue) 215 throws DBException { 216 if (fieldValue != null) { 217 super.setField(fieldName, fieldValue.trim()); 218 } else { 219 super.setField(fieldName, (String ) null); 220 } 221 } 222 223 224 } 225 | Popular Tags |