KickJava   Java API By Example, From Geeks To Geeks.

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


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.sequence.lib.SpeedoSequence;
32 import org.objectweb.util.monolog.api.Logger;
33
34 import java.util.HashMap JavaDoc;
35 import java.util.Iterator JavaDoc;
36 import java.util.Map JavaDoc;
37
38 /**
39  * Describes a package which contains persistence capable classes.
40  * @author S.Chassande-Barrioz
41  */

42 public class SpeedoPackage extends SpeedoElement {
43     /**
44      * Package name.
45      */

46     public String JavaDoc name;
47
48     /**
49      * Persistence capable classes descriptors of the package. The HashMap key
50      * is the class name.
51      */

52     public Map JavaDoc jdoClass = new HashMap JavaDoc();
53
54     /**
55      * Sequences descriptors of the package. The HashMap key
56      * is the sequence name.
57      */

58     public Map JavaDoc jdoSequence = new HashMap JavaDoc();
59     
60     /**
61      * Descriptor to which this package is associated.
62      */

63     public SpeedoXMLDescriptor jdoXMLDescriptor;
64
65     /**
66      * Transforms a SpeedoPackage into a String.
67      * @return the corresponding String.
68      */

69     public String JavaDoc toString() {
70         String JavaDoc s = "package\tname : " + name;
71         s += "\n\tclasses: ";
72         Iterator JavaDoc it = jdoClass.values().iterator();
73         while (it.hasNext()) {
74             s = s + " " + it.next().toString();
75         }
76         s += "\n\tsequences: ";
77         it = jdoSequence.values().iterator();
78         while (it.hasNext()) {
79             s = s + " " + it.next().toString();
80         }
81         return s;
82     }
83
84     /**
85      * Adds a class descriptor to the package descriptor.
86      * @param clazz class to add.
87      * @param failsOnError if an error provoques an exception or a warning message.
88      * @param logger logger where to put warning message.
89      * @exception SpeedoException If a field of the class descriptor is already
90      * defined into the package descriptor.
91      */

92     public void addClass(Object JavaDoc clazz, boolean failsOnError, Logger logger) throws SpeedoException {
93         SpeedoClass sc = (SpeedoClass) clazz;
94         //the class already exists
95
if (jdoClass.containsKey(sc.name)) {
96             //we add its fields
97
SpeedoClass cref = (SpeedoClass) jdoClass.get(sc.name);
98             Iterator JavaDoc it = sc.jdoField.values().iterator();
99             while (it.hasNext()) {
100                 cref.add(it.next(), failsOnError, logger);
101             }
102         }
103         //we add the entire class;
104
else {
105             sc.jdoPackage = this;
106             jdoClass.put(sc.name, sc);
107         }
108     }
109     
110     /**
111      * Adds a sequence descriptor to the package descriptor.
112      * If a sequence with the same name is already registered, nothing is done.
113      * @param sequence the sequence to add.
114      */

115     public void addSequence(Object JavaDoc sequence){
116         SpeedoSequence ss = (SpeedoSequence) sequence;
117         //if the sequence is not already registered
118
if (!jdoSequence.containsKey(ss.name)) {
119             //set the package name of the sequence
120
ss.packageName = this.name;
121             //add it to the list
122
jdoSequence.put(ss.name, ss);
123         }
124     }
125 } // end SpeedoPackage
126
Popular Tags