KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.IOException JavaDoc;
23
24 import org.apache.cayenne.CayenneRuntimeException;
25 import org.apache.cayenne.map.EntityResolver;
26 import org.apache.cayenne.map.ObjEntity;
27 import org.apache.cayenne.query.AbstractQuery;
28
29 import com.caucho.hessian.io.AbstractHessianInput;
30 import com.caucho.hessian.io.JavaDeserializer;
31
32 /**
33  * Deserializer that overrides query roots with server classes on deserialization.
34  *
35  * @since 1.2
36  * @author Andrus Adamchik
37  */

38 class ServerAbstractQueryDeserializer extends JavaDeserializer {
39
40     private EntityResolver clientResolver;
41
42     ServerAbstractQueryDeserializer(Class JavaDoc cl, EntityResolver clientResolver) {
43         super(cl);
44
45         this.clientResolver = clientResolver;
46     }
47
48     public Object JavaDoc readMap(AbstractHessianInput in) throws IOException JavaDoc {
49         Object JavaDoc object = super.readMap(in);
50
51         if (object instanceof AbstractQuery) {
52
53             AbstractQuery abstractClientQuery = (AbstractQuery) object;
54             Object JavaDoc root = abstractClientQuery.getRoot();
55             if (root instanceof Class JavaDoc) {
56                 ObjEntity entity = clientResolver.lookupObjEntity((Class JavaDoc) root);
57                 if (entity == null) {
58                     throw new CayenneRuntimeException("Unmapped client class: " + root);
59                 }
60                 abstractClientQuery.setRoot(entity.getName());
61             }
62         }
63
64         return object;
65     }
66 }
67
Popular Tags