KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > compiler > xdoclet > typesystem > impl > env > AnnotationProcessorEnvironmentImpl


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

18 package org.apache.beehive.netui.compiler.xdoclet.typesystem.impl.env;
19
20 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeDeclaration;
21 import org.apache.beehive.netui.compiler.typesystem.declaration.Declaration;
22 import org.apache.beehive.netui.compiler.typesystem.declaration.TypeDeclaration;
23 import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessorEnvironment;
24 import org.apache.beehive.netui.compiler.typesystem.env.Filer;
25 import org.apache.beehive.netui.compiler.typesystem.env.Messager;
26 import org.apache.beehive.netui.compiler.xdoclet.typesystem.impl.DelegatingImpl;
27 import org.apache.beehive.netui.compiler.xdoclet.typesystem.impl.WrapperFactory;
28 import org.apache.beehive.netui.compiler.xdoclet.typesystem.impl.declaration.AnnotationTypeDeclarationImpl;
29 import org.apache.beehive.netui.xdoclet.NetuiSubTask;
30 import org.apache.beehive.netui.xdoclet.XDocletCompilerUtils;
31 import xdoclet.DocletContext;
32 import xjavadoc.SourceClass;
33 import xjavadoc.XDoc;
34 import xjavadoc.XJavaDoc;
35
36 import java.util.Map JavaDoc;
37 import java.util.HashMap JavaDoc;
38
39 public class AnnotationProcessorEnvironmentImpl
40         extends DelegatingImpl
41         implements AnnotationProcessorEnvironment
42 {
43     private static final Declaration[] EMPTY_DECLARATION_ARRAY = new Declaration[0];
44     
45     private NetuiSubTask _subtask;
46     private SourceClass _sourceClass;
47     private HashMap JavaDoc _attributes;
48     
49     protected AnnotationProcessorEnvironmentImpl( DocletContext delegate, NetuiSubTask subtask, SourceClass sourceClass )
50     {
51         super( delegate );
52         _subtask = subtask;
53         _sourceClass = sourceClass;
54     }
55     
56     public static AnnotationProcessorEnvironment get( DocletContext delegate, NetuiSubTask subtask, SourceClass sc )
57     {
58         return delegate != null ? new AnnotationProcessorEnvironmentImpl( delegate, subtask, sc ) : null;
59     }
60
61     public Map JavaDoc getOptions()
62     {
63         return getDelegateDocletContext().getProperties();
64     }
65
66     public Messager getMessager()
67     {
68         return new MessagerImpl( _sourceClass );
69     }
70
71     public Filer getFiler()
72     {
73         assert false : "NYI";
74         throw new UnsupportedOperationException JavaDoc( "not implemented" );
75     }
76
77     public TypeDeclaration[] getSpecifiedTypeDeclarations()
78     {
79         /*
80         if ( _specifiedTypeDeclarations == null )
81         {
82             Collection delegateCollection = getXJavaDoc().getSourceClasses();
83             TypeDeclaration[] array = new TypeDeclaration[delegateCollection.size()];
84             int j = 0;
85             for ( Iterator i = delegateCollection.iterator(); i.hasNext(); )
86             {
87                 array[j++] = WrapperFactory.get().getTypeDeclaration( ( SourceClass ) i.next() );
88             }
89             _specifiedTypeDeclarations = array;
90         }
91
92         return _specifiedTypeDeclarations;
93         */

94         assert false : "NYI";
95         throw new UnsupportedOperationException JavaDoc( "NYI" );
96     }
97
98     public TypeDeclaration getTypeDeclaration( String JavaDoc s )
99     {
100         return XDocletCompilerUtils.resolveTypeDeclaration( s );
101     }
102
103     public Declaration[] getDeclarationsAnnotatedWith( AnnotationTypeDeclaration decl )
104     {
105         //
106
// Note: for now we only examine the single public source class for any of the given annotations.
107
//
108
XDoc doc = _sourceClass.getDoc();
109         
110         if ( doc != null )
111         {
112             assert decl instanceof AnnotationTypeDeclarationImpl : decl.getClass().getName();
113             if ( doc.getTag( ( ( AnnotationTypeDeclarationImpl ) decl ).getIntermediateName() ) != null )
114             {
115                 return new Declaration[]{ WrapperFactory.get().getTypeDeclaration( _sourceClass ) };
116             }
117         }
118         
119         return EMPTY_DECLARATION_ARRAY;
120     }
121
122     public DocletContext getDelegateDocletContext()
123     {
124         return ( DocletContext ) super.getDelegate();
125     }
126     
127     protected final XJavaDoc getXJavaDoc()
128     {
129         return _subtask.getXJavaDoc();
130     }
131     
132     public void setAttribute( String JavaDoc propertyName, Object JavaDoc value )
133     {
134         if ( _attributes == null ) _attributes = new HashMap JavaDoc();
135         _attributes.put( propertyName, value );
136     }
137
138     public Object JavaDoc getAttribute( String JavaDoc propertyName )
139     {
140         return _attributes != null ? _attributes.get( propertyName ) : null;
141     }
142 }
143
Popular Tags