001// Copyright 2005-2006 Ferdinand Prantl <prantl@users.sourceforge.net>
002// Copyright 2001-2004 The Apache Software Foundation
003// All rights reserved.
004//
005// Licensed under the Apache License, Version 2.0 (the "License");
006// you may not use this file except in compliance with the License.
007// You may obtain a copy of the License at
008//
009// http://www.apache.org/licenses/LICENSE-2.0
010//
011// Unless required by applicable law or agreed to in writing, software
012// distributed under the License is distributed on an "AS IS" BASIS,
013// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014// See the License for the specific language governing permissions and
015// limitations under the License.
016//
017// See http://ant-eclipse.sourceforge.net for the most recent version
018// and more information.
019
020package prantl.ant.eclipse;
021
022import java.io.File;
023
024import org.apache.tools.ant.BuildException;
025import org.apache.tools.ant.types.EnumeratedAttribute;
026
027/**
028 * Configures the behavior of the generation of the output files and contains descriptions
029 * of ther content.
030 * 
031 * @since Ant-Eclipse 1.0
032 * @author Ferdinand Prantl &lt;prantl@users.sourceforge.net&gt;
033 */
034public class EclipseElement {
035
036    /**
037     * EnumeratedAttribute implementation supporting the available project modes.
038     * 
039     * @since Ant-Eclipse 1.0
040     * @author Ferdinand Prantl &lt;prantl@users.sourceforge.net&gt;
041     */
042    public static class Mode extends EnumeratedAttribute {
043
044        /**
045         * Forces the Java mode to use JDT in the project.
046         */
047        public final static int JAVA = 0;
048
049        /**
050         * Forces the AspectJ mode to use AJDT in the project.
051         */
052        public final static int ASPECTJ = 1;
053
054        /**
055         * @see EnumeratedAttribute#getValues()
056         */
057        public String[] getValues() {
058            return new String[] { "java", "aspectj" };
059        }
060
061    }
062
063    private boolean updateAlways = false;
064
065    private boolean failOnError = true;
066
067    private String errorProperty = null;
068
069    private File destDir = new File(".");
070
071    private Mode mode;
072
073    private SettingsElement settings = null;
074
075    private ProjectElement project = null;
076
077    private ClassPathElement classPath = null;
078
079    /**
080     * Creates a new instance of the configuration container.
081     * 
082     * @since Ant-Eclipse 1.0
083     */
084    public EclipseElement() {
085        mode = new Mode();
086        mode.setValue(mode.getValues()[Mode.JAVA]);
087    }
088
089    /**
090     * @return Returns the updateAlways.
091     */
092    public boolean isUpdateAlways() {
093        return updateAlways;
094    }
095
096    /**
097     * @param dir
098     *        The updateAlways to set.
099     */
100    public void setUpdateAlways(boolean flag) {
101        updateAlways = flag;
102    }
103
104    /**
105     * @return Returns the destDir.
106     */
107    public File getDestDir() {
108        return destDir;
109    }
110
111    /**
112     * @param dir
113     *        The destDir to set.
114     */
115    public void setDestDir(File dir) {
116        destDir = dir;
117    }
118
119    /**
120     * @return Returns the failOnError.
121     */
122    public boolean isFailOnError() {
123        return failOnError;
124    }
125
126    /**
127     * @param flag
128     *        The failOnError to set.
129     */
130    public void setFailOnError(boolean flag) {
131        failOnError = flag;
132    }
133
134    /**
135     * @return Returns the errorProperty.
136     */
137    public String getErrorProperty() {
138        return errorProperty;
139    }
140
141    /**
142     * @param name
143     *        The name of the property to set.
144     */
145    public void setErrorProperty(String name) {
146        errorProperty = name;
147    }
148
149    /**
150     * @return Returns the mode.
151     */
152    public Mode getMode() {
153        return mode;
154    }
155
156    /**
157     * @param value
158     *        The value of the property to set.
159     */
160    public void setMode(Mode value) {
161        mode = value;
162    }
163
164    /**
165     * @return Returns the settings.
166     */
167    public SettingsElement getSettings() {
168        return settings;
169    }
170
171    /**
172     * @param element
173     *        The settings to set.
174     */
175    public void setSettings(SettingsElement element) {
176        if (project != null)
177            throw new BuildException("The element <settings> has been already defined.");
178        settings = element;
179    }
180
181    /**
182     * @return Returns the project.
183     */
184    public ProjectElement getProject() {
185        return project;
186    }
187
188    /**
189     * @param element
190     *        The project to set.
191     */
192    public void setProject(ProjectElement element) {
193        if (project != null)
194            throw new BuildException("The element <project> has been already defined.");
195        project = element;
196    }
197
198    /**
199     * @return Returns the classPath.
200     */
201    public ClassPathElement getClassPath() {
202        return classPath;
203    }
204
205    /**
206     * @param element
207     *        The classPath to set.
208     */
209    public void setClassPath(ClassPathElement element) {
210        if (classPath != null)
211            throw new BuildException("The element <classpath> has been already defined.");
212        classPath = element;
213    }
214
215}