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 26 /** 27 * Common interface that helps to run "check-processes" (processes that shall 28 * ensure the integrity of the LLRP commander and its folders/files). 29 * @author zhanghao 30 * @author sawielan 31 * 32 */ 33 public abstract class CheckItem { 34 35 public final static int CATEGORY_ERROR = 1; 36 public final static int CATEGORY_FIX = 2; 37 public final static int CATEGORY_WARN = 3; 38 public final static int CATEGORY_INFO = 4; 39 40 private ArrayList<String> report; 41 42 public CheckItem() { 43 report = new ArrayList<String>(); 44 } 45 46 /** 47 * add a specific error report. 48 * @param aItem the error report string. 49 * @param aCategory a category that describes the error. 50 */ 51 public void addReportItem(String aItem, int aCategory) { 52 53 String prefix = ""; 54 55 if (aCategory == CATEGORY_ERROR) { 56 prefix = "[ERROR] "; 57 } else if (aCategory == CATEGORY_FIX) { 58 prefix = "[FIX] "; 59 } else if (aCategory == CATEGORY_WARN) { 60 prefix = "[WARN] "; 61 } else if (aCategory == CATEGORY_INFO) { 62 prefix = "[INFO] "; 63 } 64 65 report.add(prefix + aItem); 66 } 67 68 /** 69 * adds a list of error reports to the current error list. 70 * @param aItemList new errors to add. 71 */ 72 public void addReportItem(ArrayList<String> aItemList) { 73 report.addAll(aItemList); 74 } 75 76 /** 77 * clear out all the reports collected from previous health checks. 78 */ 79 public void clearAllReport() { 80 report.clear(); 81 } 82 83 /** 84 * @return a list of error messages (if the check went wrong) that describe the errors. 85 */ 86 public ArrayList<String> getReport() { 87 return report; 88 } 89 90 /** 91 * @return true if the check went ok, false otherwise. 92 */ 93 public abstract boolean validate(); 94 95 /** 96 * invoke the repair functionality on the repair item. 97 */ 98 public abstract void fix(); 99 100 101 }