KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > controls > runtime > generator > VelocityAptLogSystem


1 package org.apache.beehive.controls.runtime.generator;
2
3 /*
4  * Copyright 2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * $Header:$
19  */

20 import org.apache.velocity.runtime.RuntimeServices;
21 import org.apache.velocity.runtime.log.LogSystem;
22
23 import com.sun.mirror.apt.Messager;
24
25 /**
26  * The VelocityAptLogSystem implements the <code>org.apache.velocity.runtime.LogSystem</code>
27  * interface for logging messages from Velocity and routes warnings and errors to the log
28  * system of APT.
29  */

30 public class VelocityAptLogSystem implements LogSystem
31 {
32     /**
33      * This is the name of the Velocity configuration property that will be used to pass
34      * the APT environment from the execution environment into the logger instance. This
35      * property must be set on the VelocityEngine instance, and the value should be the
36      * <code>com.sun.mirror.apt.Messager</apt> instance that should be used to log messages.
37      */

38     static final String JavaDoc APT_ENV_PROPERTY = VelocityAptLogSystem.class + "." + "environment";
39
40     /**
41      * The prefix to apply to Velocity error and warnings before passing to APT, to make it
42      * easier to identify Velocity output
43      */

44     static final private String JavaDoc MESSAGE_PREFIX = "VELOCITY: ";
45
46     /**
47      * This can be set to true when debugging Velocity codegen templates to have all output
48      * from Velocity sent to the APT logger
49      */

50     static final private boolean _debugging = false;
51
52     public VelocityAptLogSystem(Messager messager)
53     {
54         _messager = messager;
55     }
56
57     public void init(RuntimeServices rs) throws java.lang.Exception JavaDoc
58     {
59     }
60
61     public void logVelocityMessage(int level, java.lang.String JavaDoc message)
62     {
63         if (level == LogSystem.ERROR_ID)
64             _messager.printError(MESSAGE_PREFIX + message);
65         else if (level == LogSystem.WARN_ID)
66             _messager.printWarning(MESSAGE_PREFIX + message);
67         else if (_debugging)
68             _messager.printNotice(MESSAGE_PREFIX + message);
69     }
70
71     Messager _messager;
72 }
73
Popular Tags