1 27 28 package javax.management; 29 30 31 import com.adventnet.jmx.utils.JmxUtilities; 32 33 38 public class QueryExpSupport implements QueryExp 39 { 40 private transient MBeanServer server = null; 41 42 public static final int DIV = Query.DIV; 43 public static final int EQ = Query.EQ; 44 public static final int GE = Query.GE; 45 public static final int GT = Query.GT; 46 public static final int LE = Query.LE; 47 public static final int LT = Query.LT; 48 public static final int MINUS = Query.MINUS; 49 public static final int PLUS = Query.PLUS; 50 public static final int TIMES = Query.TIMES; 51 52 public static final int MATCH = Query.MATCH; 53 public static final int AND = Query.AND; 54 public static final int OR = Query.OR; 55 public static final int BET = Query.BET; 56 public static final int NOT = Query.NOT; 57 public static final int IN = Query.IN; 58 public static final int INITIAL = Query.INITIAL; 59 public static final int ANY = Query.ANY; 60 public static final int FINAL = Query.FINAL; 61 62 public QueryExpSupport() 63 { 64 } 65 66 private QueryExp q1 = null; 67 private QueryExp q2 = null; 68 boolean queryFlag = true; 69 70 private ValueExp v1 = null; 71 private ValueExp v2 = null; 72 private ValueExp v3 = null; 73 private ValueExp [] list = null; 74 boolean valueFlag = false; 75 76 private int type = Query.AND; 77 78 QueryExpSupport(QueryExp q1, QueryExp q2, int type) 79 { 80 this.q1 = q1; 81 this.q2 = q2; 82 this.type = type; 83 queryFlag = true; 84 } 85 86 QueryExpSupport(QueryExp q1, int type) 88 { 89 this.q1 = q1; 90 this.type = type; 91 queryFlag = true; 92 } 93 94 QueryExpSupport(ValueExp v1, ValueExp v2, int type) 95 { 96 this.v1 = v1; 97 this.v2 = v2; 98 this.type = type; 99 valueFlag = true; 100 } 101 102 QueryExpSupport(ValueExp v1, ValueExp v2, ValueExp v3, int type) 103 { 104 this.v1 = v1; 105 this.v2 = v2; 106 this.v3 = v3; 107 this.type = type; 108 valueFlag = true; 109 } 110 111 QueryExpSupport(ValueExp v1, ValueExp [] list, int type) 113 { 114 this.v1 = v1; 115 if(list != null && list.length > 0) 116 this.v2 = list[0]; 117 this.list = list; 118 this.type = type; 119 valueFlag = true; 120 } 121 122 137 public boolean apply(ObjectName object) 138 throws BadStringOperationException , 139 BadBinaryOpValueExpException , 140 BadAttributeValueExpException , 141 InvalidApplicationException 142 { 143 if(valueFlag) 144 { 145 String str1 = null; 146 String str2 = null; 147 String str3 = null; 148 149 Object obj1 = null; 150 Object obj2 = null; 151 Object obj3 = null; 152 153 v1.apply(object); 154 155 str1 = v1.toString(); 156 157 if(v1 instanceof StringValueExp ) 158 obj1 = ((StringValueExp )v1).getObject(); 159 else if(v1 instanceof AttributeValueExp ) 160 obj1 = ((AttributeValueExp )v1).getObject(); 161 162 v2.apply(object); 163 164 str2 = v2.toString(); 165 166 if(v2 instanceof StringValueExp ) 167 obj2 = ((StringValueExp )v2).getObject(); 168 else if(v2 instanceof AttributeValueExp ) 169 obj2 = ((AttributeValueExp )v2).getObject(); 170 171 if(v3 != null) 172 { 173 v3.apply(object); 174 str3 = v3.toString(); 175 if(v3 instanceof StringValueExp ) 176 obj3 = ((StringValueExp )v3).getObject(); 177 else if(v3 instanceof AttributeValueExp ) 178 obj3 = ((AttributeValueExp )v3).getObject(); 179 } 180 181 switch(type) 182 { 183 case Query.GT: 184 int ret; 185 186 if((obj1 instanceof Integer ) && (obj2 instanceof Long )) 187 { 188 if( ((Integer )obj1).intValue() > ((Long )obj2).intValue() ) 189 return true; 190 else 191 return false; 192 } 193 194 if((obj1 instanceof Long ) && (obj2 instanceof Integer )) 195 { 196 if( ((Long )obj1).intValue() > ((Integer )obj2).intValue() ) 197 return true; 198 else 199 return false; 200 } 201 202 ret = ((Comparable )obj1).compareTo(obj2); 203 204 if(ret > 0) 205 return true; 206 else 207 return false; 208 209 case Query.GE: 210 211 if((obj1 instanceof Integer ) && (obj2 instanceof Long )) 212 { 213 if( ((Integer )obj1).intValue() >= ((Long )obj2).intValue() ) 214 return true; 215 else 216 return false; 217 } 218 219 if((obj1 instanceof Long ) && (obj2 instanceof Integer )) 220 { 221 if( ((Long )obj1).intValue() >= ((Integer )obj2).intValue() ) 222 return true; 223 else 224 return false; 225 } 226 227 ret = ((Comparable )obj1).compareTo(obj2); 228 229 if(ret >= 0) 230 return true; 231 else 232 return false; 233 234 case Query.LE: 235 236 if((obj1 instanceof Integer ) && (obj2 instanceof Long )) 237 { 238 if( ((Integer )obj1).intValue() <= ((Long )obj2).intValue() ) 239 return true; 240 else 241 return false; 242 } 243 244 if((obj1 instanceof Long ) && (obj2 instanceof Integer )) 245 { 246 if( ((Long )obj1).intValue() <= ((Integer )obj2).intValue() ) 247 return true; 248 else 249 return false; 250 } 251 252 ret = ((Comparable )obj1).compareTo(obj2); 253 254 if(ret <= 0) 255 return true; 256 else 257 return false; 258 259 case Query.LT: 260 if((obj1 instanceof Integer ) && (obj2 instanceof Long )) 261 { 262 if( ((Integer )obj1).intValue() < ((Long )obj2).intValue() ) 263 return true; 264 else 265 return false; 266 } 267 268 if((obj1 instanceof Long ) && (obj2 instanceof Integer )) 269 { 270 if( ((Long )obj1).intValue() < ((Integer )obj2).intValue() ) 271 return true; 272 else 273 return false; 274 } 275 276 ret = ((Comparable )obj1).compareTo(obj2); 277 278 if(ret < 0) 279 return true; 280 else 281 return false; 282 283 case Query.EQ: 284 285 if((obj1 instanceof Integer ) && (obj2 instanceof Long )) 286 { 287 if( ((Integer )obj1).intValue() == ((Long )obj2).intValue() ) 288 return true; 289 else 290 return false; 291 } 292 293 if((obj1 instanceof Long ) && (obj2 instanceof Integer )) 294 { 295 if( ((Long )obj1).intValue() == ((Integer )obj2).intValue() ) 296 return true; 297 else 298 return false; 299 } 300 301 ret = ((Comparable )obj1).compareTo(obj2); 302 303 if(ret == 0) 304 return true; 305 else 306 return false; 307 308 case Query.BET: 309 ret = ((Comparable )obj1).compareTo(obj2); 310 311 int ret2 = ((Comparable )obj1).compareTo(obj3); 312 313 if(ret >= 0 && ret2 <= 0) 314 return true; 315 else 316 return false; 317 318 case Query.MATCH: 319 320 int length = str2.length(); 321 StringBuffer buff = new StringBuffer (); 322 for(int i=0;i<length;i++) 323 { 324 char ch = str2.charAt(i) ; 325 326 buff.append(ch); 327 } 328 329 str2 = buff.toString(); 330 331 return JmxUtilities.checkPattern(str1, str2, true); 332 333 case Query.IN: 334 for(int i=0;i<list.length;i++) 335 { 336 v2 = list[i]; 337 v2.apply(object); 338 str2 = v2.toString(); 339 if(v2 instanceof StringValueExp ) 340 obj2 = ((StringValueExp )v2).getObject(); 341 else if(v2 instanceof AttributeValueExp ) 342 obj2 = ((AttributeValueExp )v2).getObject(); 343 344 ret = ((Comparable )obj1).compareTo(obj2); 345 346 if(ret == 0) 347 return true; 348 } 349 return false; 350 351 case Query.INITIAL: 352 return str1.startsWith(str2); 353 354 case Query.ANY: 355 356 if(str1.indexOf(str2) != -1) 357 return true; 358 return false; 359 360 case Query.FINAL: 361 362 return str1.endsWith(str2); 363 364 default: 365 366 } 367 } 368 else if(queryFlag) 369 { 370 boolean f1 = false; 371 boolean f2 = false; 372 373 switch(type) 374 { 375 case Query.AND: 376 377 f1 = q1.apply(object); 378 f2 = q2.apply(object); 379 380 381 return f1 && f2; 382 case Query.OR: 384 f1 = q1.apply(object); 385 f2 = q2.apply(object); 386 387 return f1 || f2; 388 389 case Query.NOT: 390 f1 = q1.apply(object); 391 392 return !f1; 393 394 default: 395 396 } 397 } 398 399 return false; 400 } 401 402 407 public void setMBeanServer(MBeanServer server) 408 { 409 this.server = server; 410 if(v1 != null) 411 v1.setMBeanServer(server); 412 if(v2 != null) 413 v2.setMBeanServer(server); 414 if(v3 != null) 415 v3.setMBeanServer(server); 416 417 if(q1 != null) 418 q1.setMBeanServer(server); 419 if(q2 != null) 420 q2.setMBeanServer(server); 421 } 422 423 public boolean isQueryFlag() 424 { 425 return queryFlag; 426 } 427 428 public boolean isValueFlag() 429 { 430 return valueFlag; 431 } 432 433 public int getType() 434 { 435 return type; 436 } 437 438 public QueryExp getQueryExp1() 439 { 440 return q1; 441 } 442 443 public QueryExp getQueryExp2() 444 { 445 return q2; 446 } 447 448 public ValueExp getValueExp1() 449 { 450 return v1; 451 } 452 453 public ValueExp getValueExp2() 454 { 455 return v2; 456 } 457 458 public ValueExp getValueExp3() 459 { 460 return v3; 461 } 462 463 public ValueExp [] getValueExpArray() 464 { 465 return list; 466 } 467 } | Popular Tags |