1 package org.objectweb.celtix.tools.common.toolspec.parser; 2 3 import java.util.Collection ; 4 import java.util.HashSet ; 5 import java.util.Iterator ; 6 import java.util.Set ; 7 import java.util.logging.Level ; 8 import java.util.logging.Logger ; 9 10 import org.objectweb.celtix.common.logging.LogUtils; 11 12 13 public class ErrorVisitor { 14 public static final long serialVersionUID = 1L; 15 16 private static final Logger LOG = LogUtils.getL7dLogger(ErrorVisitor.class); 17 18 private final Set <Object > errors = new HashSet <Object >(); 19 20 public static class MissingOption implements CommandLineError { 21 private final Option o; 22 23 public MissingOption(Option op) { 24 this.o = op; 25 } 26 27 public String toString() { 28 return "Missing option: " + o.getPrimarySwitch(); 29 } 30 31 public Option getOption() { 32 return o; 33 } 34 35 public String getOptionSwitch() { 36 return o.getPrimarySwitch(); 37 } 38 } 39 40 public static class DuplicateOption implements CommandLineError { 41 private final String option; 42 43 public DuplicateOption(String opt) { 44 option = opt; 45 } 46 47 public String toString() { 48 return "Duplicated option: " + option; 49 } 50 51 public String getOptionSwitch() { 52 return option; 53 } 54 } 55 56 public static class DuplicateArgument implements CommandLineError { 57 private final String argument; 58 59 public DuplicateArgument(String arg) { 60 this.argument = arg; 61 } 62 63 public String toString() { 64 return "Duplicated argument: " + argument; 65 } 66 67 public String getOptionSwitch() { 68 return argument; 69 } 70 } 71 72 public static class UnexpectedOption implements CommandLineError { 73 private final String option; 74 75 public UnexpectedOption(String opt) { 76 this.option = opt; 77 } 78 79 public String toString() { 80 return "Unexpected option: " + option; 81 } 82 83 public String getOptionSwitch() { 84 return option; 85 } 86 } 87 88 public static class UnexpectedArgument implements CommandLineError { 89 private final String arg; 90 91 public UnexpectedArgument(String a) { 92 this.arg = a; 93 } 94 95 public String toString() { 96 return "Unexpected argument: " + arg; 97 } 98 99 public String getArgument() { 100 return arg; 101 } 102 } 103 104 public static class InvalidOption implements CommandLineError { 105 private final String option; 106 107 public InvalidOption(String opt) { 108 this.option = opt; 109 } 110 111 public String toString() { 112 return "Invalid option: " + option + " is missing its associated argument"; 113 } 114 115 public String getOptionSwitch() { 116 return option; 117 } 118 } 119 120 public static class MissingArgument implements CommandLineError { 121 private final String arg; 122 123 public MissingArgument(String a) { 124 this.arg = a; 125 } 126 127 public String toString() { 128 return "Missing argument: " + arg; 129 } 130 131 public String getArgument() { 132 return arg; 133 } 134 } 135 136 public static class UserError implements CommandLineError { 137 private final String msg; 138 139 public UserError(String m) { 140 this.msg = m; 141 } 142 143 public String toString() { 144 return msg; 145 } 146 147 public String getMessage() { 148 return msg; 149 } 150 } 151 152 public Collection getErrors() { 153 return errors; 154 } 155 156 public void add(CommandLineError err) { 157 if (LOG.isLoggable(Level.INFO)) { 158 LOG.info("Adding error: " + err); 159 } 160 errors.add(err); 161 } 162 163 public String toString() { 164 StringBuffer res = new StringBuffer (); 165 166 for (Iterator it = errors.iterator(); it.hasNext();) { 167 res.append(it.next().toString()).append(System.getProperty("line.separator")); 168 } 169 return res.toString(); 170 } 171 172 } 173 | Popular Tags |