Coverage Report - org.trails.component.ClassDescriptorComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
ClassDescriptorComponent
67% 
100% 
0
 
 1  
 package org.trails.component;
 2  
 
 3  
 import java.util.List;
 4  
 import java.util.Locale;
 5  
 
 6  
 import ognl.Ognl;
 7  
 import ognl.OgnlException;
 8  
 import org.apache.tapestry.BaseComponent;
 9  
 import org.apache.tapestry.annotations.InjectObject;
 10  
 import org.apache.tapestry.annotations.Parameter;
 11  
 import org.apache.tapestry.components.Block;
 12  
 import org.trails.TrailsRuntimeException;
 13  
 import org.trails.descriptor.IClassDescriptor;
 14  
 import org.trails.descriptor.IPropertyDescriptor;
 15  
 import org.trails.i18n.ResourceBundleMessageSource;
 16  
 
 17  
 public abstract class ClassDescriptorComponent extends BaseComponent
 18  
 {
 19  
 
 20  
         public ClassDescriptorComponent()
 21  
         {
 22  9
                 super();
 23  
                 // TODO Auto-generated constructor stub
 24  9
         }
 25  
 
 26  
         @Parameter(required = false, defaultValue = "page.classDescriptor", cache = true)
 27  
         public abstract IClassDescriptor getClassDescriptor();
 28  
 
 29  
         public abstract void setClassDescriptor(IClassDescriptor ClassDescriptor);
 30  
 
 31  
         @Parameter(required = false, defaultValue = "ognl:null", cache = true)
 32  
         public abstract String[] getPropertyNames();
 33  
 
 34  
         public abstract void setPropertyNames(String[] PropertyNames);
 35  
 
 36  
         /**
 37  
          * @return
 38  
          * @throws OgnlException
 39  
          */
 40  
         public List<IPropertyDescriptor> getPropertyDescriptors()
 41  
         {
 42  11
                 if (getPropertyNames() == null || getPropertyNames().length == 0)
 43  
                 {
 44  
                         try
 45  
                         {
 46  8
                                 return (List) Ognl.getValue("#this.{? not(hidden)}", getClassDescriptor().getPropertyDescriptors());
 47  
                         }
 48  0
                         catch (OgnlException oe)
 49  
                         {
 50  0
                                 throw new TrailsRuntimeException(oe, getClassDescriptor().getType());
 51  
                         }
 52  
                 } else
 53  
                 {
 54  3
                         return getClassDescriptor().getPropertyDescriptors(getPropertyNames());
 55  
                 }
 56  
         }
 57  
 
 58  
         /**
 59  
          * Return the Spring ResourceBundleMessageSource. This is used to implement
 60  
          * i18n in all Trails components, accessing a i18n properties file in the
 61  
          * application instead of accessing the property file located in org.trais.component package.
 62  
          * By doing this, someone who would need i18n wouldn't need to change the property
 63  
          * located in the org.trails.component package and rebuild the trails.jar
 64  
          *
 65  
          * @return
 66  
          */
 67  
         @InjectObject("spring:trailsMessageSource")
 68  
         public abstract ResourceBundleMessageSource getResourceBundleMessageSource();
 69  
 
 70  
         public String getMessage(String key)
 71  
         {
 72  0
                 Locale locale = getContainer().getPage().getEngine().getLocale();
 73  0
                 return getResourceBundleMessageSource().getMessageWithDefaultValue(key, locale, "[TRAILS][" + key.toUpperCase() + "]");
 74  
         }
 75  
 
 76  
         public boolean hasBlock(String propertyName)
 77  
         {
 78  2
                 if (getPage().getComponents().containsKey(propertyName))
 79  
                 {
 80  1
                         return true;
 81  
                 }
 82  1
                 return false;
 83  
         }
 84  
 
 85  
         public Block getBlock(String propertyName)
 86  
         {
 87  1
                 if (getPage().getComponents().containsKey(propertyName))
 88  
                 {
 89  1
                         return (Block) getPage().getComponent(propertyName);
 90  
                 }
 91  0
                 return null;
 92  
         }
 93  
 }