KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > bridge > implementation > BasicRelationList


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10
11 package org.mmbase.bridge.implementation;
12
13 import java.util.Collection JavaDoc;
14 import org.mmbase.bridge.*;
15 import org.mmbase.module.core.*;
16
17 /**
18  * A list of relations
19  *
20  * @author Pierre van Rooden
21  * @version $Id: BasicRelationList.java,v 1.21 2006/06/13 19:08:31 michiel Exp $
22  */

23 public class BasicRelationList extends BasicNodeList implements RelationList {
24
25     BasicRelationList() {
26         super();
27     }
28
29     BasicRelationList(Collection JavaDoc c, Cloud cloud) {
30         super(c, cloud);
31     }
32
33     BasicRelationList(Collection JavaDoc c, NodeManager nodemanager) {
34         super(c, nodemanager);
35     }
36
37     protected Object JavaDoc validate(Object JavaDoc o) throws ClassCastException JavaDoc,IllegalArgumentException JavaDoc {
38         if (o instanceof MMObjectNode) {
39             if (((MMObjectNode) o).getBuilder() instanceof org.mmbase.module.corebuilders.InsRel) {
40                 return o;
41             } else {
42                 throw new IllegalArgumentException JavaDoc("Requires a relation node, but builder of " + o + " is " + ((MMObjectNode) o).getBuilder());
43             }
44         } else {
45             if (! (o instanceof Relation)) throw new ClassCastException JavaDoc("" + o + " is not a Relation, but a " + o.getClass());
46             return o;
47         }
48     }
49
50     /**
51      *
52      */

53     public Relation getRelation(int index) {
54         return (Relation)get(index);
55     }
56
57     /**
58      *
59      */

60     public RelationList subRelationList(int fromIndex, int toIndex) {
61         if (nodeManager != null) {
62             return new BasicRelationList(subList(fromIndex, toIndex), nodeManager);
63         } else {
64             return new BasicRelationList(subList(fromIndex, toIndex), cloud);
65         }
66     }
67
68     /**
69      *
70      */

71     public RelationIterator relationIterator() {
72         return new BasicRelationIterator();
73     }
74
75     protected class BasicRelationIterator extends BasicNodeIterator implements RelationIterator {
76
77         public Relation nextRelation() {
78             return (Relation)next();
79         }
80
81         public Relation previousRelation() {
82             return (Relation)previous();
83         }
84     }
85 }
86
Popular Tags