KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > naming > BindingIteratorImpl


1 package org.jacorb.naming;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2004 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 /**
24  * Implementation of the "BindingIterator" interface
25  * @author Gerald Brose
26  * @version $Id: BindingIteratorImpl.java,v 1.7 2004/05/06 12:39:59 nicolas Exp $
27  */

28
29 import org.omg.CosNaming.*;
30
31 public class BindingIteratorImpl
32     extends org.omg.CosNaming.BindingIteratorPOA JavaDoc
33 {
34     Binding [] bindings;
35     int iterator_pos = 0;
36
37     public BindingIteratorImpl( Binding [] b )
38     {
39     bindings = b;
40     if( b.length > 0 )
41         iterator_pos = 0;
42     }
43
44     public void destroy()
45     {
46     bindings = null;
47     try
48     {
49         finalize();
50     } catch ( Throwable JavaDoc t ){}
51     }
52
53     public boolean next_n(int how_many,
54               org.omg.CosNaming.BindingListHolder JavaDoc bl)
55     {
56     int diff = bindings.length - iterator_pos;
57     if( diff > 0 )
58     {
59         Binding [] bndgs = null;
60         if( how_many <= diff )
61         {
62         bndgs = new Binding[how_many];
63         System.arraycopy(bindings, iterator_pos, bndgs, 0, how_many);
64         iterator_pos += how_many;
65         }
66         else
67         {
68         bndgs = new Binding[diff];
69         System.arraycopy(bindings, iterator_pos, bndgs, 0, diff);
70         iterator_pos = bindings.length;
71         }
72         bl.value = bndgs;
73         return true;
74     }
75     else
76     {
77         bl.value = new org.omg.CosNaming.Binding JavaDoc[0];
78         return false;
79     }
80     }
81
82     public boolean next_one(org.omg.CosNaming.BindingHolder JavaDoc b)
83     {
84     if( iterator_pos < bindings.length )
85     {
86         b.value = bindings[iterator_pos++];
87         return true;
88     }
89     else
90     {
91         b.value = new Binding(new org.omg.CosNaming.NameComponent JavaDoc[0],
92                   org.omg.CosNaming.BindingType.nobject);
93         return false;
94     }
95     }
96 }
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
Popular Tags