KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > core > storage > gammaStore > RandomAccessFileStorageFactory


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Core License version 1 published by ozone-db.org.
3
//
4
// Copyright (C) 2003-@year@, Leo Mekenkamp. All rights reserved.
5
//
6
// $Id: RandomAccessFileStorageFactory.java,v 1.1 2004/01/02 09:24:38 leomekenkamp Exp $
7

8 package org.ozoneDB.core.storage.gammaStore;
9
10 import java.io.File JavaDoc;
11 import java.io.IOException JavaDoc;
12 import java.util.Collection JavaDoc;
13 import java.util.List JavaDoc;
14 import java.util.Properties JavaDoc;
15 import java.util.logging.Logger JavaDoc;
16 import org.ozoneDB.core.storage.PropertyInfo;
17
18 /**
19  * @author <a HREF="mailto:leoATmekenkampD0Tcom">Leo Mekenkamp (mind the anti sp@m)</a>
20  * @version $Id: RandomAccessFileStorageFactory.java,v 1.1 2004/01/02 09:24:38 leomekenkamp Exp $
21  */

22 public class RandomAccessFileStorageFactory extends FileStorageFactory {
23     
24     private static Logger JavaDoc log = Logger.getLogger(RandomAccessFileStorageFactory.class.getName());
25     
26     public static final PropertyInfo MODE = new PropertyInfo(
27         ".mode",
28         "one of r, rw, rws, rwd",
29         "rws",
30         "mode for opening the storage files; see mode in java.util.RandomAccessFile#RandomAccessFile(java.io.File, String)",
31         new String JavaDoc[] {
32             "rw", "rwd"
33         }
34     );
35
36     private String JavaDoc mode;
37     
38     /**
39      * As prescribed by the <code>PropertyConfigurable</code> interface.
40      */

41     public RandomAccessFileStorageFactory(Properties JavaDoc properties, String JavaDoc prefix) {
42         super(properties, prefix);
43         String JavaDoc property = getPrefix() + MODE.getKey();
44         setMode(properties.getProperty(property, MODE.getDefaultValue()));
45     }
46     
47     public Storage createStorage(String JavaDoc name) throws IOException JavaDoc {
48         File JavaDoc file = nameToFile(name);
49         ensureParentsExist(file);
50         return new RandomAccessFileStorage(file, getMode());
51     }
52     
53     // private so it can be inlined
54
private String JavaDoc getMode() {
55         return mode;
56     }
57     
58     // private so it can be inlined
59
private void setMode(String JavaDoc mode) {
60         this.mode = mode;
61     }
62     
63     public Collection JavaDoc getPropertyInfos() {
64         Collection JavaDoc result = super.getPropertyInfos();
65         result.add(MODE);
66         return result;
67     }
68     
69 }
70
Popular Tags