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.lock.bean;
023:
024: import java.rmi.*;
025: import javax.ejb.*;
026:
027: import org.jboss.test.lock.interfaces.EnterpriseEntityHome;
028: import org.jboss.test.lock.interfaces.EnterpriseEntity;
029:
030: public class EnterpriseEntityBean implements EntityBean {
031: static org.apache.log4j.Category log = org.apache.log4j.Category
032: .getInstance(EnterpriseEntityBean.class);
033:
034: private EntityContext entityContext;
035:
036: public String name;
037: public String field;
038: public EnterpriseEntity nextEntity;
039: public String lastEntity = "UNKNOWN!!!!";
040:
041: public String ejbCreate(final String name) throws RemoteException,
042: CreateException {
043: this .name = name;
044: return null;
045: }
046:
047: public void ejbPostCreate(String name) throws RemoteException,
048: CreateException {
049: // empty
050: }
051:
052: public void ejbActivate() throws RemoteException {
053: // empty
054: }
055:
056: public void ejbLoad() throws RemoteException {
057: // empty
058: }
059:
060: public void ejbPassivate() throws RemoteException {
061: // empty
062: }
063:
064: public void ejbRemove() throws RemoteException, RemoveException {
065: // empty
066: }
067:
068: public void ejbStore() throws RemoteException {
069: // empty
070: }
071:
072: public void setField(String field) throws RemoteException {
073: //log.debug("Bean "+name+", setField("+field+") called");
074: this .field = field;
075: }
076:
077: public String getField() throws RemoteException {
078: return field;
079: }
080:
081: public void setAndCopyField(String field) throws RemoteException {
082: //log.debug("Bean "+name+", setAndCopyField("+field+") called");
083:
084: log.debug("setAndCopyField");
085: setField(field);
086: if (nextEntity == null) {
087: log.error("nextEntity is null!!!!!!!!, lastEntity: "
088: + lastEntity);
089: }
090: nextEntity.setField(field);
091: }
092:
093: public void setNextEntity(String beanName) throws RemoteException {
094: try {
095: log.debug("setNextEntity: " + beanName);
096: EJBObject ejbObject = entityContext.getEJBObject();
097: EnterpriseEntityHome home = (EnterpriseEntityHome) ejbObject
098: .getEJBHome();
099: try {
100: nextEntity = home.findByPrimaryKey(beanName);
101: } catch (FinderException e) {
102: nextEntity = home.create(beanName);
103: }
104: lastEntity = beanName;
105: } catch (Exception e) {
106: log.debug("failed", e);
107: throw new RemoteException(
108: "create entity did not work check messages");
109: }
110: }
111:
112: public void setEntityContext(EntityContext context)
113: throws RemoteException {
114: entityContext = context;
115: }
116:
117: public void unsetEntityContext() throws RemoteException {
118: entityContext = null;
119: }
120:
121: public void sleep(long time) throws InterruptedException {
122: Thread.sleep(time);
123: }
124: }
|