View Javadoc

1   import java.io.File;
2   import java.io.FileWriter;
3   import java.io.IOException;
4   import java.io.Writer;
5   
6   import org.exolab.castor.mapping.MappingException;
7   import org.exolab.castor.tools.MappingTool;
8   
9   import org.astrogrid.registry.beans.v10.cea.CeaApplicationType;
10  
11  /*
12   * $Id: GenerateMapping.java,v 1.3 2005/07/05 08:27:01 clq2 Exp $
13   * 
14   * Created on 15-Mar-2004 by Paul Harrison (pah@jb.man.ac.uk)
15   *
16   * Copyright 2004 AstroGrid. All rights reserved.
17   *
18   * This software is published under the terms of the AstroGrid 
19   * Software License version 1.2, a copy of which has been included 
20   * with this distribution in the LICENSE.txt file.  
21   *
22   */
23  
24  /***
25   * Small utility to generate a mapping file for the generated classes.
26   * @author Paul Harrison (pah@jb.man.ac.uk) 15-Mar-2004
27   * @version $Name:  $
28   * @since iteration5
29   */
30  public class GenerateMapping {
31  
32     MappingTool maptool;
33     private File outfile;
34     /***
35      * 
36      */
37     public GenerateMapping(String filename) throws MappingException {
38        
39        outfile=new File(filename);
40        maptool = new MappingTool();
41        maptool.setForceIntrospection(false); // use the descriptor classes
42        //add the class back references
43        maptool.addClass(CeaApplicationType.class, false);
44        //TODO - to be useful there would need to be a way of automatically adding all the classes here.....
45        
46     }
47     public void writeMap()
48     {
49        Writer w;
50        try {
51           w = new FileWriter(outfile);
52           maptool.write(w);
53        }
54        catch (IOException e) {
55           e.printStackTrace();
56        } catch (MappingException e) {
57           e.printStackTrace();
58        }
59        
60        
61     }
62  
63     /***
64      * @param args The first argument is the name of the output file to be generated
65      */
66     public static void main(String[] args) {
67        try {
68           GenerateMapping mapper = new GenerateMapping(args[0]);
69           mapper.writeMap();
70        }
71        catch (MappingException e) {
72   
73          e.printStackTrace();
74        }
75        
76     }
77     
78  }