KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * MEDOR: Middleware Enabling Distributed Object Requests
3  *
4  * Copyright (C) 2001-2004 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, S. Chassande-Barrioz, A. Lefebvre
22  */

23
24 package org.objectweb.medor.query.lib;
25
26 import org.objectweb.medor.api.Field;
27 import org.objectweb.medor.api.MedorException;
28 import org.objectweb.medor.expression.api.Expression;
29 import org.objectweb.medor.query.api.NestedField;
30 import org.objectweb.medor.query.api.OperationType;
31 import org.objectweb.medor.query.api.PropagatedField;
32 import org.objectweb.medor.query.api.QueryTreeField;
33 import org.objectweb.medor.query.api.UnnestQueryNode;
34 import org.objectweb.medor.type.lib.QType;
35
36 import java.util.Map JavaDoc;
37
38
39 public class Unnest extends BasicQueryNode implements UnnestQueryNode {
40     /**
41      * It lists the fields which have been grouped.
42      */

43     protected NestedField unnestedField = null;
44     protected PropagatedField[] projectedFields;
45
46     public Unnest() {
47     }
48
49     public Unnest(QueryTreeField[] queryTreeFields,
50                   Field field,
51                   String JavaDoc nodeName)
52             throws MedorException {
53
54         super(nodeName);
55
56         //creating and adding all projected fields as PropagatedFields
57
this.projectedFields = new PropagatedField[queryTreeFields.length];
58
59         for (int i = 0; i < queryTreeFields.length; i++) {
60             QueryTreeField[] anc = {queryTreeFields[i]};
61             this.projectedFields[i] = this.addPropagatedField(
62                 queryTreeFields[i].getName(),
63                 queryTreeFields[i].getType(),
64                 anc);
65         }
66
67
68         if(field.getType().getTypeCode()!=QType.TYPECODE_TUPLE_COLLECTION)
69             throw new MedorException("The field to unnest must be a TupleCollection");
70         Field[] origs;
71         if (field instanceof PropagatedField) {
72             origs = ((PropagatedField) field).getOriginFields();
73         }
74         else
75             origs = new Field[] { field };
76         if (!(origs[0] instanceof NestedField))
77             throw new MedorException("The support of Tuplecollection fields (which are not NestedFields) is not yet implemented");
78
79         unnestedField = (NestedField) origs[0];
80
81         //creating and adding all fields coming from the unnest operation
82
//as BasicPropagFromNestedField
83
for (int i = 0; i < unnestedField.getSize(); i++) {
84             QueryTreeField[] anc = {unnestedField};
85             Field f = unnestedField.getFields()[i];
86             addField(new BasicPropagFromNestedField(
87                 getFieldName(nodeName, f.getName()),
88                 f.getType(),
89                 this,
90                 anc,
91                 new Field[] {f}));
92         }
93         addChild(unnestedField.getQueryTree());
94     }
95
96     public Object JavaDoc clone(Object JavaDoc clone,
97                         Map JavaDoc obj2clone) throws CloneNotSupportedException JavaDoc {
98         clone = super.clone(clone, obj2clone);
99         Unnest un = (Unnest) clone;
100         un.unnestedField = (NestedField) getClone(unnestedField, obj2clone);
101         if (projectedFields != null) {
102             un.projectedFields = new PropagatedField[projectedFields.length];
103             for(int i=0; i<projectedFields.length; i++) {
104                 un.projectedFields[i] = (PropagatedField) getClone(projectedFields[i], obj2clone);
105             }
106         }
107         return clone;
108     }
109
110     public NestedField getUnnestedField() {
111         return unnestedField;
112     }
113
114     public PropagatedField[] getProjectedFields() {
115         return projectedFields;
116     }
117
118     public short getType() {
119         return OperationType.UNNEST;
120     }
121
122     public void setQueryFilter(Expression e) {
123         throw new UnsupportedOperationException JavaDoc("Unnest operators cannot be assigned a filter.");
124     }
125
126 }
127
Popular Tags