KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > remote > hessian > service > ServerSerializerFactory


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.service;
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.map.EntityResolver;
27 import org.apache.cayenne.query.AbstractQuery;
28 import org.apache.cayenne.util.PersistentObjectList;
29
30 import com.caucho.hessian.io.AbstractSerializerFactory;
31 import com.caucho.hessian.io.Deserializer;
32 import com.caucho.hessian.io.HessianProtocolException;
33 import com.caucho.hessian.io.Serializer;
34
35 /**
36  * An object that manages all custom (de)serializers used on the server.
37  *
38  * @since 1.2
39  * @author Andrus Adamchik
40  */

41 class ServerSerializerFactory extends AbstractSerializerFactory {
42
43     private EntityResolver serverResolver;
44
45     private ServerPersistentObjectListSerializer persistentObjectListSerializer;
46     private ServerDataRowSerializer dataRowSerilaizer;
47     private Map JavaDoc deserializers;
48
49     ServerSerializerFactory() {
50         this.persistentObjectListSerializer = new ServerPersistentObjectListSerializer();
51         this.dataRowSerilaizer = new ServerDataRowSerializer();
52     }
53
54     // this method is used by HessianCOnfig to inject resolver
55
void setEntityResolver(EntityResolver resolver) {
56         this.serverResolver = resolver;
57     }
58
59     public Serializer getSerializer(Class JavaDoc cl) throws HessianProtocolException {
60
61         if (PersistentObjectList.class.isAssignableFrom(cl)) {
62             return persistentObjectListSerializer;
63         }
64         else if (DataRow.class.isAssignableFrom(cl)) {
65             return dataRowSerilaizer;
66         }
67
68         return null;
69     }
70
71     public Deserializer getDeserializer(Class JavaDoc cl) throws HessianProtocolException {
72         Deserializer deserializer = null;
73
74         if (AbstractQuery.class.isAssignableFrom(cl)) {
75
76             synchronized (this) {
77
78                 if (deserializers != null) {
79                     deserializer = (Deserializer) deserializers.get(cl);
80                 }
81
82                 if (deserializer == null) {
83                     deserializer = new ServerAbstractQueryDeserializer(cl, serverResolver
84                             .getClientEntityResolver());
85
86                     if (deserializers == null) {
87                         deserializers = new HashMap JavaDoc();
88                     }
89
90                     deserializers.put(cl, deserializer);
91                 }
92             }
93
94         }
95
96         return deserializer;
97     }
98 }
99
Popular Tags