KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > collection > OrderedCollectionImpl


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

21 package org.jacorb.collection;
22
23 import org.omg.CosCollection.*;
24 import org.omg.PortableServer.POA JavaDoc;
25 import org.omg.PortableServer.Servant JavaDoc;
26 import org.omg.CORBA.Any JavaDoc;
27 import org.omg.CORBA.AnyHolder JavaDoc;
28
29 class OrderedCollectionImpl extends CollectionImpl
30       implements OrderedCollectionOperations {
31 /* ========================================================================= */
32     OrderedCollectionImpl( OperationsOperations ops, POA JavaDoc poa, IteratorFactory iterator_factory ){
33         super( ops, poa, iterator_factory );
34     }
35 /* ========================================================================= */
36     public synchronized void remove_element_at_position(int position) throws PositionInvalid {
37         try {
38             element_remove( position );
39         } catch ( EmptyCollection e ){
40             throw new PositionInvalid();
41         }
42     }
43 /* ------------------------------------------------------------------------- */
44     public synchronized void remove_first_element() throws EmptyCollection {
45         try {
46             remove_element_at_position(0);
47         } catch ( PositionInvalid e ){
48             throw new EmptyCollection();
49         }
50     }
51 /* ------------------------------------------------------------------------- */
52     public synchronized void remove_last_element() throws EmptyCollection {
53         int pos = data.size()-1;
54         try {
55             remove_element_at_position(pos);
56         } catch ( PositionInvalid e ){
57             throw new EmptyCollection();
58         }
59     }
60 /* ------------------------------------------------------------------------- */
61     public synchronized boolean retrieve_element_at_position(int position, org.omg.CORBA.AnyHolder JavaDoc element) throws PositionInvalid {
62         element.value = element_retrieve( position );
63         return true;
64     }
65 /* ------------------------------------------------------------------------- */
66     public synchronized boolean retrieve_first_element(org.omg.CORBA.AnyHolder JavaDoc element) throws EmptyCollection {
67         try {
68             return retrieve_element_at_position( 0, element );
69         } catch ( PositionInvalid e ){
70             throw new EmptyCollection();
71         }
72     }
73 /* ------------------------------------------------------------------------- */
74     public synchronized boolean retrieve_last_element(org.omg.CORBA.AnyHolder JavaDoc element) throws EmptyCollection {
75         int pos = data.size()-1;
76         try {
77             return retrieve_element_at_position( pos, element );
78         } catch ( PositionInvalid e ){
79             throw new EmptyCollection();
80         }
81     }
82 /* ------------------------------------------------------------------------- */
83     public synchronized OrderedIterator create_ordered_iterator(boolean read_only, boolean reverse_iteration) {
84         PositionalIteratorImpl iter = iterator_factory.create_iterator( this, read_only, reverse_iteration );
85         IteratorPOATie servant = new IteratorPOATie( iter );
86         try {
87             OrderedIterator i = OrderedIteratorHelper.narrow( poa.servant_to_reference( servant ));
88             iter.set_servant( servant );
89             return i;
90         } catch ( Exception JavaDoc e ){
91             e.printStackTrace( System.out );
92             throw new org.omg.CORBA.INTERNAL JavaDoc();
93         }
94     }
95 /* ========================================================================= */
96 /* Overrided */
97 /* ========================================================================= */
98     public synchronized Iterator create_iterator(boolean read_only) {
99         return create_ordered_iterator( read_only, false );
100     }
101
102 }
103
104
105
106
107
108
109
110
111
112
Popular Tags