KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mr > core > persistent > PersistentConst


1 /*
2  * Copyright 2002 by
3  * <a HREF="http://www.coridan.com">Coridan</a>
4  * <a HREF="mailto: support@coridan.com ">support@coridan.com</a>
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is "MantaRay" (TM).
17  *
18  * The Initial Developer of the Original Code is Amir Shevat.
19  * Portions created by the Initial Developer are Copyright (C) 2006
20  * Coridan Inc. All Rights Reserved.
21  *
22  * Contributor(s): all the names of the contributors are added in the source
23  * code where applicable.
24  *
25  * Alternatively, the contents of this file may be used under the terms of the
26  * LGPL license (the "GNU LESSER GENERAL PUBLIC LICENSE"), in which case the
27  * provisions of LGPL are applicable instead of those above. If you wish to
28  * allow use of your version of this file only under the terms of the LGPL
29  * License and not to allow others to use your version of this file under
30  * the MPL, indicate your decision by deleting the provisions above and
31  * replace them with the notice and other provisions required by the LGPL.
32  * If you do not delete the provisions above, a recipient may use your version
33  * of this file under either the MPL or the GNU LESSER GENERAL PUBLIC LICENSE.
34  
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Lesser General Public License as published by the Free Software Foundation;
39  * either version 2.1 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
44  * License for more details.
45  */

46 /*
47  * Created on Dec 15, 2003
48  *
49  * To change the template for this generated file go to
50  * Window - Preferences - Java - Code Generation - Code and Comments
51  */

52 package org.mr.core.persistent;
53
54 import java.io.File JavaDoc;
55
56 import org.mr.MantaAgent;
57 import org.mr.core.log.StartupLogger;
58 import org.mr.core.util.byteable.ByteBufferFactory;
59 import org.apache.commons.logging.LogFactory;
60
61
62 /**
63  * PersistentConst holds static data for Persistent
64  *
65  * @author Amir Shevat
66  *
67  *
68  */

69 public class PersistentConst {
70     // the folder of persistent in the system this proprty is init from the MantaAgent.getinstance()
71
private static String JavaDoc PersistentDir;
72     private static boolean created =false;
73     private static ByteBufferFactory persistentByteBufferPool;
74     
75     
76
77     /**
78      * @return Returns the persistentByteBufferPool.
79      */

80     public static ByteBufferFactory getPersistentByteBufferPool() {
81         return persistentByteBufferPool;
82     }
83
84     /**
85      * @param persistentByteBufferPool The persistentByteBufferPool to set.
86      */

87     public static void setPersistentByteBufferPool(ByteBufferFactory persistentByteBufferPool) {
88         PersistentConst.persistentByteBufferPool = persistentByteBufferPool;
89     }
90     
91     /**
92      * returns the preconfigured persistent location
93      * @param persistentName the name of the entity to be persistent
94      * @return the preconfigured persistent location
95      */

96     public static String JavaDoc getPersistentDir(String JavaDoc persistentName) {
97         String JavaDoc specialDir = MantaAgent.getInstance().getSingletonRepository().getConfigManager().getStringProperty(persistentName);
98         if(specialDir != null){
99             return specialDir;
100         }
101             
102         createPersistentFolderIfNeeded(PersistentDir);
103         
104         return PersistentDir;
105     }
106     
107     /**
108      * sets the default persistent folder for file persistency
109      * @param persistentDir the default persistent folder for file persistency
110      */

111     public static void setPersistentDir(String JavaDoc persistentDir) {
112         PersistentConst.PersistentDir = persistentDir;
113     }
114     
115     /**
116      * Creates the persistent folder if it does not exist
117      * @param persistentDir the folder to be created
118      */

119     private static void createPersistentFolderIfNeeded(String JavaDoc persistentDir){
120         if(!created){
121             File JavaDoc dir =new File JavaDoc(persistentDir);
122             if(dir.exists() == false){
123                 //System.out.println("Persistent folder does not exist, creating persistent folder at "+persistentDir);
124
//LogFactory.getLog("PersistentConst").info("Persistent folder does not exist, creating persistent folder at "+persistentDir);
125
StartupLogger.log.info("Persistent folder does not exist, creating persistent folder at "+persistentDir, "PersistentConst");
126                 dir.mkdir();
127             }else{
128                 //System.out.println("Persistent folder found at "+persistentDir);
129
//LogFactory.getLog("PersistentConst").info("Persistent folder found at "+persistentDir);
130
StartupLogger.log.info("Persistent folder found at "+persistentDir, "PersistentConst");
131             }
132             created = true;
133         }
134         
135     }
136 }
137
Popular Tags