1 21 package org.jacorb.collection; 22 23 import org.omg.CosCollection.*; 24 import org.omg.PortableServer.POA ; 25 import org.omg.PortableServer.Servant ; 26 import org.omg.CORBA.Any ; 27 import org.omg.CORBA.AnyHolder ; 28 29 class OrderedCollectionImpl extends CollectionImpl 30 implements OrderedCollectionOperations { 31 32 OrderedCollectionImpl( OperationsOperations ops, POA 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 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 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 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 e ){ 91 e.printStackTrace( System.out ); 92 throw new org.omg.CORBA.INTERNAL (); 93 } 94 } 95 96 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 |