KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Stack JavaDoc;
27 import com.sun.enterprise.deployment.annotation.*;
28 import com.sun.enterprise.deployment.annotation.context.AnnotationContext;
29
30 /**
31  * Minimal implementation of the ProcessingContext interface
32  *
33  * @author Jerome ochez
34  */

35 class ProcessingContextImpl implements ProcessingContext {
36     
37     protected AnnotationProcessor processor;
38     protected Stack JavaDoc<AnnotatedElementHandler> handlers = new Stack JavaDoc<AnnotatedElementHandler>();
39     protected Scanner scanner;
40     
41     /** Creates a new instance of ProcessingContextHelper */
42     ProcessingContextImpl(AnnotationProcessor processor) {
43         this.processor = processor;
44     }
45     
46     public AnnotationProcessor getProcessor() {
47         return processor;
48     }
49         
50     public void pushHandler(AnnotatedElementHandler handler) {
51         if (handler instanceof AnnotationContext) {
52             ((AnnotationContext) handler).setProcessingContext(this);
53         }
54         handlers.push(handler);
55     }
56     
57     public AnnotatedElementHandler getHandler() {
58         if (handlers.isEmpty())
59             return null;
60         
61         return handlers.peek();
62     }
63     
64     public AnnotatedElementHandler popHandler() {
65         if (handlers.isEmpty())
66             return null;
67         
68         return handlers.pop();
69     }
70         
71     /**
72      * @return the previously set ClientContext casted to the requestd
73      * type if possible or throw an exception otherwise.
74      */

75     public <U extends AnnotatedElementHandler> U getHandler(Class JavaDoc<U> contextType)
76         throws ClassCastException JavaDoc {
77         
78         if (handlers.isEmpty())
79             return null;
80         if (AnnotationUtils.shouldLog("handler")) {
81             AnnotationUtils.getLogger().finer("Top handler is " + handlers.peek());
82         }
83         return contextType.cast(handlers.peek());
84     }
85     
86     public Scanner getProcessingInput() {
87         return scanner;
88     }
89     public void setProcessingInput(Scanner scanner) {
90         this.scanner = scanner;
91     }
92
93     private ErrorHandler errorHandler = null;
94     
95     /**
96      * Sets the error handler for this processing context.
97      */

98     public void setErrorHandler(ErrorHandler errorHandler) {
99         this.errorHandler = errorHandler;
100     }
101     
102     /**
103      * @return the error handler for this processing context.
104      */

105     public ErrorHandler getErrorHandler() {
106         return errorHandler;
107     }
108 }
109
Popular Tags