1 package mir.producer.reader;
5 public class ReaderTool {
7 public static void checkValidIdentifier(String anIdentifier) throws ProducerConfigExc {
10 public static String getStringAttributeWithDefault(Map anAttributes, String aKey, String aDefault) {
11 if (anAttributes.containsKey(aKey))
12 return (String) anAttributes.get(aKey);
17 public static void checkIntegerAttribute(Map anAttributes, String aKey) throws ProducerConfigExc {
19 Integer.parseInt((String) anAttributes.get(aKey));
22 throw new ProducerConfigExc("attribute '"+aKey+"' is not an integer" );
26 public static int getIntegerAttributeWithDefault(Map anAttributes, String aKey, int aDefault) throws ProducerConfigExc {
29 if (anAttributes.containsKey(aKey)) {
30 checkIntegerAttribute(anAttributes, aKey);
31 return Integer.parseInt((String) anAttributes.get(aKey));
37 public static void checkAttributes(Map anAttributes, String[] aRequiredAttributes, String[] anOptionalAttributes) throws ProducerConfigExc {
38 checkAttributeSet(anAttributes.keySet(),
39 new HashSet(Arrays.asList(aRequiredAttributes)),
40 new HashSet(Arrays.asList(anOptionalAttributes)));
43 public static void checkAttributeSet(Set aSet, Set aRequiredElements, Set anOptionalElements) throws ProducerConfigExc{
48 Object item = i.next();
50 if (!(aRequiredElements.contains(item) || anOptionalElements.contains(item)))
51 throw new ProducerConfigExc("unknown attribute '" + item + "'" );
54 i = aRequiredElements.iterator();
56 Object item = i.next();
58 if (!(aSet.contains(item)))
59 throw new ProducerConfigExc("missing required attribute '" + item + "'" );