1 28 29 package com.idaremedia.antx.apis; 30 31 import org.apache.tools.ant.Project; 32 import org.apache.tools.ant.ProjectComponent; 33 34 46 47 public interface LogEnabled 48 { 49 54 void log(String message); 55 56 57 58 65 void log(String message, int msgLevel); 66 67 68 69 74 public static final LogEnabled SYSTEM= new LogEnabled() { 75 public void log(String message) { 76 System.out.println(message); 77 } 78 public void log(String message, int msgLevel) { 79 if (msgLevel>=Project.MSG_INFO) { 80 System.err.println(message); 81 } else { 82 System.out.println(message); 83 } 84 } 85 }; 86 87 88 89 98 public static class ForComponent implements LogEnabled 99 { 100 final ProjectComponent m_PC; 101 102 106 public ForComponent(ProjectComponent pc) { 107 if (pc==null) { 108 throw new IllegalArgumentException (); 109 } 110 this.m_PC = pc; 111 } 112 113 public void log(String message) { 114 m_PC.log(message); 115 } 116 117 public void log(String message, int msgLevel) { 118 m_PC.log(message,msgLevel); 119 } 120 121 public final ProjectComponent getImpl() { 122 return m_PC; 123 } 124 } 125 126 127 128 129 138 public static class ForUtility implements LogEnabled 139 { 140 final ProjectDependent m_utility; 141 142 146 public ForUtility(ProjectDependent utility) { 147 if (utility==null) { 148 throw new IllegalArgumentException (); 149 } 150 this.m_utility = utility; 151 } 152 153 public void log(String message) { 154 if (m_utility.getProject()!=null) { 155 m_utility.getProject().log(message); 156 } else { 157 SYSTEM.log(message); 158 } 159 } 160 161 public void log(String message, int msgLevel) { 162 if (m_utility.getProject()!=null) { 163 m_utility.getProject().log(message,msgLevel); 164 } else { 165 SYSTEM.log(message,msgLevel); 166 } 167 } 168 169 public final ProjectDependent getImpl() { 170 return m_utility; 171 } 172 } 173 174 175 176 187 public static class ForProject implements LogEnabled 188 { 189 final Project m_project; 190 191 195 public ForProject(Project project) { 196 this.m_project = project; 197 } 198 199 public void log(String message) { 200 if (m_project!=null) { 201 m_project.log(message); 202 } else { 203 SYSTEM.log(message); 204 } 205 } 206 207 public void log(String message, int msgLevel) { 208 if (m_project!=null) { 209 m_project.log(message,msgLevel); 210 } else { 211 SYSTEM.log(message,msgLevel); 212 } 213 } 214 215 public final Project getImpl() { 216 return m_project; 217 } 218 } 219 220 221 222 231 } 259 260 261 | Popular Tags |