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    
020    package prantl.ant.eclipse;
021    
022    import org.apache.tools.ant.BuildException;
023    import org.apache.tools.ant.types.Reference;
024    
025    /**
026     * Describes an element under the element classpath referencing a path consisting
027     * optionally from more elements (directories or files). Only one attribute of the two
028     * <tt>path</tt> and <tt>pathref</tt> is allowed.
029     * 
030     * @since Ant-Eclipse 1.0
031     * @author Ferdinand Prantl &lt;prantl@users.sourceforge.net&gt;
032     */
033    public class ClassPathEntryPathElement extends ClassPathEntryElement {
034    
035        private Reference pathRef = null;
036    
037        /**
038         * Creates a new instance of the classpathentry-src element.
039         * 
040         * @since Ant-Eclipse 1.0
041         */
042        public ClassPathEntryPathElement() {
043        }
044    
045        /**
046         * Returns a reference to the kind-of-element specific path value or <tt>null</tt>
047         * if it has not been set, which should be considered an error. However, descendant
048         * classes may set a default for this attribute or to the attribute <tt>path</tt>,
049         * which can be used instead or together.
050         * 
051         * @return A reference to the kind-of-element specific path value or <tt>null</tt>
052         *         if not having been set (descendant classes may return a default in this
053         *         case).
054         */
055        public Reference getPathRef() {
056            return pathRef;
057        }
058    
059        /**
060         * Sets the reference to a path of the classpathentry element.
061         * 
062         * @param value
063         *        A reference to the kind-of-element specific path value.
064         * @throws BuildException
065         *         If an attribute <tt>path</tt> has been set.
066         * @since Ant-Eclipse 1.0
067         */
068        public void setPathRef(Reference value) {
069            if (getPath() != null)
070                throw new BuildException(
071                        "Only one of the attributes \"path\" or \"pathref\" is allowed.");
072            pathRef = value;
073        }
074    
075        /**
076         * Sets the path of the classpathentry element.
077         * 
078         * @param value
079         *        A kind-of-element specific path value.
080         * @throws BuildException
081         *         If an attribute <tt>pathref</tt> has been set.
082         * @since Ant-Eclipse 1.0
083         */
084        public void setPath(String value) {
085            if (getPathRef() != null)
086                throw new BuildException(
087                        "Only one of the attributes \"path\" or \"pathref\" is allowed.");
088            super.setPath(value);
089        }
090    
091        /**
092         * Performs the validation of the element at the time when the whole build file was
093         * parsed checking the content of the element and possibly adding mandatory attributes
094         * with default settings.
095         * 
096         * @since Ant-Eclipse 1.0
097         */
098        public void validate() {
099            if (getPath() == null && pathRef == null)
100                throw new BuildException(
101                        "None of the attributes \"path\" or \"pathref\" was set in an element under \"classpath\".");
102        }
103    
104    }