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.util.Vector; 023 024import org.apache.tools.ant.BuildException; 025 026/** 027 * Configures contents of the file .classpath with paths to source files, binary java 028 * archives and output directories, this class specifically the root element 029 * <tt>classpath</tt>. 030 * 031 * @since Ant-Eclipse 1.0 032 * @author Ferdinand Prantl <prantl@users.sourceforge.net> 033 */ 034public class ClassPathElement { 035 036 private Vector sources = new Vector(); 037 038 private Vector libraries = new Vector(); 039 040 private ClassPathEntryContainerElement container = null; 041 042 private Vector variables = new Vector(); 043 044 private ClassPathEntryOutputElement output = null; 045 046 /** 047 * Creates a new instance of the classpath element. 048 * 049 * @since Ant-Eclipse 1.0 050 */ 051 public ClassPathElement() { 052 } 053 054 /** 055 * Returns a list of instances of the class ClassPathEntrySourceElement describing 056 * elements <tt>classpathentry</tt> of the kind "src" in the file .classpath. If it 057 * is empty, a single source element should be created with default settings. 058 * 059 * @return A list of instances of the class ClassPathEntrySourceElement. 060 */ 061 public Vector getSources() { 062 return sources; 063 } 064 065 /** 066 * Returns a list of instances of the class ClassPathEntryLibraryElement describing 067 * elements <tt>classpathentry</tt> of the kind "lib" in the file .classpath. 068 * 069 * @return A list of instances of the class ClassPathEntryLibraryElement. 070 */ 071 public Vector getLibraries() { 072 return libraries; 073 } 074 075 /** 076 * Returns an instance of the class ClassPathEntryContainerElement describing the 077 * element <tt>classpathentry</tt> of the kind "con" in the file .classpath or 078 * <tt>null</tt> if the element was not present, which means creating a default one. 079 * 080 * @return An instance of the class ClassPathEntryContainerElement or <tt>null</tt> 081 * if not having been present. 082 */ 083 public ClassPathEntryContainerElement getContainer() { 084 return container; 085 } 086 087 /** 088 * Returns a list of instances of the class ClassPathEntryVariableElement describing 089 * elements <tt>classpathentry</tt> of the kind "var" in the file .classpath. 090 * 091 * @return A list of instances of the class ClassPathEntryVariableElement. 092 */ 093 public Vector getVariables() { 094 return variables; 095 } 096 097 /** 098 * Returns an instance of the class ClassPathEntryOutputElement describing the element 099 * <tt>classpathentry</tt> of the kind "output" in the file .classpath or 100 * <tt>null</tt> if the element was not present, which means creating a default one. 101 * 102 * @return An instance of the class ClassPathEntryOutputElement or <tt>null</tt> if 103 * not having been present. 104 */ 105 public ClassPathEntryOutputElement getOutput() { 106 return output; 107 } 108 109 /** 110 * Adds a definition of the classpathentry element of the kind "src". 111 * 112 * @return A definition of the classpathentry-src element. 113 * @since Ant-Eclipse 1.0 114 */ 115 public ClassPathEntrySourceElement createSource() { 116 sources.addElement(new ClassPathEntrySourceElement()); 117 return (ClassPathEntrySourceElement) sources.lastElement(); 118 } 119 120 /** 121 * Adds a definition of the classpathentry element of the kind "lib". 122 * 123 * @return A definition of the classpathentry-lib element. 124 * @since Ant-Eclipse 1.0 125 */ 126 public ClassPathEntryLibraryElement createLibrary() { 127 libraries.addElement(new ClassPathEntryLibraryElement()); 128 return (ClassPathEntryLibraryElement) libraries.lastElement(); 129 } 130 131 /** 132 * Adds a definition of the classpathentry element of the kind "con". 133 * 134 * @return A definition of the classpathentry-con element. 135 * @since Ant-Eclipse 1.0 136 */ 137 public ClassPathEntryContainerElement createContainer() { 138 if (container != null) 139 throw new BuildException( 140 "The element <classpathentry kind=\"con\" ...> has been already defined."); 141 return container = new ClassPathEntryContainerElement(); 142 } 143 144 /** 145 * Adds a definition of the classpathentry element of the kind "var". 146 * 147 * @return A definition of the classpathentry-var element. 148 * @since Ant-Eclipse 1.0 149 */ 150 public ClassPathEntryVariableElement createVariable() { 151 variables.addElement(new ClassPathEntryVariableElement()); 152 return (ClassPathEntryVariableElement) variables.lastElement(); 153 } 154 155 /** 156 * Adds a definition of the classpathentry element of the kind "output". 157 * 158 * @return A definition of the classpathentry-output element. 159 * @since Ant-Eclipse 1.0 160 */ 161 public ClassPathEntryOutputElement createOutput() { 162 if (output != null) 163 throw new BuildException( 164 "The element <classpathentry kind=\"output\" ...> has been already defined."); 165 return output = new ClassPathEntryOutputElement(); 166 } 167 168}