KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > metainfo > api > MappingPrinter


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 package org.objectweb.jorm.metainfo.api;
24
25 import org.objectweb.jorm.metainfo.api.ClassMapping;
26 import org.objectweb.jorm.metainfo.api.PrimitiveElementMapping;
27
28 import java.io.PrintStream JavaDoc;
29 import java.util.Iterator JavaDoc;
30
31 /**
32  * This abstract class must be extends for each mapping. The aim is to print
33  * the meta objects ValueMapping and ClassMapping.
34  *
35  * @author S.Chassande-Barrioz
36  */

37 public abstract class MappingPrinter {
38
39     public final static String JavaDoc TAB = " ";
40
41     /**
42      * It retrieves true if the MappingPrinter is able to print the
43      * MappingStructure specified in parameter.
44      * This default implementation return always false.
45      */

46     public boolean canPrint(MappingStructure pem) {
47         return false;
48     }
49
50     public abstract void print(String JavaDoc p, PrimitiveElementMapping pem, PrintStream JavaDoc out);
51
52     public void print(String JavaDoc p, ClassMapping cm, PrintStream JavaDoc out) {
53         NameDef nd = (NameDef) cm.getIdentifierMapping().getLinkedMO();
54         out.println(p + "The name def '"
55                     + nd.getName()
56                     + "' is used for the class");
57         Iterator JavaDoc it = cm.getReferenceMappings().iterator();
58         while (it.hasNext()) {
59             nd = (NameDef) ((ReferenceMapping) it.next()).getLinkedMO();
60             out.println(p + "The name def '"
61                         + nd.getName()
62                         + "' is used for the reference '"
63                         + ((TypedElement) nd.getParent()).getName() + "'");
64         }
65         it = cm.getParentClassMappings().iterator();
66         if (!it.hasNext()) {
67             out.println(p + "No ParentClassMapping");
68         } else {
69             while (it.hasNext()) {
70                 print(p + TAB, (ParentClassMapping) it.next(), out);
71             }
72         }
73     }
74
75     public void print(String JavaDoc p, ParentClassMapping pcm, PrintStream JavaDoc out) {
76         out.println(p + "Super class: " + pcm.getMOClass().getFQName()
77             + ", RuleName: " + pcm.getRuleName());
78     }
79
80     public void print(String JavaDoc p, GenClassMapping gcm, PrintStream JavaDoc out) {
81         NameDef nd = (NameDef) gcm.getIdentifierMapping().getLinkedMO();
82         out.println(p + "The name def '"
83                     + nd.getName()
84                     + "' is used for the generic class '"
85                     + ((GenClassRef) gcm.getLinkedMO()).getGenClassId() + "'");
86
87         ReferenceMapping rm = gcm.getReferenceMapping();
88         if (rm != null) {
89             nd = (NameDef) rm.getLinkedMO();
90             out.println(p + "The name def '"
91                         + nd.getName()
92                         + "' is used for the element of the generic class '"
93                         + ((GenClassRef) gcm.getLinkedMO()).getGenClassId() + "'");
94         }
95     }
96 }
97
Popular Tags