Source Code Cross Referenced for MockInitialContextFactory.java in  » Database-JDBC-Connection-Pool » HA-JDBC » net » sf » hajdbc » sql » 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 » Database JDBC Connection Pool » HA JDBC » net.sf.hajdbc.sql 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * HA-JDBC: High-Availability JDBC
003:         * Copyright (c) 2004-2007 Paul Ferraro
004:         * 
005:         * This library is free software; you can redistribute it and/or modify it 
006:         * under the terms of the GNU Lesser General Public License as published by the 
007:         * Free Software Foundation; either version 2.1 of the License, or (at your 
008:         * option) any later version.
009:         * 
010:         * This library is distributed in the hope that it will be useful, but WITHOUT
011:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
012:         * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 
013:         * for more details.
014:         * 
015:         * You should have received a copy of the GNU Lesser General Public License
016:         * along with this library; if not, write to the Free Software Foundation, 
017:         * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:         * 
019:         * Contact: ferraro@users.sourceforge.net
020:         */
021:        package net.sf.hajdbc.sql;
022:
023:        import java.util.HashMap;
024:        import java.util.Hashtable;
025:        import java.util.Map;
026:
027:        import javax.naming.Binding;
028:        import javax.naming.CompositeName;
029:        import javax.naming.Context;
030:        import javax.naming.Name;
031:        import javax.naming.NameClassPair;
032:        import javax.naming.NameNotFoundException;
033:        import javax.naming.NameParser;
034:        import javax.naming.NamingEnumeration;
035:        import javax.naming.NamingException;
036:        import javax.naming.Reference;
037:        import javax.naming.Referenceable;
038:        import javax.naming.spi.InitialContextFactory;
039:        import javax.naming.spi.ObjectFactory;
040:
041:        /**
042:         * Mock initial context factory that creates mock contexts.
043:         * 
044:         * @author  Paul Ferraro
045:         * @since   1.1
046:         */
047:        public class MockInitialContextFactory implements  InitialContextFactory {
048:            private static ThreadLocal<Context> threadLocal = new ThreadLocal<Context>() {
049:                /**
050:                 * @see java.lang.ThreadLocal#initialValue()
051:                 */
052:                @Override
053:                protected Context initialValue() {
054:                    return new MockContext();
055:                }
056:            };
057:
058:            /**
059:             * @see javax.naming.spi.InitialContextFactory#getInitialContext(java.util.Hashtable)
060:             */
061:            public Context getInitialContext(Hashtable<?, ?> environment) {
062:                return threadLocal.get();
063:            }
064:
065:            /**
066:             * @author  Paul Ferraro
067:             * @since   1.1
068:             */
069:            public static class MockContext implements  Context {
070:                private Map<String, Reference> referenceMap = new HashMap<String, Reference>();
071:
072:                /**
073:                 * @see javax.naming.Context#lookup(javax.naming.Name)
074:                 */
075:                public Object lookup(Name name) throws NamingException {
076:                    return this .lookup(name.toString());
077:                }
078:
079:                /**
080:                 * @see javax.naming.Context#lookup(java.lang.String)
081:                 */
082:                public Object lookup(String name) throws NamingException {
083:                    Reference reference = this .referenceMap.get(name);
084:
085:                    if (reference == null) {
086:                        throw new NameNotFoundException(name);
087:                    }
088:
089:                    try {
090:                        ObjectFactory factory = (ObjectFactory) Thread
091:                                .currentThread().getContextClassLoader()
092:                                .loadClass(reference.getFactoryClassName())
093:                                .newInstance();
094:
095:                        return factory.getObjectInstance(reference,
096:                                new CompositeName(name), this , null);
097:                    } catch (Exception e) {
098:                        NamingException exception = new NamingException();
099:                        exception.setRootCause(e);
100:                        exception.initCause(e);
101:
102:                        throw exception;
103:                    }
104:                }
105:
106:                /**
107:                 * @see javax.naming.Context#bind(javax.naming.Name, java.lang.Object)
108:                 */
109:                public void bind(Name name, Object object)
110:                        throws NamingException {
111:                    this .bind(name.toString(), object);
112:                }
113:
114:                /**
115:                 * @see javax.naming.Context#bind(java.lang.String, java.lang.Object)
116:                 */
117:                public void bind(String name, Object object)
118:                        throws NamingException {
119:                    Reference reference = null;
120:
121:                    if (Reference.class.isInstance(object)) {
122:                        reference = (Reference) object;
123:                    } else if (Referenceable.class.isInstance(object)) {
124:                        reference = ((Referenceable) object).getReference();
125:                    } else {
126:                        throw new NamingException(
127:                                "Must extend javax.naming.Reference or implement javax.naming.Referenceable"); //$NON-NLS-1$
128:                    }
129:
130:                    this .referenceMap.put(name, reference);
131:                }
132:
133:                /**
134:                 * @see javax.naming.Context#rebind(javax.naming.Name, java.lang.Object)
135:                 */
136:                public void rebind(Name name, Object object)
137:                        throws NamingException {
138:                    this .rebind(name.toString(), object);
139:                }
140:
141:                /**
142:                 * @see javax.naming.Context#rebind(java.lang.String, java.lang.Object)
143:                 */
144:                public void rebind(String name, Object object)
145:                        throws NamingException {
146:                    this .bind(name, object);
147:                }
148:
149:                /**
150:                 * @see javax.naming.Context#unbind(javax.naming.Name)
151:                 */
152:                public void unbind(Name name) {
153:                    this .unbind(name.toString());
154:                }
155:
156:                /**
157:                 * @see javax.naming.Context#unbind(java.lang.String)
158:                 */
159:                public void unbind(String name) {
160:                    this .referenceMap.remove(name);
161:                }
162:
163:                /**
164:                 * @see javax.naming.Context#rename(javax.naming.Name, javax.naming.Name)
165:                 */
166:                public void rename(Name oldName, Name newName) {
167:                    this .rename(oldName.toString(), newName.toString());
168:                }
169:
170:                /**
171:                 * @see javax.naming.Context#rename(java.lang.String, java.lang.String)
172:                 */
173:                public void rename(String oldName, String newName) {
174:                    this .referenceMap.put(newName, this .referenceMap
175:                            .remove(oldName));
176:                }
177:
178:                /**
179:                 * @see javax.naming.Context#list(javax.naming.Name)
180:                 */
181:                public NamingEnumeration<NameClassPair> list(Name name) {
182:                    return null;
183:                }
184:
185:                /**
186:                 * @see javax.naming.Context#list(java.lang.String)
187:                 */
188:                public NamingEnumeration<NameClassPair> list(String name) {
189:                    return null;
190:                }
191:
192:                /**
193:                 * @see javax.naming.Context#listBindings(javax.naming.Name)
194:                 */
195:                public NamingEnumeration<Binding> listBindings(Name name) {
196:                    return null;
197:                }
198:
199:                /**
200:                 * @see javax.naming.Context#listBindings(java.lang.String)
201:                 */
202:                public NamingEnumeration<Binding> listBindings(String name) {
203:                    return null;
204:                }
205:
206:                /**
207:                 * @see javax.naming.Context#destroySubcontext(javax.naming.Name)
208:                 */
209:                public void destroySubcontext(Name name) {
210:                }
211:
212:                /**
213:                 * @see javax.naming.Context#destroySubcontext(java.lang.String)
214:                 */
215:                public void destroySubcontext(String name) {
216:                }
217:
218:                /**
219:                 * @see javax.naming.Context#createSubcontext(javax.naming.Name)
220:                 */
221:                public Context createSubcontext(Name name) {
222:                    return null;
223:                }
224:
225:                /**
226:                 * @see javax.naming.Context#createSubcontext(java.lang.String)
227:                 */
228:                public Context createSubcontext(String name) {
229:                    return null;
230:                }
231:
232:                /**
233:                 * @see javax.naming.Context#lookupLink(javax.naming.Name)
234:                 */
235:                public Object lookupLink(Name name) {
236:                    return null;
237:                }
238:
239:                /**
240:                 * @see javax.naming.Context#lookupLink(java.lang.String)
241:                 */
242:                public Object lookupLink(String name) {
243:                    return null;
244:                }
245:
246:                /**
247:                 * @see javax.naming.Context#getNameParser(javax.naming.Name)
248:                 */
249:                public NameParser getNameParser(Name name) {
250:                    return null;
251:                }
252:
253:                /**
254:                 * @see javax.naming.Context#getNameParser(java.lang.String)
255:                 */
256:                public NameParser getNameParser(String name) {
257:                    return null;
258:                }
259:
260:                /**
261:                 * @see javax.naming.Context#composeName(javax.naming.Name, javax.naming.Name)
262:                 */
263:                public Name composeName(Name arg0, Name arg1) {
264:                    return null;
265:                }
266:
267:                /**
268:                 * @see javax.naming.Context#composeName(java.lang.String, java.lang.String)
269:                 */
270:                public String composeName(String arg0, String arg1) {
271:                    return null;
272:                }
273:
274:                /**
275:                 * @see javax.naming.Context#addToEnvironment(java.lang.String, java.lang.Object)
276:                 */
277:                public Object addToEnvironment(String arg0, Object arg1) {
278:                    return null;
279:                }
280:
281:                /**
282:                 * @see javax.naming.Context#removeFromEnvironment(java.lang.String)
283:                 */
284:                public Object removeFromEnvironment(String arg0) {
285:                    return null;
286:                }
287:
288:                /**
289:                 * @see javax.naming.Context#getEnvironment()
290:                 */
291:                public Hashtable<?, ?> getEnvironment() {
292:                    return null;
293:                }
294:
295:                /**
296:                 * @see javax.naming.Context#close()
297:                 */
298:                public void close() {
299:                    this .referenceMap.clear();
300:                }
301:
302:                /**
303:                 * @see javax.naming.Context#getNameInNamespace()
304:                 */
305:                public String getNameInNamespace() {
306:                    return null;
307:                }
308:            }
309:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.