KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.HashMap JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import org.apache.cayenne.DataRow;
26 import org.apache.cayenne.util.PersistentObjectList;
27
28 import com.caucho.hessian.io.AbstractSerializerFactory;
29 import com.caucho.hessian.io.Deserializer;
30 import com.caucho.hessian.io.HessianProtocolException;
31 import com.caucho.hessian.io.JavaDeserializer;
32 import com.caucho.hessian.io.Serializer;
33
34 /**
35  * An object that manages all custom (de)serializers used on the client.
36  *
37  * @since 1.2
38  * @author Andrus Adamchik
39  */

40 class ClientSerializerFactory extends AbstractSerializerFactory {
41
42     private Map JavaDoc deserializers;
43     private Deserializer dataRowDeserializer;
44
45     public Serializer getSerializer(Class JavaDoc cl) throws HessianProtocolException {
46         return null;
47     }
48
49     public Deserializer getDeserializer(Class JavaDoc cl) throws HessianProtocolException {
50         Deserializer deserializer = null;
51
52         if (PersistentObjectList.class.isAssignableFrom(cl)) {
53
54             synchronized (this) {
55
56                 if (deserializers != null) {
57                     deserializer = (Deserializer) deserializers.get(cl);
58                 }
59
60                 if (deserializer == null) {
61                     deserializer = new JavaDeserializer(cl);
62
63                     if (deserializers == null) {
64                         deserializers = new HashMap JavaDoc();
65                     }
66
67                     deserializers.put(cl, deserializer);
68                 }
69             }
70         }
71         else if(DataRow.class.isAssignableFrom(cl)) {
72             if(dataRowDeserializer == null) {
73                 dataRowDeserializer = new DataRowDeserializer();
74             }
75             
76             return dataRowDeserializer;
77         }
78
79         return deserializer;
80     }
81 }
82
Popular Tags