001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.s2banttask;
043:
044: import java.io.File;
045: import java.util.StringTokenizer;
046:
047: import org.apache.tools.ant.BuildException;
048: import org.apache.tools.ant.Task;
049:
050: import org.netbeans.modules.schema2beansdev.GenBeans;
051:
052: /**
053: * @author Cliff Draper
054: * @date 2003/04/02
055: * This class is an ant task which front ends
056: * org.netbeans.modules.schema2beansdev.GenBeans. It creates a Config
057: * object and fills it in with data from the build script.
058: */
059: public class Schema2BeansAntTask extends S2bConfigDelegator {
060: public Schema2BeansAntTask() {
061: super (new GenBeans.Config());
062: }
063:
064: /**
065: * We change a few defaults from the normal GenBeans:
066: * -auto
067: * -checkUpToDate
068: * -nogenerateTimeStamp
069: */
070: public void init() {
071: setAuto(true);
072: setCheckUpToDate(true);
073: setGenerateTimeStamp(false);
074: }
075:
076: public void execute() throws BuildException {
077: if (_S2bConfig == null) {
078: throw new BuildException("Invoked for the second time!");
079: }
080: try {
081: GenBeans.doIt(getConfig());
082: } catch (java.io.IOException e) {
083: throw new BuildException(e);
084: } catch (org.netbeans.modules.schema2beans.Schema2BeansException e) {
085: throw new BuildException(e);
086: }
087: _S2bConfig = null;
088: }
089:
090: protected GenBeans.Config getConfig() {
091: return (GenBeans.Config) _S2bConfig;
092: }
093:
094: public void setOutputType(String type) {
095: if ("basebean".equalsIgnoreCase(type))
096: getConfig().setOutputType(
097: GenBeans.Config.OUTPUT_TRADITIONAL_BASEBEAN);
098: else if ("javabeans".equalsIgnoreCase(type))
099: getConfig().setOutputType(GenBeans.Config.OUTPUT_JAVABEANS);
100: else
101: throw new RuntimeException(
102: "Incorrect argument to outputType. It must be 'javabeans' or 'basebean'.");
103: }
104:
105: public void setSchema(File type) {
106: setFilename(type);
107: }
108:
109: public void setPackage(String value) {
110: setPackagePath(value);
111: }
112:
113: public void setWriteBeanGraph(File bg) {
114: setWriteBeanGraphFile(bg);
115: }
116:
117: public void setReadBeanGraph(File f) {
118: addReadBeanGraphFiles(f);
119: }
120:
121: public void setValidate(boolean v) {
122: setGenerateValidate(v);
123: }
124:
125: public void setComments(boolean value) {
126: setProcessComments(value);
127: }
128:
129: public void setDocType(boolean value) {
130: setProcessDocType(value);
131: }
132:
133: public void setDelegator(boolean value) {
134: setGenerateDelegator(value);
135: }
136:
137: public void setAttrProp(boolean value) {
138: setAttributesAsProperties(value);
139: }
140:
141: public void setCommonInterface(String commonBeanName) {
142: setGenerateCommonInterface(commonBeanName);
143: }
144:
145: public void setPropertyEvents(boolean value) {
146: setGeneratePropertyEvents(value);
147: }
148:
149: public void setMin(boolean value) {
150: setMinFeatures(value);
151: }
152:
153: public void setPremium(boolean value) {
154: if (value) {
155: getConfig().buyPremium();
156: }
157: }
158:
159: public void setStrict(boolean value) {
160: if (value) {
161: getConfig().useStrict();
162: }
163: }
164:
165: /**
166: * Add finders for those in this comman separated list.
167: * @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
168: */
169: public void setFinder(String exprList) {
170: StringTokenizer st = new StringTokenizer(exprList, ",");
171: while (st.hasMoreTokens()) {
172: String expr = st.nextToken().trim();
173: if (expr.equals(""))
174: continue;
175: addFinder(expr);
176: }
177: }
178: }
|