Source Code Cross Referenced for JndiVariableResolver.java in  » Ajax » zk » org » zkoss » zkplus » jndi » 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 » Ajax » zk » org.zkoss.zkplus.jndi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* JndiVariableResolver.java
002:
003:        {{IS_NOTE
004:        	Purpose:
005:        		
006:        	Description:
007:        		
008:        	History:
009:        		Mon Dec 1 2007, Created by jeffliu
010:        }}IS_NOTE
011:
012:        Copyright (C) 2006 Potix Corporation. All Rights Reserved.
013:
014:        {{IS_RIGHT
015:        }}IS_RIGHT
016:         */
017:        package org.zkoss.zkplus.jndi;
018:
019:        import java.util.HashMap;
020:        import java.util.Map;
021:
022:        import javax.naming.Context;
023:        import javax.naming.InitialContext;
024:        import javax.naming.NamingException;
025:
026:        import org.zkoss.util.Maps;
027:        import org.zkoss.util.logging.Log;
028:        import org.zkoss.xel.VariableResolver;
029:        import org.zkoss.xel.XelException;
030:
031:        /**
032:         * JndiVariableResolver, a jndi variableResolver 
033:         * @author Jeff
034:         *
035:         */
036:        public class JndiVariableResolver implements  VariableResolver {
037:
038:            private static final Log log = Log
039:                    .lookup(JndiVariableResolver.class);
040:
041:            private String _jndiPrepend = null;
042:
043:            private Map _jndiMapping = new HashMap();
044:
045:            /**
046:             * This constructor take agruments to initialize JNDI names. 
047:             * <ul>
048:             * <li>prepend - The prepended part of JNDI name</li>
049:             * <li>mapping - The key-value pairs for JNDI name and its corresponding variable name</li>
050:             * </ul>
051:             * 
052:             * The variable will be resolved in following priority
053:             * <ol>
054:             * <li>java:comp/env</li>
055:             * <li>java:comp</li>
056:             * <li>java:</li>
057:             * <li>The variable will be look up as a sessionBean with prepend.</li>
058:             * <li>The key-value pairs which is defined by mapping</li>
059:             * </ol>
060:             * </p>
061:             * 
062:             * <p>
063:             * For example:
064:             * </p>
065:             * <p>
066:             * By default, session beans will bind to JNDI in the form ejbName/remote for remote interfaces and ejbName/local in the case of local interfaces. When the EJBs are deployed in an .ear file, the default jndi binding will be prepended by the name of the .ear file.
067:             * As a result, if the ear file name is foo.ear, prepend is: foo
068:             * </p>
069:             * </br>
070:             * <p>
071:             * If you define your own jdni binding, the string should be in key-value pairs format as</br>
072:             * "a=custom/MySession,b=custom/MySession2,emf=java:/EntityManagerFactory"
073:             * </p>
074:             *
075:             * @param prepend prepended part of JNDI name
076:             * @param mapping key-value pairs for JNDI name and its corresponding variable name
077:             */
078:            public JndiVariableResolver(String prepend, String mapping) {
079:                _jndiMapping = new HashMap();
080:                Maps.parse(_jndiMapping, (String) mapping, ',', '=');
081:                _jndiPrepend = prepend;
082:            }
083:
084:            public JndiVariableResolver() {
085:                //Do Nothing
086:            }
087:
088:            /**
089:             * Get object from JNDI binding
090:             * @param var JNDI binding name
091:             * @return bean of context
092:             */
093:            public Object resolveVariable(String var) throws XelException {
094:                Object variable = null;
095:                /*
096:                 * First, find the variable, var in JNDI key-value map. If
097:                 * not found, look for the variable as a sessionBean
098:                 */
099:
100:                variable = jndiLookup("java:comp/env/" + var);
101:
102:                if (variable == null) {
103:                    variable = jndiLookup("java:comp/" + var);
104:                }
105:                if (variable == null) {
106:                    variable = jndiLookup("java:/" + var);
107:                }
108:                if (variable == null) {
109:                    variable = defaultBean(var);
110:                }
111:                if (!_jndiMapping.isEmpty() && variable == null) {
112:                    Object jndiPattern = _jndiMapping.get(var);
113:                    if (jndiPattern != null) {
114:                        variable = jndiLookup(jndiPattern.toString());
115:                    }
116:                }
117:                return variable;
118:            }
119:
120:            private Object defaultBean(String name) {
121:                Object variable = null;
122:
123:                variable = jndiLookup(_jndiPrepend + "/" + name + "/local");
124:                //If not found in local, lookup remote
125:                if (variable == null) {
126:                    variable = jndiLookup(_jndiPrepend + "/" + name + "/remote");
127:                }
128:                return variable;
129:            }
130:
131:            private Object jndiLookup(String jndiPattern) {
132:                Object obj = null;
133:                try {
134:                    Context ctx = new InitialContext();
135:                    obj = ctx.lookup(jndiPattern);
136:                } catch (NamingException ex) {
137:                    //Not found, logging
138:                    if (log.debugable()) {
139:                        log.debug("JNDI binding not found: " + ex);
140:                    }
141:                }
142:                return obj;
143:            }
144:
145:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.