Source Code Cross Referenced for GenericURLContextFactory.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » jndi » provider » 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 » Apache Harmony Java SE » org package » org.apache.harmony.jndi.provider 
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:         *
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */
018:
019:        /**
020:         * @author  Vasily Zakharov
021:         * @version $Revision: 1.1.2.3 $
022:         */package org.apache.harmony.jndi.provider;
023:
024:        import java.util.Hashtable;
025:
026:        import javax.naming.ConfigurationException;
027:        import javax.naming.Context;
028:        import javax.naming.Name;
029:        import javax.naming.NamingException;
030:
031:        import javax.naming.spi.ObjectFactory;
032:
033:        import org.apache.harmony.jndi.internal.nls.Messages;
034:
035:        /**
036:         * Base class for URL naming context factory implementations.
037:         * 
038:         * In many cases, subclasses should only override
039:         * {@link #createURLContext(Hashtable)} method and provide public no-args
040:         * constructor.
041:         */
042:        public abstract class GenericURLContextFactory implements  ObjectFactory {
043:
044:            /**
045:             * Default constructor for subclasses.
046:             */
047:            protected GenericURLContextFactory() {
048:                super ();
049:            }
050:
051:            /**
052:             * Lookups the specified object in the underlying context. Underlying
053:             * context instance is provided by {@link #createURLContext(Hashtable)}.
054:             * 
055:             * Follows the guidelines for URL context factories described in
056:             * {@link ObjectFactory#getObjectInstance(Object, Name, Context, Hashtable)}
057:             * specification.
058:             * 
059:             * If <code>obj</code> is <code>null</code>, just creates and returns
060:             * an underlying context.
061:             * 
062:             * If <code>obj</code> is a proper URL string, lookups and returns an
063:             * object specified by that string.
064:             * 
065:             * If <code>obj</code> is an array of URL strings, tries to lookup each of
066:             * them sequentially until lookup succeeds, then returns the result. If no
067:             * lookup succeeds, throws {@link NamingException} describing the fail of a
068:             * last lookup.
069:             * 
070:             * <code>name</code> and <code>nameCtx</code> parameters are ignored.
071:             * 
072:             * @param obj
073:             *            Object to lookup, can be <code>null</code>.
074:             * 
075:             * @param name
076:             *            Ignored.
077:             * 
078:             * @param nameCtx
079:             *            Ignored.
080:             * 
081:             * @param environment
082:             *            Environment to use in creating the underlying context, can be
083:             *            <code>null</code>.
084:             * 
085:             * @return The object created.
086:             * 
087:             * @throws ConfigurationException
088:             *             If <code>obj</code> is neither <code>null</code> nor a
089:             *             string, nor a string array, or is an empty string array.
090:             * 
091:             * @throws NamingException
092:             *             If lookup attempt failed.
093:             */
094:            public Object getObjectInstance(Object obj, Name name,
095:                    Context nameCtx, Hashtable<?, ?> environment)
096:                    throws NamingException {
097:                Context context = createURLContext(environment);
098:
099:                if (obj == null) {
100:                    // For null object - just return context.
101:                    return context;
102:                }
103:
104:                try {
105:                    if (obj instanceof  String) {
106:                        // For string object - return the object it names.
107:                        return context.lookup((String) obj);
108:                    }
109:
110:                    if (obj instanceof  String[]) {
111:                        // For string array object - search it through.
112:                        String[] strings = (String[]) obj;
113:
114:                        if (strings.length < 1) {
115:                            // jndi.2C=obj is an empty string array
116:                            throw new ConfigurationException(Messages
117:                                    .getString("jndi.2C")); //$NON-NLS-1$
118:                        }
119:
120:                        NamingException exception = null;
121:
122:                        for (String element : strings) {
123:                            try {
124:                                // If the valid object is found - return it.
125:                                return context.lookup(element);
126:                            } catch (NamingException e) {
127:                                // Invalid object, store the exception
128:                                // to throw it later if no valid object is found.
129:                                exception = e;
130:                            }
131:                        }
132:
133:                        // No valid object is found.
134:                        throw exception;
135:                    }
136:
137:                    // Unknown object type.
138:                    // jndi.2D=obj is neither null, nor a string, nor a string array:
139:                    // {0}
140:                    throw new IllegalArgumentException(Messages.getString(
141:                            "jndi.2D", obj)); //$NON-NLS-1$
142:                } finally {
143:                    context.close();
144:                }
145:            }
146:
147:            /**
148:             * Returns new instance of the necessary context. Used by
149:             * {@link #getObjectInstance(Object, Name, Context, Hashtable)}.
150:             * 
151:             * Must be overridden by particular URL context factory implementations.
152:             * 
153:             * @param environment
154:             *            Environment.
155:             * 
156:             * @return New context instance.
157:             */
158:            protected abstract Context createURLContext(
159:                    Hashtable<?, ?> environment);
160:
161:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.