Source Code Cross Referenced for Jndi.java in  » EJB-Server-resin-3.1.5 » resin » com » caucho » naming » 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 » EJB Server resin 3.1.5 » resin » com.caucho.naming 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003:         *
004:         * This file is part of Resin(R) Open Source
005:         *
006:         * Each copy or derived work must preserve the copyright notice and this
007:         * notice unmodified.
008:         *
009:         * Resin Open Source is free software; you can redistribute it and/or modify
010:         * it under the terms of the GNU General Public License as published by
011:         * the Free Software Foundation; either version 2 of the License, or
012:         * (at your option) any later version.
013:         *
014:         * Resin Open Source is distributed in the hope that it will be useful,
015:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
016:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017:         * of NON-INFRINGEMENT.  See the GNU General Public License for more
018:         * details.
019:         *
020:         * You should have received a copy of the GNU General Public License
021:         * along with Resin Open Source; if not, write to the
022:         *   Free SoftwareFoundation, Inc.
023:         *   59 Temple Place, Suite 330
024:         *   Boston, MA 02111-1307  USA
025:         *
026:         * @author Scott Ferguson
027:         */
028:
029:        package com.caucho.naming;
030:
031:        import com.caucho.log.Log;
032:        import com.caucho.util.L10N;
033:
034:        import javax.naming.Context;
035:        import javax.naming.InitialContext;
036:        import javax.naming.Name;
037:        import javax.naming.NameNotFoundException;
038:        import javax.naming.NameParser;
039:        import javax.naming.NamingException;
040:        import java.util.logging.Level;
041:        import java.util.logging.Logger;
042:
043:        /**
044:         * Static utility functions.
045:         */
046:        public class Jndi {
047:            private static Logger log = Log.open(Jndi.class);
048:            private static L10N L = new L10N(Jndi.class);
049:
050:            private Jndi() {
051:            }
052:
053:            /**
054:             * Returns the full name.
055:             */
056:            public static String getFullName(String shortName) {
057:                if (shortName.startsWith("java:"))
058:                    return shortName;
059:                else
060:                    return "java:comp/env/" + shortName;
061:            }
062:
063:            public static void bindDeepShort(String name, Object obj)
064:                    throws NamingException {
065:                bindImpl(new InitialContext(), getFullName(name), obj, name);
066:            }
067:
068:            public static void bindDeepShort(Context context, String name,
069:                    Object obj) throws NamingException {
070:                bindImpl(context, getFullName(name), obj, name);
071:            }
072:
073:            public static void bindDeep(String name, Object obj)
074:                    throws NamingException {
075:                bindImpl(new InitialContext(), name, obj, name);
076:            }
077:
078:            public static void bindDeep(Context context, String name, Object obj)
079:                    throws NamingException {
080:                bindImpl(context, name, obj, name);
081:            }
082:
083:            private static void bindImpl(Context context, String name,
084:                    Object obj, String fullName) throws NamingException {
085:                NameParser parser = context.getNameParser("");
086:                Name parsedName = parser.parse(name);
087:
088:                if (parsedName.size() == 1) {
089:                    Object value = null;
090:
091:                    try {
092:                        value = context.lookup(name);
093:                    } catch (NameNotFoundException e) {
094:                    }
095:
096:                    context.rebind(name, obj);
097:
098:                    // server/1620
099:                    if (value != null && value != obj)
100:                        log
101:                                .config(L
102:                                        .l(
103:                                                "'{0}' overrides a previous JNDI resource.  The old resource is '{1}' and the new one is '{2}'",
104:                                                fullName, value, obj));
105:
106:                    return;
107:                }
108:
109:                Object sub = null;
110:
111:                try {
112:                    sub = context.lookup(parsedName.get(0));
113:                } catch (NameNotFoundException e) {
114:                }
115:
116:                if (sub == null)
117:                    sub = context.createSubcontext(parsedName.get(0));
118:
119:                if (sub instanceof  Context)
120:                    bindImpl((Context) sub, parsedName.getSuffix(1).toString(),
121:                            obj, fullName);
122:
123:                else
124:                    throw new NamingException(
125:                            L
126:                                    .l(
127:                                            "'{0}' is an invalid JNDI name because '{1} is not a Context.  One of the subcontexts is not a Context as expected.",
128:                                            fullName, sub));
129:            }
130:
131:            /**
132:             * Binds the object into JNDI without warnings if an old
133:             * object exists.  The name may be a full name or the short
134:             * form.
135:             */
136:            public static void rebindDeepShort(String name, Object obj)
137:                    throws NamingException {
138:                rebindImpl(new InitialContext(), getFullName(name), obj, name);
139:            }
140:
141:            /**
142:             * Binds the object into JNDI without warnings if an old
143:             * object exists.  The name may be a full name or the short
144:             * form.
145:             */
146:            public static void rebindDeepShort(Context context, String name,
147:                    Object obj) throws NamingException {
148:                rebindImpl(context, getFullName(name), obj, name);
149:            }
150:
151:            /**
152:             * Binds the object into JNDI without warnings if an old
153:             * object exists, using the full JNDI name.
154:             */
155:            public static void rebindDeep(String name, Object obj)
156:                    throws NamingException {
157:                rebindImpl(new InitialContext(), name, obj, name);
158:            }
159:
160:            /**
161:             * Binds the object into JNDI without warnings if an old
162:             * object exists, using the full JNDI name.
163:             */
164:            public static void rebindDeep(Context context, String name,
165:                    Object obj) throws NamingException {
166:                rebindImpl(context, name, obj, name);
167:            }
168:
169:            /**
170:             * Binds the object into JNDI without warnings if an old
171:             * object exists.
172:             */
173:            private static void rebindImpl(Context context, String name,
174:                    Object obj, String fullName) throws NamingException {
175:                NameParser parser = context.getNameParser("");
176:                Name parsedName = parser.parse(name);
177:
178:                if (parsedName.size() == 1) {
179:                    context.rebind(name, obj);
180:                    return;
181:                }
182:
183:                Object sub = null;
184:
185:                try {
186:                    sub = context.lookup(parsedName.get(0));
187:                } catch (NameNotFoundException e) {
188:                    log.log(Level.FINEST, e.toString(), e);
189:                }
190:
191:                if (sub == null)
192:                    sub = context.createSubcontext(parsedName.get(0));
193:
194:                if (sub instanceof  Context)
195:                    rebindImpl((Context) sub, parsedName.getSuffix(1)
196:                            .toString(), obj, fullName);
197:
198:                else
199:                    throw new NamingException(
200:                            L
201:                                    .l(
202:                                            "'{0}' is an invalid JNDI name because '{1} is not a Context.  One of the subcontexts is not a Context as expected.",
203:                                            fullName, sub));
204:            }
205:
206:            // For EL
207:            public static Object lookup(String name) {
208:                Exception ex = null;
209:
210:                try {
211:                    Object value = new InitialContext().lookup(name);
212:
213:                    if (value != null)
214:                        return value;
215:                } catch (NamingException e) {
216:                    ex = e;
217:                }
218:
219:                if (!name.startsWith("java:")) {
220:                    try {
221:                        Object value = new InitialContext()
222:                                .lookup("java:comp/env/" + name);
223:
224:                        if (value != null)
225:                            return value;
226:                    } catch (NamingException e) {
227:                        ex = e;
228:                    }
229:                }
230:
231:                if (ex != null && log.isLoggable(Level.FINEST))
232:                    log.log(Level.FINEST, ex.toString(), ex);
233:
234:                return null;
235:            }
236:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.