001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.controls.runtime.generator;
020:
021: import java.util.ArrayList;
022: import java.util.Collection;
023:
024: import com.sun.mirror.declaration.AnnotationTypeDeclaration;
025: import com.sun.mirror.declaration.AnnotationTypeElementDeclaration;
026: import com.sun.mirror.declaration.MethodDeclaration;
027: import com.sun.mirror.declaration.Declaration;
028:
029: import org.apache.beehive.controls.api.properties.PropertySet;
030: import org.apache.beehive.controls.runtime.generator.apt.TwoPhaseAnnotationProcessor;
031:
032: /**
033: * The AptPropertySet class represents a control PropertySet where the property list
034: * is derived using APT metadata
035: */
036: public class AptPropertySet {
037: /**
038: * Constructs a new AptPropertySet instance from APT metadata
039: * @param controlIntf the declaring bean interface. May be null (external property set)
040: * @param propertySet the PropertySet declaration
041: * @param ap the annotation processor
042: */
043: public AptPropertySet(AptControlInterface controlIntf,
044: Declaration propertySet, TwoPhaseAnnotationProcessor ap) {
045: _ap = ap;
046: _controlIntf = controlIntf;
047:
048: if (!(propertySet instanceof AnnotationTypeDeclaration)) {
049: _ap.printError(propertySet, "propertyset.illegal.usage");
050: return;
051: }
052: _propertySet = (AnnotationTypeDeclaration) propertySet;
053:
054: _isOptional = _propertySet.getAnnotation(PropertySet.class)
055: .optional();
056: _hasSetters = _propertySet.getAnnotation(PropertySet.class)
057: .hasSetters();
058:
059: _properties = initProperties();
060: }
061:
062: /**
063: * Initializes the list of ControlProperties associated with this ControlPropertySet
064: */
065: protected ArrayList<AptProperty> initProperties() {
066: ArrayList<AptProperty> properties = new ArrayList<AptProperty>();
067:
068: if (_propertySet == null || _propertySet.getMethods() == null)
069: return properties;
070:
071: // Add all declared method, but ignore the mystery <clinit> methods
072: for (MethodDeclaration methodDecl : _propertySet.getMethods())
073: if (!methodDecl.toString().equals("<clinit>()"))
074: properties.add(new AptProperty(this ,
075: (AnnotationTypeElementDeclaration) methodDecl,
076: _ap));
077:
078: return properties;
079: }
080:
081: /**
082: * Returns the list of ControlProperties associated with this ControlPropertySet
083: */
084: public Collection<AptProperty> getProperties() {
085: return _properties;
086: }
087:
088: /**
089: * Returns the fully qualified package name of this property set
090: */
091: public String getPackage() {
092: if (_propertySet == null || _propertySet.getPackage() == null)
093: return "";
094:
095: return _propertySet.getPackage().getQualifiedName();
096: }
097:
098: /**
099: * Returns the unqualified classname of this property set
100: */
101: public String getShortName() {
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 getClassName() {
112: if (_propertySet == null)
113: return "";
114:
115: return _propertySet.getQualifiedName();
116: }
117:
118: /**
119: * Returns the property name prefix for properties in this PropertySet
120: */
121: public String getPrefix() {
122: if (_propertySet == null
123: || _propertySet.getAnnotation(PropertySet.class) == null)
124: return "";
125:
126: return _propertySet.getAnnotation(PropertySet.class).prefix();
127: }
128:
129: /**
130: * Returns whether or not this propertyset exposes setters
131: */
132: public boolean isOptional() {
133: return _isOptional;
134: }
135:
136: /**
137: * Returns whether or not this propertyset exposes setters
138: */
139: public boolean hasSetters() {
140: return _hasSetters;
141: }
142:
143: private AnnotationTypeDeclaration _propertySet;
144: private AptControlInterface _controlIntf; // may be null if an external property set
145: private ArrayList<AptProperty> _properties;
146: private TwoPhaseAnnotationProcessor _ap;
147: private boolean _isOptional;
148: private boolean _hasSetters;
149: }
|