Source Code Cross Referenced for ViewJndiBean.java in  » J2EE » openejb3 » org » apache » openejb » webadmin » clienttools » 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 » J2EE » openejb3 » org.apache.openejb.webadmin.clienttools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */package org.apache.openejb.webadmin.clienttools;
017:
018:        import java.io.IOException;
019:        import java.io.PrintWriter;
020:        import java.util.Properties;
021:
022:        import javax.ejb.EJBHome;
023:        import javax.ejb.EJBLocalHome;
024:        import javax.ejb.Stateless;
025:        import javax.ejb.RemoteHome;
026:        import javax.naming.Context;
027:        import javax.naming.InitialContext;
028:        import javax.naming.NameClassPair;
029:        import javax.naming.NamingEnumeration;
030:        import javax.naming.NamingException;
031:
032:        import org.apache.openejb.webadmin.HttpRequest;
033:        import org.apache.openejb.webadmin.HttpResponse;
034:        import org.apache.openejb.webadmin.HttpSession;
035:        import org.apache.openejb.webadmin.WebAdminBean;
036:        import org.apache.openejb.webadmin.HttpHome;
037:
038:        /**
039:         * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
040:         */
041:        @Stateless(name="ClientTools/InvokeObject")
042:        @RemoteHome(HttpHome.class)
043:        public class ViewJndiBean extends WebAdminBean implements  Constants {
044:
045:            private HttpSession session;
046:            private String selected;
047:            private String ctxID;
048:            private Context ctx;
049:
050:            public void preProcess(HttpRequest request, HttpResponse response)
051:                    throws IOException {
052:                session = request.getSession(true);
053:                selected = request.getQueryParameter("selected");
054:                if (selected == null) {
055:                    selected = "";
056:                }
057:                ctxID = request.getQueryParameter("ctx");
058:                ctx = null;
059:            }
060:
061:            public void postProcess(HttpRequest request, HttpResponse response)
062:                    throws IOException {
063:            }
064:
065:            public void writeHtmlTitle(PrintWriter out) throws IOException {
066:                out.write("Client Tools -- JNDI Viewer");
067:            }
068:
069:            public void writePageTitle(PrintWriter out) throws IOException {
070:                if (ctxID == null) {
071:                    out.print("JNDI Environment Naming Context (ENC)");
072:                } else if (ctxID.startsWith("enc")) {
073:                    out.print("OpenEJB Global JNDI Namespace");
074:                }
075:            }
076:
077:            public void writeBody(PrintWriter out) throws IOException {
078:
079:                if (ctxID == null) {
080:                    Properties p = new Properties();
081:                    p
082:                            .put(Context.INITIAL_CONTEXT_FACTORY,
083:                                    "org.apache.openejb.client.LocalInitialContextFactory");
084:                    p.put("openejb.loader", "embed");
085:                    try {
086:                        ctx = new InitialContext(p);
087:                    } catch (NamingException e) {
088:                        // TODO Auto-generated catch block
089:                        e.printStackTrace();
090:                    }
091:                    ctxID = null;
092:                    out.print("<b>OpenEJB Global JNDI Namespace</b><br><br>");
093:                } else {
094:                    ctx = (Context) session.getAttribute(ctxID);
095:                    if (ctxID.startsWith("enc")) {
096:                        out
097:                                .print("This is the private namespace of an Enterprise JavaBean.");
098:                        out.print("<BR><BR>");
099:                    }
100:                }
101:
102:                Node root = new RootNode();
103:                try {
104:                    buildNode(root, ctx);
105:
106:                    printNodes(root, out, "", selected);
107:                } catch (Exception e) {
108:                    // TODO Auto-generated catch block
109:                    e.printStackTrace(out);
110:                }
111:            }
112:
113:            class Node {
114:                static final int CONTEXT = 1;
115:                static final int BEAN = 2;
116:                static final int OTHER = 3;
117:                Node parent;
118:                Node[] children = new Node[0];
119:                String name;
120:                int type = 0;
121:
122:                public String getID() {
123:                    if (parent instanceof  RootNode) {
124:                        return name;
125:                    } else {
126:                        return parent.getID() + "/" + name;
127:                    }
128:                }
129:
130:                public String getName() {
131:                    return name;
132:                }
133:
134:                public int getType() {
135:                    return type;
136:                }
137:
138:                public void addChild(Node child) {
139:                    int len = children.length;
140:                    Node[] newChildren = new Node[len + 1];
141:                    System.arraycopy(children, 0, newChildren, 0, len);
142:                    newChildren[len] = child;
143:                    children = newChildren;
144:                    child.parent = this ;
145:                }
146:            }
147:
148:            class RootNode extends Node {
149:                public String getID() {
150:                    return "";
151:                }
152:
153:                public String getName() {
154:                    return "";
155:                }
156:
157:                public int getType() {
158:                    return Node.CONTEXT;
159:                }
160:            }
161:
162:            public void buildNode(Node parent, Context ctx) throws Exception {
163:                if (false)
164:                    throw new NullPointerException();
165:                NamingEnumeration enumeration = ctx.list("");
166:                while (enumeration.hasMoreElements()) {
167:                    NameClassPair pair = (NameClassPair) enumeration.next();
168:                    Node node = new Node();
169:                    parent.addChild(node);
170:                    node.name = pair.getName();
171:
172:                    Object obj = ctx.lookup(node.getName());
173:                    if (obj instanceof  Context) {
174:                        node.type = Node.CONTEXT;
175:                        buildNode(node, (Context) obj);
176:                    } else if (obj instanceof  EJBHome
177:                            || obj instanceof  EJBLocalHome) {
178:                        node.type = Node.BEAN;
179:                    } else {
180:                        node.type = Node.OTHER;
181:                    }
182:                }
183:            }
184:
185:            public void printNodes(Node node, PrintWriter out, String tabs,
186:                    String selected) throws Exception {
187:                switch (node.getType()) {
188:                case Node.CONTEXT:
189:                    printContextNode(node, out, tabs, selected);
190:                    break;
191:                case Node.BEAN:
192:                    printBeanNode(node, out, tabs, selected);
193:                    break;
194:                default:
195:                    printOtherNode(node, out, tabs, selected);
196:                    break;
197:                }
198:
199:            }
200:
201:            public void printContextNode(Node node, PrintWriter out,
202:                    String tabs, String selected) throws Exception {
203:                String id = node.getID();
204:                if (selected.startsWith(id)) {
205:                    if (ctxID != null) {
206:                        out.print(tabs + "<a href='" + VIEW_JNDI + "?ctx="
207:                                + ctxID + "&selected=" + id + "'>" + openImg
208:                                + "&nbsp;&nbsp;" + node.getName() + "</a><br>");
209:                    } else {
210:                        out.print(tabs + "<a href='" + VIEW_JNDI + "?selected="
211:                                + id + "'>" + openImg + "&nbsp;&nbsp;"
212:                                + node.getName() + "</a><br>");
213:                    }
214:                    for (int i = 0; i < node.children.length; i++) {
215:                        Node child = node.children[i];
216:                        printNodes(child, out, tabs
217:                                + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", selected);
218:                    }
219:                } else {
220:                    if (ctxID != null) {
221:                        out.print(tabs + "<a href='" + VIEW_JNDI + "?ctx="
222:                                + ctxID + "&selected=" + id + "'>" + closedImg
223:                                + "&nbsp;&nbsp;" + node.getName() + "</a><br>");
224:                    } else {
225:                        out.print(tabs + "<a href='" + VIEW_JNDI + "?selected="
226:                                + id + "'>" + closedImg + "&nbsp;&nbsp;"
227:                                + node.getName() + "</a><br>");
228:                    }
229:                }
230:            }
231:
232:            public void printBeanNode(Node node, PrintWriter out, String tabs,
233:                    String selected) throws Exception {
234:                String id = node.getID();
235:                //        if (ctxID != null && ctxID.startsWith("enc")) {
236:                // HACK!
237:                try {
238:                    Object ejb = ctx.lookup(id);
239:                    Object handler = org.apache.openejb.util.proxy.ProxyManager
240:                            .getInvocationHandler(ejb);
241:                    Object deploymentID = ((org.apache.openejb.core.ivm.BaseEjbProxyHandler) handler).deploymentID;
242:                    out.print(tabs + "<a href='" + VIEW_EJB + "?ejb="
243:                            + deploymentID + "'>" + ejbImg + "&nbsp;&nbsp;"
244:                            + node.getName() + "</a><br>");
245:                } catch (Exception e) {
246:                    out.print(tabs + ejbImg + "&nbsp;&nbsp;" + node.getName()
247:                            + "<br>");
248:                }
249:                //        } else {
250:                //            out.print(tabs+"<a href='"+VIEW_EJB+"?ejb="+id+"'>"+ejbImg+"&nbsp;&nbsp;"+node.getName()+"</a><br>");
251:                //        }
252:            }
253:
254:            public void printOtherNode(Node node, PrintWriter out, String tabs,
255:                    String selected) throws Exception {
256:                String id = node.getID();
257:                Object obj = ctx.lookup(id);
258:                String clazz = obj.getClass().getName();
259:                out.print(tabs + "<a href='" + VIEW_CLASS + "?class=" + clazz
260:                        + "'>" + javaImg + "&nbsp;&nbsp;" + node.getName()
261:                        + "</a><br>");
262:            }
263:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.