001: /*
002: * JacORB - a free Java ORB
003: *
004: * Copyright (C) 1999-2004 Gerald Brose
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Library General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Library General Public License for more details.
015: *
016: * You should have received a copy of the GNU Library General Public
017: * License along with this library; if not, write to the Free
018: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019: *
020: */
021: package org.jacorb.collection;
022:
023: import org.omg.CosCollection.*;
024: import org.omg.PortableServer.POA;
025: import org.omg.PortableServer.Servant;
026: import org.omg.CORBA.Any;
027: import org.omg.CORBA.AnyHolder;
028:
029: class OrderedCollectionImpl extends CollectionImpl implements
030: OrderedCollectionOperations {
031: /* ========================================================================= */
032: OrderedCollectionImpl(OperationsOperations ops, POA poa,
033: IteratorFactory iterator_factory) {
034: super (ops, poa, iterator_factory);
035: }
036:
037: /* ========================================================================= */
038: public synchronized void remove_element_at_position(int position)
039: throws PositionInvalid {
040: try {
041: element_remove(position);
042: } catch (EmptyCollection e) {
043: throw new PositionInvalid();
044: }
045: }
046:
047: /* ------------------------------------------------------------------------- */
048: public synchronized void remove_first_element()
049: throws EmptyCollection {
050: try {
051: remove_element_at_position(0);
052: } catch (PositionInvalid e) {
053: throw new EmptyCollection();
054: }
055: }
056:
057: /* ------------------------------------------------------------------------- */
058: public synchronized void remove_last_element()
059: throws EmptyCollection {
060: int pos = data.size() - 1;
061: try {
062: remove_element_at_position(pos);
063: } catch (PositionInvalid e) {
064: throw new EmptyCollection();
065: }
066: }
067:
068: /* ------------------------------------------------------------------------- */
069: public synchronized boolean retrieve_element_at_position(
070: int position, org.omg.CORBA.AnyHolder element)
071: throws PositionInvalid {
072: element.value = element_retrieve(position);
073: return true;
074: }
075:
076: /* ------------------------------------------------------------------------- */
077: public synchronized boolean retrieve_first_element(
078: org.omg.CORBA.AnyHolder element) throws EmptyCollection {
079: try {
080: return retrieve_element_at_position(0, element);
081: } catch (PositionInvalid e) {
082: throw new EmptyCollection();
083: }
084: }
085:
086: /* ------------------------------------------------------------------------- */
087: public synchronized boolean retrieve_last_element(
088: org.omg.CORBA.AnyHolder element) throws EmptyCollection {
089: int pos = data.size() - 1;
090: try {
091: return retrieve_element_at_position(pos, element);
092: } catch (PositionInvalid e) {
093: throw new EmptyCollection();
094: }
095: }
096:
097: /* ------------------------------------------------------------------------- */
098: public synchronized OrderedIterator create_ordered_iterator(
099: boolean read_only, boolean reverse_iteration) {
100: PositionalIteratorImpl iter = iterator_factory.create_iterator(
101: this , read_only, reverse_iteration);
102: IteratorPOATie servant = new IteratorPOATie(iter);
103: try {
104: OrderedIterator i = OrderedIteratorHelper.narrow(poa
105: .servant_to_reference(servant));
106: iter.set_servant(servant);
107: return i;
108: } catch (Exception e) {
109: e.printStackTrace(System.out);
110: throw new org.omg.CORBA.INTERNAL();
111: }
112: }
113:
114: /* ========================================================================= */
115: /* Overrided */
116: /* ========================================================================= */
117: public synchronized Iterator create_iterator(boolean read_only) {
118: return create_ordered_iterator(read_only, false);
119: }
120:
121: }
|