View Javadoc

1   package com.wikihouse.wildcats0201.jdbcchart.ant;
2   
3   import java.io.File;
4   import java.text.MessageFormat;
5   import java.util.Iterator;
6   import java.util.LinkedList;
7   import java.util.List;
8   
9   import org.apache.tools.ant.BuildException;
10  import org.apache.tools.ant.DirectoryScanner;
11  import org.apache.tools.ant.Project;
12  import org.apache.tools.ant.Task;
13  import org.apache.tools.ant.loader.AntClassLoader2;
14  import org.apache.tools.ant.types.FileSet;
15  import org.apache.tools.ant.types.Path;
16  import org.apache.tools.ant.types.Reference;
17  
18  import com.wikihouse.wildcats0201.jdbcchart.XYChartByJDBC;
19  
20  /***
21   * <B>XyLineChartTask </B>. Chartの作成を行うAntタスクです。
22   * 
23   * @author $Author: wildcats $
24   * @version $Revision: 5 $
25   */
26  public class XyLineChartTask extends Task {
27  
28      private List fileList = new LinkedList();
29  
30      private Path classpath;
31  
32      private String driver;
33  
34      private String user;
35  
36      private String password;
37  
38      private String url;
39  
40      /***
41       * FileSetを生成し返却します。
42       * 
43       * @return FileSet
44       */
45      public FileSet createFileSet() {
46          FileSet fs = new FileSet();
47          fileList.add(fs);
48          return fs;
49      }
50  
51      private String[] getUrlPaths() {
52          List list = new LinkedList();
53  
54          for (Iterator it = this.fileList.iterator(); it.hasNext();) {
55              FileSet fileset = (FileSet) it.next();
56              DirectoryScanner scanner = fileset
57                      .getDirectoryScanner(getProject());
58              String[] files = scanner.getIncludedFiles();
59              StringBuffer sb = new StringBuffer();
60              for (int i = 0; i < files.length; i++) {
61                  sb.append(scanner.getBasedir().getAbsolutePath());
62                  sb.append(File.separatorChar);
63                  sb.append(files[i]);
64                  list.add(sb.toString());
65                  log(MessageFormat.format("target file [{0}]", new Object[] { sb
66                          .toString() }));
67                  sb.delete(0, sb.length());
68              }
69          }
70          return (String[]) list.toArray(new String[list.size()]);
71      }
72  
73      /***
74       * クラスパスのReferenceを設定します。
75       * 
76       * @param r
77       *            Reference
78       */
79      public void setClasspathRef(Reference r) {
80          createClasspath().setRefid(r);
81      }
82  
83      /***
84       * クラスパスを設定します。
85       * 
86       * @param classpath
87       *            クラスパス
88       */
89      public void setClasspath(Path classpath) {
90          if (this.classpath == null) {
91              this.classpath = classpath;
92          } else {
93              this.classpath.append(classpath);
94          }
95      }
96  
97      /***
98       * クラスパスを返却します。
99       * 
100      * @return クラスパス
101      */
102     public Path createClasspath() {
103         if (this.classpath == null) {
104             this.classpath = new Path(getProject());
105         }
106         return this.classpath;
107     }
108 
109     /***
110      * JDBCドライバを設定します。
111      * 
112      * @param driver
113      *            JDBCドライバ名
114      * @todo Validation未実装
115      */
116     public void setDriver(String driver) {
117         this.driver = driver;
118     }
119 
120     /***
121      * JDBC接続URLを設定します。
122      * 
123      * @param url
124      *            JDBC接続URL
125      * @todo Validation未実装
126      */
127     public void setUrl(String url) {
128         this.url = url;
129     }
130 
131     /***
132      * データベースパスワードを設定します。
133      * 
134      * @param password
135      *            パスワード
136      */
137     public void setPassword(String password) {
138         this.password = password;
139     }
140 
141     /***
142      * データベースユーザ名を設定します。
143      * 
144      * @param user
145      *            ユーザ名
146      */
147     public void setUser(String user) {
148         this.user = user;
149     }
150 
151     /***
152      * @see org.apache.tools.ant.Task#execute()
153      */
154     public void execute() throws BuildException {
155         AntClassLoader2 loader = (AntClassLoader2) this.getClass()
156                 .getClassLoader();
157         loader.setClassPath(this.classpath);
158 
159         log(loader.getClasspath(), Project.MSG_INFO);
160 
161         String[] files = this.getUrlPaths();
162         for (int i = 0; i < files.length; i++) {
163             XYChartByJDBC xyChartByJDBC = new XYChartByJDBC();
164             xyChartByJDBC.execute(files[i], this.driver, this.url, this.user,
165                     this.password);
166         }
167 
168     }
169 
170 }