Source Code Cross Referenced for javaRootURLContext.java in  » Sevlet-Container » jetty-modules » org » mortbay » naming » java » 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 » Sevlet Container » jetty modules » org.mortbay.naming.java 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // ========================================================================
002:        // $Id: javaRootURLContext.java 887 2006-09-05 13:46:42Z janb $
003:        // Copyright 1999-2006 Mort Bay Consulting Pty. Ltd.
004:        // ------------------------------------------------------------------------
005:        // Licensed under the Apache License, Version 2.0 (the "License");
006:        // you may not use this file except in compliance with the License.
007:        // You may obtain a copy of the License at 
008:        // http://www.apache.org/licenses/LICENSE-2.0
009:        // Unless required by applicable law or agreed to in writing, software
010:        // distributed under the License is distributed on an "AS IS" BASIS,
011:        // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:        // See the License for the specific language governing permissions and
013:        // limitations under the License.
014:        // ========================================================================
015:
016:        package org.mortbay.naming.java;
017:
018:        import java.util.Hashtable;
019:
020:        import javax.naming.Context;
021:        import javax.naming.Name;
022:        import javax.naming.NameParser;
023:        import javax.naming.NamingEnumeration;
024:        import javax.naming.NamingException;
025:        import javax.naming.Reference;
026:        import javax.naming.StringRefAddr;
027:
028:        import org.mortbay.log.Log;
029:        import org.mortbay.naming.ContextFactory;
030:        import org.mortbay.naming.NamingContext;
031:
032:        /** javaRootURLContext
033:         * <p>This is the root of the java: url namespace
034:         *
035:         * <p><h4>Notes</h4>
036:         * <p>Thanks to Rickard Oberg for the idea of binding an ObjectFactory at "comp".
037:         *
038:         * <p><h4>Usage</h4>
039:         * <pre>
040:         */
041:        /*
042:         * </pre>
043:         *
044:         * @see
045:         *
046:         * @author <a href="mailto:janb@mortbay.com">Jan Bartel</a>
047:         * @version 1.0
048:         */
049:        public class javaRootURLContext implements  Context {
050:            public static final String URL_PREFIX = "java:";
051:
052:            protected Hashtable _env;
053:
054:            protected static NamingContext _nameRoot;
055:
056:            protected static NameParser _javaNameParser;
057:
058:            static {
059:                try {
060:                    _javaNameParser = new javaNameParser();
061:                    _nameRoot = new NamingContext();
062:                    _nameRoot.setNameParser(_javaNameParser);
063:
064:                    StringRefAddr parserAddr = new StringRefAddr("parser",
065:                            _javaNameParser.getClass().getName());
066:
067:                    Reference ref = new Reference("javax.naming.Context",
068:                            parserAddr, ContextFactory.class.getName(),
069:                            (String) null);
070:
071:                    //bind special object factory at comp
072:                    _nameRoot.bind("comp", ref);
073:                } catch (Exception e) {
074:                    Log.warn(e);
075:                }
076:            }
077:
078:            /*------------------------------------------------*/
079:            /**
080:             * Creates a new <code>javaRootURLContext</code> instance.
081:             *
082:             * @param env a <code>Hashtable</code> value
083:             */
084:            public javaRootURLContext(Hashtable env) {
085:                _env = env;
086:            }
087:
088:            public Object lookup(Name name) throws NamingException {
089:                return getRoot().lookup(stripProtocol(name));
090:            }
091:
092:            public Object lookup(String name) throws NamingException {
093:                return getRoot().lookup(stripProtocol(name));
094:            }
095:
096:            public void bind(Name name, Object obj) throws NamingException {
097:                getRoot().bind(stripProtocol(name), obj);
098:            }
099:
100:            public void bind(String name, Object obj) throws NamingException {
101:                getRoot().bind(stripProtocol(name), obj);
102:            }
103:
104:            public void unbind(String name) throws NamingException {
105:                getRoot().unbind(stripProtocol(name));
106:            }
107:
108:            public void unbind(Name name) throws NamingException {
109:                getRoot().unbind(stripProtocol(name));
110:            }
111:
112:            public void rename(String oldStr, String newStr)
113:                    throws NamingException {
114:                getRoot().rename(stripProtocol(oldStr), stripProtocol(newStr));
115:            }
116:
117:            public void rename(Name oldName, Name newName)
118:                    throws NamingException {
119:                getRoot()
120:                        .rename(stripProtocol(oldName), stripProtocol(newName));
121:            }
122:
123:            public void rebind(Name name, Object obj) throws NamingException {
124:                getRoot().rebind(stripProtocol(name), obj);
125:            }
126:
127:            public void rebind(String name, Object obj) throws NamingException {
128:                getRoot().rebind(stripProtocol(name), obj);
129:            }
130:
131:            public Object lookupLink(Name name) throws NamingException {
132:                return getRoot().lookupLink(stripProtocol(name));
133:            }
134:
135:            public Object lookupLink(String name) throws NamingException {
136:                return getRoot().lookupLink(stripProtocol(name));
137:            }
138:
139:            public Context createSubcontext(Name name) throws NamingException {
140:                return getRoot().createSubcontext(stripProtocol(name));
141:            }
142:
143:            public Context createSubcontext(String name) throws NamingException {
144:                return getRoot().createSubcontext(stripProtocol(name));
145:            }
146:
147:            public void destroySubcontext(Name name) throws NamingException {
148:                getRoot().destroySubcontext(stripProtocol(name));
149:            }
150:
151:            public void destroySubcontext(String name) throws NamingException {
152:                getRoot().destroySubcontext(stripProtocol(name));
153:            }
154:
155:            public NamingEnumeration list(Name name) throws NamingException {
156:                return getRoot().list(stripProtocol(name));
157:            }
158:
159:            public NamingEnumeration list(String name) throws NamingException {
160:                return getRoot().list(stripProtocol(name));
161:            }
162:
163:            public NamingEnumeration listBindings(Name name)
164:                    throws NamingException {
165:                return getRoot().listBindings(stripProtocol(name));
166:            }
167:
168:            public NamingEnumeration listBindings(String name)
169:                    throws NamingException {
170:                return getRoot().listBindings(stripProtocol(name));
171:            }
172:
173:            public Name composeName(Name name, Name prefix)
174:                    throws NamingException {
175:                return getRoot().composeName(name, prefix);
176:            }
177:
178:            public String composeName(String name, String prefix)
179:                    throws NamingException {
180:                return getRoot().composeName(name, prefix);
181:            }
182:
183:            public void close() throws NamingException {
184:            }
185:
186:            public String getNameInNamespace() throws NamingException {
187:                return URL_PREFIX;
188:            }
189:
190:            public NameParser getNameParser(Name name) throws NamingException {
191:                return _javaNameParser;
192:            }
193:
194:            public NameParser getNameParser(String name) throws NamingException {
195:                return _javaNameParser;
196:            }
197:
198:            public Object addToEnvironment(String propName, Object propVal)
199:                    throws NamingException {
200:                return _env.put(propName, propVal);
201:            }
202:
203:            public Object removeFromEnvironment(String propName)
204:                    throws NamingException {
205:                return _env.remove(propName);
206:            }
207:
208:            public Hashtable getEnvironment() {
209:                return _env;
210:            }
211:
212:            protected NamingContext getRoot() {
213:                return _nameRoot;
214:            }
215:
216:            protected Name stripProtocol(Name name) throws NamingException {
217:                if ((name != null) && (name.size() > 0)) {
218:                    String head = name.get(0);
219:
220:                    if (Log.isDebugEnabled())
221:                        Log.debug("Head element of name is: " + head);
222:
223:                    if (head.startsWith(URL_PREFIX)) {
224:                        head = head.substring(URL_PREFIX.length());
225:                        name.remove(0);
226:                        if (head.length() > 0)
227:                            name.add(0, head);
228:
229:                        if (Log.isDebugEnabled())
230:                            Log.debug("name modified to " + name.toString());
231:                    }
232:                }
233:
234:                return name;
235:            }
236:
237:            protected String stripProtocol(String name) {
238:                String newName = name;
239:
240:                if ((name != null) && (!name.equals(""))) {
241:                    if (name.startsWith(URL_PREFIX))
242:                        newName = name.substring(URL_PREFIX.length());
243:                }
244:
245:                return newName;
246:            }
247:
248:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.