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.invocation;
23:
24: import java.io.IOException;
25: import java.math.BigDecimal;
26: import java.math.BigInteger;
27:
28: import org.jboss.proxy.ClientContainer;
29: import org.jboss.remoting.serialization.IMarshalledValue;
30: import org.jboss.remoting.serialization.impl.jboss.LocalMarshalledValue;
31: import org.jboss.serial.objectmetamodel.safecloning.SafeClone;
32: import org.jboss.serial.objectmetamodel.safecloning.SafeCloningRepository;
33:
34: /**
35: * This MarshallingInvokerInterceptor uses JbossSerialization DataContainer's doing a faster serialization over call-by-values than For Marshalling local call-by-values using JBossSerialization
36: * @author <mailto="clebert.suconic@jboss.com">Clebert Suconic</a>
37: * */
38: public class DataContainerMarshallingInvokerInterceptor extends
39: MarshallingInvokerInterceptor {
40: private static final long serialVersionUID = -1889397492156790576L;
41:
42: /** These objects are safe to reuse in callByValue operations */
43: static final SafeClone safeToReuse = new SafeClone() {
44: public boolean isSafeToReuse(Object obj) {
45: if (obj == null) {
46: return false;
47: }
48:
49: if (obj instanceof ClientContainer || obj instanceof String
50: || obj instanceof Number
51: || obj instanceof BigDecimal
52: || obj instanceof BigInteger || obj instanceof Byte
53: || obj instanceof Double || obj instanceof Float
54: || obj instanceof Integer || obj instanceof Long
55: || obj instanceof Short) {
56: return true;
57: } else {
58: return false;
59: }
60: }
61: };
62:
63: protected IMarshalledValue createMarshalledValueForCallByValue(
64: Object value) throws IOException {
65: return new LocalMarshalledValue(value,
66: new SafeCloningRepository(safeToReuse));
67:
68: }
69:
70: }
|