Clover coverage report - JFox Service-Oriented Application Framework - 1.0-M2 Coverage timestamp: 星期四 十一月 25 2004 17:14:11 PST FRAMES NO FRAMES |
file stats: | LOC: | 283 |  | Methods: | 12
| NCLOC: | 205 |  | Classes: | 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
Source file | Conditionals | Statements | Methods | TOTAL
ServiceLocatorImpl.java | 12.5% | 12.4% | 25% | 13.6% |

1 |  |
     /**
2 |  |
      * JFoxSOAF, Service-Oriented Application Framework
3 |  |
      *
4 |  |
      * Copyright (C) www.huihoo.org
5 |  |
      *
6 |  |
      * Distributable under GNU LGPL
7 |  |
      *
8 |  |
      * For more information, please visit: http://www.huihoo.org/jfox/jfoxsoaf
9 |  |
      */
10 |  |
11 |  |
     package org.huihoo.jfox.soaf.services.ejb;
12 |  |
13 |  |
     import java.net.URL;
14 |  |
     import java.util.Collections;
15 |  |
     import java.util.HashMap;
16 |  |
     import java.util.Map;
17 |  |
18 |  |
     import javax.ejb.EJBHome;
19 |  |
     import javax.ejb.EJBLocalHome;
20 |  |
     import javax.jms.Queue;
21 |  |
     import javax.jms.QueueConnectionFactory;
22 |  |
     import javax.jms.Topic;
23 |  |
     import javax.jms.TopicConnectionFactory;
24 |  |
     import javax.mail.Session;
25 |  |
     import javax.naming.InitialContext;
26 |  |
     import javax.naming.NamingException;
27 |  |
     import javax.rmi.PortableRemoteObject;
28 |  |
     import javax.sql.DataSource;
29 |  |
30 |  |
     import org.huihoo.jfox.soaf.exception.ServiceLocatorException;
31 |  |
     import org.huihoo.jfox.soaf.services.logging.LoggingService;
32 |  |
33 |  |
     /**
34 |  |
      * <p>
35 |  |
      * ServiceLocator Implementation.
36 |  |
      * </p>
37 |  |
      *
38 |  |
      * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
39 |  |
      * @version $Revision: 1.7 $ $Date: 2004/11/16 10:26:42 $
40 |  |
      * @version Revision: 1.0
41 |  |
      */
42 |  |
43 |  |
     public class ServiceLocatorImpl implements ServiceLocator {
44 |  |
45 |  |
         private InitialContext ic = null;
46 |  |
47 |  |
         private Map cache = null;
48 |  |
49 |  |
         private LoggingService logger = null;
50 |  |
51 |  |
         private DataSource dataSource = null;
52 |  |
53 |  |
         private Session mailSession = null;
54 |  |
55 | 6 |
         public ServiceLocatorImpl() throws ServiceLocatorException {
56 | 6 |
             try {
57 | 6 |
                 ic = new InitialContext();
58 | 6 |
                 cache = Collections.synchronizedMap(new HashMap());
59 |  |
             } catch (NamingException ne) {
60 | 0 |
                 logger.error("ServiceService NamingException " + ne.getMessage());
61 | 0 |
                 throw new ServiceLocatorException(ne);
62 |  |
             } catch (Exception e) {
63 | 0 |
                 logger.error("ServiceLocator Exception " + e.getMessage());
64 | 0 |
                 throw new ServiceLocatorException(e);
65 |  |
             }
66 |  |
         }
67 |  |
68 |  |
         /**
69 |  |
          * @see org.huihoo.jfox.soaf.services.ejb.ServiceLocator#getBoolean(java.lang.String)
70 |  |
          */
71 | 0 |
         public boolean getBoolean(String envName) throws ServiceLocatorException {
72 | 0 |
             Boolean bool = null;
73 | 0 |
             try {
74 | 0 |
                 bool = (Boolean) ic.lookup(envName);
75 |  |
             } catch (NamingException ne) {
76 | 0 |
                 throw new ServiceLocatorException(ne);
77 |  |
             } catch (Exception e) {
78 | 0 |
                 throw new ServiceLocatorException(e);
79 |  |
             }
80 | 0 |
             return bool.booleanValue();
81 |  |
         }
82 |  |
83 |  |
         /**
84 |  |
          * @see org.huihoo.jfox.soaf.services.ejb.ServiceLocator#getLocalHome(java.lang.String)
85 |  |
          */
86 | 0 |
         public EJBLocalHome getLocalHome(String jndiHomeName)
87 |  |
                 throws ServiceLocatorException {
88 | 0 |
             EJBLocalHome home = null;
89 | 0 |
             try {
90 | 0 |
                 if (cache.containsKey(jndiHomeName)) {
91 | 0 |
                     home = (EJBLocalHome) cache.get(jndiHomeName);
92 |  |
                 } else {
93 | 0 |
                     home = (EJBLocalHome) ic.lookup(jndiHomeName);
94 | 0 |
                     cache.put(jndiHomeName, home);
95 |  |
                 }
96 |  |
             } catch (NamingException ne) {
97 | 0 |
                 throw new ServiceLocatorException(ne);
98 |  |
             } catch (Exception e) {
99 | 0 |
                 throw new ServiceLocatorException(e);
100 |  |
             }
101 | 0 |
             return home;
102 |  |
         }
103 |  |
104 |  |
         /**
105 |  |
          * @see org.huihoo.jfox.soaf.services.ejb.ServiceLocator#getRemoteHome(java.lang.String,
106 |  |
          *      java.lang.ClassLoadProxy)
107 |  |
          */
108 | 2 |
         public EJBHome getRemoteHome(String jndiHomeName, Class className)
109 |  |
                 throws ServiceLocatorException {
110 | 2 |
             EJBHome home = null;
111 | 2 |
             try {
112 | 2 |
                 if (cache.containsKey(jndiHomeName)) {
113 | 0 |
                     home = (EJBHome) cache.get(jndiHomeName);
114 |  |
                 } else {
115 | 2 |
                     Object objref = ic.lookup(jndiHomeName);
116 | 0 |
                     Object obj = PortableRemoteObject.narrow(objref, className);
117 | 0 |
                     home = (EJBHome) obj;
118 | 0 |
                     cache.put(jndiHomeName, home);
119 |  |
                 }
120 |  |
             } catch (NamingException ne) {
121 | 2 |
                 throw new ServiceLocatorException(ne);
122 |  |
             } catch (Exception e) {
123 | 0 |
                 throw new ServiceLocatorException(e);
124 |  |
             }
125 | 0 |
             return home;
126 |  |
         }
127 |  |
128 |  |
         /**
129 |  |
          * @see org.huihoo.jfox.soaf.services.ejb.ServiceLocator#getQueue(java.lang.String)
130 |  |
          */
131 | 0 |
         public Queue getQueue(String queueName) throws ServiceLocatorException {
132 | 0 |
             Queue queue = null;
133 | 0 |
             try {
134 | 0 |
                 if (cache.containsKey(queueName)) {
135 | 0 |
                     queue = (Queue) cache.get(queueName);
136 |  |
                 } else {
137 | 0 |
                     queue = (Queue) ic.lookup(queueName);
138 | 0 |
                     cache.put(queueName, queue);
139 |  |
                 }
140 |  |
             } catch (NamingException ne) {
141 | 0 |
                 throw new ServiceLocatorException(ne);
142 |  |
             } catch (Exception e) {
143 | 0 |
                 throw new ServiceLocatorException(e);
144 |  |
             }
145 | 0 |
             return queue;
146 |  |
         }
147 |  |
148 |  |
         /**
149 |  |
          * @see org.huihoo.jfox.soaf.services.ejb.ServiceLocator#getQueueConnectionFactory(java.lang.String)
150 |  |
          */
151 | 0 |
         public QueueConnectionFactory getQueueConnectionFactory(
152 |  |
                 String qConnFactoryName) throws ServiceLocatorException {
153 | 0 |
             QueueConnectionFactory factory = null;
154 | 0 |
             try {
155 | 0 |
                 if (cache.containsKey(qConnFactoryName)) {
156 | 0 |
                     factory = (QueueConnectionFactory) cache.get(qConnFactoryName);
157 |  |
                 } else {
158 | 0 |
                     factory = (QueueConnectionFactory) ic.lookup(qConnFactoryName);
159 | 0 |
                     cache.put(qConnFactoryName, factory);
160 |  |
                 }
161 |  |
             } catch (NamingException ne) {
162 | 0 |
                 throw new ServiceLocatorException(ne);
163 |  |
             } catch (Exception e) {
164 | 0 |
                 throw new ServiceLocatorException(e);
165 |  |
             }
166 | 0 |
             return factory;
167 |  |
         }
168 |  |
169 |  |
         /**
170 |  |
          * @see org.huihoo.jfox.soaf.services.ejb.ServiceLocator#getTopic(java.lang.String)
171 |  |
          */
172 | 0 |
         public Topic getTopic(String topicName) throws ServiceLocatorException {
173 | 0 |
             Topic topic = null;
174 | 0 |
             try {
175 | 0 |
                 if (cache.containsKey(topicName)) {
176 | 0 |
                     topic = (Topic) cache.get(topicName);
177 |  |
                 } else {
178 | 0 |
                     topic = (Topic) ic.lookup(topicName);
179 | 0 |
                     cache.put(topicName, topic);
180 |  |
                 }
181 |  |
             } catch (NamingException ne) {
182 | 0 |
                 throw new ServiceLocatorException(ne);
183 |  |
             } catch (Exception e) {
184 | 0 |
                 throw new ServiceLocatorException(e);
185 |  |
             }
186 | 0 |
             return topic;
187 |  |
         }
188 |  |
189 |  |
         /**
190 |  |
          * @see org.huihoo.jfox.soaf.services.ejb.ServiceLocator#getTopicConnectionFactory(java.lang.String)
191 |  |
          */
192 | 0 |
         public TopicConnectionFactory getTopicConnectionFactory(
193 |  |
                 String topicConnFactoryName) throws ServiceLocatorException {
194 | 0 |
             TopicConnectionFactory factory = null;
195 | 0 |
             try {
196 | 0 |
                 if (cache.containsKey(topicConnFactoryName)) {
197 | 0 |
                     factory = (TopicConnectionFactory) cache
198 |  |
                             .get(topicConnFactoryName);
199 |  |
                 } else {
200 | 0 |
                     factory = (TopicConnectionFactory) ic
201 |  |
                             .lookup(topicConnFactoryName);
202 | 0 |
                     cache.put(topicConnFactoryName, factory);
203 |  |
                 }
204 |  |
             } catch (NamingException ne) {
205 | 0 |
                 throw new ServiceLocatorException(ne);
206 |  |
             } catch (Exception e) {
207 | 0 |
                 throw new ServiceLocatorException(e);
208 |  |
             }
209 | 0 |
             return factory;
210 |  |
         }
211 |  |
212 |  |
         /**
213 |  |
          * @see org.huihoo.jfox.soaf.services.ejb.ServiceLocator#getDataSource(java.lang.String)
214 |  |
          */
215 | 1 |
         public DataSource getDataSource(String dataSourceName)
216 |  |
                 throws ServiceLocatorException {
217 |  |
218 | 1 |
             try {
219 | 1 |
                 if (cache.containsKey(dataSourceName)) {
220 | 0 |
                     dataSource = (DataSource) cache.get(dataSourceName);
221 |  |
                 } else {
222 | 1 |
                     dataSource = (DataSource) ic.lookup(dataSourceName);
223 | 0 |
                     cache.put(dataSourceName, dataSource);
224 |  |
                 }
225 |  |
             } catch (NamingException ne) {
226 | 1 |
                 throw new ServiceLocatorException(ne);
227 |  |
             } catch (Exception e) {
228 | 0 |
                 throw new ServiceLocatorException(e);
229 |  |
             }
230 | 0 |
             return dataSource;
231 |  |
         }
232 |  |
233 |  |
         /**
234 |  |
          * @see org.huihoo.jfox.soaf.services.ejb.ServiceLocator#getDataSource(java.lang.String)
235 |  |
          */
236 | 0 |
         public Session getMailSession(String mailSessionName)
237 |  |
                 throws ServiceLocatorException {
238 |  |
239 | 0 |
             try {
240 | 0 |
                 if (cache.containsKey(mailSessionName)) {
241 | 0 |
                     mailSession = (Session) cache.get(mailSessionName);
242 |  |
                 } else {
243 | 0 |
                     mailSession = (Session) ic.lookup(mailSessionName);
244 | 0 |
                     cache.put(mailSessionName, mailSession);
245 |  |
                 }
246 |  |
             } catch (NamingException ne) {
247 | 0 |
                 throw new ServiceLocatorException(ne);
248 |  |
             } catch (Exception e) {
249 | 0 |
                 throw new ServiceLocatorException(e);
250 |  |
             }
251 | 0 |
             return mailSession;
252 |  |
         }
253 |  |
254 |  |
         /**
255 |  |
          * @see org.huihoo.jfox.soaf.services.ejb.ServiceLocator#getString(java.lang.String)
256 |  |
          */
257 | 0 |
         public String getString(String envName) throws ServiceLocatorException {
258 | 0 |
             String envEntry = null;
259 | 0 |
             try {
260 | 0 |
                 envEntry = (String) ic.lookup(envName);
261 |  |
             } catch (NamingException ne) {
262 | 0 |
                 throw new ServiceLocatorException(ne);
263 |  |
             } catch (Exception e) {
264 | 0 |
                 throw new ServiceLocatorException(e);
265 |  |
             }
266 | 0 |
             return envEntry;
267 |  |
         }
268 |  |
269 |  |
         /**
270 |  |
          * @see org.huihoo.jfox.soaf.services.ejb.ServiceLocator#getUrl(java.lang.String)
271 |  |
          */
272 | 0 |
         public URL getUrl(String envName) throws ServiceLocatorException {
273 | 0 |
             URL url = null;
274 | 0 |
             try {
275 | 0 |
                 url = (URL) ic.lookup(envName);
276 |  |
             } catch (NamingException ne) {
277 | 0 |
                 throw new ServiceLocatorException(ne);
278 |  |
             } catch (Exception e) {
279 | 0 |
                 throw new ServiceLocatorException(e);
280 |  |
             }
281 | 0 |
             return url;
282 |  |
         }
283 |  |
     }