KickJava   Java API By Example, From Geeks To Geeks.

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


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: IteratorModel.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: IteratorModel.java,v 1.4 2004/02/01 05:16:27 christianc Exp $
29  */

30 public abstract class IteratorModel extends AbstractIterativeTemplateModel {
31
32     protected static Logger logger = Logger.getLogger(IteratorModel.class.getName());
33
34     /** data to iterate */
35     /** name of the model */
36     protected String JavaDoc name;
37     protected Iterator _iter;
38
39         /** current element during iteration, might be casted to appropiate class */
40     protected Object JavaDoc _current;
41
42     /** initialize the model
43      * @param name Name of the model
44      * @param iter Iterator to iterate
45      */

46     public IteratorModel(String JavaDoc name, Iterator iter) {
47         _iter = iter;
48         setName(name);
49     }
50
51     public IteratorModel(String JavaDoc name ) {
52         _iter = null;
53         setName(name);
54     }
55
56     /** get the name of the model
57      * @return name of the model
58      */

59     public String JavaDoc getName() {
60         return name;
61     }
62
63      public void setIterator(Iterator iter) {
64         _iter = iter;
65      }
66
67     /** set the name of the model
68      * @param name name of the model
69      */

70     public void setName(String JavaDoc name) {
71         this.name = name;
72     }
73
74     /**
75      *
76      */

77     public boolean hasNext() {
78         return _iter.hasNext();
79     }
80
81     /** empty implementation, does nothing. Only reason for being here is to fully
82      * implement IterativeModel.
83      */

84     public void loadNext() {
85         _current = _iter.next();
86     }
87
88 }
89
Popular Tags