KickJava   Java API By Example, From Geeks To Geeks.

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


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.AnnotationValue;
21 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeElementDeclaration;
22 import org.apache.beehive.netui.compiler.typesystem.util.SourcePosition;
23 import org.apache.beehive.netui.compiler.xdoclet.typesystem.impl.DelegatingImpl;
24 import org.apache.beehive.netui.xdoclet.XDocletCompilerUtils;
25
26 import java.util.Iterator JavaDoc;
27
28 public class AnnotationValueImpl
29         extends DelegatingImpl
30         implements AnnotationValue
31 {
32     private SourcePosition _position;
33     
34     public AnnotationValueImpl( Object JavaDoc value, SourcePosition position, AnnotationTypeElementDeclaration decl )
35     {
36         super( value );
37         _position = position;
38         
39         if ( decl != null )
40         {
41             assert decl instanceof AnnotationTypeElementDeclarationImpl : decl.getClass().getName();
42             AnnotationTypeElementDeclarationImpl declImpl = ( AnnotationTypeElementDeclarationImpl ) decl;
43             
44             if ( ! declImpl.isValidValue( value ) )
45             {
46                 StringBuffer JavaDoc values = new StringBuffer JavaDoc();
47                 for ( Iterator JavaDoc i = declImpl.getValidValues().iterator(); i.hasNext(); )
48                 {
49                     String JavaDoc validValue = ( String JavaDoc ) i.next();
50                     values.append( ' ' ).append( validValue );
51                 }
52                 
53                 XDocletCompilerUtils.addError( position, "error.invalid-enum-value",
54                                                new String JavaDoc[]{ value.toString(), decl.getSimpleName(), values.toString() } );
55             }
56         }
57     }
58
59     public Object JavaDoc getValue()
60     {
61         return getDelegate();
62     }
63
64     public SourcePosition getPosition()
65     {
66         return _position;
67     }
68
69     public boolean equals( Object JavaDoc o )
70     {
71         return this == o;
72     }
73 }
74
Popular Tags