Source Code Cross Referenced for ContextNode.java in  » Collaboration » JacORB » org » jacorb » naming » namemanager » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Collaboration » JacORB » org.jacorb.naming.namemanager 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.jacorb.naming.namemanager;
002:
003:        /*
004:         *        JacORB - a free Java ORB
005:         *
006:         *   Copyright (C) 1997-2004 Gerald Brose.
007:         *
008:         *   This library is free software; you can redistribute it and/or
009:         *   modify it under the terms of the GNU Library General Public
010:         *   License as published by the Free Software Foundation; either
011:         *   version 2 of the License, or (at your option) any later version.
012:         *
013:         *   This library is distributed in the hope that it will be useful,
014:         *   but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
016:         *   Library General Public License for more details.
017:         *
018:         *   You should have received a copy of the GNU Library General Public
019:         *   License along with this library; if not, write to the Free
020:         *   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021:         */
022:
023:        import org.omg.CosNaming.*;
024:        import org.jacorb.orb.iiop.*;
025:
026:        import java.util.*;
027:        import javax.swing.tree.*;
028:
029:        /**
030:         *  @author Gerald Brose, FU Berlin
031:         *  @version $Id: ContextNode.java,v 1.16 2005/11/13 20:45:33 alphonse.bendt Exp $
032:         */
033:
034:        public class ContextNode {
035:            protected Binding[] contents;
036:            public boolean matched;
037:            public boolean used;
038:
039:            public NamingContextExt context;
040:            private DefaultMutableTreeNode myDefaultNode;
041:            private DefaultTreeModel model;
042:            private Binding binding;
043:            private Vector bindingData;
044:            private String myName;
045:
046:            public ContextNode(NamingContextExt context, DefaultTreeModel model) {
047:                used = false;
048:                this .model = model;
049:                this .context = context;
050:            }
051:
052:            public ContextNode(NamingContextExt context, Binding b,
053:                    DefaultTreeModel model) {
054:                used = false;
055:                this .model = model;
056:                this .context = context;
057:                binding = b;
058:            }
059:
060:            /**
061:             * 
062:             */
063:
064:            public void display() {
065:                update();
066:                if (bindingData != null)
067:                    NSTree.nsTable.setData(bindingData, this );
068:            }
069:
070:            public boolean equals(ContextNode bnode) {
071:                return toString().equals(bnode.toString());
072:            }
073:
074:            public NameComponent[] getName() {
075:                return binding.binding_name;
076:            }
077:
078:            /**
079:             * 
080:             * @param node javax.swing.tree.DefaultMutableTreeNode
081:             */
082:
083:            public void setNode(DefaultMutableTreeNode node) {
084:                this .myDefaultNode = node;
085:            }
086:
087:            public String toString() {
088:                if (binding == null) {
089:                    return "RootContext";
090:                }
091:
092:                if (myName == null) {
093:                    NameComponent[] name = binding.binding_name;
094:                    String kind = name[name.length - 1].kind;
095:                    myName = name[name.length - 1].id
096:                            + (kind != null && kind.length() > 0 ? "." + kind
097:                                    : "");
098:                }
099:                return myName;
100:            }
101:
102:            public void unbind(NameComponent[] nc)
103:                    throws org.omg.CosNaming.NamingContextPackage.NotFound,
104:                    org.omg.CosNaming.NamingContextPackage.CannotProceed,
105:                    org.omg.CosNaming.NamingContextPackage.InvalidName {
106:                context.unbind(nc);
107:            }
108:
109:            /**
110:             * update the content of this node and all its children
111:             */
112:
113:            public synchronized void update() {
114:                try {
115:                    BindingListHolder blsoh = new BindingListHolder();
116:                    BindingIteratorHolder bioh = new BindingIteratorHolder();
117:                    ContextNode context_node;
118:
119:                    context.list(NSTree.MAX_BIND, blsoh, bioh);
120:                    Binding[] bindings = blsoh.value;
121:
122:                    int childCount = myDefaultNode.getChildCount();
123:
124:                    // set up lists of object bindings and subcontext bindings
125:
126:                    int context_count = 0;
127:                    int object_count = 0;
128:
129:                    for (int i = 0; i < bindings.length; i++) {
130:                        if (bindings[i].binding_type == BindingType.ncontext)
131:                            context_count++;
132:                        else
133:                            object_count++;
134:                    }
135:
136:                    ContextNode[] contexts = new ContextNode[context_count];
137:                    Binding[] objects = new Binding[object_count];
138:
139:                    for (int i = 0; i < bindings.length; i++) {
140:                        if (bindings[i].binding_type == BindingType.ncontext)
141:                            contexts[--context_count] = new ContextNode(
142:                                    NamingContextExtHelper.narrow(context
143:                                            .resolve(bindings[i].binding_name)),
144:                                    bindings[i], model);
145:                        else
146:                            objects[--object_count] = bindings[i];
147:                    }
148:
149:                    // Compare this node's sub contexts and mark those found
150:                    // in the list of context bindings as used
151:
152:                    for (int i = 0; i < childCount; i++) {
153:                        DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) myDefaultNode
154:                                .getChildAt(i);
155:                        context_node = (ContextNode) dmtn.getUserObject();
156:                        for (int j = 0; j < contexts.length; j++) {
157:                            if (context_node.equals(contexts[j])) {
158:                                context_node.matched = true;
159:                                contexts[j].matched = true;
160:                            }
161:                        }
162:                    }
163:
164:                    // Delete those child nodes that were not found in the
165:                    // list
166:
167:                    Vector removeList = new Vector();
168:                    for (int i = 0; i < childCount; i++) {
169:                        DefaultMutableTreeNode node = (DefaultMutableTreeNode) myDefaultNode
170:                                .getChildAt(i);
171:                        context_node = (ContextNode) node.getUserObject();
172:                        if (!context_node.matched) {
173:                            removeList.addElement(node);
174:                        } else
175:                            context_node.matched = false;
176:                    }
177:
178:                    int rsize = removeList.size();
179:                    for (int i = 0; i < rsize; i++) {
180:                        model
181:                                .removeNodeFromParent((DefaultMutableTreeNode) removeList
182:                                        .elementAt(i));
183:                    }
184:
185:                    bindingData = new Vector();
186:
187:                    // Insert new context nodes found in the list as
188:                    // children of this tree node
189:
190:                    for (int i = 0; i < contexts.length; i++) {
191:                        if (!contexts[i].matched) {
192:                            contexts[i].used = true;
193:
194:                            DefaultMutableTreeNode node = new DefaultMutableTreeNode();
195:
196:                            // tree node and context node need to know each other:
197:                            contexts[i].setNode(node);
198:                            node.setUserObject(contexts[i]);
199:                            node.setAllowsChildren(true);
200:                            model.insertNodeInto(node, myDefaultNode, 0);
201:                        }
202:                        NameComponent last = contexts[i].binding.binding_name[contexts[i].binding.binding_name.length - 1];
203:                        NameComponent[] ncs = { last };
204:
205:                        org.jacorb.orb.ParsedIOR pior = null;
206:                        try {
207:                            pior = ((org.jacorb.orb.Delegate) ((org.omg.CORBA.portable.ObjectImpl) context
208:                                    .resolve(ncs))._get_delegate())
209:                                    .getParsedIOR();
210:                        } catch (org.omg.CosNaming.NamingContextPackage.NotFound nf) {
211:                            // the named object could have disappeared from the 
212:                            // naming context in the meantime. If it has, we simply
213:                            // continue
214:                            continue;
215:                        }
216:                        Vector row = createRow(last, pior);
217:                        bindingData.addElement(row);
218:
219:                    }
220:
221:                    for (int i = 0; i < objects.length; i++) {
222:                        NameComponent last = objects[i].binding_name[objects[i].binding_name.length - 1];
223:                        NameComponent[] ncs = { last };
224:                        org.jacorb.orb.ParsedIOR pior = null;
225:                        try {
226:                            pior = ((org.jacorb.orb.Delegate) ((org.omg.CORBA.portable.ObjectImpl) context
227:                                    .resolve(ncs))._get_delegate())
228:                                    .getParsedIOR();
229:                        } catch (org.omg.CosNaming.NamingContextPackage.NotFound nf) {
230:                            // the named object could have disappeared from the 
231:                            // naming context in the meantime. If it has, we simply
232:                            // continue
233:                            continue;
234:                        }
235:                        Vector row = createRow(last, pior);
236:
237:                        bindingData.addElement(row);
238:                    }
239:
240:                    // recursively update child nodes
241:
242:                    childCount = myDefaultNode.getChildCount();
243:                    for (int i = 0; i < childCount; i++) {
244:                        DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) myDefaultNode
245:                                .getChildAt(i);
246:                        context_node = (ContextNode) dmtn.getUserObject();
247:                        //		Name name = new Name(bindings[i].binding_name);
248:                        context_node.update();
249:                    }
250:                } catch (Exception e) {
251:                    e.printStackTrace();
252:                }
253:            }
254:
255:            private Vector createRow(NameComponent last,
256:                    org.jacorb.orb.ParsedIOR pior) {
257:                Vector row = new Vector();
258:
259:                row.addElement(last.id);
260:                row.addElement(last.kind);
261:                row.addElement(pior.getTypeId());
262:                IIOPProfile p = (IIOPProfile) pior.getEffectiveProfile();
263:                final IIOPAddress iiopAddress = (IIOPAddress) p.getAddress();
264:                row.addElement(iiopAddress.getIP());
265:                row.addElement(Integer.toString(iiopAddress.getPort()));
266:                return row;
267:            }
268:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.