1 15 package org.josql.filters; 16 17 import org.josql.Query; 18 import org.josql.QueryParseException; 19 20 28 public abstract class AbstractJoSQLFilter 29 { 30 31 protected Query q = null; 32 protected Exception exp = null; 33 protected boolean badQuery = false; 34 35 38 protected AbstractJoSQLFilter () 39 { 40 41 } 42 43 50 public AbstractJoSQLFilter (String q) 51 throws QueryParseException 52 { 53 54 this.setQuery (q); 55 56 } 57 58 64 public abstract Class getExpectedClass (); 65 66 73 public AbstractJoSQLFilter (Query q) 74 throws IllegalStateException , 75 QueryParseException 76 { 77 78 this.setQuery (q); 79 80 } 81 82 private void checkFrom () 83 throws QueryParseException 84 { 85 86 if (!this.getExpectedClass ().isAssignableFrom (this.q.getFromObjectClass ())) 87 { 88 89 throw new QueryParseException ("Query FROM class is: " + 90 this.q.getFromObjectClass ().getName () + 91 ", however only: " + 92 this.getExpectedClass ().getName () + 93 " or sub-classes are supported."); 94 95 } 96 97 } 98 99 107 public abstract boolean accept (Object o) 108 throws UnsupportedOperationException ; 109 110 113 public void clearException () 114 { 115 116 this.exp = null; 117 this.badQuery = false; 118 119 } 120 121 130 public Exception getException () 131 { 132 133 return this.exp; 134 135 } 136 137 144 public void setQuery (String q) 145 throws QueryParseException 146 { 147 148 this.q = new Query (); 149 this.q.parse (q); 150 151 this.badQuery = false; 152 this.exp = null; 153 154 this.checkFrom (); 155 156 } 157 158 165 public void setQuery (Query q) 166 throws IllegalStateException , 167 QueryParseException 168 { 169 170 if (!q.parsed ()) 171 { 172 173 throw new IllegalStateException ("Query has not yet been parsed."); 174 175 } 176 177 this.q = q; 178 179 this.checkFrom (); 180 181 this.badQuery = false; 182 this.exp = null; 183 184 } 185 186 191 public Query getQuery () 192 { 193 194 return this.q; 195 196 } 197 198 } 199 | Popular Tags |