KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > s2banttask > Schema2BeansAntTask


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.s2banttask;
21
22 import java.io.File JavaDoc;
23 import java.util.StringTokenizer JavaDoc;
24
25 import org.apache.tools.ant.BuildException;
26 import org.apache.tools.ant.Task;
27
28 import org.netbeans.modules.schema2beansdev.GenBeans;
29
30 /**
31  * @author Cliff Draper
32  * @date 2003/04/02
33  * This class is an ant task which front ends
34  * org.netbeans.modules.schema2beansdev.GenBeans. It creates a Config
35  * object and fills it in with data from the build script.
36  */

37 public class Schema2BeansAntTask extends S2bConfigDelegator {
38     public Schema2BeansAntTask() {
39         super(new GenBeans.Config());
40     }
41     
42     /**
43      * We change a few defaults from the normal GenBeans:
44      * -auto
45      * -checkUpToDate
46      * -nogenerateTimeStamp
47      */

48     public void init() {
49         setAuto(true);
50         setCheckUpToDate(true);
51         setGenerateTimeStamp(false);
52     }
53     
54     public void execute() throws BuildException {
55         if (_S2bConfig == null) {
56             throw new BuildException("Invoked for the second time!");
57         }
58         try {
59             GenBeans.doIt(getConfig());
60         } catch (java.io.IOException JavaDoc e) {
61             throw new BuildException(e);
62         } catch (org.netbeans.modules.schema2beans.Schema2BeansException e) {
63             throw new BuildException(e);
64         }
65         _S2bConfig = null;
66     }
67
68     protected GenBeans.Config getConfig() {
69         return (GenBeans.Config) _S2bConfig;
70     }
71
72     public void setOutputType(String JavaDoc type) {
73         if ("basebean".equalsIgnoreCase(type))
74             getConfig().setOutputType(GenBeans.Config.OUTPUT_TRADITIONAL_BASEBEAN);
75         else if ("javabeans".equalsIgnoreCase(type))
76             getConfig().setOutputType(GenBeans.Config.OUTPUT_JAVABEANS);
77         else
78             throw new RuntimeException JavaDoc("Incorrect argument to outputType. It must be 'javabeans' or 'basebean'.");
79     }
80
81     public void setSchema(File JavaDoc type) {
82         setFilename(type);
83     }
84
85     public void setPackage(String JavaDoc value) {
86         setPackagePath(value);
87     }
88
89     public void setWriteBeanGraph(File JavaDoc bg) {
90         setWriteBeanGraphFile(bg);
91     }
92
93     public void setReadBeanGraph(File JavaDoc f) {
94         addReadBeanGraphFiles(f);
95     }
96  
97     public void setValidate(boolean v) {
98         setGenerateValidate(v);
99     }
100
101     public void setComments(boolean value) {
102         setProcessComments(value);
103     }
104
105     public void setDocType(boolean value) {
106         setProcessDocType(value);
107     }
108
109     public void setDelegator(boolean value) {
110         setGenerateDelegator(value);
111     }
112
113     public void setAttrProp(boolean value) {
114         setAttributesAsProperties(value);
115     }
116
117     public void setCommonInterface(String JavaDoc commonBeanName) {
118         setGenerateCommonInterface(commonBeanName);
119     }
120
121     public void setPropertyEvents(boolean value) {
122         setGeneratePropertyEvents(value);
123     }
124
125     public void setMin(boolean value) {
126         setMinFeatures(value);
127     }
128  
129     public void setPremium(boolean value) {
130         if (value) {
131             getConfig().buyPremium();
132         }
133     }
134
135     public void setStrict(boolean value) {
136         if (value) {
137             getConfig().useStrict();
138         }
139     }
140
141     /**
142      * Add finders for those in this comman separated list.
143      * @param exprList example: on /source-element find class-element by full-name,on /source-element/class-element find method-element by name,on /source-element/class-element/method-element find java-doc by name
144      */

145     public void setFinder(String JavaDoc exprList) {
146         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(exprList, ",");
147         while (st.hasMoreTokens()) {
148             String JavaDoc expr = st.nextToken().trim();
149             if (expr.equals(""))
150                 continue;
151             addFinder(expr);
152         }
153     }
154 }
155
Popular Tags