001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.testbean.bean;
023:
024: import java.rmi.*;
025: import javax.ejb.*;
026:
027: import org.jboss.test.testbean.interfaces.EnterpriseEntityHome;
028: import org.jboss.test.testbean.interfaces.EnterpriseEntity;
029:
030: /**
031: * @author Marc Fleury
032: */
033: public class EnterpriseEntityBean implements EntityBean {
034: org.apache.log4j.Category log = org.apache.log4j.Category
035: .getInstance(getClass());
036: private EntityContext entityContext;
037: public String name;
038: public int otherField = 0;
039:
040: public String ejbCreate(String name) throws RemoteException,
041: CreateException {
042:
043: log.debug("EntityBean.ejbCreate(" + name + ") called");
044: this .name = name;
045: return null;
046: }
047:
048: public String ejbCreateMETHOD(String name) throws RemoteException,
049: CreateException {
050:
051: log.debug("EntityBean.ejbCreateMETHOD(" + name + ") called");
052: this .name = name;
053: return null;
054: }
055:
056: public void ejbPostCreate(String name) throws RemoteException,
057: CreateException {
058:
059: log.debug("EntityBean.ejbPostCreate(" + name + ") called");
060:
061: EJBObject ejbObject = entityContext.getEJBObject();
062:
063: if (ejbObject == null) {
064: log
065: .debug("******************************* NULL EJBOBJECT in ejbPostCreate");
066: } else {
067: log
068: .debug("&&&&&&&&&&&&&&&& EJBObject found in ejbPostCreate id is "
069: + ejbObject.getPrimaryKey());
070: }
071:
072: }
073:
074: public void ejbPostCreateMETHOD(String name)
075: throws RemoteException, CreateException {
076:
077: log
078: .debug("EntityBean.ejbPostCreateMETHOD(" + name
079: + ") called");
080:
081: EJBObject ejbObject = entityContext.getEJBObject();
082:
083: if (ejbObject == null) {
084: log
085: .debug("******************************* NULL EJBOBJECT in ejbPostCreateMETHOD");
086: } else {
087: log
088: .debug("&&&&&&&&&&&&&&&& EJBObject found in ejbPostCreateMETHOD id is "
089: + ejbObject.getPrimaryKey());
090: }
091:
092: }
093:
094: public void ejbActivate() throws RemoteException {
095: log.debug("EntityBean.ejbActivate() called");
096: }
097:
098: public void ejbLoad() throws RemoteException {
099: log.debug("EntityBean.ejbLoad() called");
100: }
101:
102: public void ejbPassivate() throws RemoteException {
103:
104: log.debug("EntityBean.ejbPassivate() called");
105: }
106:
107: public void ejbRemove() throws RemoteException, RemoveException {
108: log.debug("EntityBean.ejbRemove() called " + hashCode());
109: }
110:
111: public void ejbStore() throws RemoteException {
112:
113: log.debug("EntityBean.ejbStore() called " + hashCode());
114: }
115:
116: public String callBusinessMethodA() {
117:
118: log.debug("EntityBean.callBusinessMethodA() called");
119: return "EntityBean.callBusinessMethodA() called, my primaryKey is "
120: + entityContext.getPrimaryKey().toString();
121: }
122:
123: public String callBusinessMethodB() {
124:
125: log.debug("EntityBean.callBusinessMethodB() called");
126:
127: EJBObject ejbObject = entityContext.getEJBObject();
128:
129: if (ejbObject == null)
130: return "NULL EJBOBJECT";
131:
132: else
133: return ejbObject.toString();
134: }
135:
136: public String callBusinessMethodB(String words) {
137:
138: log.debug("EntityBean.callBusinessMethodB(String) called");
139:
140: EJBObject ejbObject = entityContext.getEJBObject();
141:
142: if (ejbObject == null)
143: return "NULL EJBOBJECT";
144:
145: else
146: return ejbObject.toString() + " words " + words;
147:
148: }
149:
150: public void setOtherField(int value) {
151:
152: log.debug("EntityBean.setOtherField(" + value + ")");
153: otherField = value;
154: }
155:
156: public int getOtherField() {
157: log.debug("EntityBean.getOtherField() called");
158: return otherField;
159: }
160:
161: public EnterpriseEntity createEntity(String newName)
162: throws RemoteException {
163:
164: log.debug("EntityBean.createEntity() called");
165: EnterpriseEntity newBean;
166: try {
167: EJBObject ejbObject = entityContext.getEJBObject();
168: if (ejbObject == null)
169: log.debug("************************** NULL EJBOBJECT");
170: else
171: log.debug("************************** OK EJBOBJECT");
172:
173: EnterpriseEntityHome home = (EnterpriseEntityHome) entityContext
174: .getEJBObject().getEJBHome();
175: newBean = (EnterpriseEntity) home.create(newName);
176:
177: } catch (Exception e) {
178: log.debug("failed", e);
179: throw new RemoteException(
180: "create entity did not work check messages");
181: }
182:
183: return newBean;
184: }
185:
186: public void setEntityContext(EntityContext context)
187: throws RemoteException {
188: log.debug("EntityBean.setSessionContext() called");
189: entityContext = context;
190: }
191:
192: public void unsetEntityContext() throws RemoteException {
193: log.debug("EntityBean.unsetSessionContext() called");
194: entityContext = null;
195: }
196: }
|