KickJava   Java API By Example, From Geeks To Geeks.

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


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 // TODO Initializers:
24
// Currently initializers are completely ignored.
25
// You cannot see them, even if defined in the IR.
26

27 /**
28  *
29  */

30
31 import org.jacorb.ir.gui.typesystem.*;
32 import java.util.*;
33 import org.omg.CORBA.*;
34 import javax.swing.tree.*;
35  
36 public class IRValue
37     extends IRContainer
38     implements org.jacorb.ir.gui.typesystem.Value
39 {
40     private Value baseValue = null;
41     private boolean lookedUpBaseValue = false;
42     private Value[] abstractBaseValues = null;
43     private IRInterface[] interfaces = null;
44     private IRAttribute[] allFields = null;
45     private IROperation[] allOperations = null;
46     private IRValueMember[] allMembers = null;
47
48     /**
49      * Default-Konstruktor: wird von TypeSystem.createNode(...) benutzt
50      */

51     public IRValue ( ) {
52     super();
53     }
54
55     /**
56      * @param irObject org.omg.CORBA.IRObject
57      */

58     public IRValue ( IRObject irObject) {
59     super(irObject);
60     }
61
62     /**
63      * @return An array of the node-type names of node-types
64      * that can be added here.
65      */

66     public String JavaDoc[] allowedToAdd() {
67     String JavaDoc[] result = { IRAttribute.nodeTypeName(),
68                                 IROperation.nodeTypeName(),
69                                 IRConstant.nodeTypeName(),
70                                 IRTypedef.nodeTypeName(),
71                                 IRException.nodeTypeName(),
72                                 IRValueMember.nodeTypeName()
73                           };
74     return result;
75     }
76
77     /**
78      * @return A textual description of this value type.
79      */

80     public String JavaDoc description()
81     {
82     String JavaDoc result = super.description();
83
84         Value base = getBaseValue();
85         if (base != null)
86             result = result + "\nBase-Value:\t "
87                             + ((IRValue)base).getAbsoluteName();
88     else
89             result = result + "\nBase-Value:\t:none";
90
91     Interface[] implemented = getInterfaces();
92     if (implemented.length > 0) {
93             result = result + "\nImplemented-Interfaces:\t ";
94             for (int i = 0; i<implemented.length; i++) {
95                 result = result + ((TypeSystemNode)implemented[i]).getAbsoluteName();
96                 if (i != implemented.length-1)
97                     result = result + ", ";
98             }
99     } else
100             result = result + "\nImplemented-Interfaces:\t:none";
101
102         Value[] abstractBases = getAbstractBaseValues();
103         if (abstractBases.length > 0) {
104             result = result + "\nAbstract-Base-Values:\t ";
105             for (int i = 0; i < abstractBases.length; i++) {
106                 result = result + ((TypeSystemNode)abstractBases[i]).getAbsoluteName();
107                 if (i != abstractBases.length-1)
108                     result = result + ", ";
109             }
110     } else
111             result = result + "\nAbstract-Base-Values:\t:none";
112
113     return result;
114     }
115
116     /**
117      * Returns all fields defined here, including fields from
118      * the base value and interfaces.
119      */

120     public TypeSystemNode[] getAllFields()
121     {
122         if (allFields==null) {
123             Vector fields = new Vector();
124
125             // erstmal die Fields der interfaces sammeln
126
Interface[] interfaces = getInterfaces();
127             for (int i=0; i<interfaces.length; i++) {
128                 TypeSystemNode[] nextFields = interfaces[i].getAllFields();
129                 for (int n=0; n<nextFields.length; n++)
130                     fields.addElement(nextFields[n]);
131             }
132
133             Value[] abstractBases = getAbstractBaseValues();
134             for (int i = 0; i < abstractBases.length; i++) {
135                 TypeSystemNode[] nextFields = abstractBases[i].getAllFields();
136                 for (int n=0; n<nextFields.length; n++)
137                     if (nextFields[n] instanceof IRAttribute)
138                         fields.addElement(nextFields[n]);
139             }
140
141             // dann unsere eigenen Fields (also die Attributes des Interfaces)
142
ModelParticipant[] contained = contents();
143             for (int i=0; i<contained.length; i++)
144                 if (contained[i] instanceof IRAttribute)
145                     fields.addElement(contained[i]);
146
147             // convert into an array
148
allFields = new IRAttribute[fields.size()];
149             int i = 0;
150             for (Enumeration e = fields.elements(); e.hasMoreElements(); ++i)
151                 allFields[i] = (IRAttribute)e.nextElement();
152     }
153     return allFields;
154     }
155
156     /**
157      * Returns all operations defined here, including operations from
158      * the base value and interfaces, but excluding initializers.
159      */

160     public TypeSystemNode[] getAllOperations()
161     {
162     if (this.allOperations==null)
163         {
164             Vector operations = new Vector();
165             // erstmal die Operationen der interfaces sammeln
166
Interface[] interfaces = this.getInterfaces();
167             for (int i=0; i<interfaces.length; i++)
168             {
169                 TypeSystemNode[] nextOperations = interfaces[i].getAllOperations();
170                 for (int n=0; n<nextOperations.length; n++)
171                 {
172                     operations.addElement(nextOperations[n]);
173                 }
174             }
175
176             // dann unsere eigenen Operationen
177

178             ModelParticipant[] contents = this.contents();
179             for (int i=0; i<contents.length; i++)
180             {
181                 if (contents[i] instanceof IROperation)
182                 {
183                     operations.addElement(contents[i]);
184                 }
185             }
186     
187             this.allOperations = new IROperation[operations.size()];
188             int i = 0;
189             for (Enumeration e = operations.elements(); e.hasMoreElements(); )
190             {
191                 allOperations[i] = (IROperation)e.nextElement();
192                 i++;
193             }
194     } // if (allOperations==null)
195
return allOperations;
196     }
197
198     /**
199      * Return the concrete base value of this value, or null
200      * if this base value has no base value.
201      */

202     public Value getBaseValue()
203     {
204     if (!lookedUpBaseValue) {
205             ValueDef valueDef = ValueDefHelper.narrow((org.omg.CORBA.Object JavaDoc)irObject);
206             ValueDef base = valueDef.base_value();
207             if (base != null)
208                 baseValue = (Value)RemoteTypeSystem.createTypeSystemNode(base);
209             lookedUpBaseValue = true;
210     }
211     return baseValue;
212     }
213
214     /**
215      * Return the abstract base values of this value.
216      */

217     public Value[] getAbstractBaseValues()
218     {
219     if (abstractBaseValues == null) {
220             ValueDef valueDef = ValueDefHelper.narrow((org.omg.CORBA.Object JavaDoc)irObject);
221             ValueDef[] abstractBases = valueDef.abstract_base_values();
222             abstractBaseValues = new Value[abstractBases.length];
223             for (int i = 0; i < abstractBases.length; ++i)
224                 abstractBaseValues[i] = (Value)RemoteTypeSystem.createTypeSystemNode(abstractBases[i]);
225     }
226     return abstractBaseValues;
227     }
228
229     /**
230      * Returns all value members defined here, including value members from
231      * the base value.
232      */

233     public TypeSystemNode[] getAllMembers()
234     {
235     if (allMembers == null) {
236             Vector members = new Vector();
237
238             // first collect value members of our base value
239
Value base = getBaseValue();
240             if (base != null) {
241                 TypeSystemNode[] baseMembers = base.getAllMembers();
242
243                 for (int i = 0; i < baseMembers.length; i++)
244                     members.addElement(baseMembers[i]);
245             }
246
247             // add members from abstract_base_values
248
Value[] abstractBases = getAbstractBaseValues();
249             for (int i = 0; i < abstractBases.length; i++) {
250                 TypeSystemNode[] nextMembers = abstractBases[i].getAllMembers();
251                 for (int n=0; n<nextMembers.length; n++)
252                     members.addElement(nextMembers[n]);
253             }
254
255
256             // then our own value members
257
ModelParticipant[] contents = this.contents();
258             for (int i = 0; i < contents.length; i++) {
259                 if (contents[i] instanceof IRValueMember)
260                     members.addElement(contents[i]);
261             }
262     
263             allMembers = new IRValueMember[members.size()];
264             int i = 0;
265             for (Enumeration e = members.elements(); e.hasMoreElements(); ) {
266                 allMembers[i] = (IRValueMember)e.nextElement();
267                 i++;
268             }
269     }
270     return allMembers;
271     }
272
273
274     /**
275      * Get the interfaces implemented by this value type.
276      * This will create the <code>interfaces</code> array, fill it in with
277      * the <code>InterfaceDef</code> of the interfaces implemented by the
278      * value type, and return the array.
279      *
280      * @return A reference to the <code>interfaces</code> field.
281      */

282     public Interface[] getInterfaces()
283     {
284     if (interfaces==null) {
285             // interfaces in unserem dazugehörigen Field speichern
286
ValueDef valueDef = ValueDefHelper.narrow((org.omg.CORBA.Object JavaDoc)irObject);
287             InterfaceDef[] supportedInterfaces = valueDef.supported_interfaces();
288             interfaces = new IRInterface[supportedInterfaces.length];
289             for (int i=0; i<supportedInterfaces.length; i++) {
290                 // für alle base interfaces die zugehörige TypeSystemNode holen
291
IRInterface intf = (IRInterface)RemoteTypeSystem.createTypeSystemNode(supportedInterfaces[i]);
292                 interfaces[i] = intf;
293             }
294     }
295     return interfaces;
296     }
297
298     /**
299      * @return A string denoting the node type implemented here.
300      */

301     public static String JavaDoc nodeTypeName()
302     {
303     return "value";
304     }
305
306     /**
307      * Set the CORBA reference of the IR object we represent.
308      *
309      * @param irObject The CORBA reference to be set.
310      */

311     protected void setIRObject(org.omg.CORBA.IRObject JavaDoc irObject)
312     {
313     super.setIRObject(irObject);
314     }
315 }
316
317
Popular Tags