Coverage Report - de.smartics.properties.api.core.domain.PropertyDescriptorException
 
Classes in this File Line Coverage Branch Coverage Complexity
PropertyDescriptorException
0%
0/22
0%
0/8
1,667
 
 1  
 /*
 2  
  * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
 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
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package de.smartics.properties.api.core.domain;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 
 20  
 
 21  
 
 22  
 /**
 23  
  * Base exception of the library for signaling an unspecific cause that is
 24  
  * concerned with a specific property providing the {@link PropertyDescriptor
 25  
  * property declaration} information.
 26  
  */
 27  
 public class PropertyDescriptorException extends PropertyException
 28  
 {
 29  
   // ********************************* Fields *********************************
 30  
 
 31  
   // --- constants ------------------------------------------------------------
 32  
 
 33  
   /**
 34  
    * The class version identifier.
 35  
    * <p>
 36  
    * The value of this constant is {@value}.
 37  
    * </p>
 38  
    */
 39  
   private static final long serialVersionUID = 1L;
 40  
 
 41  
   // --- members --------------------------------------------------------------
 42  
 
 43  
   /**
 44  
    * The descriptor of the property raising the exception.
 45  
    *
 46  
    * @serial
 47  
    */
 48  
   private final PropertyDescriptor propertyDescriptor;
 49  
 
 50  
   // ****************************** Initializer *******************************
 51  
 
 52  
   // ****************************** Constructors ******************************
 53  
 
 54  
   /**
 55  
    * Constructor.
 56  
    *
 57  
    * @param message the detail message (which is saved for later retrieval by
 58  
    *          the {@link #getMessage()} method).
 59  
    * @param cause the cause (which is saved for later retrieval by the
 60  
    *          {@link #getCause()} method). (A <tt>null</tt> value is permitted,
 61  
    *          and indicates that the cause is nonexistent or unknown.)
 62  
    * @param propertyDescriptor the descriptor of the property raising the
 63  
    *          exception.
 64  
    */
 65  
   public PropertyDescriptorException(final String message,
 66  
       final Throwable cause, final PropertyDescriptor propertyDescriptor)
 67  
   {
 68  0
     super(message, cause, propertyDescriptor.getKey());
 69  0
     this.propertyDescriptor = propertyDescriptor;
 70  0
   }
 71  
 
 72  
   /**
 73  
    * Constructor.
 74  
    *
 75  
    * @param message the detail message (which is saved for later retrieval by
 76  
    *          the {@link #getMessage()} method).
 77  
    * @param propertyDescriptor the descriptor of the property raising the
 78  
    *          exception.
 79  
    */
 80  
   public PropertyDescriptorException(final String message,
 81  
       final PropertyDescriptor propertyDescriptor)
 82  
   {
 83  0
     this(message, null, propertyDescriptor);
 84  0
   }
 85  
 
 86  
   /**
 87  
    * Constructor.
 88  
    *
 89  
    * @param cause the cause (which is saved for later retrieval by the
 90  
    *          {@link #getCause()} method). (A <tt>null</tt> value is permitted,
 91  
    *          and indicates that the cause is nonexistent or unknown.)
 92  
    * @param propertyDescriptor the descriptor of the property raising the
 93  
    *          exception.
 94  
    */
 95  
   public PropertyDescriptorException(final Throwable cause,
 96  
       final PropertyDescriptor propertyDescriptor)
 97  
   {
 98  0
     this(null, cause, propertyDescriptor);
 99  0
   }
 100  
 
 101  
   // ****************************** Inner Classes *****************************
 102  
 
 103  
   // ********************************* Methods ********************************
 104  
 
 105  
   // --- init -----------------------------------------------------------------
 106  
 
 107  
   // --- get&set --------------------------------------------------------------
 108  
 
 109  
   /**
 110  
    * Returns the descriptor of the property raising the exception.
 111  
    *
 112  
    * @return the descriptor of the property raising the exception.
 113  
    */
 114  
   public final PropertyDescriptor getPropertyDescriptor()
 115  
   {
 116  0
     return propertyDescriptor;
 117  
   }
 118  
 
 119  
   // --- business -------------------------------------------------------------
 120  
 
 121  
   /**
 122  
    * Returns information on meta data of the property.
 123  
    *
 124  
    * @param descriptor the descriptor to use. This method is static to allow it
 125  
    *          to be called from subclasses in their constructor.
 126  
    * @return information on meta data of the property.
 127  
    */
 128  
   protected static final String getMetaDataMessage(
 129  
       final PropertyDescriptor descriptor)
 130  
   {
 131  0
     final StringBuilder buffer = new StringBuilder(128);
 132  0
     appendMetaDataMessage(buffer, descriptor);
 133  0
     return buffer.toString();
 134  
   }
 135  
 
 136  
   /**
 137  
    * Returns information on meta data of the property.
 138  
    *
 139  
    * @param buffer the buffer to append to.
 140  
    * @param descriptor the descriptor to use. This method is static to allow it
 141  
    *          to be called from subclasses in their constructor.
 142  
    */
 143  
   protected static final void appendMetaDataMessage(final StringBuilder buffer,
 144  
       final PropertyDescriptor descriptor)
 145  
   {
 146  0
     final PropertyComment comment = descriptor.getComment();
 147  
 
 148  0
     final String url = descriptor.getContext().getPropertyReportUrl();
 149  
 
 150  0
     if (StringUtils.isNotBlank(comment.getText()))
 151  
     {
 152  0
       if (buffer.length() > 0)
 153  
       {
 154  0
         buffer.append('\n'); // TODO should be indent. Pretty formatting
 155  
                              // needed here.
 156  
       }
 157  
 
 158  0
       buffer.append("    Documentation: ").append(comment);
 159  
     }
 160  
 
 161  0
     if (StringUtils.isNotBlank(url))
 162  
     {
 163  0
       if (buffer.length() > 0)
 164  
       {
 165  0
         buffer.append('\n');
 166  
       }
 167  
 
 168  0
       buffer.append("    For further details, please refer to: ").append(url);
 169  
     }
 170  0
   }
 171  
 
 172  
   // --- object basics --------------------------------------------------------
 173  
 
 174  
 }