Coverage Report - pt.digitalis.dif.dem.Entity
 
Classes in this File Line Coverage Branch Coverage Complexity
Entity
0%
0/26
0%
0/10
3
 
 1  0
 /**
 2  
  * - Digitalis Internal Framework v2.0 -
 3  
  *
 4  
  * (C) 2007, Digitalis Informatica.
 5  
  *
 6  
  * Distribuicao e Gestao de Informatica, Lda.
 7  
  * Estrada de Paco de Arcos num.9 - Piso -1
 8  
  * 2780-666 Paco de Arcos
 9  
  * Telefone: (351) 21 4408990
 10  
  * Fax: (351) 21 4408999
 11  
  * http://www.digitalis.pt
 12  
  */
 13  
 package pt.digitalis.dif.dem;
 14  
 
 15  
 import java.util.Map;
 16  
 
 17  
 import pt.digitalis.dif.dem.annotations.entities.ApplicationDefinition;
 18  
 import pt.digitalis.dif.dem.annotations.entities.ProviderDefinition;
 19  
 import pt.digitalis.dif.dem.annotations.entities.ServiceDefinition;
 20  
 import pt.digitalis.dif.dem.annotations.entities.StageDefinition;
 21  
 import pt.digitalis.dif.dem.annotations.entities.ValidatorDefinition;
 22  
 import pt.digitalis.utils.bytecode.holders.AnnotationHolder;
 23  
 import pt.digitalis.utils.bytecode.holders.ClassHolder;
 24  
 import pt.digitalis.utils.inspection.exception.ResourceNotFoundException;
 25  
 
 26  
 /**
 27  
  * Defines the known entity types to the framework.
 28  
  *
 29  
  * @author Rodrigo Gonçalves <a href="mailto:rgoncalves@digitalis.pt">rgoncalves@digitalis.pt</a>
 30  
  * @author Pedro Viegas <a href="mailto:pviegas@digitalis.pt">pviegas@digitalis.pt</a>
 31  
  * @created 2007/09/13
 32  
  *
 33  
  */
 34  0
 public enum Entity {
 35  
 
 36  
     /**
 37  
      * A <code>@ValidatorDefinition</code> annotated Entity.
 38  
      */
 39  0
     VALIDATOR(ValidatorDefinition.class),
 40  
 
 41  
     /**
 42  
      * A <code>@ProviderDefinition</code> annotated Entity.
 43  
      */
 44  0
     PROVIDER(ProviderDefinition.class),
 45  
 
 46  
     /**
 47  
      * A <code>@ApplicationDefinition</code> annotated Entity.
 48  
      */
 49  0
     APPLICATION(ApplicationDefinition.class),
 50  
 
 51  
     /**
 52  
      * A <code>@ServiceDefinition</code> annotated Entity.
 53  
      */
 54  0
     SERVICE(ServiceDefinition.class),
 55  
 
 56  
     /**
 57  
      * A <code>@StageDefinition</code> annotated Entity.
 58  
      */
 59  0
     STAGE(StageDefinition.class);
 60  
 
 61  
     /** The Entity's FQN. */
 62  
     private String fullyQualifiedName;
 63  
 
 64  
     /** The Entity's name. */
 65  
     private String name;
 66  
 
 67  
     /**
 68  
      * Constructor.
 69  
      *
 70  
      * @param clazz
 71  
      *            the Entity's class
 72  
      */
 73  0
     Entity(Class<?> clazz) {
 74  0
         this.name = clazz.getName();
 75  0
         this.fullyQualifiedName = clazz.getCanonicalName();
 76  0
     }
 77  
 
 78  
     /**
 79  
      * Returns the Entity's FQN.
 80  
      *
 81  
      * @return the Entity's FQN.
 82  
      */
 83  
     public String getFullyQualifiedName() {
 84  0
         return this.fullyQualifiedName;
 85  
     }
 86  
 
 87  
     /**
 88  
      * Returns the Entity's name.
 89  
      *
 90  
      * @return the Entity's name.
 91  
      */
 92  
     public String getName() {
 93  0
         return this.name;
 94  
     }
 95  
 
 96  
     /**
 97  
      * The ID builder utility method.
 98  
      *
 99  
      * @param type
 100  
      *            the type of the entity
 101  
      * @param id
 102  
      *            the id of the entity
 103  
      * @return the compiled unique id for the given entity
 104  
      */
 105  
     static public String getID(Entity type, String id) {
 106  0
         return (type + ":" + id.toLowerCase());
 107  
     }
 108  
 
 109  
     /**
 110  
      * Returns the Entity type of annotated class, null if no valid entity annotation is found.
 111  
      *
 112  
      * @param clazz
 113  
      *            the class to inspect
 114  
      * @return the entity type, null if no valid entity annotation is found.
 115  
      * @throws ResourceNotFoundException
 116  
      *             if the class annotations can't be read
 117  
      */
 118  
     static public Entity getEntityTypeFromClass(ClassHolder clazz) throws ResourceNotFoundException {
 119  
 
 120  
         // Read class annotation
 121  0
         Map<String, AnnotationHolder> orignalClassAnnotations = clazz.getAnnotations();
 122  
 
 123  
         // Return the appropriate entity type
 124  0
         if (orignalClassAnnotations.containsKey(ValidatorDefinition.class.getCanonicalName()))
 125  0
             return Entity.VALIDATOR;
 126  0
         else if (orignalClassAnnotations.containsKey(ProviderDefinition.class.getCanonicalName()))
 127  0
             return Entity.PROVIDER;
 128  0
         else if (orignalClassAnnotations.containsKey(ApplicationDefinition.class.getCanonicalName()))
 129  0
             return Entity.APPLICATION;
 130  0
         else if (orignalClassAnnotations.containsKey(ServiceDefinition.class.getCanonicalName()))
 131  0
             return Entity.SERVICE;
 132  0
         else if (orignalClassAnnotations.containsKey(StageDefinition.class.getCanonicalName()))
 133  0
             return Entity.STAGE;
 134  
         else
 135  0
             return null;
 136  
     }
 137  
 }