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. package org.apache.tools.ant;
  18. /**
  19. * Base class for components of a project, including tasks and data types.
  20. * Provides common facilities.
  21. *
  22. */
  23. public abstract class ProjectComponent {
  24. /**
  25. * Project object of this component.
  26. * @deprecated You should not be directly accessing this variable
  27. * directly. You should access project object via the getProject()
  28. * or setProject() accessor/mutators.
  29. */
  30. protected Project project;
  31. /** Sole constructor. */
  32. public ProjectComponent() {
  33. }
  34. /**
  35. * Sets the project object of this component. This method is used by
  36. * Project when a component is added to it so that the component has
  37. * access to the functions of the project. It should not be used
  38. * for any other purpose.
  39. *
  40. * @param project Project in whose scope this component belongs.
  41. * Must not be <code>null</code>.
  42. */
  43. public void setProject(Project project) {
  44. this.project = project;
  45. }
  46. /**
  47. * Returns the project to which this component belongs.
  48. *
  49. * @return the components's project.
  50. */
  51. public Project getProject() {
  52. return project;
  53. }
  54. /**
  55. * Logs a message with the default (INFO) priority.
  56. *
  57. * @param msg The message to be logged. Should not be <code>null</code>.
  58. */
  59. public void log(String msg) {
  60. log(msg, Project.MSG_INFO);
  61. }
  62. /**
  63. * Logs a message with the given priority.
  64. *
  65. * @param msg The message to be logged. Should not be <code>null</code>.
  66. * @param msgLevel the message priority at which this message is
  67. * to be logged.
  68. */
  69. public void log(String msg, int msgLevel) {
  70. if (project != null) {
  71. project.log(msg, msgLevel);
  72. } else {
  73. // 'reasonable' default, if the component is used without
  74. // a Project ( for example as a standalone Bean ).
  75. // Most ant components can be used this way.
  76. if (msgLevel <= Project.MSG_INFO) {
  77. System.err.println(msg);
  78. }
  79. }
  80. }
  81. }