1 package org.directwebremoting.create; 2 3 import java.util.Properties ; 4 5 import javax.naming.Context ; 6 import javax.naming.InitialContext ; 7 8 import org.directwebremoting.extend.Creator; 9 import org.directwebremoting.util.LocalUtil; 10 import org.directwebremoting.util.Messages; 11 12 17 public class Ejb3Creator extends AbstractCreator implements Creator 18 { 19 26 public void setInterface(String className) 27 { 28 this.className = className; 29 this.bean = className.substring(className.lastIndexOf('.') + 1); 30 } 31 32 36 public void setBean(String bean) 37 { 38 this.bean = bean; 39 } 40 41 46 public void setInterfaceType(String iface) 47 { 48 remote = !iface.equalsIgnoreCase(LOCAL); 49 } 50 51 56 public void setBeanNamePostfix(String beanNamePostfix) 57 { 58 this.beanNamePostfix = beanNamePostfix; 59 } 60 61 64 public Class getType() 65 { 66 try 67 { 68 return LocalUtil.classForName(className); 69 } 70 catch (ClassNotFoundException ex) 71 { 72 throw new IllegalArgumentException (Messages.getString("Creator.BeanClassNotFound", className)); 73 } 74 } 75 76 79 public Object getInstance() throws InstantiationException 80 { 81 String type = remote ? "remote" : "local"; 82 83 try 84 { 85 Properties props = new Properties (); 86 props.load(getClass().getResourceAsStream("/jndi.properties")); 87 Context jndi = new InitialContext (props); 88 89 return jndi.lookup(bean + beanNamePostfix + "/" + type); 90 } 91 catch (Exception ex) 92 { 93 throw new InstantiationException (bean + "/" + type + " not bound:" + ex.getMessage()); 94 } 95 } 96 97 100 private final static String LOCAL = "local"; 101 102 105 private boolean remote = true; 106 107 110 private String bean; 111 112 115 private String className; 116 117 120 private String beanNamePostfix = "Bean"; 121 } 122 | Popular Tags |