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.jnp.interfaces;
23:
24: import java.io.IOException;
25: import java.io.Serializable;
26: import java.rmi.MarshalledObject;
27:
28: /** An encapsulation of a JNDI binding as both the raw object and its
29: MarshalledObject form. When accessed in the same VM as the JNP server,
30: the raw object reference is used to avoid deserialization.
31:
32: @author Scott.Stark@jboss.org
33: @version $Revision: 57199 $
34: */
35: public class MarshalledValuePair implements Serializable {
36: /** @since 3.2.0 */
37: private static final long serialVersionUID = -3403843515711139134L;
38:
39: private static boolean enableCallByReference = true;
40: public MarshalledObject marshalledValue;
41: public transient Object value;
42:
43: /** Get the lookp call by reference flag.
44: * @return false if all lookups are unmarshalled using the caller's TCL,
45: * true if in VM lookups return the value by reference.
46: */
47: public static boolean getEnableCallByReference() {
48: return enableCallByReference;
49: }
50:
51: /** Set the lookp call by reference flag.
52: * @param flag - false if all lookups are unmarshalled using the caller's TCL,
53: * true if in VM lookups return the value by reference.
54: */
55: public static void setEnableCallByReference(boolean flag) {
56: enableCallByReference = flag;
57: }
58:
59: /** Creates a new instance of MashalledValuePair */
60: public MarshalledValuePair(Object value) throws IOException {
61: this .value = value;
62: this .marshalledValue = new MarshalledObject(value);
63: }
64:
65: public Object get() throws ClassNotFoundException, IOException {
66: Object theValue = enableCallByReference ? value : null;
67: if (theValue == null && marshalledValue != null)
68: theValue = marshalledValue.get();
69: return theValue;
70: }
71: }
|