KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > ir > gui > typesystem > TypeSystemNode


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;
22
23
24 /**
25  * This class was generated by a SmartGuide.
26  *
27  */

28  
29 import java.util.*;
30 import javax.swing.tree.*;
31 import java.lang.reflect.*;
32  
33 public abstract class TypeSystemNode
34     extends ModelParticipant
35 {
36     protected DefaultMutableTreeNode treeNode;
37     protected String JavaDoc name = "";
38     protected String JavaDoc absoluteName = "";
39
40     /**
41      */

42     public TypeSystemNode ( ) {
43     }
44
45     /**
46      * @param treeModel javax.swing.tree.DefaultTreeModel
47      * @param parent javax.swing.tree.DefaultMutableTreeNode
48      */

49     protected TypeSystemNode ( DefaultMutableTreeNode treeNode) {
50     this();
51     this.treeNode = treeNode;
52     }
53
54     /**
55      * @param name java.lang.String
56      */

57
58     public TypeSystemNode ( String JavaDoc name) {
59     this();
60     this.name = name;
61     }
62
63     /**
64      * Gibt Array mit Strings zurück: die Node-Typen, die zu dieser Node
65      * hinzugefügt werden können.
66      * IRModule z.B. gibt "module", "interface" usw. zurück.
67      * @return java.util.Enumeration
68      */

69
70     public String JavaDoc[] allowedToAdd ( )
71     {
72         return null;
73     }
74
75     /**
76      * @return int
77      * @param other org.jacorb.ir.gui.typesystem.ModelParticipant
78      */

79     public int compareTo(ModelParticipant other) {
80     return this.toString().compareTo(other.toString());
81     }
82
83     /**
84      * @return java.lang.String
85      */

86
87     public String JavaDoc description() {
88     return getInstanceNodeTypeName() + " " + getAbsoluteName();
89     }
90
91     /**
92      * @return java.lang.String
93      */

94     public String JavaDoc getAbsoluteName() {
95     return absoluteName;
96     }
97
98     /**
99      * @return java.lang.String
100      */

101
102     public String JavaDoc getInstanceNodeTypeName ( )
103     {
104     // Für die Textrepräsentation einer Node kann nodeTypeName abhängig vom Zustand sein,
105
// z.B. bei IRAttribute: gegebenenfalls muß es dort "readonly attribute" heißen und nicht "attribute"
106
// Dynamischen Lookup einer static Methode simulieren:
107
Method nodeTypeNameMethod;
108     String JavaDoc nodeTypeName = "";
109     try {
110             nodeTypeNameMethod = getClass().getMethod("nodeTypeName", new Class JavaDoc[0]);
111             nodeTypeName = (String JavaDoc) nodeTypeNameMethod.invoke(null, new Object JavaDoc[0]) ;
112     }
113     catch (Exception JavaDoc e) {
114             e.printStackTrace();
115     }
116     return nodeTypeName;
117     }
118
119     /**
120      * @return java.lang.String
121      */

122
123     public String JavaDoc getName ( )
124     {
125         return name;
126     }
127
128     /**
129      * Füge neues Child zu Node hinzu. Wird nur von TypeSystem.insertChild(..) aufgerufen.
130      * Macht hier nichts als Exception zu werfen, wenn newChild nicht zugelassen ist, muß also
131      * von Unterklassen überschrieben werden, um z.B. entsprechende Methode auf IR aufzurufen.
132      * Bei illegalem Child-Typ wird IllegalChildException geworfen.
133      * @param newChild TypeSystemNode
134      */

135
136     protected void insertChild ( TypeSystemNode newChild)
137         throws IllegalChildException
138     {
139     String JavaDoc[] allowedTypes = allowedToAdd();
140     int i;
141     for (i = 0;
142              i <allowedTypes.length && !allowedTypes[i].equals(newChild.nodeTypeName());
143              i++);
144
145     if (!allowedTypes[i].equals(newChild.nodeTypeName())) {
146             throw new IllegalChildException();
147     }
148     // Das eigentliche Einfügen der DefaultMutableTreeNode wird von TypeSystem vorgenommen,
149
// um entsprechende Events des TreeModels wird sich dort gekümmert.
150
// Unterklassen müssen Methode überschreiben (inkl. Aufruf von super.addChild(..)) und z.B.
151
// entsprechende Methode auf dem InterfaceRepository aufrufen
152
}
153
154     /**
155      * Gib den Namen des Typen der Node zurück, z.B. den IDL-Bezeichner "Module"
156      * @return java.lang.String
157      */

158
159     public static String JavaDoc nodeTypeName ( ) {
160     // static Methoden können nicht abstract sein
161
return null;
162     }
163
164     /**
165      */

166     protected void setAbsoluteName(String JavaDoc absoluteName ) {
167     this.absoluteName = absoluteName;
168     }
169
170     /**
171      * wird von Unterklassen von TypeSystemNode aufgerufen, deswegen protected
172      * @param name java.lang.String
173      */

174
175     protected void setName( String JavaDoc name) {
176     this.name = name;
177     }
178
179     /**
180      * Soll möglichst IDL-ähnliche komplette Textrepräsentation zurückgeben
181      * aber nur der Node selbst.
182      * @return java.lang.String
183      */

184     public String JavaDoc toString ( ) {
185     return getInstanceNodeTypeName() + " " + getName();
186     }
187 }
188
189
190
191
192
193
194
195
196
197
198
199
200
201
Popular Tags