KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdo > tools > ant > CopyDatabaseTask


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdo.tools.ant;
13
14 import org.apache.tools.ant.Task;
15 import org.apache.tools.ant.BuildException;
16
17 import java.io.InputStream JavaDoc;
18 import java.io.IOException JavaDoc;
19 import java.util.Properties JavaDoc;
20
21 import com.versant.core.common.BindingSupportImpl;
22
23 /**
24  * Ant wrapper for the CopyDatabaseBean.
25  * @see CopyDatabaseBean
26  * @keep-all
27  */

28 public class CopyDatabaseTask extends Task {
29
30     private String JavaDoc config = "versant.properties";
31     private CopyDatabaseBean cbean = new CopyDatabaseBean();
32
33     public void execute() throws BuildException {
34         if (config == null) {
35             throw new BuildException("project attribute is required " +
36                 "(name of .jdogenie project on the classpath)");
37         }
38         try {
39             cbean.setSrcProps(loadProperties(config));
40             cbean.copyDatabase();
41         } catch (Throwable JavaDoc t) {
42             t.printStackTrace(System.out);
43             throw new BuildException(t);
44         }
45     }
46
47     private Properties JavaDoc loadProperties(String JavaDoc filename) throws IOException JavaDoc {
48         ClassLoader JavaDoc cl = getClass().getClassLoader();
49         InputStream JavaDoc in = null;
50         try {
51             if (filename.startsWith("/")) filename = filename.substring(1);
52             in = cl.getResourceAsStream(filename);
53             if (in == null) {
54                 throw BindingSupportImpl.getInstance().runtime("Resource not found: " + filename);
55             }
56             Properties JavaDoc p = new Properties JavaDoc();
57             p.load(in);
58             return p;
59         } finally {
60             if (in != null) in.close();
61         }
62     }
63
64     public void setConfig(String JavaDoc config) {
65         this.config = config;
66     }
67
68     public void setProject(String JavaDoc config) {
69         setConfig(config);
70     }
71
72     public void setDatastore(String JavaDoc datastore) {
73         cbean.setDatastore(datastore);
74     }
75
76     public void setDb(String JavaDoc db) {
77         cbean.setDb(db);
78     }
79
80     public void setUrl(String JavaDoc url) {
81         cbean.setUrl(url);
82     }
83
84     public void setDriver(String JavaDoc driver) {
85         cbean.setDriver(driver);
86     }
87
88     public void setUser(String JavaDoc user) {
89         cbean.setUser(user);
90     }
91
92     public void setPassword(String JavaDoc password) {
93         cbean.setPassword(password);
94     }
95
96     public void setProperties(String JavaDoc properties) {
97         cbean.setProperties(properties);
98     }
99
100     public void setDropTables(boolean dropTables) {
101         cbean.setDropTables(dropTables);
102     }
103
104     public void setCreateTables(boolean createTables) {
105         cbean.setCreateTables(createTables);
106     }
107
108     public void setRowsPerTransaction(int rowsPerTransaction) {
109         cbean.setRowsPerTransaction(rowsPerTransaction);
110     }
111
112     public void setLogEvents(String JavaDoc logEvents) {
113         cbean.setLogEvents(logEvents);
114     }
115
116 }
117
Popular Tags