KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > remoting > caucho > Hessian1SkeletonInvoker


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.remoting.caucho;
18
19 import java.io.InputStream JavaDoc;
20 import java.io.OutputStream JavaDoc;
21 import java.lang.reflect.Method JavaDoc;
22
23 import com.caucho.hessian.io.HessianInput;
24 import com.caucho.hessian.io.HessianOutput;
25 import com.caucho.hessian.io.SerializerFactory;
26 import com.caucho.hessian.server.HessianSkeleton;
27
28 import org.springframework.util.ClassUtils;
29
30 /**
31  * Concrete HessianSkeletonInvoker for the Hessian 1 protocol
32  * (version 3.0.19 or lower).
33  *
34  * @author Juergen Hoeller
35  * @since 2.0
36  */

37 class Hessian1SkeletonInvoker extends HessianSkeletonInvoker {
38
39     private static final Method JavaDoc invokeMethod;
40
41     private static final boolean applySerializerFactoryToOutput;
42
43     static {
44         invokeMethod = ClassUtils.getMethodIfAvailable(
45                 HessianSkeleton.class, "invoke", new Class JavaDoc[] {HessianInput.class, HessianOutput.class});
46         applySerializerFactoryToOutput =
47                 ClassUtils.hasMethod(HessianOutput.class, "setSerializerFactory", new Class JavaDoc[] {SerializerFactory.class});
48     }
49
50
51     public Hessian1SkeletonInvoker(HessianSkeleton skeleton, SerializerFactory serializerFactory) {
52         super(skeleton, serializerFactory);
53         if (invokeMethod == null) {
54             throw new IllegalStateException JavaDoc("Hessian 1 (version 3.0.19-) not present");
55         }
56     }
57
58     public void invoke(InputStream JavaDoc inputStream, OutputStream JavaDoc outputStream) throws Throwable JavaDoc {
59         HessianInput in = new HessianInput(inputStream);
60         HessianOutput out = new HessianOutput(outputStream);
61         if (this.serializerFactory != null) {
62             in.setSerializerFactory(this.serializerFactory);
63             if (applySerializerFactoryToOutput) {
64                 out.setSerializerFactory(this.serializerFactory);
65             }
66         }
67         invokeMethod.invoke(this.skeleton, new Object JavaDoc[] {in, out});
68     }
69
70 }
71
Popular Tags