KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > compiler > xdoclet > typesystem > impl > declaration > AnnotationInstanceImpl


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.declaration;
19
20 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
21 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeElementDeclaration;
22 import org.apache.beehive.netui.compiler.typesystem.type.AnnotationType;
23 import org.apache.beehive.netui.compiler.typesystem.util.SourcePosition;
24 import org.apache.beehive.netui.compiler.xdoclet.typesystem.impl.DelegatingImpl;
25 import org.apache.beehive.netui.compiler.xdoclet.typesystem.impl.env.SourcePositionImpl;
26 import org.apache.beehive.netui.xdoclet.XDocletCompilerUtils;
27 import xjavadoc.XProgramElement;
28 import xjavadoc.XTag;
29
30 import java.util.ArrayList JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.Map JavaDoc;
34
35 public class AnnotationInstanceImpl
36         extends DelegatingImpl
37         implements AnnotationInstance
38 {
39     
40     private AnnotationType _type;
41     private SourcePosition _sourcePosition;
42     
43     // Map<AnnotationTypeElementDeclaration, AnnotationValue> getElementValues();
44
private HashMap JavaDoc _elementValues;
45     
46     public AnnotationInstanceImpl( XTag tag, XProgramElement element, AnnotationType type, HashMap JavaDoc elementValues )
47     {
48         super( tag );
49         _sourcePosition = SourcePositionImpl.get( tag, element );
50         _type = type;
51         _elementValues = elementValues;
52     }
53     
54     public AnnotationType getAnnotationType()
55     {
56         return _type;
57     }
58
59     public SourcePosition getPosition()
60     {
61         return _sourcePosition;
62     }
63     
64     public void addElementValue( String JavaDoc memberName, boolean memberIsArray, Object JavaDoc value, SourcePosition sourcePosition )
65     {
66         AnnotationTypeElementDeclaration elementDecl = _type.getAnnotationTypeDeclaration().getMember( memberName );
67         
68         if ( elementDecl == null )
69         {
70             XDocletCompilerUtils.addError( getPosition(), "error.no-such-member",
71                                            new String JavaDoc[]{ memberName, _type.getAnnotationTypeDeclaration().getQualifiedName() } );
72         }
73         else if ( memberIsArray )
74         {
75             AnnotationValueImpl av = ( AnnotationValueImpl ) _elementValues.get( elementDecl );
76             List JavaDoc list;
77             
78             if ( av == null )
79             {
80                 list = new ArrayList JavaDoc();
81                 av = new AnnotationValueImpl( list, sourcePosition, elementDecl );
82                 _elementValues.put( elementDecl, av );
83             }
84             else
85             {
86                 list = ( List JavaDoc ) av.getValue();
87             }
88             
89             list.add( new AnnotationValueImpl( value, sourcePosition, null ) );
90         }
91         else
92         {
93             _elementValues.put( elementDecl, new AnnotationValueImpl( value, sourcePosition, elementDecl ) );
94         }
95     }
96     
97     // Map<AnnotationTypeElementDeclaration, AnnotationValue> getElementValues();
98
public Map JavaDoc getElementValues()
99     {
100         return _elementValues;
101     }
102
103     public boolean equals( Object JavaDoc o )
104     {
105         if ( o == null ) return false;
106         if ( o == this ) return true;
107         if ( ! ( o instanceof AnnotationInstanceImpl ) ) return false;
108         assert false : "didn't finish equals()";
109         return false;
110     }
111     
112     public String JavaDoc toString()
113     {
114         assert false : "NYI";
115         throw new UnsupportedOperationException JavaDoc( "NYI" );
116     }
117     
118     public XTag getDelegateXTag()
119     {
120         return ( XTag ) super.getDelegate();
121     }
122 }
123
Popular Tags