1 | /*
|
---|
2 | * Copyright 2001-2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 |
|
---|
18 | package org.apache.tools.ant;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Base class for components of a project, including tasks and data types.
|
---|
22 | * Provides common facilities.
|
---|
23 | *
|
---|
24 | */
|
---|
25 | public abstract class ProjectComponent {
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Project object of this component.
|
---|
29 | * @deprecated You should not be directly accessing this variable
|
---|
30 | * directly. You should access project object via the getProject()
|
---|
31 | * or setProject() accessor/mutators.
|
---|
32 | */
|
---|
33 | protected Project project;
|
---|
34 |
|
---|
35 | /** Sole constructor. */
|
---|
36 | public ProjectComponent() {
|
---|
37 | }
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Sets the project object of this component. This method is used by
|
---|
41 | * Project when a component is added to it so that the component has
|
---|
42 | * access to the functions of the project. It should not be used
|
---|
43 | * for any other purpose.
|
---|
44 | *
|
---|
45 | * @param project Project in whose scope this component belongs.
|
---|
46 | * Must not be <code>null</code>.
|
---|
47 | */
|
---|
48 | public void setProject(Project project) {
|
---|
49 | this.project = project;
|
---|
50 | }
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Returns the project to which this component belongs.
|
---|
54 | *
|
---|
55 | * @return the components's project.
|
---|
56 | */
|
---|
57 | public Project getProject() {
|
---|
58 | return project;
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Logs a message with the default (INFO) priority.
|
---|
63 | *
|
---|
64 | * @param msg The message to be logged. Should not be <code>null</code>.
|
---|
65 | */
|
---|
66 | public void log(String msg) {
|
---|
67 | log(msg, Project.MSG_INFO);
|
---|
68 | }
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Logs a message with the given priority.
|
---|
72 | *
|
---|
73 | * @param msg The message to be logged. Should not be <code>null</code>.
|
---|
74 | * @param msgLevel the message priority at which this message is
|
---|
75 | * to be logged.
|
---|
76 | */
|
---|
77 | public void log(String msg, int msgLevel) {
|
---|
78 | if (project != null) {
|
---|
79 | project.log(msg, msgLevel);
|
---|
80 | } else {
|
---|
81 | // 'reasonable' default, if the component is used without
|
---|
82 | // a Project ( for example as a standalone Bean ).
|
---|
83 | // Most ant components can be used this way.
|
---|
84 | if (msgLevel <= Project.MSG_INFO) {
|
---|
85 | System.err.println(msg);
|
---|
86 | }
|
---|
87 | }
|
---|
88 | }
|
---|
89 | }
|
---|