01: /*
02: * sqlc 1
03: * SQL Compiler
04: * Copyright (C) 2003 Hammurapi Group
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: *
20: * URL: http://www.hammurapi.biz/products/sqlc/index.html
21: * e-Mail: support@hammurapi.biz
22: */
23: package biz.hammurapi.sqlc;
24:
25: import java.io.File;
26: import java.io.FileReader;
27: import java.io.IOException;
28: import java.io.InputStreamReader;
29: import java.io.Reader;
30: import java.net.URL;
31:
32: import org.apache.tools.ant.BuildException;
33:
34: /**
35: * SQL script to execute.
36: * @ant.element name="script"
37: * @author Pavel Vlasov
38: * @version $Revision: 1.1 $
39: */
40: public class ScriptEntry {
41: private File file;
42: private URL url;
43:
44: /**
45: * Script file.
46: * @ant.required
47: * @param file
48: */
49: public void setFile(File file) {
50: if (url != null) {
51: throw new BuildException(
52: "File and URL are mutually exclusive. URL already set");
53: }
54: this .file = file;
55: }
56:
57: /**
58: * Script URL. One and only one of 'file' and 'url' is required.
59: * @nat.required
60: * @param url
61: */
62: public void setUrl(URL url) {
63: if (file != null) {
64: throw new BuildException(
65: "File and URL are mutually exclusive. File already set");
66: }
67: this .url = url;
68: }
69:
70: public Reader getScript() {
71: if (file != null) {
72: try {
73: return new FileReader(file);
74: } catch (IOException e) {
75: throw new BuildException("Cannot read file "
76: + file.getAbsolutePath());
77: }
78: } else if (url != null) {
79: try {
80: return new InputStreamReader(url.openStream());
81: } catch (IOException e) {
82: throw new BuildException("Cannot open URL " + url);
83: }
84: } else {
85: throw new BuildException("File or URL shall be set");
86: }
87: }
88: }
|