001: /*
002: * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.corba.se.impl.ior;
027:
028: import java.util.ArrayList;
029: import java.util.Iterator;
030:
031: import org.omg.CORBA_2_3.portable.InputStream;
032: import org.omg.CORBA_2_3.portable.OutputStream;
033:
034: import com.sun.corba.se.spi.ior.IORTemplate;
035: import com.sun.corba.se.spi.ior.IORTemplateList;
036: import com.sun.corba.se.spi.ior.ObjectId;
037: import com.sun.corba.se.spi.ior.IORTemplate;
038: import com.sun.corba.se.spi.ior.IOR;
039: import com.sun.corba.se.spi.ior.IORFactory;
040: import com.sun.corba.se.spi.ior.IORFactories;
041:
042: import com.sun.corba.se.spi.orb.ORB;
043:
044: public class IORTemplateListImpl extends FreezableList implements
045: IORTemplateList {
046: /* This class must override add( int, Object ) and set( int, Object )
047: * so that adding an IORTemplateList to an IORTemplateList just results
048: * in a list of TaggedProfileTemplates.
049: */
050: public Object set(int index, Object element) {
051: if (element instanceof IORTemplate) {
052: return super .set(index, element);
053: } else if (element instanceof IORTemplateList) {
054: Object result = remove(index);
055: add(index, element);
056: return result;
057: } else
058: throw new IllegalArgumentException();
059: }
060:
061: public void add(int index, Object element) {
062: if (element instanceof IORTemplate) {
063: super .add(index, element);
064: } else if (element instanceof IORTemplateList) {
065: IORTemplateList tl = (IORTemplateList) element;
066: addAll(index, tl);
067: } else
068: throw new IllegalArgumentException();
069: }
070:
071: public IORTemplateListImpl() {
072: super (new ArrayList());
073: }
074:
075: public IORTemplateListImpl(InputStream is) {
076: this ();
077: int size = is.read_long();
078: for (int ctr = 0; ctr < size; ctr++) {
079: IORTemplate iortemp = IORFactories.makeIORTemplate(is);
080: add(iortemp);
081: }
082:
083: makeImmutable();
084: }
085:
086: public void makeImmutable() {
087: makeElementsImmutable();
088: super .makeImmutable();
089: }
090:
091: public void write(OutputStream os) {
092: os.write_long(size());
093: Iterator iter = iterator();
094: while (iter.hasNext()) {
095: IORTemplate iortemp = (IORTemplate) (iter.next());
096: iortemp.write(os);
097: }
098: }
099:
100: public IOR makeIOR(ORB orb, String typeid, ObjectId oid) {
101: return new IORImpl(orb, typeid, this , oid);
102: }
103:
104: public boolean isEquivalent(IORFactory other) {
105: if (!(other instanceof IORTemplateList))
106: return false;
107:
108: IORTemplateList list = (IORTemplateList) other;
109:
110: Iterator this Iterator = iterator();
111: Iterator listIterator = list.iterator();
112: while (this Iterator.hasNext() && listIterator.hasNext()) {
113: IORTemplate this Template = (IORTemplate) this Iterator
114: .next();
115: IORTemplate listTemplate = (IORTemplate) listIterator
116: .next();
117: if (!this Template.isEquivalent(listTemplate))
118: return false;
119: }
120:
121: return thisIterator.hasNext() == listIterator.hasNext();
122: }
123: }
|