1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 package org.jomc.standalone.ri.naming;
38
39 import java.lang.reflect.InvocationTargetException;
40 import java.lang.reflect.Method;
41 import java.util.Hashtable;
42 import javax.naming.Context;
43 import javax.naming.NamingException;
44 import javax.naming.spi.InitialContextFactory;
45 import org.jomc.standalone.ri.StandaloneEnvironment;
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
63
64
65 public class StandaloneContextFactory implements InitialContextFactory
66 {
67
68
69 private static Context instance;
70
71 public Context getInitialContext( final Hashtable env ) throws NamingException
72 {
73 synchronized ( StandaloneContextFactory.class )
74 {
75 try
76 {
77 if ( instance == null )
78 {
79 instance = new StandaloneContext();
80
81 if ( env != null )
82 {
83 System.getProperties().putAll( env );
84 instance.getEnvironment().putAll( env );
85
86 if ( this.getStandaloneEnvironment().getDataSourceContextFactoryName() != null )
87 {
88 final InitialContextFactory dataSourceContextFactory = (InitialContextFactory) Class.forName(
89 this.getStandaloneEnvironment().getDataSourceContextFactoryName() ).newInstance();
90
91 dataSourceContextFactory.getInitialContext( env );
92 }
93 if ( this.getStandaloneEnvironment().getJtaContextFactoryName() != null )
94 {
95 final InitialContextFactory jtaContextFactory = (InitialContextFactory) Class.forName(
96 this.getStandaloneEnvironment().getJtaContextFactoryName() ).newInstance();
97
98 jtaContextFactory.getInitialContext( env );
99 }
100 if ( this.getStandaloneEnvironment().getJpaContextFactoryName() != null )
101 {
102 final InitialContextFactory jpaContextFactory = (InitialContextFactory) Class.forName(
103 this.getStandaloneEnvironment().getJpaContextFactoryName() ).newInstance();
104
105 jpaContextFactory.getInitialContext( env );
106 }
107
108 this.isXAPoolInitialized();
109 }
110 }
111
112 return instance;
113 }
114 catch ( final InstantiationException e )
115 {
116 throw (NamingException) new NamingException( e.getMessage() ).initCause( e );
117 }
118 catch ( final IllegalAccessException e )
119 {
120 throw (NamingException) new NamingException( e.getMessage() ).initCause( e );
121 }
122 catch ( final ClassNotFoundException e )
123 {
124 throw (NamingException) new NamingException( e.getMessage() ).initCause( e );
125 }
126 }
127 }
128
129
130
131 private StandaloneEnvironment standaloneEnvironment;
132
133 public StandaloneEnvironment getStandaloneEnvironment()
134 {
135 if ( this.standaloneEnvironment == null )
136 {
137 this.standaloneEnvironment = new StandaloneEnvironment();
138 }
139
140 return this.standaloneEnvironment;
141 }
142
143 protected boolean isXAPoolInitialized()
144 {
145 try
146 {
147 Class.forName( "org.enhydra.jdbc.standard.StandardXADataSource" );
148 final Class helperClass = Class.forName( "org.jomc.standalone.ri.naming.support.XAPoolHelper" );
149 final Method helperMethod = helperClass.getDeclaredMethod(
150 "initializeXAPool", StandaloneEnvironment.class, Context.class );
151
152 helperMethod.invoke( null, this.getStandaloneEnvironment(), instance );
153 return true;
154 }
155 catch ( final IllegalAccessException e )
156 {
157 return false;
158 }
159 catch ( final InvocationTargetException e )
160 {
161 return false;
162 }
163 catch ( final NoSuchMethodException e )
164 {
165 return false;
166 }
167 catch ( final ClassNotFoundException e )
168 {
169 return false;
170 }
171 }
172
173
174
175
176
177
178 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
179 public StandaloneContextFactory()
180 {
181
182 super();
183
184 }
185
186
187
188
189
190
191
192
193 }