KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > controls > runtime > generator > AptPropertySet


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

19
20 import java.util.ArrayList JavaDoc;
21 import java.util.Collection JavaDoc;
22
23 import com.sun.mirror.declaration.AnnotationTypeDeclaration;
24 import com.sun.mirror.declaration.AnnotationTypeElementDeclaration;
25 import com.sun.mirror.declaration.MethodDeclaration;
26 import com.sun.mirror.declaration.Declaration;
27
28 import org.apache.beehive.controls.api.properties.PropertySet;
29 import org.apache.beehive.controls.runtime.generator.apt.TwoPhaseAnnotationProcessor;
30
31 /**
32  * The AptPropertySet class represents a control PropertySet where the property list
33  * is derived using APT metadata
34  */

35 public class AptPropertySet
36 {
37     /**
38      * Constructs a new AptPropertySet instance from APT metadata
39      * @param controlIntf the declaring bean interface. May be null (external property set)
40      * @param propertySet the PropertySet declaration
41      * @param ap the annotation processor
42      */

43     public AptPropertySet(AptControlInterface controlIntf, Declaration propertySet,
44                           TwoPhaseAnnotationProcessor ap)
45     {
46         _ap = ap;
47         _controlIntf = controlIntf;
48
49         if (!(propertySet instanceof AnnotationTypeDeclaration))
50         {
51             _ap.printError( propertySet, "propertyset.illegal.usage" );
52             return;
53         }
54         _propertySet = (AnnotationTypeDeclaration)propertySet;
55
56         _isOptional = _propertySet.getAnnotation(PropertySet.class).optional();
57         _hasSetters = _propertySet.getAnnotation(PropertySet.class).hasSetters();
58
59         _properties = initProperties();
60     }
61
62     /**
63      * Initializes the list of ControlProperties associated with this ControlPropertySet
64      */

65     protected ArrayList JavaDoc<AptProperty> initProperties()
66     {
67         ArrayList JavaDoc<AptProperty> properties = new ArrayList JavaDoc<AptProperty>();
68
69         if (_propertySet == null || _propertySet.getMethods() == null )
70             return properties;
71         
72         // Add all declared method, but ignore the mystery <clinit> methods
73
for (MethodDeclaration methodDecl : _propertySet.getMethods())
74             if (!methodDecl.toString().equals("<clinit>()"))
75                 properties.add(
76                     new AptProperty(this,(AnnotationTypeElementDeclaration)methodDecl,_ap));
77
78         return properties;
79     }
80
81     /**
82      * Returns the list of ControlProperties associated with this ControlPropertySet
83      */

84     public Collection JavaDoc<AptProperty> getProperties() { return _properties; }
85
86     /**
87      * Returns the fully qualified package name of this property set
88      */

89     public String JavaDoc getPackage()
90     {
91         if (_propertySet == null || _propertySet.getPackage() == null )
92             return "";
93         
94         return _propertySet.getPackage().getQualifiedName();
95     }
96
97     /**
98      * Returns the unqualified classname of this property set
99      */

100     public String JavaDoc getShortName()
101     {
102         if (_propertySet == null )
103             return "";
104         
105         return _propertySet.getSimpleName();
106     }
107
108     /**
109      * Returns the fully qualified class name of the property set
110      */

111     public String JavaDoc getClassName()
112     {
113         if (_propertySet == null )
114             return "";
115
116         return _propertySet.getQualifiedName();
117     }
118
119     /**
120      * Returns the property name prefix for properties in this PropertySet
121      */

122     public String JavaDoc getPrefix()
123     {
124         if (_propertySet == null || _propertySet.getAnnotation(PropertySet.class) == null )
125             return "";
126         
127         return _propertySet.getAnnotation(PropertySet.class).prefix();
128     }
129
130     /**
131      * Returns whether or not this propertyset exposes setters
132      */

133     public boolean isOptional()
134     {
135         return _isOptional;
136     }
137
138     /**
139      * Returns whether or not this propertyset exposes setters
140      */

141     public boolean hasSetters()
142     {
143         return _hasSetters;
144     }
145
146     private AnnotationTypeDeclaration _propertySet;
147     private AptControlInterface _controlIntf; // may be null if an external property set
148
private ArrayList JavaDoc<AptProperty> _properties;
149     private TwoPhaseAnnotationProcessor _ap;
150     private boolean _isOptional;
151     private boolean _hasSetters;
152 }
153
Popular Tags