KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > generation > serializer > MISerializer


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  */

25
26 package org.objectweb.speedo.generation.serializer;
27
28 import java.util.Iterator JavaDoc;
29
30 import org.objectweb.speedo.api.SpeedoException;
31 import org.objectweb.speedo.api.SpeedoProperties;
32 import org.objectweb.speedo.generation.lib.AbstractGeneratorComponent;
33 import org.objectweb.speedo.mapper.lib.Object2StringSerializer;
34 import org.objectweb.speedo.metadata.SpeedoXMLDescriptor;
35
36 /**
37  * @author Y.Bersihand
38  */

39 public class MISerializer extends AbstractGeneratorComponent {
40
41     public final static String JavaDoc LOGGER_NAME
42         = SpeedoProperties.LOGGER_NAME + ".generation.jorm";
43     
44     public boolean init() throws SpeedoException {
45         if (scp.getXmldescriptor().isEmpty()) {
46             return false;
47         }
48         logger = scp.loggerFactory.getLogger(LOGGER_NAME);
49         return true;
50     }
51
52     /**
53      * Launch the serialization.
54      */

55     public void process() throws SpeedoException {
56         if (scp.getXmldescriptor().isEmpty()) {
57             return;
58         }
59         try {
60             for (Iterator JavaDoc itDesc = scp.getXmldescriptor().values().iterator(); itDesc.hasNext();) {
61                 SpeedoXMLDescriptor desc = (SpeedoXMLDescriptor) itDesc.next();
62                 serialize(desc);
63             }
64         } catch (SpeedoException e) {
65             throw new SpeedoException("Error during serialization of meta information", e);
66         }
67     }
68     
69     private void serialize(SpeedoXMLDescriptor desc) throws SpeedoException {
70         //Serialize the list in the file
71
try {
72             Object2StringSerializer.serialize(scp.output, desc.xmlFile, desc.mos, logger);
73         } catch (Exception JavaDoc io) {
74             throw new SpeedoException("IO Exception, impossible to write the " +
75                     "meta information for the jdo file " + desc.xmlFile, io);
76         }
77     }
78
79
80 }
81
Popular Tags