/**
* 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
*
*/
package org.objectweb.speedo.generation.serializer;
import java.util.Iterator;
import org.objectweb.speedo.api.SpeedoException;
import org.objectweb.speedo.api.SpeedoProperties;
import org.objectweb.speedo.generation.lib.AbstractGeneratorComponent;
import org.objectweb.speedo.lib.Personality;
import org.objectweb.speedo.mapper.lib.Object2StringSerializer;
import org.objectweb.speedo.metadata.SpeedoXMLDescriptor;
/**
* @author Y.Bersihand
*/
public class MISerializer extends AbstractGeneratorComponent {
public final static String LOGGER_NAME
= SpeedoProperties.LOGGER_NAME + ".generation.jorm";
public MISerializer(Personality p) {
super(p);
}
public boolean init() throws SpeedoException {
if (scp.getXmldescriptor().isEmpty()) {
return false;
}
logger = scp.loggerFactory.getLogger(LOGGER_NAME);
return true;
}
public String getTitle() {
return "Serializing Meta Info...";
}
public String getSummary() {
return scp.getXmldescriptor().size() + " .jmi file(s) written.";
}
/**
* Launch the serialization.
*/
public void process() throws SpeedoException {
if (scp.getXmldescriptor().isEmpty()) {
return;
}
try {
for (Iterator itDesc = scp.getXmldescriptor().values().iterator(); itDesc.hasNext();) {
SpeedoXMLDescriptor desc = (SpeedoXMLDescriptor) itDesc.next();
serialize(desc);
}
} catch (SpeedoException e) {
throw new SpeedoException("Error during serialization of meta information", e);
}
}
private void serialize(SpeedoXMLDescriptor desc) throws SpeedoException {
//Serialize the list in the file
try {
Object2StringSerializer.serialize(scp.output, desc.xmlFile, desc.mos, logger);
} catch (Exception io) {
throw new SpeedoException("IO Exception, impossible to write the " +
"meta information for the jdo file " + desc.xmlFile, io);
}
}
}