1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.anttasks;
18
19 import org.apache.tools.ant.BuildException;
20 import org.apache.tools.ant.Task;
21 import java.sql.Driver;
22 import java.sql.Connection;
23 import org.apache.tools.ant.Project;
24 import java.util.Hashtable;
25
26
27 public class StartDerby
28 extends Task {
29
30
31
32
33 public void execute()
34 throws BuildException {
35 try {
36 if (StartDerby.getDriver(getProject()) != null)
37 {
38 System.out.println("Derby Driver has ALREADY BEEN ESTABLISHED!");
39 return;
40 }
41 StartDerby.setDriver(getProject(),(java.sql.Driver)(Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance()));
42 System.out.println("Derby Driver has been started!");
43 } catch (Exception e) {
44 System.out.println(
45 "Derby could not start. This is most likely " +
46 "due to missing Derby JAR files. Please check your classpath" +
47 "and try again.");
48 throw new BuildException(e);
49 }
50 }
51
52 public static void setDriver(Project project, Driver d)
53 {
54 try
55 {
56 if (d != null)
57 {
58 project.addReference("DRIVER",d);
59 System.out.println("Driver reference in Project set ");
60 }
61 else
62 {
63 Hashtable h = project.getReferences();
64 h.remove("DRIVER");
65 System.out.println("Driver reference in Project removed ");
66 }
67 }
68 catch (Exception e)
69 {
70 System.out.println("Could't SET Driver reference in Project : " + e.getLocalizedMessage());
71
72 }
73 }
74 public static Driver getDriver(Project project)
75 {
76 try
77 {
78 Object o = project.getReference("DRIVER");
79 if (o != null)
80 return (Driver)o;
81 else return null;
82 }
83 catch (Exception e)
84 {
85 System.out.println("Could't get Driver reference in Project : " + e.getLocalizedMessage());
86 return null;
87 }
88 }
89
90 public static void setConnection(Project project, Connection d)
91 {
92 try
93 {
94 if (d != null)
95 {
96 project.addReference("Connection",d);
97 System.out.println("Connection reference in Project set ");
98 }
99 else
100 {
101 Hashtable h = project.getReferences();
102 h.remove("Connection");
103 System.out.println("Connection reference in Project removed ");
104 }
105 }
106 catch (Exception e)
107 {
108 System.out.println("Could't SET Connection reference in Project : " + e.getLocalizedMessage());
109
110 }
111 }
112 public static Connection getConnection(Project project)
113 {
114 try
115 {
116 Object o = project.getReference("Connection");
117 if (o != null)
118 return (Connection)o;
119 else return null;
120 }
121 catch (Exception e)
122 {
123 System.out.println("Could't get Connection reference in Project : " + e.getLocalizedMessage());
124 return null;
125 }
126 }
127 }