001    /*
002     * Copyright 2004-2005 Stephen J. McConnell.
003     *
004     * Licensed  under the  Apache License,  Version 2.0  (the "License");
005     * you may not use  this file  except in  compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *   http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed  under the  License is distributed on an "AS IS" BASIS,
012     * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
013     * implied.
014     *
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    
019    package net.dpml.transit.tools;
020    
021    import java.net.URL;
022    
023    import net.dpml.transit.monitor.Adapter;
024    import net.dpml.util.ExceptionHelper;
025    import net.dpml.util.Logger;
026    
027    import org.apache.tools.ant.Task;
028    import org.apache.tools.ant.Project;
029    
030    /**
031     * A ant montor for download messages.
032     *
033     * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
034     * @version 1.0.3
035     */
036    public class AntAdapter implements Adapter
037    {
038       /**
039        * The ant task that this adapter is assigned to.
040        */
041        private Task m_task;
042    
043       /**
044        * Creation of a new ant logging adapter.
045        * @param task the task establishing the adapter
046        */
047        public AntAdapter( Task task )
048        {
049             m_task = task;
050        }
051    
052       /**
053        * Return TRUE is trace level logging is enabled.
054        * @return the enabled state of trace logging
055        */
056        public boolean isTraceEnabled()
057        {
058            return true;
059        }
060    
061       /**
062        * Return TRUE is debug level logging is enabled.
063        * @return the enabled state of debug logging
064        */
065        public boolean isDebugEnabled()
066        {
067            return true;
068        }
069        
070       /**
071        * Return TRUE is info level logging is enabled.
072        * @return the enabled state of info logging
073        */
074        public boolean isInfoEnabled()
075        {
076            return true;
077        }
078    
079       /**
080        * Return TRUE is warn level logging is enabled.
081        * @return the enabled state of warn logging
082        */
083        public boolean isWarnEnabled()
084        {
085            return true;
086        }
087    
088       /**
089        * Return TRUE is error level logging is enabled.
090        * @return the enabled state of error logging
091        */
092        public boolean isErrorEnabled()
093        {
094            return true;
095        }
096    
097       /**
098        * Record a debug level message.
099        * @param message the debug message to record
100        */
101        public void debug( String message )
102        {
103            m_task.log( message, Project.MSG_VERBOSE );
104        }
105    
106       /**
107        * Record a trace level message.
108        * @param message the trace message to record
109        */
110        public void trace( String message )
111        {
112            m_task.log( message, Project.MSG_VERBOSE );
113        }
114    
115       /**
116        * Record a informative message.
117        * @param message the info message to record
118        */
119        public void info( String message )
120        {
121            m_task.log( message, Project.MSG_INFO );
122        }
123    
124       /**
125        * Record a warning message.
126        * @param message the warning message to record
127        */
128        public void warn( String message )
129        {
130            m_task.log( message, Project.MSG_WARN );
131        }
132    
133       /**
134        * Record a warning message.
135        * @param message the warning message to record
136        * @param cause the causal exception
137        */
138        public void warn( String message, Throwable cause )
139        {
140            m_task.log( message, Project.MSG_WARN );
141            if( null != cause  )
142            {
143                final String error = ExceptionHelper.packException( message, cause, true );
144                m_task.log( error, Project.MSG_WARN );
145            }
146        }
147    
148       /**
149        * Record a error level message.
150        * @param message the error message to record
151        */
152        public void error( String message )
153        {
154            error( message, null );
155        }
156    
157       /**
158        * Record a error level message.
159        * @param message the error message to record
160        * @param e the error
161        */
162        public void error( String message, Throwable e )
163        {
164            m_task.log( message, Project.MSG_ERR );
165            if( null != e )
166            {
167                final String error = ExceptionHelper.packException( message, e, true );
168                m_task.log( error, Project.MSG_ERR );
169            }
170        }
171    
172       /**
173        * Create a new subsidiary logging channel.
174        * @param category the channel name relative to this logging channel
175        * @return the new logging channel
176        */
177        public Logger getChildLogger( String category )
178        {
179            return this;
180        }
181    
182        /**
183         * Hnadle download notification.
184         * @param resource the resource under attention
185         * @param total the estimated download size
186         * @param count the progress towards expected
187         */
188        public void notify( URL resource, int total, int count )
189        {
190        }
191    }
192