KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > coach > actor > componentBrowser > ComponentNode


1 /***************************************************************************/
2 /* COACH: Component Based Open Source Architecture for */
3 /* Distributed Telecom Applications */
4 /* See: http://www.objectweb.org/ */
5 /* */
6 /* Copyright (C) 2003 Lucent Technologies Nederland BV */
7 /* Bell Labs Advanced Technologies - EMEA */
8 /* */
9 /* Initial developer(s): Harold Batteram */
10 /* */
11 /* This library is free software; you can redistribute it and/or */
12 /* modify it under the terms of the GNU Lesser General Public */
13 /* License as published by the Free Software Foundation; either */
14 /* version 2.1 of the License, or (at your option) any later version. */
15 /* */
16 /* This library is distributed in the hope that it will be useful, */
17 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
19 /* Lesser General Public License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public */
22 /* License along with this library; if not, write to the Free Software */
23 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
24 /***************************************************************************/
25 package org.coach.actor.componentBrowser;
26
27 import javax.swing.tree.*;
28 import org.omg.CORBA.*;
29 import org.omg.Components.*;
30
31 class ComponentNode extends DefaultMutableTreeNode {
32     protected static org.omg.CORBA.ORB JavaDoc orb;
33     protected boolean explored = false;
34     protected boolean leaf = true;
35     protected String JavaDoc name = "";
36     protected org.omg.CORBA.Object JavaDoc obj;
37     
38
39     public ComponentNode(String JavaDoc name) {
40         this.name = name;
41         setUserObject(this);
42     }
43
44     public ComponentNode(String JavaDoc name, org.omg.CORBA.Object JavaDoc obj) {
45         this.name = name;
46         this.obj = obj;
47         leaf = false;
48         setUserObject(this);
49     }
50     
51     private ComponentNode(String JavaDoc name, org.omg.CORBA.Object JavaDoc obj, boolean leaf) {
52         this.name = name;
53         this.obj = obj;
54         this.leaf = leaf;
55         setUserObject(this);
56     }
57     
58     public static void setOrb(org.omg.CORBA.ORB JavaDoc o) {
59         orb = o;
60     }
61
62     public boolean getAllowsChildren() {
63         return !leaf;
64     }
65
66     public boolean isLeaf() {
67         return leaf;
68     }
69
70     public void explore() {
71         explore(false);
72     }
73
74     public boolean isExplored() {
75         return explored;
76     }
77
78     public String JavaDoc toString() {
79         return name;
80     }
81
82     public String JavaDoc getIor() {
83         String JavaDoc ior = "not an object!";
84         org.omg.CORBA.Object JavaDoc obj = getObject();
85         if (obj != null) {
86             try {
87                 ior = orb.object_to_string(obj);
88             } catch (Exception JavaDoc e) {
89                 e.printStackTrace();
90             }
91         }
92         return ior;
93     }
94
95     public org.omg.CORBA.Object JavaDoc getObject() {
96         if (obj != null) {
97             return obj;
98         }
99         if (leaf) {
100             try {
101                 ComponentNode p = (ComponentNode)getParent();
102                 CCMObject c = (CCMObject)p.getObject();
103                 obj = c.provide_facet(name);
104                 return obj;
105             } catch (Exception JavaDoc e) {
106                 e.printStackTrace();
107             }
108         }
109         return null;
110     }
111
112     public boolean ping() {
113         if (obj == null) {
114             getObject();
115         }
116         if (obj != null) {
117             try {
118                 obj._is_a("dummy");
119             } catch (Exception JavaDoc e) {
120                 return false;
121             }
122             return true;
123         }
124         return false;
125     }
126
127     public void explore(boolean force) {
128         if(!leaf && (!isExplored() || force)) {
129             removeAllChildren();
130             try {
131                 add(new ComponentNode(name, obj, true));
132                 FacetDescription[] facetDescription = ((CCMObject)obj).get_all_facets();
133                 for(int i = 0; i < facetDescription.length; i++) {
134                     add(new ComponentNode(facetDescription[i].name));
135                 }
136
137 // String[] opr = ((dsc.i_Component)obj).getFacets();
138
// for(int i = 0; i < opr.length; i++) {
139
// add(new ComponentNode(opr[i]));
140
// }
141

142             } catch (Exception JavaDoc e) {
143                 e.printStackTrace();
144             }
145
146             explored = true;
147         }
148     }
149 }
150
Popular Tags