KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > ProjectComponent


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18
19 package org.apache.tools.ant;
20
21
22 /**
23  * Base class for components of a project, including tasks and data types.
24  * Provides common facilities.
25  *
26  */

27 public abstract class ProjectComponent implements Cloneable JavaDoc {
28
29     // CheckStyle:VisibilityModifier OFF - bc
30
/**
31      * Project object of this component.
32      * @deprecated since 1.6.x.
33      * You should not be directly accessing this variable directly.
34      * You should access project object via the getProject()
35      * or setProject() accessor/mutators.
36      */

37     protected Project project;
38
39     /**
40      * Location within the build file of this task definition.
41      * @deprecated since 1.6.x.
42      * You should not be accessing this variable directly.
43      * Please use the {@link #getLocation()} method.
44      */

45     protected Location location = Location.UNKNOWN_LOCATION;
46
47     /**
48      * Description of this component, if any.
49      * @deprecated since 1.6.x.
50      * You should not be accessing this variable directly.
51      */

52     protected String JavaDoc description;
53     // CheckStyle:VisibilityModifier ON
54

55     /** Sole constructor. */
56     public ProjectComponent() {
57     }
58
59     /**
60      * Sets the project object of this component. This method is used by
61      * Project when a component is added to it so that the component has
62      * access to the functions of the project. It should not be used
63      * for any other purpose.
64      *
65      * @param project Project in whose scope this component belongs.
66      * Must not be <code>null</code>.
67      */

68     public void setProject(Project project) {
69         this.project = project;
70     }
71
72     /**
73      * Returns the project to which this component belongs.
74      *
75      * @return the components's project.
76      */

77     public Project getProject() {
78         return project;
79     }
80
81     /**
82      * Returns the file/location where this task was defined.
83      *
84      * @return the file/location where this task was defined.
85      * Should not return <code>null</code>. Location.UNKNOWN_LOCATION
86      * is used for unknown locations.
87      *
88      * @see Location#UNKNOWN_LOCATION
89      */

90     public Location getLocation() {
91         return location;
92     }
93
94     /**
95      * Sets the file/location where this task was defined.
96      *
97      * @param location The file/location where this task was defined.
98      * Should not be <code>null</code>--use
99      * Location.UNKNOWN_LOCATION if the location isn't known.
100      *
101      * @see Location#UNKNOWN_LOCATION
102      */

103     public void setLocation(Location location) {
104         this.location = location;
105     }
106
107     /**
108      * Sets a description of the current action. This may be used for logging
109      * purposes.
110      *
111      * @param desc Description of the current action.
112      * May be <code>null</code>, indicating that no description is
113      * available.
114      *
115      */

116     public void setDescription(String JavaDoc desc) {
117         description = desc;
118     }
119
120     /**
121      * Returns the description of the current action.
122      *
123      * @return the description of the current action, or <code>null</code> if
124      * no description is available.
125      */

126     public String JavaDoc getDescription() {
127         return description;
128     }
129
130     /**
131      * Logs a message with the default (INFO) priority.
132      *
133      * @param msg The message to be logged. Should not be <code>null</code>.
134      */

135     public void log(String JavaDoc msg) {
136         log(msg, Project.MSG_INFO);
137     }
138
139     /**
140      * Logs a message with the given priority.
141      *
142      * @param msg The message to be logged. Should not be <code>null</code>.
143      * @param msgLevel the message priority at which this message is
144      * to be logged.
145      */

146     public void log(String JavaDoc msg, int msgLevel) {
147         if (getProject() != null) {
148             getProject().log(msg, msgLevel);
149         } else {
150             // 'reasonable' default, if the component is used without
151
// a Project ( for example as a standalone Bean ).
152
// Most ant components can be used this way.
153
if (msgLevel <= Project.MSG_INFO) {
154                 System.err.println(msg);
155             }
156         }
157     }
158     /**
159      * @since Ant 1.7
160      * @return a shallow copy of this projectcomponent.
161      * @throws CloneNotSupportedException does not happen,
162      * but is declared to allow subclasses to do so.
163      */

164     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
165         ProjectComponent pc = (ProjectComponent) super.clone();
166         pc.setLocation(getLocation());
167         pc.setProject(getProject());
168         return pc;
169     }
170 }
171
Popular Tags