Coverage Report - pt.digitalis.dif.codegen.CGAncillaries
 
Classes in this File Line Coverage Branch Coverage Complexity
CGAncillaries
0%
0/24
0%
0/6
3
 
 1  
 /**
 2  
  * - Digitalis Internal Framework v2.0 - (C) 2007, Digitalis Informatica. Distribuicao e Gestao de Informatica, Lda.
 3  
  * Estrada de Paco de Arcos num.9 - Piso -1 2780-666 Paco de Arcos Telefone: (351) 21 4408990 Fax: (351) 21 4408999
 4  
  * http://www.digitalis.pt
 5  
  */
 6  
 package pt.digitalis.dif.codegen;
 7  
 
 8  
 import java.util.List;
 9  
 import java.util.Map;
 10  
 
 11  
 import pt.digitalis.dif.controller.interfaces.IDIFContext;
 12  
 import pt.digitalis.dif.controller.objects.DIFContext;
 13  
 import pt.digitalis.dif.dem.interfaces.IStage;
 14  
 import pt.digitalis.dif.dem.objects.ViewObject;
 15  
 import pt.digitalis.dif.dem.objects.parameters.IParameters;
 16  
 
 17  
 /**
 18  
  * Place holder for some DIF CG-related constants and operations that are used on the code generation process.
 19  
  * 
 20  
  * @author Rodrigo Gonçalves <a href="mailto:rgoncalves@digitalis.pt">rgoncalves@digitalis.pt</a><br/>
 21  
  * @author Pedro Viegas <a href="mailto:pviegas@digitalis.pt">pviegas@digitalis.pt</a><br/>
 22  
  * @created 2007/10/29
 23  
  */
 24  0
 public class CGAncillaries {
 25  
 
 26  
     /** The name of the method that calls the user-defined application's initialization method. */
 27  
     final static public String APP_INIT_METHOD = "__CG__initialize";
 28  
 
 29  
     /** The IApplication 'getProvider' method name. */
 30  
     final static public String APPLICATION_GET_PROVIDER_METHOD = "getProvider";
 31  
 
 32  
     /** The boolean return as a String. */
 33  
     final static public String BOOLEAN_RETURN = "Z";
 34  
 
 35  
     /** The name of the method that calls the event handler method. */
 36  
     final static public String CALL_EVENT_METHOD = "callEventMethod";
 37  
 
 38  
     /** The name of the method that calls the user-defined execution method. */
 39  
     final static public String CALL_EXEC_METHOD = "callExecuteMethod";
 40  
 
 41  
     /** The name of the method that calls the user-defined execution method for a specified event. */
 42  
     final static public String CALL_EXEC_ONEVENT_METHOD = "callExecuteOnEventMethod";
 43  
 
 44  
     /** The name of the method that calls the user-defined execution method. */
 45  
     final static public String CALL_FINALIZE_METHOD = "callFinalizeMethod";
 46  
 
 47  
     /** The name of the method that calls the user-defined parameter definition method. */
 48  
     final static public String CALL_INIT_CUSTOM_PARAMETERS_METHOD = "callInitCustomParametersMethod";
 49  
 
 50  
     /** The name of the method that calls the user-defined initialization method. */
 51  
     final static public String CALL_INIT_METHOD = "callInitMethod";
 52  
 
 53  
     /** The ICallback 'getCallbackType' method name. */
 54  
     final static public String CALLBACK_GET_CALLBACK_TYPE_METHOD = "getCallbackType";
 55  
 
 56  
     /** The ICallback 'hasCallbackEnabled' method name. */
 57  
     final static public String CALLBACK_HAS_CALLBACK_ENABLED_METHOD = "hasCallbackEnabled";
 58  
 
 59  
     /** This message is used as return for Boolean-returning methods whose bodies will be implemented by the CodeGen. */
 60  
     final static public boolean CG_TO_BE_IMPLEMENTED_BOOLEAN = true;
 61  
 
 62  
     /** This message is used as return for String-returning methods whose bodies will be implemented by the CodeGen. */
 63  0
     final static public String CG_TO_BE_IMPLEMENTED_MESSAGE = "This will be replaced with generated code".toLowerCase();
 64  
 
 65  
     /** This message is used as return for Object-returning methods whose bodies will be implemented by the CodeGen. */
 66  0
     final static public Object CG_TO_BE_IMPLEMENTED_OBJECT = null;
 67  
 
 68  
     /** This message is used as return for Stage-returning methods whose bodies will be implemented by the CodeGen. */
 69  0
     final static public IStage CG_TO_BE_IMPLEMENTED_STAGE = null;
 70  
 
 71  
     /** This message is used as return for ViewObject-returning methods whose bodies will be implemented by the CodeGen. */
 72  0
     final static public ViewObject CG_TO_BE_IMPLEMENTED_VIEW = null;
 73  
 
 74  
     /** The comma character as a String. */
 75  
     final static public String COMMA = ",";
 76  
 
 77  
     /** Java's end block char as a String constant. */
 78  
     final static public String END_BLOCK = "}";
 79  
 
 80  
     /** The IEntity 'getID' method name. */
 81  
     final static public String ENTITY_GET_ID_METHOD = "getID";
 82  
 
 83  
     /** The IEntity 'getName' method name. */
 84  
     final static public String ENTITY_GET_NAME_METHOD = "getName";
 85  
 
 86  
     /** The IEntity 'getOriginalClassName' method name. */
 87  
     final static public String ENTITY_GET_ORIGINALCLASSNAME_METHOD = "getOriginalClassName";
 88  
 
 89  
     /** The IEntity 'getID' method name. */
 90  
     final static public String ENTITY_GET_OVERRIDE_METHOD = "getOverridesStageID";
 91  
 
 92  
     /** The IEntity 'getOriginalClassName' method name. */
 93  
     final static public String ENTITY_GET_STAGEINSTANCECLASSNAME_METHOD = "getStageInstanceClassName";
 94  
 
 95  
     /** The DIFContext argument as a String. */
 96  0
     final static public String IDIF_CONTEXT_ARGS = "(L" + IDIFContext.class.getCanonicalName().replace(".", "/") + ";)";
 97  
 
 98  
     /** The IParameters argument as a String. */
 99  0
     final static public String IPARAMETERS_ARGS = "(L" + IParameters.class.getCanonicalName().replace(".", "/") + ";)";
 100  
 
 101  
     /** The List return as a String. */
 102  0
     final static public String LIST_RETURN = "L" + List.class.getCanonicalName().replace(".", "/") + ";";
 103  
 
 104  
     /** The Map return as a String. */
 105  0
     final static public String MAP_RETURN = "L" + Map.class.getCanonicalName().replace(".", "/") + ";";
 106  
 
 107  
     /** The method body tag as String constant. */
 108  
     final static public String METHOD_BODY_TAG = "${body}";
 109  
 
 110  
     /** The new line character as a String. */
 111  
     final static public String NEW_LINE = "\n";
 112  
 
 113  
     /** The id tag for the non-stage enriched class. */
 114  
     final static public String NON_STAGE_ENRICHED_CLASS_ID = "EnrichedClass";
 115  
 
 116  
     /** The IService 'getApplication' method name. */
 117  
     final static public String SERVICE_GET_APPLICATION_METHOD = "getApplication";
 118  
 
 119  
     /** The error stages builder method name */
 120  
     final static public String STAGE_EVENT_HANDLERS_BUILDER = "eventHandlersBuilder";
 121  
 
 122  
     /** The IStage 'getDefaultErrorStage' method name. */
 123  
     final static public String STAGE_GET_DEFAULT_ERROR_STAGE = "getDefaultErrorStage";
 124  
 
 125  
     /** The IStage 'getDefaultErrorView' method name. */
 126  
     final static public String STAGE_GET_DEFAULT_ERROR_VIEW = "getDefaultErrorView";
 127  
 
 128  
     /** The IStage 'getDefaultView' method name. */
 129  
     final static public String STAGE_GET_DEFAULT_VIEW = "getDefaultView";
 130  
 
 131  
     /** The IStage 'getService' method name. */
 132  
     final static public String STAGE_GET_SERVICE_METHOD = "getService";
 133  
 
 134  
     /** The IStage 'hasAuthentication' method name. */
 135  
     final static public String STAGE_HAS_AUTHENTICATION = "hasAuthentication";
 136  
 
 137  
     /** The IStage 'hasAuthenticationErrorInjection' method name. */
 138  
     final static public String STAGE_HAS_AUTHENTICATION_ERROR_INJECTION = "hasAuthenticationErrorInjection";
 139  
 
 140  
     /** The IStage 'hasAuthorization' method name. */
 141  
     final static public String STAGE_HAS_AUTHORIZATION = "hasAuthorization";
 142  
 
 143  
     /** The IStage 'hasInjectedContributions' method name. */
 144  
     final static public String STAGE_HAS_INJECTED_CONTRIBUTIONS = "hasInjectedContributions";
 145  
 
 146  
     /** The IStage 'hasParameterErrorInjection' method name. */
 147  
     final static public String STAGE_HAS_PARAMETER_ERROR_INJECTION = "hasParameterErrorInjection";
 148  
 
 149  
     /** Defines the name of the entity internal init method */
 150  
     final static public String STAGE_INJECTED_ATTRIBUTES_INIT_METHOD_NAME = "__Stage__InjectedAttributesInitMethod__";
 151  
 
 152  
     /** Defines the source of the entity internal init method. The ${body} enables later substitution of method body. */
 153  0
     final static public String STAGE_INJECTED_ATTRIBUTES_INIT_METHOD_NAME_SOURCE = "public void "
 154  0
             + STAGE_INJECTED_ATTRIBUTES_INIT_METHOD_NAME + "(" + DIFContext.class.getCanonicalName()
 155  0
             + " difContext) { ${body}  }";
 156  
 
 157  
     /** The error stages builder method name */
 158  
     final static public String STAGE_INJECTED_ERRORSTAGES_BUILDER = "injectedErrorStagesBuilder";
 159  
 
 160  
     /** The error views builder method name */
 161  
     final static public String STAGE_INJECTED_ERRORVIEWS_BUILDER = "injectedErrorViewsBuilder";
 162  
 
 163  
     /** The stages builder method name */
 164  
     final static public String STAGE_INJECTED_STAGES_BUILDER = "injectedStagesBuilder";
 165  
 
 166  
     /** The views builder method name */
 167  
     final static public String STAGE_INJECTED_VIEWS_BUILDER = "injectedViewsBuilder";
 168  
 
 169  
     /** The id tag for the stage instance. */
 170  
     final static public String STAGE_INSTANCE_ID = "CGStageInstance";
 171  
 
 172  
     /** Defines the name of the entity internal finalize method */
 173  
     final static public String STAGE_POSTPROCESSING_METHOD_NAME = "__Stage__PostProcessingMethod__";
 174  
 
 175  
     /** Defines the source of the entity internal init method. The ${body} enables later substitution of method body. */
 176  0
     final static public String STAGE_POSTPROCESSING_METHOD_NAME_SOURCE = "public void "
 177  0
             + STAGE_POSTPROCESSING_METHOD_NAME + "(" + DIFContext.class.getCanonicalName()
 178  0
             + " difContext) { ${body}  }";
 179  
 
 180  
     /** The id tag for the stage proxy. */
 181  
     final static public String STAGE_PROXY_ID = "CGStageProxy";
 182  
 
 183  
     /** Java's start block char as a String constant. */
 184  
     final static public String START_BLOCK = "{";
 185  
 
 186  
     /** The String return as a String. */
 187  0
     final static public String STRING_RETURN = "L" + String.class.getCanonicalName().replace(".", "/") + ";";
 188  
 
 189  
     /** The IValidator 'getBoundParameterIDs' method name. */
 190  
     final static public String VALIDATOR_GET_BOUND_PARAMETER_IDS_METHOD = "getBoundParameterIDs";
 191  
 
 192  
     /** The ViewObject return as a String. */
 193  0
     final static public String VIEW_OBJECT_RETURN = "L" + ViewObject.class.getCanonicalName().replace(".", "/") + ";";
 194  
 
 195  
     /** The void argument as a String. */
 196  
     final static public String VOID_ARGS = "()";
 197  
 
 198  
     /** The void return as a String. */
 199  
     final static public String VOID_RETURN = "V";
 200  
 
 201  
     /**
 202  
      * @param clazz
 203  
      *            the class
 204  
      * @return the method signature
 205  
      */
 206  
     static public String getReturnSignatureForClass(Class<?> clazz)
 207  
     {
 208  
 
 209  
         /** The String return as a String. */
 210  0
         return "L" + clazz.getCanonicalName().replace(".", "/") + ";";
 211  
 
 212  
     }
 213  
 
 214  
     /**
 215  
      * Separates a string into multiple strings by splitting the original string around matches of a given pattern.
 216  
      * Trims the destination strings to remove leading and trailing white spaces.
 217  
      * 
 218  
      * @param stringToSplit
 219  
      *            the string to split
 220  
      * @param regex
 221  
      *            the pattern used to separate the string
 222  
      * @return an array of strings with the original string split and trimmed.
 223  
      */
 224  
     final static public String[] parse(String stringToSplit, String regex)
 225  
     {
 226  
 
 227  0
         if (stringToSplit == null || "".equals(stringToSplit))
 228  0
             return new String[0];
 229  
 
 230  0
         String[] result = stringToSplit.split(regex);
 231  
 
 232  0
         for (int i = 0; i < result.length; i++)
 233  
         {
 234  0
             result[i] = result[i].trim();
 235  
         }
 236  
 
 237  0
         return result;
 238  
     }
 239  
 }