1 22 package org.jboss.ejb3.test.reference21_30; 23 24 import javax.ejb.Init ; 25 import javax.ejb.Local ; 26 import javax.annotation.PreDestroy; 27 import javax.ejb.Remote ; 28 import javax.ejb.Stateful ; 29 import javax.naming.InitialContext ; 30 import org.jboss.annotation.ejb.LocalBinding; 31 import org.jboss.annotation.ejb.RemoteBinding; 32 import org.jboss.logging.Logger; 33 34 38 @Stateful (name="StatefulSession30") 39 @Local (LocalStatefulSession30.class) 40 @Remote (StatefulSession30.class) 41 @RemoteBinding(jndiBinding = "StatefulSession30") 42 @LocalBinding(jndiBinding = "LocalStatefulSession30") 43 public class StatefulSession30Bean implements java.io.Serializable 44 { 45 private static final Logger log = Logger.getLogger(StatefulSession30Bean.class); 46 47 private String value = null; 48 49 public void setValue(String value) 50 { 51 this.value = value; 52 } 53 54 public String getValue() 55 { 56 return value; 57 } 58 59 public void setLocalValue(String value) 60 { 61 this.value = value; 62 } 63 64 public String getLocalValue() 65 { 66 return value; 67 } 68 69 public String accessLocalStateless() 70 { 71 try { 72 InitialContext jndiContext = new InitialContext (); 73 Session30LocalHome localHome = (Session30LocalHome)jndiContext.lookup("LocalSession30Home"); 74 LocalSession30 localSession = localHome.create(); 75 return localSession.access(); 76 } catch (Exception e) 77 { 78 e.printStackTrace(); 79 return null; 80 } 81 } 82 83 public String accessLocalHome() 84 { 85 try 86 { 87 InitialContext jndiContext = new InitialContext (); 88 StatefulSession30LocalHome home = (StatefulSession30LocalHome)jndiContext.lookup("HomedLocalStatefulSession30Home"); 89 LocalStatefulSession30 session = (LocalStatefulSession30)home.create(); 90 session.setLocalValue("LocalHome"); 91 return session.getLocalValue(); 92 } catch (Exception e) 93 { 94 e.printStackTrace(); 95 return null; 96 } 97 98 } 99 100 @Init 101 public void ejbCreate() 102 { 103 value="default"; 104 } 105 106 @Init 107 public void ejbCreate(String value) 108 { 109 this.value=value; 110 } 111 112 @Init 113 public void ejbCreate(String value, Integer suffix) 114 { 115 this.value=value + suffix; 116 } 117 118 @PreDestroy 119 public void preDestroy() 120 { 121 log.info("Invoking PreDestroy"); 122 } 123 } 124 | Popular Tags |