KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > annotation > impl > DefaultErrorHandler


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.deployment.annotation.impl;
25
26 import com.sun.enterprise.deployment.annotation.ErrorHandler;
27 import com.sun.enterprise.deployment.annotation.AnnotationInfo;
28 import com.sun.enterprise.deployment.annotation.AnnotationProcessorException;
29
30 import java.util.logging.Logger JavaDoc;
31 import java.util.logging.Level JavaDoc;
32
33 /**
34  * Default implementation of the ErrorHandler
35  *
36  * @author Jerome Dochez
37  */

38 public class DefaultErrorHandler implements ErrorHandler {
39     
40     Logger JavaDoc logger;
41
42     /**
43      * Creates a new ErrorHandler with the default logger
44      */

45     public DefaultErrorHandler() {
46         logger = AnnotationUtils.getLogger();
47     }
48     
49     /**
50      * Creates a new ErrorHandler with the provided looger;
51      */

52     public DefaultErrorHandler(Logger JavaDoc logger){
53         this.logger = logger;
54     }
55
56     /**
57      * Receive notication of a fine error message
58      * @param ape The warning information
59      * @throws any exception to stop the annotation processing
60      */

61     public void fine(AnnotationProcessorException ape) throws
62             AnnotationProcessorException {
63         
64         if (logger.isLoggable(Level.FINE)){
65             AnnotationInfo info = ape.getLocator();
66             if (info==null){
67                 logger.fine(ape.getMessage());
68             } else{
69                 logger.fine(AnnotationUtils.getLocalString(
70                     "enterprise.deployment.annotation.error",
71                     "{2}\n symbol: {0}\n location: {1}\n\n",
72                     new Object JavaDoc[] { info.getElementType(), info.getAnnotatedElement(), ape.getMessage()}));
73             }
74         }
75         
76     }
77     
78     /**
79      * Receive notification of a warning
80      * @param ape The warning information
81      * @throws any exception to stop the annotation processing
82      */

83     public void warning(AnnotationProcessorException ape) throws
84             AnnotationProcessorException {
85         
86         if (logger.isLoggable(Level.WARNING)){
87             AnnotationInfo info = ape.getLocator();
88             if (info==null){
89                 logger.warning(ape.getMessage());
90             } else{
91                 logger.warning(AnnotationUtils.getLocalString(
92                     "enterprise.deployment.annotation.error",
93                     "{2}\n symbol: {0}\n location: {1}\n\n",
94                     new Object JavaDoc[] { info.getElementType(), info.getAnnotatedElement(), ape.getMessage()}));
95             }
96         }
97     }
98     
99     /**
100      * Receive notification of an error
101      * @param ape The error information
102      * @throws amy exception to stop the annotation processing
103      */

104     public void error(AnnotationProcessorException ape) throws
105             AnnotationProcessorException {
106         
107         AnnotationInfo info = ape.getLocator();
108         if (info==null){
109             logger.severe(ape.getMessage());
110         } else{
111             logger.severe(AnnotationUtils.getLocalString(
112                 "enterprise.deployment.annotation.error",
113                 "{2}\n symbol: {0} location: {1}\n\n",
114                 new Object JavaDoc[] { info.getElementType(), info.getAnnotatedElement(), ape.getMessage()}));
115         }
116     }
117 }
118
Popular Tags