KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > io > URLStorageFactory


1 /*
2
3    Derby - Class org.apache.derby.impl.io.URLStorageFactory
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.io;
23
24 import org.apache.derby.iapi.services.sanity.SanityManager;
25
26 import org.apache.derby.io.StorageFactory;
27 import org.apache.derby.io.StorageFile;
28
29 import java.io.FileNotFoundException JavaDoc;
30 import java.io.InputStream JavaDoc;
31 import java.io.OutputStream JavaDoc;
32 import java.io.IOException JavaDoc;
33
34 /**
35  * This class provides a http based implementation of the StorageFactory interface. It is used by the
36  * database engine to access persistent data and transaction logs under the http and https subsubprotocols.
37  */

38
39 public class URLStorageFactory extends BaseStorageFactory
40 {
41     
42     /**
43      * Construct a persistent StorageFile from a path name.
44      *
45      * @param path The path name of the file
46      *
47      * @return A corresponding StorageFile object
48      */

49     StorageFile newPersistentFile( String JavaDoc path)
50     {
51         return new URLFile( this, path);
52     }
53
54     /**
55      * Construct a StorageFile from a directory and file name.
56      *
57      * @param directoryName The directory part of the path name. Must not be null, nor may it be in the temp dir.
58      * @param fileName The name of the file within the directory.
59      *
60      * @return A corresponding StorageFile object
61      */

62     StorageFile newPersistentFile( String JavaDoc directoryName, String JavaDoc fileName)
63     {
64         if( directoryName == null || directoryName.length() == 0)
65             return newPersistentFile( fileName);
66         return new URLFile( this, directoryName, fileName);
67     }
68
69     /**
70      * Construct a StorageFile from a directory and file name.
71      *
72      * @param directoryName The directory part of the path name.
73      * @param fileName The name of the file within the directory.
74      *
75      * @return A corresponding StorageFile object
76      */

77     StorageFile newPersistentFile( StorageFile directoryName, String JavaDoc fileName)
78     {
79         if( directoryName == null)
80             return newPersistentFile( fileName);
81         return new URLFile( (URLFile) directoryName, fileName);
82     }
83
84     void doInit() throws IOException JavaDoc
85     {
86         if( dataDirectory != null)
87         {
88             if( dataDirectory.endsWith( "/"))
89             {
90                 separatedDataDirectory = dataDirectory;
91                 dataDirectory = dataDirectory.substring( 0, dataDirectory.length() - 1);
92             }
93             else
94                 separatedDataDirectory = dataDirectory + '/'; // URLs use '/' as a separator
95
canonicalName = dataDirectory;
96             createTempDir();
97         }
98     } // end of doInit
99
}
100
Popular Tags