Coverage Report - net.sf.webphotos.locator.BasicEJBLocator
 
Classes in this File Line Coverage Branch Coverage Complexity
BasicEJBLocator
0%
0/19
0%
0/2
1,667
 
 1  
 /**
 2  
  * Copyright 2008 WebPhotos
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package net.sf.webphotos.locator;
 17  
 
 18  
 import java.util.Hashtable;
 19  
 import javax.naming.Context;
 20  
 import javax.naming.InitialContext;
 21  
 import javax.naming.NamingException;
 22  
 import org.apache.log4j.Logger;
 23  
 
 24  
 /**
 25  
  *
 26  
  * @author Guilherme
 27  
  */
 28  0
 public class BasicEJBLocator {
 29  
 
 30  
         /**
 31  
      *
 32  
      */
 33  0
     protected InitialContext cachedContext = null;
 34  
         /**
 35  
      *
 36  
      */
 37  0
     public static String EJB_URL_PREFIXES = "org.jboss.naming";
 38  
         /**
 39  
      *
 40  
      */
 41  0
     public static String EJB_CONTEXT_FACTORY = "org.jnp.interfaces.NamingContextFactory";
 42  
         /**
 43  
      *
 44  
      */
 45  0
     public static String EJB_SERVER = "127.0.0.1:1099";
 46  
 
 47  0
         private static Logger logger = Logger.getLogger(BasicEJBLocator.class);
 48  
 
 49  
         /**
 50  
      *
 51  
      */
 52  
     public void initEJBContext() {
 53  
                 try {
 54  0
                         cachedContext = (InitialContext) getRemoteEJBsInitialContext();
 55  0
                 } catch (NamingException e) {
 56  0
                         logger.error("Erro fatal com context de EJBs", e);
 57  0
                 }
 58  0
         }
 59  
 
 60  
         /**
 61  
      *
 62  
      * @return
 63  
      */
 64  
     public InitialContext getEJBContext() {
 65  0
                 if (cachedContext == null) {
 66  0
                         initEJBContext();
 67  
                 }
 68  0
                 return cachedContext;
 69  
         }
 70  
 
 71  
         /**
 72  
      *
 73  
      * @return
 74  
      * @throws NamingException
 75  
      */
 76  
     public Context getRemoteEJBsInitialContext() throws NamingException {
 77  0
                 Hashtable<String, String> props = new Hashtable<String, String>();
 78  0
                 props.put(Context.INITIAL_CONTEXT_FACTORY, EJB_CONTEXT_FACTORY);
 79  0
                 props.put(Context.PROVIDER_URL, EJB_SERVER);
 80  0
                 props.put(Context.URL_PKG_PREFIXES, EJB_URL_PREFIXES);
 81  0
                 return new InitialContext(props);
 82  
         }
 83  
 
 84  
 }