01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.controls.runtime.generator;
20:
21: import org.apache.velocity.runtime.RuntimeServices;
22: import org.apache.velocity.runtime.log.LogSystem;
23:
24: import com.sun.mirror.apt.Messager;
25:
26: /**
27: * The VelocityAptLogSystem implements the <code>org.apache.velocity.runtime.LogSystem</code>
28: * interface for logging messages from Velocity and routes warnings and errors to the log
29: * system of APT.
30: */
31: public class VelocityAptLogSystem implements LogSystem {
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 APT_ENV_PROPERTY = VelocityAptLogSystem.class
39: + "." + "environment";
40:
41: /**
42: * The prefix to apply to Velocity error and warnings before passing to APT, to make it
43: * easier to identify Velocity output
44: */
45: static final private String MESSAGE_PREFIX = "VELOCITY: ";
46:
47: /**
48: * This can be set to true when debugging Velocity codegen templates to have all output
49: * from Velocity sent to the APT logger
50: */
51: static final private boolean _debugging = false;
52:
53: public VelocityAptLogSystem(Messager messager) {
54: _messager = messager;
55: }
56:
57: public void init(RuntimeServices rs) throws java.lang.Exception {
58: }
59:
60: public void logVelocityMessage(int level, java.lang.String message) {
61: if (level == LogSystem.ERROR_ID)
62: _messager.printError(MESSAGE_PREFIX + message);
63: else if (level == LogSystem.WARN_ID)
64: _messager.printWarning(MESSAGE_PREFIX + message);
65: else if (_debugging)
66: _messager.printNotice(MESSAGE_PREFIX + message);
67: }
68:
69: Messager _messager;
70: }
|