Source Code Cross Referenced for DirtyLittleCheatingContextFactory.java in  » J2EE » enhydra » jtaDiscRack » 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 » J2EE » enhydra » jtaDiscRack 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* DirtyLittleCheatingContextFactory.java */
002:        package jtaDiscRack;
003:
004:        import java.util.Hashtable;
005:        import java.util.Properties;
006:
007:        import javax.naming.*;
008:        import javax.naming.spi.InitialContextFactory;
009:        import javax.transaction.TransactionManager;
010:
011:        import org.enhydra.jdbc.standard.StandardXADataSource;
012:        import org.objectweb.jotm.Jotm;
013:
014:        public class DirtyLittleCheatingContextFactory implements 
015:                InitialContextFactory {
016:
017:            private static class Instance {
018:                static final Context value = new MyContext(null);
019:            }
020:
021:            public Context getInitialContext(Hashtable environment)
022:                    throws NamingException {
023:                return Instance.value;
024:            }
025:
026:            public static void setup(String[] datasourceNames) throws Exception {
027:                System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
028:                        DirtyLittleCheatingContextFactory.class.getName());
029:                System.setProperty(Context.URL_PKG_PREFIXES, "jtaDiscRack");
030:                Properties p = new Properties();
031:                InitialContext ictx = new InitialContext();
032:                TransactionManager tm = (TransactionManager) ictx
033:                        .lookup("java:comp/UserTransaction");
034:                for (int i = 0; i < datasourceNames.length; i++) {
035:                    try {
036:                        p.load(ClassLoader
037:                                .getSystemResourceAsStream(datasourceNames[i]
038:                                        + ".properties"));
039:                        StandardXADataSource xads = new StandardXADataSource();
040:                        xads.setDriverName(p
041:                                .getProperty("datasource.classname"));
042:                        xads.setUrl(p.getProperty("datasource.url"));
043:                        xads.setUser(p.getProperty("datasource.username"));
044:                        xads.setPassword(p.getProperty("datasource.password"));
045:                        xads.setMinCon(Integer.parseInt(p
046:                                .getProperty("jdbc.minconpool")));
047:                        xads.setMaxCon(Integer.parseInt(p
048:                                .getProperty("jdbc.maxconpool")));
049:                        xads.setTransactionManager(tm);
050:                        ictx.bind("java:comp/env/" + datasourceNames[i], xads);
051:                    } catch (Exception e) {
052:                        System.err.println("Configuration read for "
053:                                + datasourceNames[i] + " failed!");
054:                    } finally {
055:                        p.clear();
056:                    }
057:                }
058:            }
059:
060:            public static void main(String[] args) throws Throwable {
061:                new InitialContext().lookup("java:/Vidi");
062:                System.out
063:                        .println("\n" + new InitialContext().getEnvironment());
064:                Instance.value.close();
065:            }
066:        }
067:
068:        class MyContext implements  javax.naming.Context {
069:
070:            private Hashtable env;
071:
072:            private Hashtable collective;
073:
074:            private Jotm jotm;
075:
076:            public MyContext(Hashtable environment) {
077:                env = environment;
078:                collective = new Hashtable();
079:                try {
080:                    jotm = new Jotm(true, false);
081:                    bind("java:comp/env", this );
082:                    bind("java:comp/UserTransaction", jotm
083:                            .getTransactionManager());
084:                } catch (Exception e) {
085:                    throw new Error("FATAL", e);
086:                }
087:                System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
088:                        DirtyLittleCheatingContextFactory.class.getName());
089:                System.setProperty(Context.URL_PKG_PREFIXES, "jtaDiscRack");
090:            }
091:
092:            public void close() throws NamingException {
093:                collective = env = null;
094:                jotm.stop();
095:            }
096:
097:            public String getNameInNamespace() throws NamingException {
098:                new Throwable().printStackTrace();
099:                return null;
100:            }
101:
102:            public void destroySubcontext(String name) throws NamingException {
103:                new Throwable().printStackTrace();
104:
105:            }
106:
107:            public void unbind(String name) throws NamingException {
108:                new Throwable().printStackTrace();
109:
110:            }
111:
112:            public Hashtable getEnvironment() throws NamingException {
113:                return env;
114:            }
115:
116:            public void destroySubcontext(Name name) throws NamingException {
117:                new Throwable().printStackTrace();
118:
119:            }
120:
121:            public void unbind(Name name) throws NamingException {
122:                if (null == collective.remove(name))
123:                    throw new NamingException(name + " were not there!");
124:            }
125:
126:            public Object lookup(String name) throws NamingException {
127:                return lookup(new CompositeName(name));
128:            }
129:
130:            public Object lookupLink(String name) throws NamingException {
131:                new Throwable().printStackTrace();
132:                return null;
133:            }
134:
135:            public Object removeFromEnvironment(String propName)
136:                    throws NamingException {
137:                new Throwable().printStackTrace();
138:                return null;
139:            }
140:
141:            public void bind(String name, Object obj) throws NamingException {
142:                bind(new CompositeName(name), obj);
143:            }
144:
145:            public void rebind(String name, Object obj) throws NamingException {
146:                rebind(new CompositeName(name), obj);
147:            }
148:
149:            public Object lookup(Name name) throws NamingException {
150:                return collective.get(name);
151:            }
152:
153:            public Object lookupLink(Name name) throws NamingException {
154:                new Throwable().printStackTrace();
155:                return null;
156:            }
157:
158:            public void bind(Name name, Object obj) throws NamingException {
159:                collective.put(name, obj);
160:            }
161:
162:            public void rebind(Name name, Object obj) throws NamingException {
163:                collective.put(name, obj);
164:            }
165:
166:            public void rename(String oldName, String newName)
167:                    throws NamingException {
168:                new Throwable().printStackTrace();
169:
170:            }
171:
172:            public Context createSubcontext(String name) throws NamingException {
173:                new Throwable().printStackTrace();
174:                return null;
175:            }
176:
177:            public Context createSubcontext(Name name) throws NamingException {
178:                new Throwable().printStackTrace();
179:                return null;
180:            }
181:
182:            public void rename(Name oldName, Name newName)
183:                    throws NamingException {
184:                new Throwable().printStackTrace();
185:
186:            }
187:
188:            public NameParser getNameParser(String name) throws NamingException {
189:                new Throwable().printStackTrace();
190:                return null;
191:            }
192:
193:            public NameParser getNameParser(Name name) throws NamingException {
194:                new Throwable().printStackTrace();
195:                return null;
196:            }
197:
198:            public NamingEnumeration list(String name) throws NamingException {
199:                new Throwable().printStackTrace();
200:                return null;
201:            }
202:
203:            public NamingEnumeration listBindings(String name)
204:                    throws NamingException {
205:                new Throwable().printStackTrace();
206:                return null;
207:            }
208:
209:            public NamingEnumeration list(Name name) throws NamingException {
210:                new Throwable().printStackTrace();
211:                return null;
212:            }
213:
214:            public NamingEnumeration listBindings(Name name)
215:                    throws NamingException {
216:                new Throwable().printStackTrace();
217:                return null;
218:            }
219:
220:            public Object addToEnvironment(String propName, Object propVal)
221:                    throws NamingException {
222:                new Throwable().printStackTrace();
223:                return null;
224:            }
225:
226:            public String composeName(String name, String prefix)
227:                    throws NamingException {
228:                new Throwable().printStackTrace();
229:                return null;
230:            }
231:
232:            public Name composeName(Name name, Name prefix)
233:                    throws NamingException {
234:                new Throwable().printStackTrace();
235:                return null;
236:            }
237:
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.