KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > ior > IORTemplateListImpl


1 /*
2  * @(#)IORTemplateListImpl.java 1.8 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.ior;
9
10 import java.util.ArrayList JavaDoc ;
11 import java.util.Iterator JavaDoc ;
12
13 import org.omg.CORBA_2_3.portable.InputStream JavaDoc ;
14 import org.omg.CORBA_2_3.portable.OutputStream JavaDoc ;
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     /* This class must override add( int, Object ) and set( int, Object )
29      * so that adding an IORTemplateList to an IORTemplateList just results
30      * in a list of TaggedProfileTemplates.
31      */

32     public Object JavaDoc set( int index, Object JavaDoc element )
33     {
34     if (element instanceof IORTemplate) {
35         return super.set( index, element ) ;
36     } else if (element instanceof IORTemplateList) {
37         Object JavaDoc result = remove( index ) ;
38         add( index, element ) ;
39         return result ;
40     } else
41         throw new IllegalArgumentException JavaDoc() ;
42     }
43
44     public void add( int index, Object JavaDoc 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 JavaDoc() ;
53     }
54
55     public IORTemplateListImpl()
56     {
57     super( new ArrayList JavaDoc() ) ;
58     }
59
60     public IORTemplateListImpl( InputStream JavaDoc 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 JavaDoc os )
79     {
80     os.write_long( size() ) ;
81     Iterator JavaDoc 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 JavaDoc 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 JavaDoc thisIterator = iterator() ;
101     Iterator JavaDoc 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