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.jacorb.collection.util.*;
025: import org.omg.PortableServer.POA;
026: import org.omg.PortableServer.Servant;
027: import org.omg.CORBA.Any;
028: import org.omg.CORBA.AnyHolder;
029:
030: class SequentialCollectionImpl extends OrderedCollectionImpl implements
031: SequentialCollectionOperations {
032: /* ========================================================================= */
033: SequentialCollectionImpl(OperationsOperations ops, POA poa,
034: IteratorFactory iterator_factory) {
035: super (ops, poa, iterator_factory);
036: }
037:
038: /* ========================================================================= */
039: public synchronized void add_element_as_first(Any element)
040: throws ElementInvalid {
041: try {
042: add_element_at_position(0, element);
043: } catch (PositionInvalid e) {
044: throw new ElementInvalid(
045: ElementInvalidReason.positioning_property_invalid);
046: }
047: }
048:
049: /* ------------------------------------------------------------------------- */
050: public synchronized void add_element_as_first_set_iterator(
051: Any element, Iterator where) throws ElementInvalid,
052: IteratorInvalid {
053: PositionalIteratorImpl i = check_iterator(where);
054: add_element_as_first(element);
055: i.set_pos(0);
056: i.set_in_between(false);
057: }
058:
059: /* ------------------------------------------------------------------------- */
060: public synchronized void add_element_as_last(Any element)
061: throws ElementInvalid {
062: int pos = data.size();
063: try {
064: add_element_at_position(pos, element);
065: } catch (PositionInvalid e) {
066: throw new ElementInvalid(
067: ElementInvalidReason.positioning_property_invalid);
068: }
069: }
070:
071: /* ------------------------------------------------------------------------- */
072: public synchronized void add_element_as_last_set_iterator(
073: Any element, Iterator where) throws ElementInvalid,
074: IteratorInvalid {
075: PositionalIteratorImpl i = check_iterator(where);
076: add_element_as_last(element);
077: i.set_pos(data.size() - 1);
078: i.set_in_between(false);
079: }
080:
081: /* ------------------------------------------------------------------------- */
082: public synchronized void add_element_as_next(Any element,
083: Iterator where) throws ElementInvalid, IteratorInvalid {
084: PositionalIteratorImpl i = check_iterator(where);
085: int pos = i.get_pos();
086: try {
087: add_element_at_position(pos + 1, element);
088: } catch (PositionInvalid e) {
089: throw new ElementInvalid(
090: ElementInvalidReason.positioning_property_invalid);
091: }
092: }
093:
094: /* ------------------------------------------------------------------------- */
095: public synchronized void add_element_as_previous(Any element,
096: Iterator where) throws ElementInvalid, IteratorInvalid {
097: PositionalIteratorImpl i = check_iterator(where);
098: int pos = i.get_pos();
099: try {
100: add_element_at_position(pos, element);
101: } catch (PositionInvalid e) {
102: throw new ElementInvalid(
103: ElementInvalidReason.positioning_property_invalid);
104: }
105: }
106:
107: /* ------------------------------------------------------------------------- */
108: public synchronized void add_element_at_position(int position,
109: Any element) throws PositionInvalid, ElementInvalid {
110: check_element(element);
111: try {
112: if (data.insertElementAt(element, position)) {
113: element_inserted(position);
114: } else {
115: throw new ElementInvalid(
116: ElementInvalidReason.positioning_property_invalid);
117: }
118: } catch (ObjectInvalid e) {
119: throw new ElementInvalid(
120: ElementInvalidReason.element_type_invalid);
121: }
122: }
123:
124: /* ------------------------------------------------------------------------- */
125: public synchronized void add_element_at_position_set_iterator(
126: int position, Any element, Iterator where)
127: throws PositionInvalid, ElementInvalid, IteratorInvalid {
128: PositionalIteratorImpl i = check_iterator(where);
129: add_element_at_position(position, element);
130: i.set_pos(position);
131: i.set_in_between(false);
132: }
133:
134: /* ------------------------------------------------------------------------- */
135: public synchronized void replace_element_at_position(int position,
136: Any element) throws PositionInvalid, ElementInvalid {
137: element_replace(position, element);
138: }
139:
140: /* ------------------------------------------------------------------------- */
141: public synchronized void replace_first_element(Any element)
142: throws ElementInvalid, EmptyCollection {
143: try {
144: replace_element_at_position(0, element);
145: } catch (PositionInvalid e) {
146: throw new ElementInvalid(
147: ElementInvalidReason.positioning_property_invalid);
148: }
149: }
150:
151: /* ------------------------------------------------------------------------- */
152: public synchronized void replace_last_element(Any element)
153: throws ElementInvalid, EmptyCollection {
154: if (data.size() == 0) {
155: throw new EmptyCollection();
156: }
157: try {
158: replace_element_at_position(data.size() - 1, element);
159: } catch (PositionInvalid e) {
160: throw new ElementInvalid(
161: ElementInvalidReason.positioning_property_invalid);
162: }
163: }
164:
165: /* ------------------------------------------------------------------------- */
166: public synchronized void sort(Comparator comparison) {
167: throw new org.omg.CORBA.NO_IMPLEMENT();
168: }
169:
170: /* ------------------------------------------------------------------------- */
171: public synchronized void reverse() {
172: throw new org.omg.CORBA.NO_IMPLEMENT();
173: }
174:
175: }
|