001    // Copyright 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.annotations;
016    
017    import org.apache.hivemind.ApplicationRuntimeException;
018    import org.apache.hivemind.Location;
019    import org.apache.tapestry.IPage;
020    import org.apache.tapestry.TapestryUtils;
021    import org.apache.tapestry.enhance.EnhancementOperation;
022    import org.apache.tapestry.spec.IComponentSpecification;
023    
024    /**
025     * Sets properties of the {@link org.apache.tapestry.spec.IComponentSpecification} based on the
026     * {@link org.apache.tapestry.annotations.ComponentClass} annotation. In addition, marks the
027     * component as deprecated if the {@link java.lang.Deprecated} annotation is present on the class.
028     * 
029     * @author Howard Lewis Ship
030     * @since 4.0
031     */
032    public class ComponentClassAnnotationWorker implements ClassAnnotationEnhancementWorker
033    {
034    
035        public void performEnhancement(EnhancementOperation op, IComponentSpecification spec,
036                Class baseClass, Location location)
037        {
038            if (IPage.class.isAssignableFrom(baseClass))
039            {
040                throw new ApplicationRuntimeException(
041                        AnnotationMessages.invalidAnnotationInClass(ComponentClass.class, baseClass));            
042            }
043            ComponentClass component = (ComponentClass) baseClass.getAnnotation(ComponentClass.class);
044    
045            spec.setAllowBody(component.allowBody());
046            spec.setAllowInformalParameters(component.allowInformalParameters());
047            spec.setLocation(location);
048    
049            String[] names = TapestryUtils.split(component.reservedParameters());
050            for (String name : names)
051                spec.addReservedParameterName(name);
052    
053            if (baseClass.isAnnotationPresent(Deprecated.class))
054                spec.setDeprecated(true);
055        }
056    
057    }