001    /*
002     * Created on Jan 30, 2005
003     *
004     * Copyright 2004 Chris Nelson
005     * 
006     * Licensed under the Apache License, Version 2.0 (the "License"); 
007     * you may not use this file except in compliance with the License. 
008     * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
009     * Unless required by applicable law or agreed to in writing, 
010     * software 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 limitations under the License.
013     */
014    package org.trails.link;
015    
016    import org.apache.tapestry.IMarkupWriter;
017    import org.apache.tapestry.IRequestCycle;
018    import org.apache.tapestry.annotations.Component;
019    import org.apache.tapestry.annotations.ComponentClass;
020    import org.apache.tapestry.annotations.InjectObject;
021    import org.apache.tapestry.annotations.Parameter;
022    import org.trails.component.InsertI18N;
023    import org.trails.descriptor.DescriptorService;
024    import org.trails.descriptor.IClassDescriptor;
025    
026    /**
027     * Common functionality for ListAllLink, NewLink, SearchLink
028     */
029    @ComponentClass
030    public abstract class AbstractTypeNavigationLink extends TrailsLink
031    {
032            @InjectObject("spring:descriptorService")
033            public abstract DescriptorService getDescriptorService();
034    
035            /**
036             * @return Class object that this link targets.
037             */
038            @Parameter(required = true)
039            public abstract Class getType();
040    
041            /**
042             * @return the class descriptor for the class that this link targets
043             */
044            public IClassDescriptor getClassDescriptor()
045            {
046                    return getDescriptorService().getClassDescriptor(getType());
047            }
048    
049            @Parameter(required = true)
050            public abstract String getBundleKey();
051    
052            @Parameter(required = true)
053            public abstract String getDefaultMessage();
054    
055            @Parameter(required = true)
056            public abstract Object getParams();
057    
058            @Component(bindings = {"bundleKey=ognl:bundleKey", "defaultMessage=ognl:defaultMessage", "params=ognl:params"})
059            public abstract InsertI18N getInsertI18N();
060    
061            public void renderBody(IMarkupWriter writer, IRequestCycle cycle)
062            {
063                    if (getBodyCount() > 0)
064                    {
065                            super.renderBody(writer, cycle);
066                    } else
067                    {
068                            getInsertI18N().render(writer, cycle);
069                    }
070            }
071    }