1 22 package org.jboss.injection; 23 24 import org.jboss.naming.Util; 25 26 import javax.naming.NameNotFoundException ; 27 28 34 public class PuEncInjector implements EncInjector 35 { 36 private String encName; 37 private Class injectionType; 38 private String unitName; 39 private String error; 40 41 public PuEncInjector(String encName, Class injectionType, String unitName, String error) 42 { 43 this.encName = encName; 44 this.injectionType = injectionType; 45 this.error = error; 46 this.unitName = unitName; 47 } 48 49 public void inject(InjectionContainer container) 50 { 51 Object factory = null; 52 try 53 { 54 factory = PersistenceUnitHandler.getFactory(injectionType, unitName, container); 55 } 56 catch (NameNotFoundException e) 57 { 58 throw new RuntimeException (e); 59 } 60 if (factory == null) 61 { 62 throw new RuntimeException ("Failed to locate " + error + " of unit name: " + unitName + " for " + container.getIdentifier()); 63 } 64 65 try 66 { 67 Util.rebind(container.getEnc(), encName, factory); 68 } 69 catch (Exception e) 70 { 71 throw new RuntimeException ("Failed to bind " + error + " of unit name: " + unitName + " ref-name" + encName + " for container " + container.getIdentifier(), e); 72 } 73 } 74 } 75 | Popular Tags |