KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > generation > parser > JdoParser


1 /**
2  * Speedo: an implementation of JDO compliant personality on top of JORM generic
3  * I/O sub-system.
4  * Copyright (C) 2001-2004 France Telecom R&D
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  *
21  *
22  * Contact: speedo@objectweb.org
23  *
24  * Authors: S.Chassande-Barrioz.
25  *
26  */

27
28 package org.objectweb.speedo.generation.parser;
29
30 import java.io.File JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.Properties JavaDoc;
33 import java.util.StringTokenizer JavaDoc;
34
35 import org.apache.tools.ant.types.DTDLocation;
36 import org.objectweb.jorm.xml2mi.lib.SAXParserHelper;
37 import org.objectweb.speedo.api.SpeedoException;
38 import org.objectweb.speedo.api.SpeedoProperties;
39 import org.objectweb.speedo.generation.api.SpeedoXMLError;
40 import org.objectweb.speedo.generation.lib.AbstractGeneratorComponent;
41 import org.objectweb.speedo.metadata.SpeedoArray;
42 import org.objectweb.speedo.metadata.SpeedoClass;
43 import org.objectweb.speedo.metadata.SpeedoCollection;
44 import org.objectweb.speedo.metadata.SpeedoDatastoreId;
45 import org.objectweb.speedo.metadata.SpeedoElement;
46 import org.objectweb.speedo.metadata.SpeedoExtension;
47 import org.objectweb.speedo.metadata.SpeedoFetchGroup;
48 import org.objectweb.speedo.metadata.SpeedoField;
49 import org.objectweb.speedo.metadata.SpeedoIdentity;
50 import org.objectweb.speedo.metadata.SpeedoMap;
51 import org.objectweb.speedo.metadata.SpeedoModifier;
52 import org.objectweb.speedo.metadata.SpeedoNullValue;
53 import org.objectweb.speedo.metadata.SpeedoPackage;
54 import org.objectweb.speedo.metadata.SpeedoPredefinedQuery;
55 import org.objectweb.speedo.metadata.SpeedoTuple;
56 import org.objectweb.speedo.metadata.SpeedoVersion;
57 import org.objectweb.speedo.metadata.SpeedoXMLDescriptor;
58 import org.objectweb.speedo.sequence.lib.SpeedoSequence;
59 import org.objectweb.util.monolog.api.BasicLevel;
60 import org.w3c.dom.Document JavaDoc;
61 import org.w3c.dom.Node JavaDoc;
62 import org.w3c.dom.NodeList JavaDoc;
63 import org.xml.sax.SAXException JavaDoc;
64
65 /**
66  * @author S.Chassande-Barrioz
67  */

68 public class JdoParser
69     extends AbstractGeneratorComponent {
70
71     public final static String JavaDoc LOGGER_NAME
72             = SpeedoProperties.LOGGER_NAME + ".generation.parser";
73
74     SAXParserHelper parser;
75     
76     /**
77      * The parser instance is reused at each process method call
78      */

79
80     // IMPLEMENTATION OF THE GeneratorComponent INTERFACE //
81
//----------------------------------------------------//
82

83     public boolean init() throws SpeedoException {
84         logger = scp.loggerFactory.getLogger(LOGGER_NAME);
85         if (scp.jdo.isEmpty())
86             return false;
87         Properties JavaDoc p = new Properties JavaDoc();
88         for (Iterator JavaDoc iter = scp.dtdLocations.iterator(); iter.hasNext();) {
89             DTDLocation element = (DTDLocation) iter.next();
90             p.setProperty(element.getPublicId(), element.getLocation());
91         }
92         try {
93             parser = new SAXParserHelper(p, logger, getClass().getClassLoader(), false);
94         } catch (SAXException JavaDoc e) {
95             throw new SpeedoException(e);
96         }
97         return true;
98     }
99
100     public void process() throws SpeedoException {
101         if (scp.jdo.isEmpty())
102             return;
103         logger.log(BasicLevel.DEBUG, scp.jdo.size() + " files to parse");
104         for (Iterator JavaDoc it = scp.jdo.iterator(); it.hasNext();) {
105             String JavaDoc xmlFileName = (String JavaDoc) it.next();
106             logger.log(BasicLevel.DEBUG, "Parse " + xmlFileName);
107             scp.getXmldescriptor().put(xmlFileName, createObjectModel(xmlFileName));
108         }
109
110         for (Iterator JavaDoc itDesc = scp.getXmldescriptor().values().iterator(); itDesc.hasNext();) {
111             SpeedoXMLDescriptor desc = (SpeedoXMLDescriptor) itDesc.next();
112             for (Iterator JavaDoc itPack = desc.jdoPackage.values().iterator(); itPack.hasNext();) {
113                 SpeedoPackage sp = (SpeedoPackage) itPack.next();
114                 for (Iterator JavaDoc itclass = sp.jdoClass.values().iterator(); itclass.hasNext();) {
115                     SpeedoClass jdoclass = (SpeedoClass) itclass.next();
116                     jdoclass.computeFieldNumbers();
117                 }
118             }
119         }
120     }
121
122
123     // PRIVATE METHODS //
124
//-----------------//
125

126     /**
127      * This method constructs an object descriptor for a XML file ".jdo".
128      * It returns the new object descriptor.
129      * If the file isn't well formed, a SpeedoXMLError is thrown.
130      * @param xmlFile file name.
131      * @return object descriptor for this file
132      * @exception SpeedoException if the XML file doesn't follow jdo dtd.
133      */

134     private SpeedoXMLDescriptor createObjectModel(String JavaDoc xmlFile)
135             throws SpeedoException {
136         try {
137             // parse the document
138
Document JavaDoc document = parser.parse(scp.jdoDir + File.separator + xmlFile);
139
140             //create a descriptor for the document
141
SpeedoXMLDescriptor desc = new SpeedoXMLDescriptor(scp.smi);
142             desc.xmlFile = xmlFile;
143             //fill and return the file descriptor
144
return (SpeedoXMLDescriptor) treatDocument(document, desc);
145         } catch (SpeedoException e) {
146             throw e;
147         } catch (Exception JavaDoc e) {
148             throw new SpeedoException("Error with the construction of file "
149                     + scp.jdoDir + File.separator + xmlFile, e);
150         }
151     }
152
153     /**
154      * This methods creates the object descriptor for describing a tag of the XML file.
155      * It returns the descriptor for the root tag.
156      * It throws an exception if an attribute is missing.
157      * @param node node which will be described.
158      * @param o default descriptor to return.
159      * @return node descriptor.
160      * @exception SpeedoException if a compulsory attribute is missing for
161      * the current tag.
162      */

163     private Object JavaDoc treatNode(Node JavaDoc node, Object JavaDoc o) throws SpeedoException {
164         // type of node
165
int type = node.getNodeType();
166         if (type != Node.ELEMENT_NODE)
167             return o;
168         //tag name
169
String JavaDoc tag = node.getNodeName();
170         Node JavaDoc n = null;
171         logger.log(BasicLevel.DEBUG, "Parse tag: " + tag);
172
173         //tag jdo
174
if (tag.equals("jdo")) {
175             //there is no descriptor to create
176
return o;
177
178         } else if (tag.equals("package")) { //tag package
179
SpeedoPackage p = new SpeedoPackage();
180
181             //attribute name (compulsory)
182
n = node.getAttributes().getNamedItem("name");
183             if (n == null)
184                 throw new SpeedoXMLError("Attribute name for tag package requested.");
185             p.name = n.getNodeValue();
186
187             logger.log(BasicLevel.DEBUG, "New package: name= " + p.name);
188             return p;
189
190         } else if (tag.equals("class")) { //tag class
191
SpeedoClass c = new SpeedoClass();
192
193             //attribute name (compulsory)
194
n = node.getAttributes().getNamedItem("name");
195             if (n == null)
196                 throw new SpeedoXMLError("Attribute name for tag class requested.");
197             c.name = n.getNodeValue();
198
199             //attribute identity-type
200
n = node.getAttributes().getNamedItem("identity-type");
201             if (n != null)
202                 c.identityType = SpeedoIdentity.toByte(n.getNodeValue());
203               
204             //attribute object-id
205
n = node.getAttributes().getNamedItem("objectid-class");
206             if (n != null) {
207                 c.objectidClass = n.getNodeValue();
208                 c.identityType = SpeedoIdentity.USER_ID;
209             }
210
211             //attribute requires-extent
212
n = node.getAttributes().getNamedItem("requires-extent");
213             if (n != null)
214                 c.requiresExtent = Boolean.valueOf(n.getNodeValue()).booleanValue();
215
216             //attribute detachable
217
n = node.getAttributes().getNamedItem("detachable");
218             if (n != null)
219                 c.isDetachable = Boolean.valueOf(n.getNodeValue()).booleanValue();
220                   
221             //attribute persistence-capable-superclass
222
n = node.getAttributes().getNamedItem("persistence-capable-superclass");
223             if (n != null)
224                 c.superClassName = n.getNodeValue();
225
226             logger.log(BasicLevel.DEBUG, "New class: "
227                     + "name=" + c.name
228                     + " / id = " + c.identityType
229                     + " / idClass = " + c.objectidClass
230                     + " / requiresExtent = " + c.requiresExtent
231                     + " / detachable = " + c.isDetachable
232             );
233             return c;
234         } else if (tag.equals("sequence")) { //tag sequence
235
SpeedoSequence s = new SpeedoSequence();
236             
237             //attribute name (compulsory)
238
n = node.getAttributes().getNamedItem("name");
239             if (n == null)
240                 throw new SpeedoXMLError("Attribute name for tag sequence requested.");
241             s.name = n.getNodeValue();
242
243             //attribute datastore-sequence
244
n = node.getAttributes().getNamedItem("datastore-sequence");
245             if (n != null)
246                 s.datastoreName = n.getNodeValue();
247               
248             //attribute factory-class
249
n = node.getAttributes().getNamedItem("factory-class");
250             if (n != null) {
251                 s.factoryClass = n.getNodeValue();
252             }
253
254             //attribute strategy (compulsory)
255
n = node.getAttributes().getNamedItem("strategy");
256             if (n == null)
257                 throw new SpeedoXMLError("Attribute strategy for tag sequence requested.");
258                 s.strategy = SpeedoSequence.strategyToByte(n.getNodeValue());
259
260             logger.log(BasicLevel.DEBUG, "New sequence: "
261                     + "name=" + s.name
262                     + " / datastoreName = " + s.datastoreName
263                     + " / factoryClass = " + s.factoryClass
264                     + " / strategy = " + s.strategy
265             );
266             
267             return s;
268         } else if (tag.equals("field")) { //tag field
269
SpeedoField f = new SpeedoField();
270
271             //attribut name (compulsory)
272
n = node.getAttributes().getNamedItem("name");
273             if (n == null)
274                 throw new SpeedoXMLError("Attribute name for tag field requested.");
275             String JavaDoc name = n.getNodeValue();
276             if(name.indexOf(".") != -1){
277                 
278             }
279             f.name = n.getNodeValue();
280
281             //attribute persistence-modifier
282
n = node.getAttributes().getNamedItem("persistence-modifier");
283             if (n != null)
284                 f.persistenceModifier = SpeedoModifier.toByte(n.getNodeValue());
285
286             //attribute primary-key
287
n = node.getAttributes().getNamedItem("primary-key");
288             if (n != null)
289                 f.primaryKey = Boolean.valueOf(n.getNodeValue()).booleanValue();
290
291             //attribute null-value
292
n = node.getAttributes().getNamedItem("null-value");
293             if (n != null) {
294                 f.nullValue = SpeedoNullValue.toByte(n.getNodeValue());
295             }
296
297             //attribute default-fetch-group
298
n = node.getAttributes().getNamedItem("default-fetch-group");
299             if (n != null)
300                 f.defaultFetchGroup = Boolean.valueOf(n.getNodeValue()).booleanValue();
301
302             //attribute fetch-group
303
n = node.getAttributes().getNamedItem("fetch-group");
304             if (n != null)
305                 f.fetchGroup = n.getNodeValue();
306                 
307             //attribute depth
308
n = node.getAttributes().getNamedItem("depth");
309             if (n != null)
310                 f.depth = Integer.valueOf(n.getNodeValue()).intValue();
311
312             //attribute embbedded
313
n = node.getAttributes().getNamedItem("embedded");
314             if (n != null)
315                 f.embedded = Boolean.valueOf(n.getNodeValue()).booleanValue();
316
317             //attribute value-strategy
318
n = node.getAttributes().getNamedItem("value-strategy");
319             if (n != null)
320                 f.valueStrategy = n.getNodeValue();
321             
322             //attribute sequence
323
n = node.getAttributes().getNamedItem("sequence");
324             if (n != null)
325                 f.sequence = n.getNodeValue();
326             
327             logger.log(BasicLevel.DEBUG, "New field: "
328                     + "name=" + f.name
329                     + " / persistenceModifier = " + f.persistenceModifier
330                     + " / primaryKey = " + f.primaryKey
331                     + " / nullValue = " + f.nullValue
332                     + " / defaultFetchGroup = " + f.defaultFetchGroup
333                     + " / embedded = " + f.embedded
334                     + " / depth = " + f.depth
335                     + " / valueStrategy = " + f.valueStrategy
336                     + " / sequence = " + f.sequence
337             );
338             return f;
339
340         } else if (tag.equals("datastore-identity")) { //tag datastore-identity
341
SpeedoDatastoreId d = new SpeedoDatastoreId();
342             
343             //attribute strategy
344
n = node.getAttributes().getNamedItem("strategy");
345             if (n == null)
346                 throw new SpeedoXMLError("Attribute strategy for tag datastore-identity requested.");
347             d.strategy = SpeedoDatastoreId.toByte(n.getNodeValue());
348
349             //attribute sequence
350
n = node.getAttributes().getNamedItem("sequence");
351             if (n != null)
352                 d.sequence = n.getNodeValue();
353               
354             logger.log(BasicLevel.DEBUG, "New datastore-identity: "
355                     + "strategy =" + d.strategy
356                     + " / sequence = " + d.sequence
357             );
358             return d;
359         } else if (tag.equals("collection")) { //tag collection
360
SpeedoCollection co = new SpeedoCollection();
361
362             //attribute element-type
363
n = node.getAttributes().getNamedItem("element-type");
364             if (n != null)
365                 co.elementType = n.getNodeValue();
366
367             //attribute embedded-element
368
n = node.getAttributes().getNamedItem("embedded-element");
369             if (n != null)
370                 co.embeddedElement = Boolean.valueOf(n.getNodeValue()).booleanValue();
371
372             logger.log(BasicLevel.DEBUG, "New collection: "
373                     + "elementType=" + co.elementType
374                     + " / embeddedElement = " + co.embeddedElement
375             );
376             return co;
377
378         } else if (tag.equals("map")) { //tag map
379
SpeedoMap m = new SpeedoMap();
380
381             //attribut key-type
382
n = node.getAttributes().getNamedItem("key-type");
383             if (n != null)
384                 m.keyType = n.getNodeValue();
385
386             //attribut embedded-key
387
n = node.getAttributes().getNamedItem("embedded-key");
388             if (n != null)
389                 m.embeddedKey = Boolean.valueOf(n.getNodeValue()).booleanValue();
390
391             //attribute value-type
392
n = node.getAttributes().getNamedItem("value-type");
393             if (n != null)
394                 m.valueType = n.getNodeValue();
395
396             //attribute embedded-value
397
n = node.getAttributes().getNamedItem("embedded-value");
398             if (n != null)
399                 m.embeddedValue = Boolean.valueOf(n.getNodeValue()).booleanValue();
400
401             logger.log(BasicLevel.DEBUG, "New map: "
402                     + "keyType=" + m.keyType
403                     + " / embeddedKey = " + m.embeddedKey
404                     + " / valueType = " + m.valueType
405                     + " / embeddedValue = " + m.embeddedValue
406             );
407             return m;
408
409         } else if (tag.equals("array")) { //tag array
410
SpeedoArray a = new SpeedoArray();
411
412             //attribute embedded-element
413
n = node.getAttributes().getNamedItem("embedded-element");
414             if (n != null)
415                 a.embeddedElement = Boolean.valueOf(n.getNodeValue()).booleanValue();
416
417             logger.log(BasicLevel.DEBUG, "New array: "
418                     + "embeddedElement=" + a.embeddedElement
419             );
420             return a;
421         } else if (tag.equals("version")) { //tag version
422
SpeedoVersion v = new SpeedoVersion();
423
424             //attribute embedded-element
425
n = node.getAttributes().getNamedItem("strategy");
426             v.strategy = SpeedoVersion.toByte(n.getNodeValue());
427             
428             logger.log(BasicLevel.DEBUG, "New version: "
429                        + "strategy=" + v.strategy);
430             return v;
431         } else if (tag.equals("extension")) { //tag extension
432
SpeedoExtension e = new SpeedoExtension();
433
434             //attribute vendor-name
435
n = node.getAttributes().getNamedItem("vendor-name");
436             e.vendorName = n.getNodeValue();
437
438             //attribute key
439
n = node.getAttributes().getNamedItem("key");
440             if (n != null)
441                 e.key = n.getNodeValue();
442
443             //attribute value
444
n = node.getAttributes().getNamedItem("value");
445             if (n != null)
446                 e.value = n.getNodeValue();
447
448             return e;
449         } else if (tag.equals("fetch-group")) { //tag fetch-group
450
SpeedoFetchGroup fg = new SpeedoFetchGroup();
451             
452             //attribute name
453
n = node.getAttributes().getNamedItem("name");
454             fg.name = n.getNodeValue();
455             
456             //attribute post-load
457
n = node.getAttributes().getNamedItem("post-load");
458             if (n != null){
459                 fg.postLoad = Boolean.valueOf(n.getNodeValue()).booleanValue();
460             }
461             else{
462                 if(fg.name.equals("default"))
463                     fg.postLoad = true;
464                 else
465                     fg.postLoad = false;
466             }
467             return fg;
468         } else if (tag.equals("query")) {
469             SpeedoPredefinedQuery spq = new SpeedoPredefinedQuery();
470             
471             spq.name = getStringAttributeValue(node, "name", null);
472             spq.language = getStringAttributeValue(node, "language", null);
473             spq.filter = getStringAttributeValue(node, "filter", null);
474             spq.ordering = getStringAttributeValue(node, "ordering", null);
475             spq.sql = getStringAttributeValue(node, "sql", null);
476             spq.ignoreCache = getBooleanAttributeValue(node, "ignore-cache", false);
477             spq.includeSubclasses = getBooleanAttributeValue(node, "include-subclasses", true);
478             
479             String JavaDoc range = getStringAttributeValue(node, "range", null);
480             if (range != null) {
481                 StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(range, ",.;:/#", false);
482                 if (st.hasMoreTokens()) {
483                     spq.rangeFirst = Integer.valueOf(st.nextToken()).intValue();
484                     if (st.hasMoreTokens()) {
485                         spq.rangeLast = Integer.valueOf(st.nextToken()).intValue();
486                     }
487                     if (st.hasMoreTokens()) {
488                         logger.log(BasicLevel.WARN,
489                                 "Query range contains too values, first="
490                                 + spq.rangeFirst + ", last=" + spq.rangeLast
491                                 + ", query=" + spq.name + ", range: " + range);
492                     }
493                 } else {
494                     logger.log(BasicLevel.WARN,
495                             "Query range value malformed (ignored), query:"
496                             + spq.name + ", range: " + range);
497                 }
498             }
499             return spq;
500         } else if (tag.equals("declare")) { //quer.declare
501
SpeedoPredefinedQuery spq = (SpeedoPredefinedQuery) o;
502             spq.declareImports = getStringAttributeValue(node, "imports", null);
503             spq.declareParameters = getStringAttributeValue(node, "parameters", null);
504             spq.declareVariables = getStringAttributeValue(node, "variables", null);
505             return spq;
506         } else if (tag.equals("result")) { //query.result
507
SpeedoPredefinedQuery spq = (SpeedoPredefinedQuery) o;
508             spq.resultGrouping = getStringAttributeValue(node, "grouping", null);
509             spq.resultClass = getStringAttributeValue(node, "class", null);
510             spq.resultUnique = getBooleanAttributeValue(node, "unique", false);
511             return spq;
512         } else
513             return o;
514     }
515
516     private String JavaDoc getStringAttributeValue(Node JavaDoc node, String JavaDoc attribName, String JavaDoc defaultValue) {
517         Node JavaDoc n = node.getAttributes().getNamedItem(attribName);
518         if (n != null) {
519             return n.getNodeValue();
520         } else {
521             return defaultValue;
522         }
523     }
524     
525
526     private boolean getBooleanAttributeValue(Node JavaDoc node, String JavaDoc attribName, boolean defaultValue) {
527         Node JavaDoc n = node.getAttributes().getNamedItem(attribName);
528         if (n != null) {
529             return Boolean.valueOf(n.getNodeValue()).booleanValue();
530         } else {
531             return defaultValue;
532         }
533     }
534
535     /**
536      * Create the XML file descriptor.
537      * It throws an exception if the XML file doesn't follow the jdo dtd.
538      * @param node root node of the descriptor which will be return.
539      * @param o default descriptor to return.
540      * @return descriptor.
541      */

542     private Object JavaDoc treatDocument(Node JavaDoc node, Object JavaDoc o) throws SpeedoException {
543         //o is descriptor of the node root
544
o = treatNode(node, o);
545         //list of child node
546
NodeList JavaDoc children = node.getChildNodes();
547
548         //if the node has a child
549
if (children != null) {
550             //for each child
551
for (int i = 0; i < children.getLength(); i++) {
552                 //create a descriptor for the child
553
Object JavaDoc fils = treatDocument(children.item(i), o);
554                 //add this descriptor to the parent descriptor
555
add(o, fils, children.item(i).getNodeName());
556             }
557         }
558         return o;
559     }
560
561     /**
562      * This methods adds an element into a descriptor.
563      * @param graph descriptor.
564      * @param newElem object to add.
565      * @param tag object type.
566      * @return the new descriptor.
567      * @exception SpeedoException if a field is described twice.
568      */

569     private void add(Object JavaDoc graph, Object JavaDoc newElem, String JavaDoc tag)
570             throws SpeedoException {
571
572         if (tag.equals("package")) { //the new element is a package
573
logger.log(BasicLevel.DEBUG, "add package '" + ((SpeedoPackage) newElem).name + "'");
574             ((SpeedoXMLDescriptor) graph).add(newElem, true, logger);
575
576         } else if (tag.equals("class")) { //the new element is a class
577
logger.log(BasicLevel.DEBUG, "add class '" + ((SpeedoClass) newElem).name + "'");
578             ((SpeedoPackage) graph).addClass(newElem, true, logger);
579
580         } else if (tag.equals("sequence")) { //the new element is a sequence
581
logger.log(BasicLevel.DEBUG, "add sequence '" + ((SpeedoSequence) newElem).name + "'");
582             ((SpeedoPackage) graph).addSequence(newElem);
583             
584         } else if (tag.equals("datastore-identity")) { //the new element is a datastore-identity
585
logger.log(BasicLevel.DEBUG, "add datastore-identity '" + ((SpeedoDatastoreId) newElem).strategy + "'");
586             ((SpeedoClass) graph).addDatastoreId(newElem);
587             
588         } else if (tag.equals("field")) { //the new element is a field
589
if(graph instanceof SpeedoClass){
590                 if (logger.isLoggable(BasicLevel.DEBUG)) {
591                     logger.log(BasicLevel.DEBUG,
592                             "add field '" + ((SpeedoField) newElem).name
593                             + "' into the class '" + ((SpeedoClass) graph).name +"'");
594                 }
595                 ((SpeedoClass) graph).add(newElem, true, logger);
596                 if (((SpeedoField) newElem).valueStrategy != null &&
597                         ((SpeedoField) newElem).valueStrategy.equals("sequence") &&
598                         ((SpeedoField) newElem).sequence != null) {
599                     //add the datastoreSequence to the class
600
((SpeedoClass) graph).datastoreSequence = ((SpeedoField) newElem).sequence;
601                 }
602             }
603             else{
604                 if (logger.isLoggable(BasicLevel.DEBUG)) {
605                     logger.log(BasicLevel.DEBUG,
606                         "add field '" + ((SpeedoField) newElem).name
607                         + "' into the fetchgroup '" + ((SpeedoFetchGroup) graph).name +"'");
608                 }
609                 ((SpeedoFetchGroup) graph).addField(newElem);
610             }
611         } else if (tag.equals("version")) { //the new element is a version
612
if (logger.isLoggable(BasicLevel.DEBUG)) {
613                 logger.log(BasicLevel.DEBUG,
614                         "add version into the class '" + ((SpeedoClass) graph).name +"'");
615             }
616             ((SpeedoClass) graph).addVersion(newElem);
617         } else if (tag.equals("collection")) { //the new element is a collection
618
logger.log(BasicLevel.DEBUG,
619                     "add collection: '" + ((SpeedoField) graph).name + "'");
620             ((SpeedoField) graph).jdoTuple = (SpeedoTuple) newElem;
621             ((SpeedoTuple) newElem).jdoField = (SpeedoField) graph;
622
623         } else if (tag.equals("map")) { //the new element is a map
624
logger.log(BasicLevel.DEBUG,
625                     "add map: '" + ((SpeedoField) graph).name + "'");
626             ((SpeedoField) graph).jdoTuple = (SpeedoTuple) newElem;
627             ((SpeedoTuple) newElem).jdoField = (SpeedoField) graph;
628
629         } else if (tag.equals("array")) { //the new element is an array
630
logger.log(BasicLevel.DEBUG,
631                     "add array: '" + ((SpeedoField) graph).name + "'");
632             ((SpeedoField) graph).jdoTuple = (SpeedoTuple) newElem;
633             ((SpeedoTuple) newElem).jdoField = (SpeedoField) graph;
634
635         } else if (tag.equals("extension")) { //the new element is an extension
636
logger.log(BasicLevel.DEBUG, "add extension");
637             ((SpeedoElement) graph).addExtension((SpeedoExtension) newElem);
638             ((SpeedoExtension) newElem).jdoElement = (SpeedoElement) graph;
639             
640         } else if (tag.equals("fetch-group")) { //the new element is a fetch-group
641
if (graph instanceof SpeedoClass){
642                 if (logger.isLoggable(BasicLevel.DEBUG)) {
643                         logger.log(BasicLevel.DEBUG,
644                         "add fetchgroup '" + ((SpeedoFetchGroup) newElem).name +
645                         "' into the class '" + ((SpeedoClass) graph).name +"'");
646                 }
647                 ((SpeedoClass) graph).addFetchGroup(newElem);
648             }
649             else{
650                 if (logger.isLoggable(BasicLevel.DEBUG)) {
651                     logger.log(BasicLevel.DEBUG,
652                         "add fetchgroup '" + ((SpeedoFetchGroup) newElem).name +
653                         "' into the class '" + ((SpeedoClass) graph).name +"'");
654                 }
655                 ((SpeedoFetchGroup) graph).addFetchGroup(newElem);
656             }
657         } else if (tag.equals("query")) {
658             ((SpeedoClass) graph).name2query.put(
659                     ((SpeedoPredefinedQuery) newElem).name, newElem);
660         }
661     }
662 }
663
Popular Tags