KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > relation > lcp > Session2Bean


1 package org.objectweb.jonas.jtests.beans.relation.lcp;
2
3 import javax.naming.Context JavaDoc;
4 import javax.naming.InitialContext JavaDoc;
5
6
7 public class Session2Bean implements javax.ejb.SessionBean JavaDoc {
8
9     // Variables
10
public javax.ejb.SessionContext JavaDoc ejbctx;
11
12     // Methods
13

14
15
16     /*****************************************************************************
17      *
18      * No args constructor
19      *
20      *****************************************************************************/

21     public Session2Bean() {
22         System.out.println(this.getClass().getName() + " - Successfully constructed session bean (EJB)");
23
24     }
25
26     /*****************************************************************************
27      *
28      * No args creator
29      *
30      *****************************************************************************/

31     public void ejbCreate() {
32         System.out.println(this.getClass().getName() + " - Successfully created session bean (EJB)");
33
34     }
35
36     /*****************************************************************************
37      *
38      * Remove bean
39      *
40      *****************************************************************************/

41     public void ejbRemove() {
42         System.out.println(this.getClass().getName() + " - Successfully removed session bean (EJB)");
43
44     }
45
46     /*****************************************************************************
47      *
48      * Passivate bean
49      *
50      *****************************************************************************/

51     public void ejbPassivate() {
52
53     }
54
55     /*****************************************************************************
56      *
57      * Activate bean
58      *
59      *****************************************************************************/

60     public void ejbActivate() {
61
62     }
63
64     /*****************************************************************************
65      *
66      * Sets the bean session context
67      *
68      *****************************************************************************/

69     public void setSessionContext(javax.ejb.SessionContext JavaDoc ctx) {
70         ejbctx = ctx;
71
72     }
73
74     public String JavaDoc getSimpleChildren(String JavaDoc id) {
75         try {
76             Context JavaDoc ic = new InitialContext JavaDoc();
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 JavaDoc childs = bean.getSimpleparentSimplechild();
83                 if (childs != null) {
84                     StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
85                     //ret.append("Parent desc:" + bean.getSpDesc() + "<br>");
86
int ct = 1;
87                     SIMPLECHILDLocal bean2 = null;
88                     java.util.Iterator JavaDoc i = childs.iterator();
89                     while (i.hasNext()) {
90                         bean2 = (SIMPLECHILDLocal) i.next();
91                         //ret.append("Child" + ct + ":" + bean2.getScDesc() + "<br>");
92
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 JavaDoc ne) {
106             return "Error: Unable to find parent & child (" + ne.getClass().getName() + ") - " + ne.getMessage();
107         }
108
109     }
110
111     public String JavaDoc getChildParent(String JavaDoc id) {
112         try {
113             Context JavaDoc ic = new InitialContext JavaDoc();
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 JavaDoc ret = new StringBuffer JavaDoc();
121                 if (par != null) {
122                     //ret.append("Child desc:" + bean.getScDesc() + "<br>");
123
//ret.append("Parent desc:" + par.getSpDesc() + "<br>");
124
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 JavaDoc ne) {
131             return "Error: Unable to find parent & child (" + ne.getClass().getName() + ") - " + ne.getMessage();
132         }
133
134     }
135
136
137 }
138
Popular Tags