KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > mi2xml > lib > BasicDomtreeBuilder


1 /**
2  * JORM: an implementation of a generic mapping system for persistent Java
3  * objects. Two mapping are supported: to RDBMS and to binary files.
4  * Copyright (C) 2001-2003 France Telecom R&D - INRIA
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  * Contact: jorm-team@objectweb.org
21  *
22  */

23
24 package org.objectweb.jorm.mi2xml.lib;
25
26 import org.apache.xerces.dom.DocumentImpl;
27 import org.objectweb.jorm.metainfo.api.*;
28 import org.objectweb.jorm.metainfo.api.Package;
29 import org.objectweb.jorm.metainfo.api.Class;
30 import org.objectweb.jorm.mi2xml.api.MappingDomtreeBuilder;
31 import org.objectweb.jorm.mi2xml.api.DomtreeBuilder;
32 import org.objectweb.jorm.util.api.Loggable;
33 import org.objectweb.jorm.api.PException;
34 import org.objectweb.jorm.compiler.api.PExceptionCompiler;
35 import org.objectweb.util.monolog.api.Logger;
36 import org.objectweb.util.monolog.api.LoggerFactory;
37 import org.objectweb.util.monolog.api.BasicLevel;
38 import org.w3c.dom.Document JavaDoc;
39 import org.w3c.dom.Element JavaDoc;
40
41 import java.util.*;
42
43 /**
44  * BasicDomtreeBuilder implements the DomtreeBuilder interface.
45  */

46 public class BasicDomtreeBuilder implements DomtreeBuilder, Loggable {
47     //TODO: declare this in a class
48
public final static String JavaDoc ID = "ID";
49     public final static String JavaDoc REF = "REF";
50     public final static String JavaDoc IDVALUE_SEP = ".";
51     public final static String JavaDoc JORM = "jorm";
52     public final static String JavaDoc PACKAGE = "package";
53     public final static String JavaDoc CLASS = "class";
54     public final static String JavaDoc MAPPING = "mapping";
55     public final static String JavaDoc COMPOSITE_NAME = "composite-name";
56     public final static String JavaDoc FIELD = "field";
57     public final static String JavaDoc SCALAR_FIELD = "scalar-field";
58     public final static String JavaDoc EXTENSION = "extension";
59     public final static String JavaDoc NAME_DEF = "name-def";
60     public final static String JavaDoc PRIMITIVE_TYPE = "primitive-type";
61     public final static String JavaDoc CLASS_REF = "class-ref";
62     public final static String JavaDoc GEN_CLASS_REF = "gen-class-ref";
63     public final static String JavaDoc FIELD_REF = "field-ref";
64     public final static String JavaDoc SCALAR_TYPE = "scalar-type";
65     public final static String JavaDoc NULL_VALUE = "null-value";
66     public final static String JavaDoc GEN_CLASS = "gen-class";
67     public final static String JavaDoc INDEX = "index";
68     public final static String JavaDoc SYSTEM = "system";
69     public final static String JavaDoc COMPOSITE_NAME_REF = "composite-name-ref";
70     public final static String JavaDoc COMPOSITE_NAME_FIELD_PROJECTION =
71             "composite-name-field-projection";
72
73     /**
74      * This hashmap associates a mapper name with a MappingDomtreeBuilder object.
75      */

76     private Map mappingDomtreeBuilders;
77
78     /**
79      * a simple logger to log
80      */

81     private Logger logger;
82
83     /**
84      * a logger factory to create other loggers if needed
85      */

86     private LoggerFactory loggerFactory;
87
88     /**
89      * A Map of GenClassRef objects.
90      * key = a GenClassRef object,
91      * value = a String object that represents the associated id value.
92      */

93     private Map metaobject2idvalue;
94
95     /**
96      * Main constructor for BasicDomtreeBuilder.
97      */

98     public BasicDomtreeBuilder() {
99         metaobject2idvalue = new Hashtable();
100         mappingDomtreeBuilders = new HashMap();
101     }
102
103     /**
104      * Adds a MappingDomtreeBuilder object.
105      * @param mapperName a mapper name,
106      * mdb a MappingDomtreeBuilder object.
107      */

108     public void addMappingDomtreeBuilder(String JavaDoc mapperName, MappingDomtreeBuilder mdb) {
109         if (getLogger().isLoggable(BasicLevel.DEBUG)) {
110             getLogger().log(BasicLevel.DEBUG,
111                             "Add a MappingDomtreeBuilder (" + mapperName +
112                             ") for the current builder");
113         }
114         if (!mappingDomtreeBuilders.containsKey(mapperName)) {
115             mappingDomtreeBuilders.put(mapperName, mdb);
116         }
117     }
118
119     /**
120      * Returns a MappingDomtreeBuilder object.
121      * @param mapperName a mapper name,
122      * @return a MappingDomtreeBuilder object.
123      */

124     private MappingDomtreeBuilder getMappingDomtreeBuilder(String JavaDoc mapperName) throws PException {
125         MappingDomtreeBuilder mdb = (MappingDomtreeBuilder) mappingDomtreeBuilders.get(mapperName);
126         if (mdb == null) {
127             throw new PExceptionCompiler("<" + mapperName +
128                                          ">DomtreeBuilder has not been created.");
129         }
130         return mdb;
131     }
132
133     /**
134      * Generates the org.w3c.dom.Document object from a <tt>Class</tt>
135      * or a <tt>CompositeName</tt> object.
136      * @param metaObject a <tt>Class</tt> or a <tt>CompositeName</tt> object.
137      * @return the corresponding <tt>org.w3c.dom.Document</tt> object.
138      *
139      * @see org.w3c.dom.Document
140      */

141     public Document JavaDoc build(MetaObject metaObject) throws PException {
142         Document JavaDoc document = new DocumentImpl();
143         Element JavaDoc rootElement =
144                 document.createElement(JORM);
145         // Creates an Element object for the Package object
146
String JavaDoc packageName = ((Package JavaDoc) metaObject.getParent()).getName();
147         Element JavaDoc packageElement = document.createElement(PACKAGE);
148         packageElement.appendChild(document.createTextNode(packageName));
149         // Adds packageElement to rootElement.
150
rootElement.appendChild(packageElement);
151
152         // Creates an Element object for a Class or a CompositeName object
153
if (metaObject instanceof Class JavaDoc) {
154             Class JavaDoc clazz = (Class JavaDoc) metaObject;
155             String JavaDoc className = clazz.getName();
156             Element JavaDoc classElement = document.createElement(CLASS);
157             // Adds attributes to classElement.
158
classElement.setAttribute("name", className);
159             classElement.setAttribute("abstract",
160                                       ("" + clazz.isAbstract()).toUpperCase());
161             // Adds classElement to rootElement
162
rootElement.appendChild(classElement);
163             // Builds the domtree enrooted at classElement
164
processClass(document, classElement, clazz);
165             if (!clazz.getClassProjects().isEmpty()) {
166                 processMappings(document, rootElement, clazz);
167             }
168         } else {
169             CompositeName compositeName = (CompositeName) metaObject;
170             Element JavaDoc compositeNameElement =
171                     document.createElement(COMPOSITE_NAME);
172             // Add attributes to compositeName Element
173
compositeNameElement.setAttribute("name", compositeName.getName());
174             // Adds compositenameElement to rootElement
175
rootElement.appendChild(compositeNameElement);
176             // builds the domtree enrooted at classElement
177
processCompositeName(document, compositeNameElement, compositeName);
178         }
179         document.appendChild(rootElement);
180         return document;
181     }
182
183
184     /**
185      * Adds field elements, scalar field elements, inherited class elements, name defintions elements
186      * to a class element.
187      * @param document an org.w3c.dom.Document object,
188      * classElement a class element,
189      * clazz a <tt>Class</tt> object.
190      */

191     private void processClass(Document JavaDoc document, Element JavaDoc classElement, Class JavaDoc clazz) {
192         Iterator fieldIterator = clazz.getFields().iterator();
193         // Processes the class fields.
194
while (fieldIterator.hasNext()) {
195             TypedElement typedElement = (TypedElement) fieldIterator.next();
196             String JavaDoc fieldName = typedElement.getName();
197             String JavaDoc idValue = fieldName;
198             Element JavaDoc fieldElement = document.createElement(FIELD);
199             fieldElement.setAttribute("name", fieldName);
200             classElement.appendChild(fieldElement);
201             // Processes PrimitiveElement objects if any.
202
if (typedElement instanceof PrimitiveElement) {
203                 Element JavaDoc ptElement = document.createElement(PRIMITIVE_TYPE);
204                 //ptElement.setAttribute("id", idValue);
205
ptElement.setAttribute("type", typedElement.getType().getJormName());
206                 fieldElement.appendChild(ptElement);
207                 //metaobject2idvalue.put(typedElement, idValue);
208
}
209             // Processes ClassRef objects if any.
210
//TODO : add getFQName() to ClassRef
211
else if (typedElement instanceof ClassRef) {
212                 Element JavaDoc crElement = document.createElement(CLASS_REF);
213                 crElement.setAttribute("class-name", ((ClassRef) typedElement).getMOClass().getFQName());
214                 fieldElement.appendChild(crElement);
215                 processClassRef(document, crElement, (ClassRef) typedElement, idValue);
216             }
217             // Processes GenClassRef objects if any.
218
else if (typedElement instanceof GenClassRef) {
219                 Element JavaDoc gcrElement = document.createElement(GEN_CLASS_REF);
220                 //gcrElement.setAttribute("shared", ...);
221
fieldElement.appendChild(gcrElement);
222                 processGenClassRef(document, gcrElement, (GenClassRef) typedElement, idValue);
223             }
224         }
225         // Processes the ScalarField objects.
226
Iterator sfIterator = clazz.getHiddenFields().iterator();
227         while (sfIterator.hasNext()) {
228             ScalarField scalarField = (ScalarField) sfIterator.next();
229             String JavaDoc name = scalarField.getName();
230             String JavaDoc idValue = name;
231             Element JavaDoc sfElement = document.createElement(SCALAR_FIELD);
232             sfElement.setAttribute("name", name);
233             classElement.appendChild(sfElement);
234             processScalarField(document, sfElement, scalarField, idValue);
235         }
236         // Processes the super classes.
237
Iterator superIterator = clazz.getSuperClasses().iterator();
238         while (superIterator.hasNext()) {
239             Class JavaDoc superClazz = (Class JavaDoc) superIterator.next();
240             Element JavaDoc extElement = document.createElement(EXTENSION);
241             extElement.setAttribute("name", superClazz.getFQName());
242             classElement.appendChild(extElement);
243         }
244         // Processes the NameDef objects.
245
Iterator ndIterator = clazz.getNameDefs().iterator();
246         while (ndIterator.hasNext()) {
247             NameDef nameDef = (NameDef) ndIterator.next();
248             /* String name = nameDef.getName();
249             String idValue = ID + IDVALUE_SEP + nameDef.getName();
250             Element ndElement = document.createElement(NAME_DEF);
251             ndElement.setAttribute("id", idValue);
252             */

253             Element JavaDoc ndElement = document.createElement(NAME_DEF);
254             ndElement.setAttribute("name", nameDef.getName());
255             classElement.appendChild(ndElement);
256             //metaobject2idvalue.put(nameDef, idValue);
257
processNameDef(document, ndElement, nameDef);
258         }
259     }
260
261     /**
262      * Adds name definition elements to a class reference element.
263      * @param document an org.w3c.dom.Document object,
264      * crElement a class reference element,
265      * classRef a <tt>ClassRef</tt> object,
266      * parentIdValue a String value identifying the class reference element.
267      */

268     private void processClassRef(Document JavaDoc document, Element JavaDoc crElement,
269                                  ClassRef classRef, String JavaDoc parentIdValue) {
270         // Processes the NameDef objects.
271
Iterator ndIterator = classRef.getRefNameDef().iterator();
272         while (ndIterator.hasNext()) {
273             NameDef nameDef = (NameDef) ndIterator.next();
274             /* String name = nameDef.getName();
275             String idValue = parentIdValue + IDVALUE_SEP + REF + IDVALUE_SEP + name;
276             Element ndElement = document.createElement(NAME_DEF);
277             ndElement.setAttribute("id", idValue);
278             */

279             Element JavaDoc ndElement = document.createElement(NAME_DEF);
280             ndElement.setAttribute("name", nameDef.getName());
281             crElement.appendChild(ndElement);
282             //metaobject2idvalue.put(nameDef, idValue);
283
processNameDef(document, ndElement, nameDef);
284         }
285     }
286
287     /**
288      * Adds a generic class element and name definition elements to a
289      * generic class reference element.
290      * @param document an org.w3c.dom.Document object,
291      * gcrElement a generic class reference element,
292      * genClassRef a <tt>GenClassRef</tt> object,
293      * parentIdValue a String value identifying the generic class reference element.
294      */

295     private void processGenClassRef(Document JavaDoc document, Element JavaDoc gcrElement,
296                                     GenClassRef genClassRef, String JavaDoc parentIdValue) {
297         // Processes the generic class.
298
/* String genClassName = genClassRef.getGenClassName();
299         String genclassIdValue = parentIdValue + IDVALUE_SEP + genClassName;
300         */

301         Element JavaDoc gcElement = document.createElement(GEN_CLASS);
302         //gcElement.setAttribute("id", genclassIdValue);
303
gcElement.setAttribute("gen-class-name", genClassRef.getGenClassName());
304         gcrElement.appendChild(gcElement);
305         metaobject2idvalue.put(genClassRef, genClassRef.getGenClassId());
306         processGenClass(document, gcElement, genClassRef, "");
307         // Processes the NameDef objects.
308
Iterator ndIterator = genClassRef.getRefNameDef().iterator();
309         while (ndIterator.hasNext()) {
310             NameDef nameDef = (NameDef) ndIterator.next();
311             /* String name = nameDef.getName();
312             String nameDefIdValue = parentIdValue + IDVALUE_SEP + REF + IDVALUE_SEP + name;
313             Element ndElement = document.createElement(NAME_DEF);
314             ndElement.setAttribute("id", nameDefIdValue);
315             */

316             Element JavaDoc ndElement = document.createElement(NAME_DEF);
317             ndElement.setAttribute("name", nameDef.getName());
318             gcrElement.appendChild(ndElement);
319             //metaobject2idvalue.put(nameDef, nameDefIdValue);
320
processNameDef(document, ndElement, nameDef);
321         }
322     }
323
324     /**
325      * Adds a scalar type element and possibly a null value element to
326      * a scalar field element.
327      * @param document an org.w3c.dom.Document object,
328      * sfElement a name definiton element,
329      * nameDef a <tt>NameDef</tt> object,
330      * idValue a String value identifying the scalar field element.
331      */

332     private void processScalarField(Document JavaDoc document, Element JavaDoc sfElement,
333                                     ScalarField scalarField, String JavaDoc idValue) {
334         // Processes the scalar type.
335
Element JavaDoc stElement = document.createElement(SCALAR_TYPE);
336         //stElement.setAttribute("id", idValue);
337
stElement.setAttribute("type", scalarField.getType().getJormName());
338         sfElement.appendChild(stElement);
339         //metaobject2idvalue.put(scalarField, idValue);
340
// Processes the null value.
341
if (scalarField.getNullValue() != null) {
342             Element JavaDoc nvElement = document.createElement(NULL_VALUE);
343             nvElement.setAttribute("value", scalarField.getNullValue());
344             stElement.appendChild(nvElement);
345         }
346     }
347
348     /**
349      * Adds a system or a field reference or a composite name reference element to
350      * a name definition element.
351      * @param document an org.w3c.dom.Document object,
352      * ndElement a name definiton element,
353      * nameDef a <tt>NameDef</tt> object.
354      */

355     private void processNameDef(Document JavaDoc document, Element JavaDoc ndElement, NameDef nameDef) {
356         // Processes a system or a field reference, or a composite name reference.
357
if (nameDef.isSystem()) {
358             Element JavaDoc systemElement = document.createElement(SYSTEM);
359             ndElement.appendChild(systemElement);
360         } else if (nameDef.getFieldName() != null) {
361             Element JavaDoc frElement = document.createElement(FIELD_REF);
362             frElement.setAttribute("field-name", nameDef.getFieldName());
363             ndElement.appendChild(frElement);
364         } else if (nameDef.isNameRef()) {
365             NameRef nameRef = nameDef.getNameRef();
366             Element JavaDoc cnrElement = document.createElement(COMPOSITE_NAME_REF);
367             cnrElement.setAttribute("composite-name-name",
368                                     nameRef.getCNPackageName() + "." + nameRef.getName());
369             ndElement.appendChild(cnrElement);
370             processCompositeNameRef(document, cnrElement, nameRef);
371         }
372     }
373
374     /**
375      * Adds composite name field projection elements to a composite name reference element.
376      * @param document an org.w3c.dom.Document object,
377      * cnrElement a composite name reference element,
378      * nameRef a <tt>NameRef</tt> object.
379      */

380     private void processCompositeNameRef(Document JavaDoc document, Element JavaDoc cnrElement, NameRef nameRef) {
381         // Processes the composite name field projection(s).
382
Iterator projIterator = nameRef.getProjection().keySet().iterator();
383         while (projIterator.hasNext()) {
384             String JavaDoc fieldName = (String JavaDoc) projIterator.next();
385             String JavaDoc classFieldName = nameRef.getClassFieldName(fieldName);
386             Element JavaDoc cnfpElement = document.createElement(COMPOSITE_NAME_FIELD_PROJECTION);
387             cnfpElement.setAttribute("composite-name-field-name", fieldName);
388             cnfpElement.setAttribute("class-field-name", classFieldName);
389             cnrElement.appendChild(cnfpElement);
390         }
391     }
392
393     /**
394      * Adds a generic class element and name definition elements to a
395      * generic class reference element.
396      * @param document an org.w3c.dom.Document object,
397      * gcrElement a generic class reference element,
398      * genClassRef a <tt>GenClassRef</tt> object,
399      * parentIdValue a String value identifying the generic class element.
400      */

401     private void processGenClass(Document JavaDoc document, Element JavaDoc gcElement,
402                                  GenClassRef genClassRef, String JavaDoc parentIdValue) {
403         // Processes the ScalarField objects.
404
Iterator sfIterator = genClassRef.getHiddenFields().iterator();
405         while (sfIterator.hasNext()) {
406             ScalarField scalarField = (ScalarField) sfIterator.next();
407             //String name = scalarField.getName();
408
//String idValue = parentIdValue + IDVALUE_SEP + name;
409
Element JavaDoc sfElement = document.createElement(SCALAR_FIELD);
410             sfElement.setAttribute("name", scalarField.getName());
411             gcElement.appendChild(sfElement);
412             //metaobject2idvalue.put(scalarField, idValue);
413
processScalarField(document, sfElement, scalarField, "");
414         }
415         // Processes the NameDef objects.
416
Iterator ndIterator = genClassRef.getIdNameDef().iterator();
417         while (ndIterator.hasNext()) {
418             NameDef nameDef = (NameDef) ndIterator.next();
419             /*
420             String name = nameDef.getName();
421             String idValue = parentIdValue + IDVALUE_SEP + ID + IDVALUE_SEP + name;
422             Element ndElement = document.createElement(NAME_DEF);
423             ndElement.setAttribute("id", idValue);
424             */

425             Element JavaDoc ndElement = document.createElement(NAME_DEF);
426             ndElement.setAttribute("name", nameDef.getName());
427             gcElement.appendChild(ndElement);
428             //metaobject2idvalue.put(nameDef, idValue);
429
processNameDef(document, ndElement, nameDef);
430         }
431         // Processes the index.
432
Iterator frIterator = genClassRef.getIndexFields().iterator();
433         if (frIterator.hasNext()) {
434             Element JavaDoc indexElement = document.createElement(SCALAR_FIELD);
435             gcElement.appendChild(indexElement);
436             while (frIterator.hasNext()) {
437                 ScalarField scalarField = (ScalarField) frIterator.next();
438                 String JavaDoc name = scalarField.getName();
439                 Element JavaDoc frElement = document.createElement(FIELD_REF);
440                 frElement.setAttribute("name", name);
441                 indexElement.appendChild(frElement);
442             }
443         }
444         // Processes PrimitiveElement objects if any.
445
if (genClassRef.isPrimitive()) {
446             PrimitiveElement primitiveElement = genClassRef.getPrimitiveElement();
447             String JavaDoc fieldName = primitiveElement.getName();
448             /*
449             String idValue = parentIdValue + IDVALUE_SEP + fieldName;
450             Element ptElement = document.createElement(PRIMITIVE_TYPE);
451             ptElement.setAttribute("id", idValue);
452             */

453             Element JavaDoc ptElement = document.createElement(PRIMITIVE_TYPE);
454             ptElement.setAttribute("type", primitiveElement.getType().getJormName());
455             //metaobject2idvalue.put(primitiveElement, idValue);
456
gcElement.appendChild(ptElement);
457
458         }
459         // Processes ClassRef objects if any.
460
else if (genClassRef.isClassRef()) {
461             ClassRef classRef = genClassRef.getClassRef();
462             Element JavaDoc crElement = document.createElement(CLASS_REF);
463             crElement.setAttribute("name", classRef.getClassName());
464             gcElement.appendChild(crElement);
465             processClassRef(document, crElement, classRef, parentIdValue);
466         }
467         // Processes GenClassRef objects if any.
468
else if (genClassRef.isGenClassRef()) {
469             GenClassRef subGenClassRef = genClassRef.getGenClassRef();
470             Element JavaDoc gcrElement = document.createElement(GEN_CLASS_REF);
471             gcElement.appendChild(gcrElement);
472             processGenClassRef(document, gcrElement, subGenClassRef, parentIdValue);
473         }
474     }
475
476     //TODO : extension
477
/**
478      * Adds a composite name element to a jorm element (the root).
479      * @param document an org.w3c.dom.Document object,
480      * indexElement an index element,
481      * scalarField a <tt>ScalarField</tt> object.
482      */

483     private void processCompositeName(Document JavaDoc document, Element JavaDoc cnElement,
484                                       CompositeName compositeName) {
485         // Processes the ScalarField objects.
486
Iterator sfIterator = compositeName.getFields().iterator();
487         while (sfIterator.hasNext()) {
488             ScalarField scalarField = (ScalarField) sfIterator.next();
489             String JavaDoc name = scalarField.getName();
490             Element JavaDoc sfElement = document.createElement(SCALAR_FIELD);
491             sfElement.setAttribute("name", name);
492             cnElement.appendChild(sfElement);
493             processScalarField(document, sfElement, scalarField, name);
494         }
495         // Processes the inherited CompositeName objects.
496
Iterator icnIterator = compositeName.getSuperCompositeNames().iterator();
497         while (icnIterator.hasNext()) {
498             CompositeName aCompositeName = (CompositeName) icnIterator.next();
499             Element JavaDoc extensionElement = document.createElement(EXTENSION);
500             extensionElement.appendChild(document.createTextNode(aCompositeName.getName()));
501             cnElement.appendChild(extensionElement);
502         }
503     }
504
505     /**
506      * Adds mapping elements to a jorm element (the root).
507      * @param document an org.w3c.dom.Document object,
508      * rootElement the jorm element,
509      * clazz the current <tt>Class</tt> object.
510      */

511     private void processMappings(Document JavaDoc document, Element JavaDoc rootElement, Class JavaDoc clazz)
512             throws PException {
513         MappingDomtreeBuilder mdb = null;
514         // Processes the ClassProject objects.
515
Iterator cpIterator = clazz.getClassProjects().iterator();
516         while (cpIterator.hasNext()) {
517             ClassProject classProject = (ClassProject) cpIterator.next();
518             String JavaDoc projectName = classProject.getProjectName();
519             Element JavaDoc mappingElement = document.createElement(MAPPING);
520             mappingElement.setAttribute("project-name", projectName);
521             rootElement.appendChild(mappingElement);
522             // Processes the Mapping objects.
523
Iterator mappingIterator = classProject.getMappings().iterator();
524             while (mappingIterator.hasNext()) {
525                 Mapping mapping = (Mapping) mappingIterator.next();
526                 String JavaDoc mapperName = mapping.getMapperName();
527                 // Gets the right builder according to the current mapper type
528
// ("rdb", "fos", etc.)
529
mdb = getMappingDomtreeBuilder(mapperName);
530                 ((Loggable) mdb).setLogger(logger);
531                 mdb.setCurrentClass(clazz);
532                 mdb.setmetaobject2idvalue(metaobject2idvalue);
533                 ClassMapping classMapping = mapping.getClassMapping();
534                 if (logger.isLoggable(BasicLevel.DEBUG)) {
535                     logger.log(BasicLevel.DEBUG,
536                                "current class =<" + clazz.getName() + ">");
537                     logger.log(BasicLevel.DEBUG,
538                                "current project =<" + projectName + ">");
539                     logger.log(BasicLevel.DEBUG,
540                                "current mapping =<" + mapperName + ">");
541                 }
542                 mdb.processClassMapping(document, mappingElement, classMapping);
543                 Iterator gcmIterator = mapping.getGenClassMappings().iterator();
544                 while (gcmIterator.hasNext()) {
545                     GenClassMapping genClassMapping = (GenClassMapping) gcmIterator.next();
546                     mdb.processGenClassMapping(document, mappingElement, genClassMapping);
547                 }
548             }
549         }
550     }
551     ///////////////////////////////////////////////////////////////////
552
// from Loggable interface
553
///////////////////////////////////////////////////////////////////
554

555     /**
556      * Defines a logger object.
557      *
558      * @param logger the logger object
559      */

560     public void setLogger(Logger logger) {
561         this.logger = logger;
562     }
563
564     /**
565      * Defines the logger factory to obtain new loggers.
566      *
567      * @param loggerfactory The LoggerFactory object to obtain a logger object
568      */

569     public void setLoggerFactory(LoggerFactory loggerfactory) {
570         this.loggerFactory = loggerfactory;
571         if (logger == null && loggerFactory != null) {
572             logger = loggerFactory.getLogger("org.objectweb.jorm.mi2xml.rdb");
573         }
574     }
575
576     public Logger getLogger() {
577         return logger;
578     }
579
580     public LoggerFactory getLoggerFactory() {
581         return loggerFactory;
582     }
583 }
584
Popular Tags