Coverage Report - org.trails.descriptor.TrailsPropertyDescriptor
 
Classes in this File Line Coverage Branch Coverage Complexity
TrailsPropertyDescriptor
67% 
90% 
0
 
 1  
 /*
 2  
  * Copyright 2004 Chris Nelson
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 7  
  * Unless required by applicable law or agreed to in writing,
 8  
  * software distributed under the License is distributed on an "AS IS" BASIS,
 9  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 10  
  * See the License for the specific language governing permissions and limitations under the License.
 11  
  */
 12  
 package org.trails.descriptor;
 13  
 
 14  
 import java.lang.reflect.InvocationTargetException;
 15  
 
 16  
 import org.apache.commons.beanutils.BeanUtils;
 17  
 import org.apache.commons.lang.builder.EqualsBuilder;
 18  
 
 19  
 /**
 20  
  * @author fus8882
 21  
  *         <p/>
 22  
  *         TODO To change the template for this generated type comment go to Window -
 23  
  *         Preferences - Java - Code Style - Code Templates
 24  
  */
 25  
 public class TrailsPropertyDescriptor extends TrailsDescriptor implements
 26  
         IPropertyDescriptor
 27  
 {
 28  
         private Class beanType;
 29  
 
 30  
         private String name;
 31  
 
 32  1516
         private boolean searchable = true;
 33  
 
 34  
         private boolean required;
 35  
 
 36  
         private boolean readOnly;
 37  
 
 38  1516
         private int index = UNDEFINED_INDEX;
 39  
 
 40  1516
         private int length = DEFAULT_LENGTH;
 41  
 
 42  
         private boolean large;
 43  
 
 44  
         private String format;
 45  
 
 46  1516
         private boolean summary = true;
 47  
 
 48  
         private boolean richText;
 49  
 
 50  
         // ///////////////////////////////////////////////////////////////////////////////////////////////////////
 51  
         // constructors
 52  
         // ///////////////////////////////////////////////////////////////////////////////////////////////////////
 53  
         /**
 54  
          * It's kinda like an old-skool C++ copy constructor
 55  
          */
 56  
         public TrailsPropertyDescriptor(Class beanType,
 57  
                                                                         IPropertyDescriptor descriptor)
 58  
         {
 59  0
                 this(beanType, descriptor.getPropertyType());
 60  
 
 61  
                 try
 62  
                 {
 63  0
                         BeanUtils.copyProperties(this,
 64  0
                                 (TrailsPropertyDescriptor) descriptor);
 65  0
                 } catch (IllegalAccessException e)
 66  
                 {
 67  0
                         LOG.error(e.getMessage());
 68  0
                         e.printStackTrace();
 69  0
                 } catch (InvocationTargetException e)
 70  
                 {
 71  0
                         LOG.error(e.getMessage());
 72  0
                         e.printStackTrace();
 73  0
                 } catch (Exception e)
 74  
                 {
 75  0
                         LOG.error(e.toString());
 76  0
                         e.printStackTrace();
 77  
                 }
 78  0
         }
 79  
 
 80  
         public TrailsPropertyDescriptor(Class beanType, Class type)
 81  
         {
 82  1416
                 super(type);
 83  1416
                 this.beanType = beanType;
 84  1416
         }
 85  
 
 86  
         public TrailsPropertyDescriptor(Class beanType, String name, Class type)
 87  
         {
 88  308
                 this(beanType, type);
 89  308
                 this.setName(name);
 90  308
                 setDisplayName(name);
 91  308
         }
 92  
 
 93  
         /**
 94  
          * @param dto
 95  
          */
 96  
         public TrailsPropertyDescriptor(TrailsPropertyDescriptor dto)
 97  
         {
 98  100
                 super(dto);
 99  
 
 100  
                 try
 101  
                 {
 102  100
                         BeanUtils.copyProperties(this, dto);
 103  0
                 } catch (IllegalAccessException e)
 104  
                 {
 105  0
                         LOG.error(e.getMessage());
 106  0
                         e.printStackTrace();
 107  0
                 } catch (InvocationTargetException e)
 108  
                 {
 109  0
                         LOG.error(e.getMessage());
 110  0
                         e.printStackTrace();
 111  0
                 } catch (Exception e)
 112  
                 {
 113  0
                         LOG.error(e.toString());
 114  0
                         e.printStackTrace();
 115  
                 }
 116  100
         }
 117  
 
 118  
         // ///////////////////////////////////////////////////////////////////////////////////////////////////////
 119  
         // methods
 120  
         // ///////////////////////////////////////////////////////////////////////////////////////////////////////
 121  
 
 122  
         /**
 123  
          * @return
 124  
          */
 125  
         public Class getPropertyType()
 126  
         {
 127  292
                 return getType();
 128  
         }
 129  
 
 130  
         /**
 131  
          * @return
 132  
          */
 133  
         public boolean isNumeric()
 134  
         {
 135  56
                 return getPropertyType().getName().endsWith("Double")
 136  24
                         || getPropertyType().getName().endsWith("Integer")
 137  24
                         || getPropertyType().getName().endsWith("Float")
 138  24
                         || getPropertyType().getName().endsWith("double")
 139  24
                         || getPropertyType().getName().endsWith("int")
 140  24
                         || getPropertyType().getName().endsWith("float")
 141  24
                         || getPropertyType().getName().endsWith("BigDecimal");
 142  
         }
 143  
 
 144  
         public boolean isBoolean()
 145  
         {
 146  8
                 return getPropertyType().getName().endsWith("boolean")
 147  0
                         || getPropertyType().getName().endsWith("Boolean");
 148  
         }
 149  
 
 150  
         /**
 151  
          * @return
 152  
          */
 153  
         public boolean isDate()
 154  
         {
 155  
                 // TODO Auto-generated method stub
 156  20
                 return getPropertyType().getName().endsWith("Date");
 157  
         }
 158  
 
 159  
         /**
 160  
          * @return
 161  
          */
 162  
         public boolean isString()
 163  
         {
 164  
                 // TODO Auto-generated method stub
 165  16
                 return getPropertyType().getName().endsWith("String");
 166  
         }
 167  
 
 168  
         public boolean isObjectReference()
 169  
         {
 170  0
                 return false;
 171  
         }
 172  
 
 173  
         // ///////////////////////////////////////////////////////////////////////////////////////////////////////
 174  
         // bean setters / getters
 175  
         // ///////////////////////////////////////////////////////////////////////////////////////////////////////
 176  
 
 177  
         public int getIndex()
 178  
         {
 179  328
                 return index;
 180  
         }
 181  
 
 182  
         public void setIndex(int index)
 183  
         {
 184  296
                 this.index = index;
 185  296
         }
 186  
 
 187  
         /**
 188  
          * @return Returns the required.
 189  
          */
 190  
         public boolean isRequired()
 191  
         {
 192  288
                 return required;
 193  
         }
 194  
 
 195  
         /**
 196  
          * @param required The required to set.
 197  
          */
 198  
         public void setRequired(boolean required)
 199  
         {
 200  280
                 this.required = required;
 201  280
         }
 202  
 
 203  
         /**
 204  
          * @return
 205  
          */
 206  
         public boolean isReadOnly()
 207  
         {
 208  280
                 return readOnly;
 209  
         }
 210  
 
 211  
         /**
 212  
          * @param readOnly The readOnly to set.
 213  
          */
 214  
         public void setReadOnly(boolean readOnly)
 215  
         {
 216  308
                 this.readOnly = readOnly;
 217  308
         }
 218  
 
 219  
         /**
 220  
          * @return Returns the identifier.
 221  
          */
 222  
         public boolean isIdentifier()
 223  
         {
 224  216
                 return false;
 225  
         }
 226  
 
 227  
         /**
 228  
          * @return Returns the collection.
 229  
          */
 230  
         public boolean isCollection()
 231  
         {
 232  480
                 return false;
 233  
         }
 234  
 
 235  
         @Override
 236  
         public Object clone()
 237  
         {
 238  100
                 return new TrailsPropertyDescriptor(this);
 239  
         }
 240  
 
 241  
         @Override
 242  
         public void copyFrom(IDescriptor descriptor)
 243  
         {
 244  36
                 super.copyFrom(descriptor);
 245  
 
 246  36
                 if (descriptor instanceof TrailsPropertyDescriptor)
 247  
                 {
 248  
                         try
 249  
                         {
 250  72
                                 BeanUtils.copyProperties(this,
 251  36
                                         (TrailsPropertyDescriptor) descriptor);
 252  0
                         } catch (IllegalAccessException e)
 253  
                         {
 254  0
                                 LOG.error(e.getMessage());
 255  0
                                 e.printStackTrace();
 256  0
                         } catch (InvocationTargetException e)
 257  
                         {
 258  0
                                 LOG.error(e.getMessage());
 259  0
                                 e.printStackTrace();
 260  0
                         } catch (Exception e)
 261  
                         {
 262  0
                                 LOG.error(e.toString());
 263  0
                                 e.printStackTrace();
 264  
                         }
 265  
                 }
 266  36
         }
 267  
 
 268  
         public boolean equals(Object obj)
 269  
         {
 270  84
                 return EqualsBuilder.reflectionEquals(this, obj);
 271  
         }
 272  
 
 273  
         public int getLength()
 274  
         {
 275  280
                 return length;
 276  
         }
 277  
 
 278  
         public void setLength(int length)
 279  
         {
 280  280
                 this.length = length;
 281  280
         }
 282  
 
 283  
         public boolean isLarge()
 284  
         {
 285  280
                 return large;
 286  
         }
 287  
 
 288  
         public void setLarge(boolean large)
 289  
         {
 290  276
                 this.large = large;
 291  276
         }
 292  
 
 293  
         public String getFormat()
 294  
         {
 295  316
                 return format;
 296  
         }
 297  
 
 298  
         public void setFormat(String format)
 299  
         {
 300  288
                 this.format = format;
 301  288
         }
 302  
 
 303  
         public boolean isSearchable()
 304  
         {
 305  292
                 return searchable;
 306  
         }
 307  
 
 308  
         public void setSearchable(boolean searchable)
 309  
         {
 310  440
                 this.searchable = searchable;
 311  440
         }
 312  
 
 313  
         public boolean isSummary()
 314  
         {
 315  424
                 return summary;
 316  
         }
 317  
 
 318  
         public void setSummary(boolean summary)
 319  
         {
 320  320
                 this.summary = summary;
 321  320
         }
 322  
 
 323  
         public boolean isRichText()
 324  
         {
 325  280
                 return richText;
 326  
         }
 327  
 
 328  
         public void setRichText(boolean richText)
 329  
         {
 330  304
                 this.richText = richText;
 331  304
         }
 332  
 
 333  
         public boolean isEmbedded()
 334  
         {
 335  28
                 return false;
 336  
         }
 337  
 
 338  
         public Class getBeanType()
 339  
         {
 340  416
                 return beanType;
 341  
         }
 342  
 
 343  
         public void setBeanType(Class beanType)
 344  
         {
 345  276
                 this.beanType = beanType;
 346  276
         }
 347  
 
 348  
         public String getName()
 349  
         {
 350  1204
                 return name;
 351  
         }
 352  
 
 353  
         public void setName(String name)
 354  
         {
 355  1632
                 this.name = name;
 356  1632
         }
 357  
 }