Project

General

Profile

Download (1.94 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2015 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.util;
11

    
12
import java.io.File;
13
import java.io.FileOutputStream;
14
import java.io.IOException;
15
import java.io.ObjectOutputStream;
16

    
17
import org.apache.log4j.Logger;
18
import org.hibernate.cfg.Configuration;
19

    
20
import eu.etaxonomy.taxeditor.remoting.cache.CdmModelCacher;
21

    
22
/**
23
 * @author cmathew
24
 * @date 27 May 2015
25
 *
26
 */
27
public class Serializer {
28
    private static final Logger logger = Logger.getLogger(Serializer.class);
29

    
30

    
31
    public static String HB_CONFIG_SER_FILE_NAME = "hibernate.cfg.ser";
32

    
33
    public static boolean checkDir(String dirString) {
34
        if(dirString == null || dirString.isEmpty()) {
35
            logger.warn("Directory not set or set to empty string");
36
            return false;
37
        }
38

    
39
        File dir = new File(dirString);
40

    
41
        if(!dir.exists()) {
42
            logger.warn("Directory does not exist");
43
            return false;
44
        }
45

    
46
        return true;
47

    
48
    }
49
    public static void serializeHbConfig() {
50

    
51
        Configuration configuration = CdmModelCacher.buildConfiguration();
52
        String hbConfigDir = System.getProperty("hb.config.dir");
53
        if(checkDir(hbConfigDir)) {
54
            try {
55
               FileOutputStream fileOut = new FileOutputStream(hbConfigDir + File.separator + HB_CONFIG_SER_FILE_NAME);
56
               ObjectOutputStream out = new ObjectOutputStream(fileOut);
57
               out.writeObject(configuration);
58
               out.close();
59
               fileOut.close();
60
               logger.info("Serialized configuration object");
61
            } catch(IOException i) {
62
                i.printStackTrace();
63
            }
64
        }
65
    }
66

    
67
    public static void main(String[] args) {
68
        serializeHbConfig();
69

    
70
    }
71

    
72
}
    (1-1/1)