Coverage Report - org.trails.page.ModelPage
 
Classes in this File Line Coverage Branch Coverage Complexity
ModelPage
71% 
100% 
2
 
 1  
 package org.trails.page;
 2  
 
 3  
 import ognl.Ognl;
 4  
 import ognl.OgnlException;
 5  
 import org.trails.TrailsRuntimeException;
 6  
 import org.trails.descriptor.IClassDescriptor;
 7  
 import org.trails.exception.EmptyModelException;
 8  
 
 9  
 /**
 10  
  * A page which has a model object.
 11  
  *
 12  
  * @author Chris Nelson
 13  
  */
 14  61
 public abstract class ModelPage extends TrailsPage
 15  
 {
 16  
 
 17  
         public abstract Object getModel();
 18  
 
 19  
         public abstract void setModel(Object model);
 20  
 
 21  
         protected boolean isModelNew(Object model)
 22  
         {
 23  
                 try
 24  
                 {
 25  23
                         return Ognl.getValue(getClassDescriptor().getIdentifierDescriptor().getName(), model) == null;
 26  0
                 } catch (OgnlException e)
 27  
                 {
 28  0
                         throw new TrailsRuntimeException(e);
 29  
                 }
 30  
         }
 31  
 
 32  
         public boolean isModelNew()
 33  
         {
 34  23
                 return isModelNew(getModel());
 35  
         }
 36  
 
 37  
         public IClassDescriptor getClassDescriptor()
 38  
         {
 39  30
                 if (getModel() == null) throw new EmptyModelException("Model does not exist");
 40  30
                 return getDescriptorService().getClassDescriptor(getModel().getClass());
 41  
         }
 42  
 
 43  
 }