01: package com.sun.portal.sra.util;
02:
03: import java.util.*;
04:
05: public class AttributeExtractor {
06:
07: public AttributeExtractor() {
08: }
09:
10: public static String getString(Map source, String name,
11: String defaultValue) {
12: Set set = (Set) source.get(name);
13: if (null == set) {
14: return defaultValue;
15: } else {
16: Iterator it = set.iterator();
17: return it.hasNext() ? (String) it.next() : defaultValue;
18: }
19: }
20:
21: public static int getInt(Map source, String name, int defaultValue) {
22: Set set = (Set) source.get(name);
23: if (null == set) {
24: return defaultValue;
25: } else {
26: Iterator it = set.iterator();
27: return it.hasNext() ? Integer.parseInt((String) it.next())
28: : defaultValue;
29: }
30: }
31:
32: public static boolean getBoolean(Map source, String name,
33: boolean defaultValue) {
34: Set set = (Set) source.get(name);
35: if (null == set) {
36: return defaultValue;
37: } else {
38: Iterator it = set.iterator();
39: return it.hasNext() ? (new Boolean((String) it.next()))
40: .booleanValue() : defaultValue;
41: }
42: }
43:
44: public static List getStringList(Map source, String name) {
45: Set set = (Set) source.get(name);
46: if (null == set)
47: return new ArrayList();
48: List ret = new ArrayList(set.size());
49: for (Iterator it = set.iterator(); it.hasNext(); ret
50: .add((String) it.next()))
51: ;
52: return ret;
53: }
54: }
|