001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.anttasks;
018:
019: import org.apache.tools.ant.BuildException;
020: import org.apache.tools.ant.Task;
021: import java.sql.Driver;
022: import java.sql.Connection;
023: import org.apache.tools.ant.Project;
024: import java.util.Hashtable;
025:
026: public class StartDerby extends Task {
027:
028: // public static Driver DERBY_DRIVER = null;
029: // public static Connection DERBY_CONNECTION = null;
030:
031: public void execute() throws BuildException {
032: try {
033: if (StartDerby.getDriver(getProject()) != null) {
034: System.out
035: .println("Derby Driver has ALREADY BEEN ESTABLISHED!");
036: return;
037: }
038: StartDerby.setDriver(getProject(), (java.sql.Driver) (Class
039: .forName("org.apache.derby.jdbc.EmbeddedDriver")
040: .newInstance()));
041: System.out.println("Derby Driver has been started!");
042: } catch (Exception e) {
043: System.out
044: .println("Derby could not start. This is most likely "
045: + "due to missing Derby JAR files. Please check your classpath"
046: + "and try again.");
047: throw new BuildException(e);
048: }
049: }
050:
051: public static void setDriver(Project project, Driver d) {
052: try {
053: if (d != null) {
054: project.addReference("DRIVER", d);
055: System.out.println("Driver reference in Project set ");
056: } else {
057: Hashtable h = project.getReferences();
058: h.remove("DRIVER");
059: System.out
060: .println("Driver reference in Project removed ");
061: }
062: } catch (Exception e) {
063: System.out
064: .println("Could't SET Driver reference in Project : "
065: + e.getLocalizedMessage());
066:
067: }
068: }
069:
070: public static Driver getDriver(Project project) {
071: try {
072: Object o = project.getReference("DRIVER");
073: if (o != null)
074: return (Driver) o;
075: else
076: return null;
077: } catch (Exception e) {
078: System.out
079: .println("Could't get Driver reference in Project : "
080: + e.getLocalizedMessage());
081: return null;
082: }
083: }
084:
085: public static void setConnection(Project project, Connection d) {
086: try {
087: if (d != null) {
088: project.addReference("Connection", d);
089: System.out
090: .println("Connection reference in Project set ");
091: } else {
092: Hashtable h = project.getReferences();
093: h.remove("Connection");
094: System.out
095: .println("Connection reference in Project removed ");
096: }
097: } catch (Exception e) {
098: System.out
099: .println("Could't SET Connection reference in Project : "
100: + e.getLocalizedMessage());
101:
102: }
103: }
104:
105: public static Connection getConnection(Project project) {
106: try {
107: Object o = project.getReference("Connection");
108: if (o != null)
109: return (Connection) o;
110: else
111: return null;
112: } catch (Exception e) {
113: System.out
114: .println("Could't get Connection reference in Project : "
115: + e.getLocalizedMessage());
116: return null;
117: }
118: }
119: }
|