Coverage Report - pt.digitalis.dif.utils.logging.DEMEntityLogAspect
 
Classes in this File Line Coverage Branch Coverage Complexity
DEMEntityLogAspect
0%
0/79
0%
0/22
0
 
 1  0
 package pt.digitalis.dif.utils.logging;
 2  
 
 3  
 import java.util.List;
 4  
 
 5  
 import pt.digitalis.dif.codegen.util.DEMLoaderEntityRegistry;
 6  
 import pt.digitalis.dif.codegen.util.DEMLoaderHelper;
 7  
 import pt.digitalis.log.LogLevel;
 8  
 import pt.digitalis.utils.bytecode.holders.ClassHolder;
 9  
 
 10  
 /**
 11  
  * Contains the logging logic to be applied on the DEM building procedure.
 12  
  *
 13  
  * @author Pedro Viegas <a href="mailto:pviegas@digitalis.pt">pviegas@digitalis.pt</a>
 14  
  * @author Rodrigo Gonçalves <a href="mailto:rgoncalves@digitalis.pt">rgoncalves@digitalis.pt</a>
 15  
  * @created 2007/08/21
 16  
  */
 17  0
 final public aspect DEMEntityLogAspect extends DIFLogAspect {
 18  
 
 19  
     /** Class counter */
 20  0
     private long classCount = 0;
 21  
 
 22  
     /** First time the DEMAnnotatyions search is ran? */
 23  0
     private boolean firstDEMAnnotationsSearch = true;
 24  
 
 25  
     /** Keeps the class enhancing start timestamp */
 26  
     private long classEnhanceStartTime;
 27  
 
 28  
     /**
 29  
      * Captures the construction of each new DEM Entity class class while performing the search for entities on a given
 30  
      * package. Exposes the javassist CtClass object used on the construction.
 31  
      *
 32  
      * @param className
 33  
      *            the class name
 34  
      */
 35  0
     private pointcut buildClassHolder(String className) : withincode (* pt.digitalis.dif.codegen.util.DEMLoaderHelper.getDEMEntityClassesInPackage(..)) && call (pt.digitalis.utils.bytecode.holders.ClassHolder.new(String)) && args (className) && excludeLoggingAppliances();
 36  
 
 37  
     /**
 38  
      * Captures the search for existing DEM Entity classes, exposing the name of the package from where the classes are
 39  
      * read.
 40  
      *
 41  
      * @param packageName
 42  
      *            the name of the package
 43  
      */
 44  0
     private pointcut searchForDEMEntities(String packageName) : execution (* pt.digitalis.dif.codegen.util.DEMLoaderHelper.getDEMEntityClassesInPackage(String)) && args (packageName) && excludeLoggingAppliances();
 45  
 
 46  
     /** Captures the existing package classes. */
 47  0
     private pointcut existingDEMAnnotations() : execution (* pt.digitalis.dif.codegen.util.DEMLoaderHelper.getDEMEntitiesAnnontations()) && excludeLoggingAppliances();
 48  
 
 49  
     /** Captures the DEMLoaderHelper clean up point. */
 50  0
     private pointcut theDEMLoaderHelperCleanUpPoint() : execution (* pt.digitalis.dif.codegen.util.DEMLoaderHelper.cleanUp()) && excludeLoggingAppliances();
 51  
 
 52  
     /** Captures the DEM Entity classes fetching for a package. */
 53  0
     private pointcut DEMEntityClassesLoading() : execution (* pt.digitalis.dif.codegen.util.DEMLoaderHelper.getDEMEntityClassesInPackage(String)) && excludeLoggingAppliances();
 54  
 
 55  
     /** Captures the DEM Entity classes identifying process. */
 56  0
     private pointcut DEMEntitiesEnhanceStart() : execution (* pt.digitalis.dif.codegen.DIFCodeGenerator+.enhanceDEMClasses(..)) && excludeLoggingAppliances();
 57  
 
 58  
     /** Captures the DEM Entity classes enhancing process end. */
 59  0
     private pointcut DEMEntitiesEnhanceEnd() : execution (* pt.digitalis.dif.codegen.DIFCodeGenerator.cleanUp()) && excludeLoggingAppliances();
 60  
 
 61  
     /** Captures the registry of an app suite. */
 62  0
     private pointcut appSuiteRegistry() : execution (* pt.digitalis.dif.dem.config.IDEMRegistrator+.registerAppSuiteBasePackage(String)) && excludeLoggingAppliances();
 63  
 
 64  
     /** Captures the registry of a single meta-model package. */
 65  0
     private pointcut singleMetaModelPackageRegistry() : execution (* pt.digitalis.dif.dem.config.IDEMRegistrator+.registerMetaModelPackage(String)) && excludeLoggingAppliances();
 66  
 
 67  
     /**
 68  
      * Logs the number of analysed classes after searching a given package for DEM Entities.
 69  
      *
 70  
      * @param packageName
 71  
      *            the name of the package
 72  
      */
 73  
     after(String packageName) : searchForDEMEntities (packageName)
 74  
     {
 75  0
         getLogger().info("Package \"" + packageName + "\": Analysed " + classCount + " classes.");
 76  
 
 77  
         // Reset class counter
 78  0
         classCount = 0;
 79  0
     }
 80  
 
 81  
     /**
 82  
      * Traces the each read class
 83  
      *
 84  
      * @param className
 85  
      *            the class name
 86  
      */
 87  
     after(String className) : buildClassHolder (className)
 88  
     {
 89  0
         getLogger().trace("Analyzing class: " + className + "...");
 90  
 
 91  0
         classCount++;
 92  0
     }
 93  
 
 94  
     /**
 95  
      * Logs the existing DEM annotations.
 96  
      *
 97  
      * @param existingDEMAnnotations
 98  
      *            the exposed method return
 99  
      */
 100  
     after() returning (List<String> existingDEMAnnotations) : existingDEMAnnotations ()
 101  
     {
 102  0
         if (firstDEMAnnotationsSearch) {
 103  
 
 104  0
             firstDEMAnnotationsSearch = false;
 105  
 
 106  
             // Get defined log level
 107  0
             LogLevel logLevel = LogLevel.DEBUG;
 108  
 
 109  
             // DIFInitializer message to log...
 110  0
             String messageToLog = null;
 111  
 
 112  
             // If DEM Annotations could be read
 113  0
             if (existingDEMAnnotations.size() != 0 && existingDEMAnnotations != null) {
 114  
 
 115  
                 // Using StringBuffer to prevent multiple String copies while
 116  
                 // appending annotations names
 117  0
                 StringBuffer annotationsAsString = new StringBuffer(" ");
 118  0
                 annotationsAsString.append("\n   \\");
 119  
 
 120  
                 // Compose message
 121  0
                 for (String annotation : existingDEMAnnotations) {
 122  0
                     annotationsAsString.append("\n   | " + annotation);
 123  
                 }
 124  
 
 125  0
                 messageToLog = "Found the following DEM Entity annotations: " + annotationsAsString.toString() + "\n";
 126  
 
 127  
             } else {
 128  0
                 logLevel = LogLevel.WARN;
 129  0
                 messageToLog = "No DEM Entity annotations found!!";
 130  
             }
 131  
 
 132  
             // Log message
 133  0
             this.log(logLevel, messageToLog);
 134  
         }
 135  0
     }
 136  
 
 137  
     /** Logs the DEMLoaderHelper clean up. */
 138  
     after() : theDEMLoaderHelperCleanUpPoint()
 139  
     {
 140  0
         getLogger().debug("Cleaned DEMLoaderHelper resources...");
 141  0
     }
 142  
 
 143  
     /**
 144  
      * Logs DEM Entities that were identified
 145  
      */
 146  
     before() : DEMEntitiesEnhanceStart()
 147  
     {
 148  0
         classEnhanceStartTime = System.currentTimeMillis();
 149  
 
 150  0
         getLogger().info(
 151  0
                 "Loading DEM Entities from " + DEMLoaderHelper.getPackageList().size() + " registered packages...");
 152  0
     }
 153  
 
 154  
     /**
 155  
      * Logs DEM Entities that were identified
 156  
      */
 157  
     before() : DEMEntitiesEnhanceEnd()
 158  
     {
 159  0
         getLogger().info(
 160  0
                 "Loaded " + DEMLoaderEntityRegistry.getEntityCount() + " Entities in "
 161  0
                         + (System.currentTimeMillis() - classEnhanceStartTime) + " ms.");
 162  0
     }
 163  
 
 164  
     /**
 165  
      * Logs DEM Entity class information.
 166  
      *
 167  
      * @param packageName
 168  
      *            the name of the package
 169  
      * @param demClassNames
 170  
      *            the exposed method's return
 171  
      */
 172  
     after(String packageName) returning (List<ClassHolder> demClassNames) : DEMEntityClassesLoading() && args (packageName)
 173  
     {
 174  
         // Get defined log level
 175  0
         LogLevel logLevel = LogLevel.INFO;
 176  
 
 177  
         // DIFInitializer message to log...
 178  0
         StringBuffer messageToLog = new StringBuffer();
 179  
 
 180  
         // If classes were found...
 181  0
         if (demClassNames.size() > 0) {
 182  
 
 183  0
             if (super.getLogger().isDebugEnabled() || super.getLogger().isTraceEnabled()) {
 184  0
                 logLevel = LogLevel.DEBUG;
 185  0
                 messageToLog.append("Package \"" + packageName + "\": Found the following DEM Entity classes");
 186  0
                 messageToLog.append("\n   \\");
 187  
 
 188  0
                 for (ClassHolder clazz : demClassNames) {
 189  0
                     messageToLog.append("\n   | " + clazz.getFQName());
 190  
                 }
 191  
 
 192  0
                 messageToLog.append("\n");
 193  
             } else {
 194  0
                 logLevel = LogLevel.INFO;
 195  0
                 messageToLog.append("Package \"" + packageName + "\": Found " + demClassNames.size()
 196  0
                         + " DEM Entity classes");
 197  
             }
 198  
 
 199  
             // Log message...
 200  0
             this.log(logLevel, messageToLog.toString());
 201  
         }
 202  
         // ...if the package doesn't contain any DEM Entity
 203  
         else {
 204  
             // Change log level to WARN!!
 205  0
             logLevel = LogLevel.WARN;
 206  
             // Compose error message...
 207  0
             messageToLog.append("Package \"" + packageName + "\": Didn't find any DEM Entity classes in package!");
 208  
             // Log message...
 209  0
             this.log(logLevel, messageToLog.toString());
 210  
         }
 211  
 
 212  0
     }
 213  
 
 214  
     /**
 215  
      * Log information regarding the registry of an app suite.
 216  
      *
 217  
      * @param topLevelPackage
 218  
      *            the top-level package for the app suite
 219  
      * @param success
 220  
      *            the exposed method result
 221  
      */
 222  
     after(String topLevelPackage) returning (boolean success) : appSuiteRegistry() && args(topLevelPackage)
 223  
     {
 224  
         // DIFInitializer message to log
 225  0
         String messageToLog = null;
 226  
         // Default log level...
 227  0
         LogLevel level = LogLevel.DEBUG;
 228  
 
 229  0
         if (success) {
 230  
             // Compose message
 231  0
             messageToLog = "Successfully registered the app suite on: " + topLevelPackage + ".";
 232  
 
 233  
         } else {
 234  
             // Log message as a warn...
 235  0
             level = LogLevel.WARN;
 236  
             // Compose error message
 237  0
             messageToLog = "Could not register app suite on: " + topLevelPackage + "!";
 238  
         }
 239  
 
 240  
         // Log message...
 241  0
         this.log(level, messageToLog);
 242  
 
 243  0
     }
 244  
 
 245  
     /**
 246  
      * Log information regarding the registry of as single meta model package.
 247  
      *
 248  
      * @param packageName
 249  
      *            the package name
 250  
      * @param success
 251  
      *            the exposed method result
 252  
      */
 253  
     after(String packageName) returning (boolean success) : singleMetaModelPackageRegistry() && args(packageName)
 254  
     {
 255  
         // DIFInitializer message to log
 256  0
         String messageToLog = null;
 257  
         // Default log level...
 258  0
         LogLevel level = LogLevel.DEBUG;
 259  
 
 260  0
         if (success) {
 261  
             // Compose message
 262  0
             messageToLog = "Package \"" + packageName + "\": Successfully registered as a meta model package.";
 263  
 
 264  
         } else {
 265  
             // Log message as a warn...
 266  0
             level = LogLevel.WARN;
 267  
             // Compose error message
 268  0
             messageToLog = "Package \"" + packageName + "\": Could not register as a meta model package!";
 269  
         }
 270  
 
 271  
         // Log message...
 272  0
         this.log(level, messageToLog);
 273  
 
 274  0
     }
 275  
 
 276  
     /**
 277  
      * Helper method that logs a given message with a given level.
 278  
      *
 279  
      * @param level
 280  
      *            the log level
 281  
      * @param message
 282  
      *            the message to log
 283  
      */
 284  
     private void log(LogLevel level, String message) {
 285  0
         super.getLogger().log(level, message);
 286  0
     }
 287  
 }