KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > metadata > SpeedoXMLDescriptor


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.metadata;
29
30 import org.objectweb.speedo.api.SpeedoException;
31 import org.objectweb.speedo.generation.lib.NamingRules;
32 import org.objectweb.util.monolog.api.Logger;
33
34 import java.util.ArrayList JavaDoc;
35 import java.util.Collections JavaDoc;
36 import java.util.Enumeration JavaDoc;
37 import java.util.HashMap JavaDoc;
38 import java.util.HashSet JavaDoc;
39 import java.util.Iterator JavaDoc;
40 import java.util.List JavaDoc;
41 import java.util.Map JavaDoc;
42 import java.util.Set JavaDoc;
43
44 /**
45  * This class describes all persistence capable classes.
46  * @author S.Chassande-Barrioz
47  */

48 public class SpeedoXMLDescriptor {
49     /**
50      * List of packages descriptions which contains persistence capable classes.
51      */

52     public Map JavaDoc jdoPackage = new HashMap JavaDoc();
53
54     public SpeedoMetaInfo smi;
55
56     public String JavaDoc xmlFile = null;
57
58     public boolean requireEnhancement = true;
59     
60     /**
61      * The list of meta objects to serialize
62      */

63     public Set JavaDoc mos = new HashSet JavaDoc();
64
65     public SpeedoXMLDescriptor(SpeedoMetaInfo smi) {
66         this.smi = smi;
67     }
68
69     /**
70      * Transform this object into a String.
71      * @return the string corresponding to the object.
72      */

73     public String JavaDoc toString() {
74         Enumeration JavaDoc e = Collections.enumeration(jdoPackage.values());
75         String JavaDoc s = "descriptor ";
76         while (e.hasMoreElements()) {
77             s = s + " " + e.nextElement().toString();
78         }
79         return s;
80     }
81
82     /**
83      * Adds a package descriptor to the global descriptor.
84      * Throws an exception if there are persistent capable fields defined twice.
85      * @param pac package descriptor to add.
86      * @param failsOnError if an error provoques an exception or a warning message.
87      * @param logger logger where to put warning message.
88      * @exception SpeedoException If a persistent field of the package was already
89      * described in the global descriptor.
90      */

91     public void add(Object JavaDoc pac, boolean failsOnError, Logger logger) throws SpeedoException {
92         SpeedoPackage p = (SpeedoPackage) pac;
93         //the package already exixts in the descriptor.
94
if (jdoPackage.containsKey(p.name)) {
95             SpeedoPackage pref = (SpeedoPackage) jdoPackage.get(p.name);
96             //we add all its classes
97
Enumeration JavaDoc e = Collections.enumeration(p.jdoClass.values());
98             while (e.hasMoreElements()) {
99                 pref.addClass(e.nextElement(), failsOnError, logger);
100             }
101             //we add all its sequences
102
e = Collections.enumeration(p.jdoSequence.values());
103             while (e.hasMoreElements()) {
104                 pref.addSequence(e.nextElement());
105             }
106         }
107         //we add the entire package
108
else {
109             p.jdoXMLDescriptor = this;
110             jdoPackage.put(p.name, pac);
111         }
112     }
113
114     public List JavaDoc getSpeedoClasses() {
115         List JavaDoc scs = new ArrayList JavaDoc();
116         Iterator JavaDoc it = jdoPackage.values().iterator();
117         while(it.hasNext()) {
118             scs.addAll(((SpeedoPackage) it.next()).jdoClass.values());
119         }
120         return scs;
121     }
122
123     public List JavaDoc getSpeedoSequences() {
124         List JavaDoc ss = new ArrayList JavaDoc();
125         Iterator JavaDoc it = jdoPackage.values().iterator();
126         while(it.hasNext()) {
127             ss.addAll(((SpeedoPackage) it.next()).jdoSequence.values());
128         }
129         return ss;
130     }
131     
132     public SpeedoClass getSpeedoClass(String JavaDoc fqn, boolean other) {
133         //System.out.println("XML.getSpeedoClass(" + fqn + ", " + other + "): XML=" + xmlFile);
134
SpeedoClass sc = null;
135         if (other) {
136             sc = smi.getSpeedoClass(fqn, this);
137         }
138         if (sc != null) {
139             //System.out.println("XML.getSpeedoClass(): return " + sc);
140
return sc;
141         }
142         SpeedoPackage sp = (SpeedoPackage) jdoPackage.get(NamingRules.packageName(fqn));
143         if (sp != null) {
144             sc = (SpeedoClass) sp.jdoClass.get(NamingRules.className(fqn));
145         }
146         //System.out.println("XML.getSpeedoClass(): return " + sc);
147
return sc;
148     }
149 }
150
Popular Tags