01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.ejb3.stateful;
23:
24: import java.io.IOException;
25: import java.io.ObjectInput;
26: import java.io.ObjectOutput;
27: import java.util.HashMap;
28: import java.util.List;
29:
30: import javax.persistence.EntityManager;
31: import org.jboss.aop.metadata.SimpleMetaData;
32:
33: /**
34: * Overrides superclass to not use MarshalledValue in externalization,
35: * as a nested context is meant to be serialized as part of its parent
36: * context and to share with it object references to any XPC or managed
37: * entities. Serializing with a MarshalledValue would result in separate
38: * deserializations of the XPCs and managed entities.
39: *
40: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
41: * @version $Revision: 60651 $
42: */
43: public class NestedStatefulBeanContext extends StatefulBeanContext {
44: /** The serialVersionUID */
45: private static final long serialVersionUID = 7835719320529968045L;
46:
47: public void writeExternal(ObjectOutput out) throws IOException {
48: out.writeUTF(getContainer().getObjectName().getCanonicalName());
49: out.writeObject(id);
50: out.writeObject(metadata);
51: out.writeObject(bean);
52: out.writeObject(persistenceContexts);
53: out.writeObject(interceptorInstances);
54: out.writeObject(contains);
55: // Cannot write a ref to our parent as that seems to blow up serialization
56: //out.writeObject(containedIn);
57: out.writeBoolean(removed);
58: out.writeBoolean(replicationIsPassivation);
59: }
60:
61: public void readExternal(ObjectInput in) throws IOException,
62: ClassNotFoundException {
63: containerName = in.readUTF();
64: id = in.readObject();
65: metadata = (SimpleMetaData) in.readObject();
66: bean = in.readObject();
67: persistenceContexts = (HashMap<String, EntityManager>) in
68: .readObject();
69: interceptorInstances = (HashMap<Class, Object>) in.readObject();
70: contains = (List<StatefulBeanContext>) in.readObject();
71: removed = in.readBoolean();
72: replicationIsPassivation = in.readBoolean();
73:
74: // Since we can't write a ref to our parent, our children also
75: // don't have a ref to use. So reestablish it.
76: if (contains != null) {
77: for (StatefulBeanContext contained : contains) {
78: contained.containedIn = this ;
79: }
80: }
81:
82: // If we've just been deserialized, we are passivated
83: passivated = true;
84: }
85:
86: }
|