01: /**
02: * High Availability Service (HA) for JOnAS
03: *
04: * Copyright (C) 2006 Distributed Systems Lab.
05: * Universidad Polit??cnica de Madrid (Spain)
06: * Contact: http://lsd.ls.fi.upm.es/lsd
07: *
08: * This library is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU Lesser General Public
10: * License as published by the Free Software Foundation; either
11: * version 2.1 of the License, or any later version.
12: *
13: * This library is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16: * Lesser General Public License for more details.
17: *
18: * You should have received a copy of the GNU Lesser General Public
19: * License along with this library; if not, write to the Free Software
20: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21: * USA
22: *
23: * --------------------------------------------------------------------------
24: * $Id: EntityBeanRefImpl.java 10286 2007-04-25 15:39:47Z japaz $
25: * --------------------------------------------------------------------------
26: */package org.objectweb.jonas.ha;
27:
28: import java.lang.reflect.Method;
29:
30: import javax.ejb.EntityBean;
31:
32: import org.objectweb.carol.cmi.ha.EntityBeanReference;
33: import org.objectweb.jonas_ejb.container.JEntityContext;
34: import org.objectweb.jonas_ejb.deployment.api.EntityCmp1Desc;
35: import org.objectweb.jonas_ejb.deployment.api.EntityDesc;
36:
37: /**
38: * This class implements reference to entity beans for CMI HA
39: * @author Francisco Perez-Sorrosal (fpsorrosal@no-spam@fi.upm.es)
40: * @author Alberto Paz-Jimenez (apaz@no-spam@fi.upm.es)
41: */
42: public class EntityBeanRefImpl implements EntityBeanReference {
43:
44: private JEntityContext jec;
45:
46: /**
47: * Constructor
48: * @param bs the entity switch
49: */
50: public EntityBeanRefImpl(JEntityContext jec) {
51: this .jec = jec;
52: }
53:
54: public Object getPrimaryKey() {
55: return jec.getPrimaryKey();
56: }
57:
58: public boolean isModified() {
59: EntityDesc ed = (EntityDesc) jec.getEntityFactory()
60: .getDeploymentDescriptor();
61: if (ed instanceof EntityCmp1Desc) {
62: EntityCmp1Desc ecd = (EntityCmp1Desc) ed;
63: if (ecd.hasIsModifiedMethod()) {
64: Method isModifiedMethod = ecd.getIsModifiedMethod();
65: try {
66: EntityBean sb = (EntityBean) jec.getInstance();// getStatefulContext().getInstance();
67: return ((Boolean) isModifiedMethod.invoke(sb,
68: (Object[]) null)).booleanValue();
69: } catch (Exception e) {
70: e.printStackTrace();
71: return true;
72: }
73: } else {
74: return true;
75: }
76: } else {
77: return true;
78: }
79: }
80:
81: }
|