1 package org.objectweb.jonas.jtests.beans.relation.lcp; 2 3 import javax.naming.Context ; 4 import javax.naming.InitialContext ; 5 6 7 public class Session2Bean implements javax.ejb.SessionBean { 8 9 public javax.ejb.SessionContext ejbctx; 11 12 14 15 16 21 public Session2Bean() { 22 System.out.println(this.getClass().getName() + " - Successfully constructed session bean (EJB)"); 23 24 } 25 26 31 public void ejbCreate() { 32 System.out.println(this.getClass().getName() + " - Successfully created session bean (EJB)"); 33 34 } 35 36 41 public void ejbRemove() { 42 System.out.println(this.getClass().getName() + " - Successfully removed session bean (EJB)"); 43 44 } 45 46 51 public void ejbPassivate() { 52 53 } 54 55 60 public void ejbActivate() { 61 62 } 63 64 69 public void setSessionContext(javax.ejb.SessionContext ctx) { 70 ejbctx = ctx; 71 72 } 73 74 public String getSimpleChildren(String id) { 75 try { 76 Context ic = new InitialContext (); 77 SIMPLEPARENTLocalHome home = (SIMPLEPARENTLocalHome) ic.lookup("java:comp/env/ejb/SIMPLEPARENT-local"); 78 SIMPLEPARENTPK pk = new SIMPLEPARENTPK(); 79 pk.spPkId = id; 80 SIMPLEPARENTLocal bean = home.findByPrimaryKey(pk); 81 if (bean != null) { 82 java.util.Collection childs = bean.getSimpleparentSimplechild(); 83 if (childs != null) { 84 StringBuffer ret = new StringBuffer (); 85 int ct = 1; 87 SIMPLECHILDLocal bean2 = null; 88 java.util.Iterator i = childs.iterator(); 89 while (i.hasNext()) { 90 bean2 = (SIMPLECHILDLocal) i.next(); 91 if (ct != 1) { 93 ret.append(","); 94 } 95 ret.append(bean2.getScDesc()); 96 ct++; 97 } 98 return ret.toString(); 99 } else { 100 return "Unable to find parent & child details (null childs bean)"; 101 } 102 } else { 103 return "Unable to find parent & child details (null parent bean)"; 104 } 105 } catch (Exception ne) { 106 return "Error: Unable to find parent & child (" + ne.getClass().getName() + ") - " + ne.getMessage(); 107 } 108 109 } 110 111 public String getChildParent(String id) { 112 try { 113 Context ic = new InitialContext (); 114 SIMPLECHILDLocalHome home = (SIMPLECHILDLocalHome) ic.lookup("java:comp/env/ejb/SIMPLECHILD-local"); 115 SIMPLECHILDPK pk = new SIMPLECHILDPK(); 116 pk.scPkId = id; 117 SIMPLECHILDLocal bean = home.findByPrimaryKey(pk); 118 if (bean != null) { 119 SIMPLEPARENTLocal par = bean.getSimplechildSimpleparent(); 120 StringBuffer ret = new StringBuffer (); 121 if (par != null) { 122 ret.append(par.getSpDesc()); 125 } 126 return ret.toString(); 127 } else { 128 return "Unable to find parent of child details (null child bean)"; 129 } 130 } catch (Exception ne) { 131 return "Error: Unable to find parent & child (" + ne.getClass().getName() + ") - " + ne.getMessage(); 132 } 133 134 } 135 136 137 } 138 | Popular Tags |