01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19:
20: package org.apache.axis2.util;
21:
22: import java.io.File;
23: import java.io.IOException;
24:
25: public class FileWriter {
26:
27: /**
28: * Creates/ returns a file object
29: *
30: * @param rootLocation - Location to be written
31: * @param packageName - package, can be '.' separated
32: * @param fileName name of the file
33: * @param extension type of the file, java, cpp etc
34: * @return the File that was created
35: * @throws IOException
36: * @throws Exception
37: */
38: public static File createClassFile(File rootLocation,
39: String packageName, String fileName, String extension)
40: throws IOException, Exception {
41: File returnFile = null;
42: File root = rootLocation;
43:
44: if (packageName != null) {
45: String directoryNames[] = packageName.split("\\.");
46: File tempFile = null;
47: int length = directoryNames.length;
48: for (int i = 0; i < length; i++) {
49: tempFile = new File(root, directoryNames[i]);
50: root = tempFile;
51: if (!tempFile.exists()) {
52: tempFile.mkdir();
53: }
54: }
55: }
56:
57: if (!fileName.endsWith(extension)) {
58: fileName = fileName + extension;
59: }
60:
61: returnFile = new File(root, fileName);
62:
63: if (!returnFile.exists()) {
64: // returnFile.createNewFile();
65: }
66: return returnFile;
67: }
68:
69: }
|