KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > medor > query > lib > MedorTCQueryLeaf


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, S. Chassande-Barrioz
22  */

23 package org.objectweb.medor.query.lib;
24
25 import org.objectweb.jorm.type.api.PType;
26 import org.objectweb.medor.api.Field;
27 import org.objectweb.medor.api.MedorException;
28 import org.objectweb.medor.api.TupleStructure;
29 import org.objectweb.medor.datasource.api.DataStore;
30 import org.objectweb.medor.datasource.lib.BasicDataStore;
31 import org.objectweb.medor.lib.BasicTupleStructure;
32 import org.objectweb.medor.query.api.QueryTreeField;
33 import org.objectweb.medor.query.api.TCQueryLeaf;
34 import org.objectweb.medor.query.api.OrderField;
35 import org.objectweb.medor.tuple.api.TupleCollection;
36 import org.objectweb.medor.tuple.api.TupleLoader;
37 import org.objectweb.medor.expression.api.Expression;
38
39 import java.util.Map JavaDoc;
40
41 /**
42  * A TupleCollection is one of the DataStore that is queryable by Medor.
43  * <p>This
44  * class reprensents a QueryLeaf wich take its data from a Medor
45  * TupleCollection.
46  */

47 public class MedorTCQueryLeaf extends BasicTupleStructure
48         implements TCQueryLeaf {
49
50     protected TupleCollection tcData;
51     protected TupleLoader loader;
52     protected DataStore ds;
53     protected Expression filter;
54     protected String JavaDoc nodeName;
55
56     public MedorTCQueryLeaf() {
57     }
58
59     public MedorTCQueryLeaf(String JavaDoc nodeName, String JavaDoc tcName,
60                             TupleCollection tcData)
61             throws MedorException {
62         super();
63         this.nodeName = nodeName;
64         this.tcData = tcData;
65         ds = new BasicDataStore(DataStore.MEDORTC_STORE, tcName);
66     }
67
68     public QueryTreeField addField(String JavaDoc fieldName, PType type, Field tcField)
69             throws MedorException {
70         QueryTreeField qtf =
71                 new BasicQueryTreeField(
72                         getFieldName(nodeName, fieldName), type, this);
73         name2field.put(qtf.getName(), qtf);
74         fields.add(qtf);
75         return qtf;
76     }
77
78     public Object JavaDoc clone(Object JavaDoc clone,
79                         Map JavaDoc obj2clone) throws CloneNotSupportedException JavaDoc {
80         clone = super.clone(clone, obj2clone);
81         MedorTCQueryLeaf mql = (MedorTCQueryLeaf) clone;
82         mql.nodeName = nodeName;
83         mql.tcData = tcData;
84         mql.ds = ds;
85         mql.loader = loader;
86         mql.filter = (Expression) getClone(filter, obj2clone);
87         return clone;
88     }
89
90     public String JavaDoc getName() {
91         return nodeName;
92     }
93
94     public TupleStructure getTupleStructure() {
95         return this;
96     }
97
98     public void setDistinct(boolean d) throws MedorException {
99         throw new MedorException("Distinct not yet supported on MedorTCQueryLeaf");
100     }
101
102     public boolean getDistinct() {
103         return false;
104     }
105
106     public void setOrderBy(OrderField[] orderfields) throws MedorException {
107         throw new MedorException("Order by not supported on MedorTCQueryLeaf");
108     }
109
110     public OrderField[] getOrderBy() {
111         return null;
112     }
113
114     public DataStore getDataStore() {
115         return ds;
116     }
117
118     public TupleCollection getTupleCollection() {
119         return tcData;
120     }
121
122     public TupleLoader getTupleLoader() {
123         return loader;
124     }
125
126     public void setTupleLoader(TupleLoader tl) {
127         this.loader = tl;
128     }
129
130     public Expression getQueryFilter() {
131         return filter;
132     }
133
134     public void setQueryFilter(Expression filter) {
135         this.filter = filter;
136     }
137
138     private String JavaDoc getFieldName(String JavaDoc nodeName, String JavaDoc fieldName) {
139         if (nodeName == null || nodeName.length() == 0)
140             return fieldName;
141         else
142             return nodeName + "." + fieldName;
143     }
144
145 }
146
Popular Tags