001: package org.objectweb.jonas.jtests.beans.relation.lcp;
002:
003: import javax.naming.Context;
004: import javax.naming.InitialContext;
005:
006: public class Session2Bean implements javax.ejb.SessionBean {
007:
008: // Variables
009: public javax.ejb.SessionContext ejbctx;
010:
011: // Methods
012:
013: /*****************************************************************************
014: *
015: * No args constructor
016: *
017: *****************************************************************************/
018: public Session2Bean() {
019: }
020:
021: /*****************************************************************************
022: *
023: * No args creator
024: *
025: *****************************************************************************/
026: public void ejbCreate() {
027: }
028:
029: /*****************************************************************************
030: *
031: * Remove bean
032: *
033: *****************************************************************************/
034: public void ejbRemove() {
035: }
036:
037: /*****************************************************************************
038: *
039: * Passivate bean
040: *
041: *****************************************************************************/
042: public void ejbPassivate() {
043:
044: }
045:
046: /*****************************************************************************
047: *
048: * Activate bean
049: *
050: *****************************************************************************/
051: public void ejbActivate() {
052:
053: }
054:
055: /*****************************************************************************
056: *
057: * Sets the bean session context
058: *
059: *****************************************************************************/
060: public void setSessionContext(javax.ejb.SessionContext ctx) {
061: ejbctx = ctx;
062:
063: }
064:
065: public String getSimpleChildren(String id) {
066: try {
067: Context ic = new InitialContext();
068: SIMPLEPARENTLocalHome home = (SIMPLEPARENTLocalHome) ic
069: .lookup("java:comp/env/ejb/SIMPLEPARENT-local");
070: SIMPLEPARENTPK pk = new SIMPLEPARENTPK();
071: pk.spPkId = id;
072: SIMPLEPARENTLocal bean = home.findByPrimaryKey(pk);
073: if (bean != null) {
074: java.util.Collection childs = bean
075: .getSimpleparentSimplechild();
076: if (childs != null) {
077: StringBuffer ret = new StringBuffer();
078: //ret.append("Parent desc:" + bean.getSpDesc() + "<br>");
079: int ct = 1;
080: SIMPLECHILDLocal bean2 = null;
081: java.util.Iterator i = childs.iterator();
082: while (i.hasNext()) {
083: bean2 = (SIMPLECHILDLocal) i.next();
084: //ret.append("Child" + ct + ":" + bean2.getScDesc() + "<br>");
085: if (ct != 1) {
086: ret.append(",");
087: }
088: ret.append(bean2.getScDesc());
089: ct++;
090: }
091: return ret.toString();
092: } else {
093: return "Unable to find parent & child details (null childs bean)";
094: }
095: } else {
096: return "Unable to find parent & child details (null parent bean)";
097: }
098: } catch (Exception ne) {
099: return "Error: Unable to find parent & child ("
100: + ne.getClass().getName() + ") - "
101: + ne.getMessage();
102: }
103:
104: }
105:
106: public String getChildParent(String id) {
107: try {
108: Context ic = new InitialContext();
109: SIMPLECHILDLocalHome home = (SIMPLECHILDLocalHome) ic
110: .lookup("java:comp/env/ejb/SIMPLECHILD-local");
111: SIMPLECHILDPK pk = new SIMPLECHILDPK();
112: pk.scPkId = id;
113: SIMPLECHILDLocal bean = home.findByPrimaryKey(pk);
114: if (bean != null) {
115: SIMPLEPARENTLocal par = bean
116: .getSimplechildSimpleparent();
117: StringBuffer ret = new StringBuffer();
118: if (par != null) {
119: //ret.append("Child desc:" + bean.getScDesc() + "<br>");
120: //ret.append("Parent desc:" + par.getSpDesc() + "<br>");
121: ret.append(par.getSpDesc());
122: }
123: return ret.toString();
124: } else {
125: return "Unable to find parent of child details (null child bean)";
126: }
127: } catch (Exception ne) {
128: return "Error: Unable to find parent & child ("
129: + ne.getClass().getName() + ") - "
130: + ne.getMessage();
131: }
132:
133: }
134:
135: }
|