KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > remote > hessian > EnumSerializerProxy


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20 package org.apache.cayenne.remote.hessian;
21
22 import org.apache.cayenne.util.Util;
23
24 import com.caucho.hessian.io.AbstractSerializerFactory;
25 import com.caucho.hessian.io.Deserializer;
26 import com.caucho.hessian.io.HessianProtocolException;
27 import com.caucho.hessian.io.Serializer;
28
29 /**
30  * A JDK14 compatible wrapper for JDK15 EnumSerializer proxy. Under JDK 1.4 this object
31  * does nothing.
32  *
33  * @since 1.2
34  * @author Andrus Adamchik
35  */

36 public class EnumSerializerProxy extends AbstractSerializerFactory {
37
38     static final String JavaDoc FACTORY_CLASS = "org.apache.cayenne.remote.hessian.EnumSerializerFactory";
39
40     private AbstractSerializerFactory enumSerializer;
41
42     public EnumSerializerProxy() {
43         try {
44             // sniff JDK 1.5
45
Class.forName("java.lang.StringBuilder");
46
47             Class JavaDoc factoryClass = Util.getJavaClass(FACTORY_CLASS);
48             this.enumSerializer = (AbstractSerializerFactory) factoryClass.newInstance();
49         }
50         catch (Throwable JavaDoc th) {
51             // ignore.. jdk 1.4
52
}
53     }
54
55     public Serializer getSerializer(Class JavaDoc cl) throws HessianProtocolException {
56         return enumSerializer != null ? enumSerializer.getSerializer(cl) : null;
57     }
58
59     public Deserializer getDeserializer(Class JavaDoc cl) throws HessianProtocolException {
60         return enumSerializer != null ? enumSerializer.getDeserializer(cl) : null;
61     }
62 }
63
Popular Tags