/**
* Speedo: an implementation of JDO compliant personality on top of JORM generic
* I/O sub-system.
* Copyright (C) 2001-2004 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
*
* Contact: speedo@objectweb.org
*
* Authors: S.Chassande-Barrioz.
*
*/
package org.objectweb.speedo.metadata;
import org.objectweb.speedo.api.SpeedoException;
import org.objectweb.speedo.sequence.lib.SpeedoSequence;
import org.objectweb.util.monolog.api.Logger;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* Describes a package which contains persistence capable classes.
* @author S.Chassande-Barrioz
*/
public class SpeedoPackage extends SpeedoElement {
/**
* Comment for <code>serialVersionUID</code>
*/
private static final long serialVersionUID = -4376613964706359037L;
/**
* Package name.
*/
public String name;
/**
* Persistence capable classes descriptors of the package. The HashMap key
* is the class name.
*/
public Map classes = new HashMap();
/**
* Sequences descriptors of the package. The HashMap key
* is the sequence name.
*/
public Map sequences = new HashMap();
/**
* Descriptor to which this package is associated.
*/
public SpeedoXMLDescriptor xmlDescriptor;
public SpeedoPackage() {
SpeedoDefaults.setDefaults(this);
}
/**
* Transforms a SpeedoPackage into a String.
* @return the corresponding String.
*/
public String toString() {
String s = "package\tname : " + name;
s += "\n\tclasses: ";
Iterator it = classes.values().iterator();
while (it.hasNext()) {
s = s + " " + it.next().toString();
}
s += "\n\tsequences: ";
it = sequences.values().iterator();
while (it.hasNext()) {
s = s + " " + it.next().toString();
}
return s;
}
/**
* Adds a class descriptor to the package descriptor.
* @param clazz class to add.
* @param failsOnError if an error provoques an exception or a warning message.
* @param logger logger where to put warning message.
* @exception SpeedoException If a field of the class descriptor is already
* defined into the package descriptor.
*/
public void addClass(Object clazz, boolean failsOnError, Logger logger) throws SpeedoException {
SpeedoClass sc = (SpeedoClass) clazz;
//the class already exists
if (classes.containsKey(sc.name)) {
//we add its fields
SpeedoClass cref = (SpeedoClass) classes.get(sc.name);
Iterator it = sc.fields.values().iterator();
while (it.hasNext()) {
cref.add(it.next(), failsOnError, logger);
}
}
//we add the entire class;
else {
sc.moPackage = this;
classes.put(sc.name, sc);
}
}
/**
* Adds a sequence descriptor to the package descriptor.
* If a sequence with the same name is already registered, nothing is done.
* @param sequence the sequence to add.
*/
public void addSequence(Object sequence){
SpeedoSequence ss = (SpeedoSequence) sequence;
//if the sequence is not already registered
if (!sequences.containsKey(ss.name)) {
//set the package name of the sequence
ss.packageName = this.name;
//add it to the list
sequences.put(ss.name, ss);
}
}
} // end SpeedoPackage