1 7 8 package com.sun.corba.se.impl.ior; 9 10 import java.util.ArrayList ; 11 import java.util.Iterator ; 12 13 import org.omg.CORBA_2_3.portable.InputStream ; 14 import org.omg.CORBA_2_3.portable.OutputStream ; 15 16 import com.sun.corba.se.spi.ior.IORTemplate ; 17 import com.sun.corba.se.spi.ior.IORTemplateList ; 18 import com.sun.corba.se.spi.ior.ObjectId ; 19 import com.sun.corba.se.spi.ior.IORTemplate ; 20 import com.sun.corba.se.spi.ior.IOR ; 21 import com.sun.corba.se.spi.ior.IORFactory ; 22 import com.sun.corba.se.spi.ior.IORFactories ; 23 24 import com.sun.corba.se.spi.orb.ORB ; 25 26 public class IORTemplateListImpl extends FreezableList implements IORTemplateList 27 { 28 32 public Object set( int index, Object element ) 33 { 34 if (element instanceof IORTemplate) { 35 return super.set( index, element ) ; 36 } else if (element instanceof IORTemplateList) { 37 Object result = remove( index ) ; 38 add( index, element ) ; 39 return result ; 40 } else 41 throw new IllegalArgumentException () ; 42 } 43 44 public void add( int index, Object element ) 45 { 46 if (element instanceof IORTemplate) { 47 super.add( index, element ) ; 48 } else if (element instanceof IORTemplateList) { 49 IORTemplateList tl = (IORTemplateList)element ; 50 addAll( index, tl ) ; 51 } else 52 throw new IllegalArgumentException () ; 53 } 54 55 public IORTemplateListImpl() 56 { 57 super( new ArrayList () ) ; 58 } 59 60 public IORTemplateListImpl( InputStream is ) 61 { 62 this() ; 63 int size = is.read_long() ; 64 for (int ctr=0; ctr<size; ctr++) { 65 IORTemplate iortemp = IORFactories.makeIORTemplate( is ) ; 66 add( iortemp ) ; 67 } 68 69 makeImmutable() ; 70 } 71 72 public void makeImmutable() 73 { 74 makeElementsImmutable() ; 75 super.makeImmutable() ; 76 } 77 78 public void write( OutputStream os ) 79 { 80 os.write_long( size() ) ; 81 Iterator iter = iterator() ; 82 while (iter.hasNext()) { 83 IORTemplate iortemp = (IORTemplate)(iter.next()) ; 84 iortemp.write( os ) ; 85 } 86 } 87 88 public IOR makeIOR( ORB orb, String typeid, ObjectId oid ) 89 { 90 return new IORImpl( orb, typeid, this, oid ) ; 91 } 92 93 public boolean isEquivalent( IORFactory other ) 94 { 95 if (!(other instanceof IORTemplateList)) 96 return false ; 97 98 IORTemplateList list = (IORTemplateList)other ; 99 100 Iterator thisIterator = iterator() ; 101 Iterator listIterator = list.iterator() ; 102 while (thisIterator.hasNext() && listIterator.hasNext()) { 103 IORTemplate thisTemplate = (IORTemplate)thisIterator.next() ; 104 IORTemplate listTemplate = (IORTemplate)listIterator.next() ; 105 if (!thisTemplate.isEquivalent( listTemplate )) 106 return false ; 107 } 108 109 return thisIterator.hasNext() == listIterator.hasNext() ; 110 } 111 } 112 | Popular Tags |