KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > contrib > sam > models > IterativeMapModel


1 /*
2  * Copyright (C) 2003 Stefan Armbruster [stefan@armbruster-it.de]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: IterativeMapModel.java,v 1.4 2004/02/01 05:16:27 christianc Exp $
19  */

20 package org.enhydra.barracuda.contrib.sam.models;
21
22 import org.enhydra.barracuda.core.comp.*;
23 import org.apache.log4j.*;
24 import java.util.*;
25
26 /** iterates over a Map, uses the special keys "Key" and "Value" for returning key-value-pairs
27  * @author Stefan Armbruster
28  * @version $Id: IterativeMapModel.java,v 1.4 2004/02/01 05:16:27 christianc Exp $
29  */

30 public class IterativeMapModel extends IteratorModel {
31
32     protected static Logger logger = Logger.getLogger(IterativeMapModel.class.getName());
33
34     protected Map map;
35
36     /** initialize the model
37      * @param name Name of the model
38      * @param map Map to iterate
39      */

40     public IterativeMapModel(String JavaDoc name, Map map) {
41         super(name, map.entrySet().iterator());
42         this.map = map;
43     }
44
45     public IterativeMapModel(String JavaDoc name) {
46         super(name);
47     }
48
49     public Object JavaDoc getItem(String JavaDoc key) {
50
51         Map.Entry entry = (Map.Entry)_current;
52         logger.debug("trying to get key " + key + " from " + map);
53         if (key.equals("Key")) {
54             return entry.getKey();
55         } else if (key.equals("Value")) {
56             return entry.getValue();
57         } else {
58             //return super.getItem(key);
59
return map.get(key);
60         }
61     }
62     }
63
64
Popular Tags