1 64 65 package com.jcorporate.expresso.ext.dbobj; 66 67 import com.jcorporate.expresso.core.db.DBConnection; 68 import com.jcorporate.expresso.core.db.DBException; 69 import com.jcorporate.expresso.core.dbobj.DBObject; 70 import com.jcorporate.expresso.core.dbobj.RequestContext; 71 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 72 import org.apache.oro.util.CacheLRU; 73 74 75 82 public class RestrictedCountries 83 extends SecuredDBObject { 84 static public final String FLD_RESTRICTID = "RestrictedID"; 85 static public final String FLD_DOMAINID = "DomainID"; 86 87 91 static protected CacheLRU lookupCache = new CacheLRU(20); 92 93 98 public RestrictedCountries() 99 throws DBException { 100 super(); 101 } 102 103 109 public RestrictedCountries(DBConnection myConnection) 110 throws DBException { 111 super(myConnection); 112 } 113 114 121 public RestrictedCountries(int uid) 122 throws DBException { 123 super(uid); 124 } 125 126 133 public RestrictedCountries(RequestContext request) 134 throws DBException { 135 super(request); 136 } 137 138 144 public synchronized void populateDefaultValues() 145 throws DBException { 146 int i; 147 int len = restrictedIDs.length; 148 149 for (i = 0; i < len; i++) { 150 this.clear(); 151 this.setField(FLD_DOMAINID, restrictedIDs[i]); 152 153 if (!this.find()) { 154 this.add(); 155 } 156 } 157 } 158 159 160 166 public int getExpectedDefaultPopulation() { 167 return restrictedIDs.length; 168 } 169 170 175 public synchronized DBObject getThisDBObj() 176 throws DBException { 177 return new RestrictedCountries(); 178 } 179 180 181 184 protected void setupFields() 185 throws DBException { 186 setTargetTable("RESTRICTCNTRY"); 187 setDescription("Reverse Domain Lookup Descriptions"); 188 setCharset("ISO-8859-1"); 189 addField(FLD_RESTRICTID, "auto-inc", 0, false, "Restricted Country ID"); 190 addField(FLD_DOMAINID, "varchar", 20, false, "Restricted Domain ID"); 191 addKey(FLD_RESTRICTID); 192 setLookupObject(FLD_DOMAINID, 193 "com.jcorporate.expresso.ext.dbobj.ReverseLookupDomains"); 194 setMultiValued(FLD_DOMAINID); 195 } 196 197 198 int[] restrictedIDs = {}; 199 200 209 public boolean isRestricted(String ipAddress) 210 throws DBException { 211 212 if (ipAddress.equals("127.0.0.1")) { 216 return false; 217 } 218 219 Boolean cachedResult = this.getCachedLookup(ipAddress); 220 221 if (cachedResult != null) { 222 return cachedResult.booleanValue(); 223 } 224 225 ReverseLookupDomains rld = new ReverseLookupDomains(this.getRequestingUid()); 226 rld.setDataContext(this.getDataContext()); 227 228 String domainID = rld.getDomainId(ipAddress); 229 RestrictedCountries rc = new RestrictedCountries(this.getRequestingUid()); 230 rc.setDataContext(this.getDataContext()); 231 rc.setField(FLD_DOMAINID, domainID); 232 233 if (rc.find() == true) { 234 cachedResult = Boolean.TRUE; 235 } else { 236 cachedResult = Boolean.FALSE; 237 } 238 239 setCachedLookup(ipAddress, cachedResult); 240 241 return cachedResult.booleanValue(); 242 } 243 244 251 protected synchronized Boolean getCachedLookup(String ipAddress) { 252 return (Boolean ) lookupCache.getElement(ipAddress); 253 } 254 255 262 protected synchronized void setCachedLookup(String ipAddress, 263 Boolean newValue) { 264 lookupCache.addElement(ipAddress, newValue); 265 } 266 } | Popular Tags |