01: package org.jacorb.naming;
02:
03: /*
04: * JacORB - a free Java ORB
05: *
06: * Copyright (C) 1997-2004 Gerald Brose.
07: *
08: * This library is free software; you can redistribute it and/or
09: * 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 extends
32: org.omg.CosNaming.BindingIteratorPOA {
33: Binding[] bindings;
34: int iterator_pos = 0;
35:
36: public BindingIteratorImpl(Binding[] b) {
37: bindings = b;
38: if (b.length > 0)
39: iterator_pos = 0;
40: }
41:
42: public void destroy() {
43: bindings = null;
44: try {
45: finalize();
46: } catch (Throwable t) {
47: }
48: }
49:
50: public boolean next_n(int how_many,
51: org.omg.CosNaming.BindingListHolder bl) {
52: int diff = bindings.length - iterator_pos;
53: if (diff > 0) {
54: Binding[] bndgs = null;
55: if (how_many <= diff) {
56: bndgs = new Binding[how_many];
57: System.arraycopy(bindings, iterator_pos, bndgs, 0,
58: how_many);
59: iterator_pos += how_many;
60: } else {
61: bndgs = new Binding[diff];
62: System
63: .arraycopy(bindings, iterator_pos, bndgs, 0,
64: diff);
65: iterator_pos = bindings.length;
66: }
67: bl.value = bndgs;
68: return true;
69: } else {
70: bl.value = new org.omg.CosNaming.Binding[0];
71: return false;
72: }
73: }
74:
75: public boolean next_one(org.omg.CosNaming.BindingHolder b) {
76: if (iterator_pos < bindings.length) {
77: b.value = bindings[iterator_pos++];
78: return true;
79: } else {
80: b.value = new Binding(
81: new org.omg.CosNaming.NameComponent[0],
82: org.omg.CosNaming.BindingType.nobject);
83: return false;
84: }
85: }
86: }
|