KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > medor > optim > jorm > JormQueryRewriter


1 /**
2  * MEDOR: Middleware Enabling Distributed Object Requests
3  *
4  * Copyright (C) 2001-2003 France Telecom R&D
5  * Contact: alexandre.lefebvre@rd.francetelecom.com
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * Initial developers: M. Alia, A. Lefebvre
22  */

23 package org.objectweb.medor.optim.jorm;
24
25 import org.objectweb.medor.lib.Log;
26 import org.objectweb.medor.optim.api.LeafRewriteRule;
27 import org.objectweb.medor.optim.api.LeafRewriter;
28 import org.objectweb.medor.optim.lib.BasicQueryRewriter;
29
30 import java.util.Collection JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.Map JavaDoc;
33
34 /**
35  * This QueryRewriter is able to rewrite a query tree which
36  * contains JORM leaves.
37  *
38  * @author S.Chassande-Barrioz
39  */

40 public class JormQueryRewriter extends BasicQueryRewriter {
41
42     /**
43      * It builds a QueryRewriter which the configuration is composed by the rule
44      * needed to rewrite a query tree containing jorm leaves (ClassExtent or
45      * GenClassExtent).
46      * @param jormName2Mapper is map which associated the jorm leaves to their
47      * mapper instance.
48      * @param jormName2Project is map which associated the jorm leaves to their
49      * project name.
50      * @param leafRewriters is a collection of LeafRewriter which knows how to
51      * rewrite the JORM leaves.
52      * These LeafRewriter depend on the mapping used by the Jorm leaves
53      */

54     public JormQueryRewriter(Map JavaDoc jormName2Mapper, Map JavaDoc jormName2Project,
55                              Collection JavaDoc leafRewriters) {
56         super();
57         log = Log.loggerFactory.getLogger(
58             Log.MEDOR_PREFIX + ".optim.rewriter.JormQueryRewriter");
59         rules = getDefaultRules();
60
61         JormAssignMapperRule am = new JormAssignMapperRule();
62         am.setJormName2Mapper(jormName2Mapper, jormName2Project);
63         rules.add(0, am);
64
65         LeafRewriteRule lrr = new JormLeafRewriteRule();
66         for (Iterator JavaDoc it = leafRewriters.iterator(); it.hasNext();)
67             lrr.addLeafRewriter((LeafRewriter) it.next());
68         rules.add(1, lrr);
69         rules.add(2, new JormGoUpDecodeRule());
70     }
71
72     /**
73      * It builds a QueryRewriter which the configuration is composed by the rule
74      * needed to rewrite a query tree containing jorm leaves (ClassExtent or
75      * GenClassExtent).
76      * @param leafRewriters is a collection of LeafRewriter which knows how to
77      * rewrite the JORM leaves.
78      * These LeafRewriter depend on the mapping used by the Jorm leaves
79      */

80     public JormQueryRewriter(Collection JavaDoc leafRewriters) {
81         super();
82         log = Log.loggerFactory.getLogger(
83             Log.MEDOR_PREFIX + ".optim.rewriter.JormQueryRewriter");
84         rules = getDefaultRules();
85         LeafRewriteRule lrr = new JormLeafRewriteRule();
86         for (Iterator JavaDoc it = leafRewriters.iterator(); it.hasNext();)
87             lrr.addLeafRewriter((LeafRewriter) it.next());
88         rules.add(0, lrr);
89         rules.add(1, new JormGoUpDecodeRule());
90     }
91 }
92
Popular Tags