Coverage Report - org.trails.component.AbstractTypeNavigationLink
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractTypeNavigationLink
62% 
33% 
0
 
 1  
 /*
 2  
  * Created on Jan 30, 2005
 3  
  *
 4  
  * Copyright 2004 Chris Nelson
 5  
  * 
 6  
  * Licensed under the Apache License, Version 2.0 (the "License"); 
 7  
  * you may not use this file except in compliance with the License. 
 8  
  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
 9  
  * Unless required by applicable law or agreed to in writing, 
 10  
  * software distributed under the License is distributed on an "AS IS" BASIS, 
 11  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 12  
  * See the License for the specific language governing permissions and limitations under the License.
 13  
  */
 14  
 package org.trails.component;
 15  
 
 16  
 import java.util.Locale;
 17  
 
 18  
 import org.apache.tapestry.IComponent;
 19  
 import org.apache.tapestry.IEngine;
 20  
 import org.apache.tapestry.IPage;
 21  
 import org.apache.tapestry.annotations.InjectObject;
 22  
 import org.apache.tapestry.annotations.Parameter;
 23  
 import org.trails.descriptor.DescriptorService;
 24  
 import org.trails.descriptor.IClassDescriptor;
 25  
 import org.trails.i18n.ResourceBundleMessageSource;
 26  
 
 27  
 /**
 28  
  * Common functionality for ListAllLink, NewLink, SearchLink
 29  
  *
 30  
  * @author fus8882
 31  
  */
 32  7
 public abstract class AbstractTypeNavigationLink extends Link
 33  
 {
 34  
         @InjectObject("spring:descriptorService")
 35  
         public abstract DescriptorService getDescriptorService();
 36  
 
 37  
         /**
 38  
          * @return Class object that this link targets.
 39  
          */
 40  
         @Parameter(required = true)
 41  
         public abstract Class getType();
 42  
 
 43  
         public abstract void setType(Class type);
 44  
 
 45  
         /**
 46  
          * @return the class descriptor for the class that this link targets
 47  
          */
 48  
         public IClassDescriptor getClassDescriptor()
 49  
         {
 50  2
                 return getDescriptorService().getClassDescriptor(getType());
 51  
         }
 52  
 
 53  
         protected String generateLinkText(String displayName, String bundleKey, String defaultMessage)
 54  
         {
 55  2
                 Locale locale = null;
 56  2
                 IComponent container = getContainer();
 57  
 
 58  
                 // attempt to find the locale or accept null
 59  2
                 if (container != null)
 60  
                 {
 61  0
                         IPage page = container.getPage();
 62  0
                         if (page != null)
 63  
                         {
 64  0
                                 IEngine engine = page.getEngine();
 65  0
                                 if (engine != null)
 66  
                                 {
 67  0
                                         locale = engine.getLocale();
 68  
                                 }
 69  
                         }
 70  
                 }
 71  
 
 72  2
                 Object[] params = new Object[]{displayName};
 73  2
                 ResourceBundleMessageSource messageSource = getResourceBundleMessageSource();
 74  2
                 return messageSource.getMessageWithDefaultValue(bundleKey, params, locale, defaultMessage);
 75  
         }
 76  
 }