KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > ir > gui > typesystem > remote > IRInterface


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21 package org.jacorb.ir.gui.typesystem.remote;
22
23 /**
24  *
25  */

26
27 import org.jacorb.ir.gui.typesystem.*;
28 import java.util.*;
29 import org.omg.CORBA.*;
30 import javax.swing.tree.*;
31  
32 public class IRInterface
33     extends IRContainer
34     implements org.jacorb.ir.gui.typesystem.Interface
35 {
36     private IRInterface[] superInterfaces = null;
37     private IRAttribute[] allFields = null;
38     private IROperation[] allOperations = null;
39
40     /**
41      * Default-Konstruktor: wird von TypeSystem.createNode(...) benutzt
42      */

43     public IRInterface ( ) {
44     super();
45     }
46
47     /**
48      * This method was created by a SmartGuide.
49      * @param irObject org.omg.CORBA.IRObject
50      */

51     public IRInterface ( IRObject irObject) {
52     super(irObject);
53     }
54
55     /**
56      * This method was created by a SmartGuide.
57      * @return java.lang.String[]
58      */

59     public String JavaDoc[] allowedToAdd() {
60     String JavaDoc[] result = { IRAttribute.nodeTypeName(),
61                                 IROperation.nodeTypeName(),
62                                 IRConstant.nodeTypeName(),
63                                 IRTypedef.nodeTypeName(),
64                                 IRException.nodeTypeName()};
65     return result;
66     }
67
68     /**
69      * @return java.lang.String
70      */

71
72     public String JavaDoc description()
73     {
74     String JavaDoc result = super.description();
75     Interface[] superinterfaces = getSuperInterfaces();
76
77     if (superinterfaces.length>0)
78         {
79             result = result + "\nSuper-Interfaces:\t ";
80             for (int i = 0; i<superinterfaces.length; i++)
81             {
82                 result = result + ((TypeSystemNode)superinterfaces[i]).getAbsoluteName();
83                 if (!(i==superinterfaces.length-1))
84                 {
85                     result = result + ", ";
86                 }
87             }
88     }
89     else
90         {
91             result = result + "\nSuper-Interfaces:\t:none";
92     }
93     return result;
94     }
95
96     /**
97      * Gibt alle Fields inkl. der Fields der Super-Interfaces zurück
98      * @return org.jacorb.ir.gui.typesystem.TypeSystemNode[]
99      */

100
101     public TypeSystemNode[] getAllFields()
102     {
103         if (this.allFields==null)
104         {
105             Vector fields = new Vector();
106             // erstmal die Fields der superInterfaces sammeln
107
Interface[] superInterfaces = this.getSuperInterfaces();
108             for (int i=0; i<superInterfaces.length; i++)
109             {
110                 TypeSystemNode[] nextFields = superInterfaces[i].getAllFields();
111                 for (int n=0; n<nextFields.length; n++) {
112                     fields.addElement(nextFields[n]);
113                 }
114             }
115             // dann unsere eigenen Fields (also die Attributes des Interfaces)
116
ModelParticipant[] contents = this.contents();
117
118             for (int i=0; i<contents.length; i++)
119             {
120                 if (contents[i] instanceof IRAttribute) {
121                     fields.addElement(contents[i]);
122                 }
123             }
124
125             this.allFields = new IRAttribute[fields.size()];
126             int i = 0;
127             for (Enumeration e = fields.elements(); e.hasMoreElements(); )
128             {
129                 allFields[i] = (IRAttribute)e.nextElement();
130                 i++;
131             }
132     } // if (allFields==null)
133
return allFields;
134     }
135
136     /**
137      * Gibt alle Fields inkl. der Fields der Super-Interfaces zurück
138      * @return org.jacorb.ir.gui.typesystem.TypeSystemNode[]
139      */

140
141     public TypeSystemNode[] getAllOperations()
142     {
143     if (this.allOperations==null)
144         {
145             Vector operations = new Vector();
146             // erstmal die Operationen der superInterfaces sammeln
147
Interface[] superInterfaces = this.getSuperInterfaces();
148             for (int i=0; i<superInterfaces.length; i++)
149             {
150                 TypeSystemNode[] nextOperations = superInterfaces[i].getAllOperations();
151                 for (int n=0; n<nextOperations.length; n++)
152                 {
153                     operations.addElement(nextOperations[n]);
154                 }
155             }
156
157             // dann unsere eigenen Operationen
158

159             ModelParticipant[] contents = this.contents();
160             for (int i=0; i<contents.length; i++)
161             {
162                 if (contents[i] instanceof IROperation)
163                 {
164                     operations.addElement(contents[i]);
165                 }
166             }
167     
168             this.allOperations = new IROperation[operations.size()];
169             int i = 0;
170             for (Enumeration e = operations.elements(); e.hasMoreElements(); )
171             {
172                 allOperations[i] = (IROperation)e.nextElement();
173                 i++;
174             }
175     } // if (allOperations==null)
176
return allOperations;
177     }
178
179     /**
180      * This method was created by a SmartGuide.
181      * @return org.jacorb.ir.gui.typesystem.Interface[]
182      */

183
184     public Interface[] getSuperInterfaces()
185     {
186     if (superInterfaces==null)
187         {
188             // superInterfaces in unserem dazugehörigen Field speichern
189
InterfaceDef interfaceDef = InterfaceDefHelper.narrow((org.omg.CORBA.Object JavaDoc)irObject);
190             InterfaceDef[] baseInterfaces = interfaceDef.base_interfaces(); // base interfaces aus IR holen
191
this.superInterfaces = new IRInterface[baseInterfaces.length];
192             for (int i=0; i<baseInterfaces.length; i++)
193             {
194                 // für alle base interfaces die zugehörige TypeSystemNode holen
195
IRInterface superInterface = (IRInterface)RemoteTypeSystem.createTypeSystemNode(baseInterfaces[i]);
196                 this.superInterfaces[i] = superInterface;
197             }
198     }
199     return superInterfaces;
200     }
201
202     /**
203      * @return java.lang.String
204      */

205
206     public static String JavaDoc nodeTypeName()
207     {
208     return "interface";
209     }
210
211     /**
212      * @param irObject org.omg.CORBA.IRObject
213      */

214
215     protected void setIRObject(org.omg.CORBA.IRObject JavaDoc irObject)
216     {
217     super.setIRObject(irObject);
218     }
219 }
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
Popular Tags