1 /* 2 * 3 * Fosstrak LLRP Commander (www.fosstrak.org) 4 * 5 * Copyright (C) 2008 ETH Zurich 6 * 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/> 19 * 20 */ 21 22 package org.fosstrak.llrp.commander.check; 23 24 import java.util.ArrayList; 25 import java.util.Iterator; 26 27 /** 28 * This HealthCheck maintain a chain of <code>CheckItem</code>. 29 * when the PlugIn start up, it is triggered by validate each <code>CheckItem</code> 30 * in the chain. If any of them failed validation, the specific fix function 31 * will be called. 32 * 33 * @author Haoning Zhang 34 * @version 1.0 35 */ 36 public class HealthCheck extends CheckItem { 37 38 private ArrayList<CheckItem> checkList; 39 40 /** 41 * Default Constructor. 42 */ 43 public HealthCheck() { 44 checkList = new ArrayList<CheckItem>(); 45 } 46 47 /** 48 * Register new check items 49 * @param aItem New Check Item 50 */ 51 public void registerCheckItem(CheckItem aItem) { 52 checkList.add(aItem); 53 } 54 55 /** 56 * Validate each check item in the chain. 57 */ 58 public boolean validate() { 59 60 boolean isHealth = true; 61 this.clearAllReport(); 62 63 Iterator<CheckItem> i = checkList.iterator(); 64 while (i.hasNext()) { 65 CheckItem item = i.next(); 66 isHealth = isHealth && item.validate(); 67 this.addReportItem(item.getReport()); 68 } 69 70 return isHealth; 71 } 72 73 /** 74 * Execute <code>fix</code> function of each check item in the chain 75 */ 76 public void fix() { 77 78 this.clearAllReport(); 79 80 Iterator<CheckItem> i = checkList.iterator(); 81 while (i.hasNext()) { 82 CheckItem item = i.next(); 83 if (!item.validate()) { 84 item.fix(); 85 this.addReportItem(item.getReport()); 86 } 87 } 88 } 89 }