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