Source Code Cross Referenced for componentURLContextFactory.java in  » UML » MetaBoss » com » metaboss » naming » component » 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 » UML » MetaBoss » com.metaboss.naming.component 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002:        // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003:        // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004:        // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005:        // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006:        // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007:        // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008:        // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009:        // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010:        // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011:        // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012:        // POSSIBILITY OF SUCH DAMAGE.
013:        //
014:        // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015:        package com.metaboss.naming.component;
016:
017:        import java.util.Collections;
018:        import java.util.HashMap;
019:        import java.util.Hashtable;
020:        import java.util.Map;
021:
022:        import javax.naming.ConfigurationException;
023:        import javax.naming.Context;
024:        import javax.naming.Name;
025:        import javax.naming.NamingException;
026:        import javax.naming.spi.ObjectFactory;
027:
028:        import org.apache.commons.logging.Log;
029:        import org.apache.commons.logging.LogFactory;
030:
031:        /** A 'component:/....' URL context factory. */
032:        public class componentURLContextFactory implements  ObjectFactory {
033:            private static final Log sLogger = LogFactory
034:                    .getLog(componentURLContextFactory.class);
035:
036:            // Name of the system property which controlls if we should cache the factories once they are found for the particular caller 
037:            private static final String sEnableContextCachingSystemPropertyKey = "com.metaboss.naming.component.EnableContextCaching";
038:            private static Map sContextsMap = null;
039:            private static boolean sEnableContextCaching = true;
040:
041:            static {
042:                // Find out if context caching is enabled or disabled
043:                sEnableContextCaching = Boolean
044:                        .valueOf(
045:                                System.getProperty(
046:                                        sEnableContextCachingSystemPropertyKey,
047:                                        "true")).booleanValue();
048:                if (sEnableContextCaching)
049:                    sContextsMap = Collections.synchronizedMap(new HashMap());
050:
051:                if (sLogger.isDebugEnabled())
052:                    sLogger.debug("Component factory caching is "
053:                            + (sEnableContextCaching ? "enabled" : "disabled"));
054:            }
055:
056:            /** Must have public no-arg constructor. */
057:            public componentURLContextFactory() {
058:            }
059:
060:            /**  The "component" url is of the form component:/<name of interface>. */
061:            public Object getObjectInstance(Object urlInfo, Name name,
062:                    Context nameCtx, Hashtable env) throws Exception {
063:
064:                // Case 1: urlInfo is null
065:                // This means to create a URL context that can accept
066:                // arbitrary "foo" URLs.
067:                if (urlInfo == null) {
068:                    return createURLContext(env);
069:                }
070:
071:                // Case 2: urlInfo is a single string
072:                // This means to create/get the object named by urlInfo
073:                if (urlInfo instanceof  String) {
074:                    Context urlCtx = createURLContext(env);
075:                    try {
076:                        return urlCtx.lookup((String) urlInfo);
077:                    } finally {
078:                        urlCtx.close();
079:                    }
080:                }
081:
082:                // Case 3: urlInfo is an array of strings
083:                // This means each entry in array is equal alternative; create/get
084:                // the object named by one of the URls
085:                if (urlInfo instanceof  String[]) {
086:
087:                    // Try each URL until lookup() succeeds for one of them.
088:                    // If all URLs fail, throw one of the exceptions arbitrarily.
089:                    String[] urls = (String[]) urlInfo;
090:                    if (urls.length == 0) {
091:                        throw (new ConfigurationException(
092:                                "componentURLContextFactory: empty URL array"));
093:                    }
094:                    Context urlCtx = createURLContext(env);
095:                    try {
096:                        NamingException ne = null;
097:                        for (int i = 0; i < urls.length; i++) {
098:                            try {
099:                                return urlCtx.lookup(urls[i]);
100:                            } catch (NamingException e) {
101:                                ne = e;
102:                            }
103:                        }
104:                        throw ne;
105:                    } finally {
106:                        urlCtx.close();
107:                    }
108:                }
109:
110:                // Case 4: urlInfo is of an unknown type
111:                // Provider-specific action: reject input
112:
113:                throw new IllegalArgumentException(
114:                        "Argument must be a component URL string or an array of them");
115:            }
116:
117:            protected Context createURLContext(Hashtable env)
118:                    throws NamingException {
119:                if (sEnableContextCaching) {
120:                    // Work with the cache of the contexts
121:                    Context lContext = (Context) sContextsMap.get(env);
122:                    if (lContext == null) {
123:                        if (sLogger.isDebugEnabled()) {
124:                            sLogger
125:                                    .debug("Creating new JNDI context for the 'component:.....' URLs env = "
126:                                            + env.toString());
127:                        }
128:                        sContextsMap.put(env, lContext = new componentContext(
129:                                env));
130:                    } else {
131:                        if (sLogger.isDebugEnabled()) {
132:                            sLogger
133:                                    .debug("Reusing existing JNDI context for the 'component:.....' URLs env = "
134:                                            + env.toString());
135:                        }
136:                    }
137:                    return lContext;
138:                } else {
139:                    // Always return new context
140:                    return new componentContext(env);
141:                }
142:            }
143:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.