Changes between Version 1 and Version 2 of CORE_MVC_BASE_R2


Ignore:
Timestamp:
07/21/09 15:35:18 (16 years ago)
Author:
mitex
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CORE_MVC_BASE_R2

    v1 v2  
    2020== Implementation idea == 
    2121 * Create an annotation which would mark that an existing operation has a sort order key. 
    22  * Add functionality to get the sortKey of an operation in the class org.sophie2.core.mvc.SimpleOperation. Using Reflection get the sort order key through the annotation if it is available for this operation otherwise assume that the sortKey is an empty string. This makes certain that all operations which have not provided a sortKey will have equal prioryty when they are rigisterred as extensions. 
    23  * Assure that the extension point will sort the registered extensions according to the sort order key. Override the method getSorter() from the class SophieExtensionPoint<T> in org.sophie2.core.mvc.CoreMvcModule, to provide a proper Comparator which would compare the operations acording to their sorKey if such is available. 
     22 * Add functionality to get the sortKey of an operation in the class org.sophie2.core.mvc.SimpleOperation. 
     23  * Using Reflection get the sort order key through the annotation if it is available for this operation 
     24  * otherwise assume that the sortKey is an empty string. 
     25  * This makes certain that all operations which have not provided a sortKey will have equal prioryty when they are rigisterred as extensions. 
     26 * Assure that the extension point will sort the registered extensions according to the sort order key. 
     27  * Override the method getSorter() from the class SophieExtensionPoint<T> in org.sophie2.core.mvc.CoreMvcModule, to provide a proper Comparator which would compare the operations acording to their sorKey if such is available. 
    2428 
    2529== Related == 
     
    2933= Design = 
    3034 
    31  * A new annotation will be introduced. Using this annotation an operation will define its sort order key and this assures that different operations which have similar event filters can have different priority.  
    32         /** 
    33         * Annotation that marks an operation which can be sorted using its sortKey. 
    34         * 
    35         */ 
    36         @Target(ElementType.FIELD) 
    37         @Retention(RetentionPolicy.RUNTIME) 
    38         public @interface Sortable { 
    39                 /** 
    40                  * The sorting key for the field. 
    41                 *  
    42                 * @return The sorting key for the operation. 
    43                 */ 
    44                 String sortKey(); 
     35 * A new annotation will be introduced. 
     36  * Using this annotation an operation will define its sort order key and this assures that different operations which have similar event filters can have different priority.  
     37  * The annotation will have {{{String sortKey();}}} 
    4538 
    46         } 
    47  * The class org.sophie2.core.mvc.SimpleOperation will be modified. A method getSortKey() will be added. It will return the sort order key of the current SimpleOperation object. If the operation hasn't defined sortKey through the Sortable annotation the method will return an empty string, otherwise the method should return the corresponding sort order key. This is achieved in the following manner - we obtain the operationDef object - corresponding to the particular operation, then we get from the enumeration the appropriate enum field representing the current SimpleOperation and finally we obtain its sortkey if such is available. 
    48         /** 
    49          * Gets the sorting key for this operation. 
    50          *  
    51          * @return The sorting key of this SimpleOperation or an  
    52          *                 empty string if the operation has not provided a sorting key. 
    53          */ 
    54         public String getSortKey() 
    55         { 
    56                 String sortKey = ""; 
    57                  
    58                 Enum<?> op = (Enum<?>) this.opDef; 
    59                 try { 
    60                          
    61                         Field field = this.opDef.getClass().getField(op.name()); 
    62                         Sortable s = field.getAnnotation(Sortable.class); 
    63                         if(s != null) 
    64                                 sortKey = s.sortKey(); 
    65                          
    66                 } catch (SecurityException e) { 
    67                         e.printStackTrace(); 
    68                 } catch (NoSuchFieldException e) { 
    69                         e.printStackTrace(); 
    70                 } 
    71                  
    72                 return sortKey; 
    73         } 
     39 * The interface org.sophie2.core.mvc.OperationR3 will be modified. 
     40  * A method getSortKey() will be added. 
     41   * It will return the sort order key of the current OperationR3 object. 
     42   * If the operation hasn't defined sortKey through the Sortable annotation the method will return an empty string, otherwise the method should return the corresponding sort order key. 
     43   * This is achieved in the following manner - we obtain the operationDef object - corresponding to the particular operation, then we get from the enumeration the appropriate enum field representing the current SimpleOperation and finally we obtain its sortkey if such is available. 
    7444 
    75  * The class org.sophie2.core.mvc will be modified. In the existing public static class OperationPoint which extends SophieExtensionPoint<OperationR3>  we will  overload the method getSorter() inherited from SophieExtensionPoint<T> located in org.sophie2.core.modularity. 
    76         @Override 
    77         protected Comparator<SophieExtension<OperationR3>> getSorter() { 
    78                 return new Comparator<SophieExtension<OperationR3>>() { 
    79                         public int compare(SophieExtension<OperationR3> se1, SophieExtension<OperationR3> se2) { 
    80                                          
    81                                 if((se1.getObject() instanceof SimpleOperation)&& (se2.getObject() instanceof SimpleOperation)) 
    82                                 { 
    83                                         SimpleOperation so1 = (SimpleOperation)se1.getObject(); 
    84                                         SimpleOperation so2 = (SimpleOperation)se2.getObject(); 
    85                                          
    86                                         return so1.getSortKey().compareTo(so2.getSortKey()); 
    87                                 } 
    88                                          
    89                                 return 0; 
    90                         } 
    91                 }; 
    92         } 
     45 * The class org.sophie2.core.mvc will be modified. 
     46  * In the existing public static class OperationPoint which extends SophieExtensionPoint<OperationR3> we will overload the method getSorter() inherited from SophieExtensionPoint<T> located in org.sophie2.core.modularity. 
     47  * The method should return the result of {{{compareTo}}} applied to the keys. 
     48  * Follow this rule: 
     49   * Smaller sort key means higher priority. 
     50   * Exception case: empty sort key has lower priority than any other key. 
    9351 
    94  
    95  
     52 * Test: [source:/branches/private/mitex/bobi/logic-priority/modules/org.sophie2.core.modularity/src/test/java/org/sophie2/core/modularity/LogicPriorityTest.java] 
    9653 
    9754= Implementation = 
    98 * Done according to design. 
     55 * Done according to design. 
     56 
     57 * Source code: [source:/branches/private/mitex/bobi/logic-priority] 
    9958 
    10059= Testing =