buildframework/helium/sf/java/metadata/src/com/nokia/helium/metadata/ant/types/MetaDataFilter.java
changeset 628 7c4a911dc066
parent 587 85df38eb4012
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
    16 */
    16 */
    17 
    17 
    18  
    18  
    19 package com.nokia.helium.metadata.ant.types;
    19 package com.nokia.helium.metadata.ant.types;
    20 
    20 
       
    21 import java.util.ArrayList;
       
    22 import java.util.Collection;
       
    23 import java.util.regex.Pattern;
       
    24 import java.util.regex.PatternSyntaxException;
       
    25 
       
    26 import org.apache.tools.ant.BuildException;
    21 import org.apache.tools.ant.types.DataType;
    27 import org.apache.tools.ant.types.DataType;
    22 import org.apache.log4j.Logger;
       
    23 import java.util.regex.Pattern;
       
    24 
    28 
    25 
    29 
    26 /**
    30 /**
    27  * This class provides filter input to the metadata task.
    31  * This class provides filter input to the metadata task.
    28  * <pre>
    32  * <pre>
    29  * &lt;metadatafilter priority=&quot;error&quot; regex=&quot;&quot; description=&quot;&quot; /&gt;
    33  * &lt;metadatafilter severity=&quot;error&quot; regex=&quot;&quot; description=&quot;&quot; /&gt;
    30  * </pre>
    34  * </pre>
    31  * @ant.task name="metadatafilter" category="Metadata"
    35  * @ant.task name="metadatafilter" category="Metadata"
    32  */
    36  */
    33 public class MetaDataFilter extends DataType
    37 public class MetaDataFilter extends DataType implements MetaDataFilterCollection {
    34 {
       
    35 
    38 
    36     private Logger log = Logger.getLogger(MetaDataFilter.class);
    39     private SeverityEnum.Severity severity;
    37 
       
    38     private String priority;
       
    39     private String regex;
    40     private String regex;
    40     private String description;
    41     private String description;
    41     private Pattern pattern;
    42     private Pattern pattern;
    42     
    43     
    43 
    44 
    44     /**
    45     /**
    45      * Helper function called by ant to set the priority type
    46      * Defines what is the severity level for this pattern
    46      * @param priority type of priority for this input.
    47      * @param severity type of severity for this input.
    47      */
    48      */
    48     public void setPriority(String prty) throws Exception {
    49     @Deprecated
    49         if (prty == null || prty.trim().length() == 0) {
    50     public void setPriority(SeverityEnum severity) {
    50             throw new Exception(" Invalid Priority");
    51         setSeverity(severity);
    51         }
       
    52         priority = prty;
       
    53     }
    52     }
    54 
    53 
    55     /**
    54     /**
    56      * Helper function to return the priority type
    55      * Defines what is the severity level for this pattern
    57      * @return priority type
    56      * @param severity type of severity for this input.
    58      */
    57      */
    59     public String getPriority() {
    58     public void setSeverity(SeverityEnum severity) {
    60         return priority;
    59         this.severity = severity.getSeverity();
       
    60     }
       
    61 
       
    62     /**
       
    63      * Helper function to return the severity type
       
    64      * @return severity type
       
    65      * @ant.required
       
    66      */
       
    67     public SeverityEnum.Severity getSeverity() {
       
    68         return severity;
    61     }
    69     }
    62 
    70 
    63     /**
    71     /**
    64      * Helper function called by ant to set the regex
    72      * Helper function called by ant to set the regex
    65      * @param regx regular expression of the filter
    73      * @param regx regular expression of the filter
       
    74      * @ant.required
    66      */
    75      */
    67     public void setRegex(String regx) throws Exception {
    76     public void setRegex(String regex) {
    68         if (regx == null || regx.trim().length() == 0) {
    77         if (regex == null || regex.trim().length() == 0) {
    69             throw new Exception(" Invalid Regular expression");
    78             throw new BuildException("Invalid Regular expression: the regex attribute cannot be an empty string.");
    70         }
    79         }
    71         regex = regx;
    80         this.regex = regex;
    72         createPattern(regx);
    81         try {
       
    82             pattern = Pattern.compile(this.regex);
       
    83         } catch (PatternSyntaxException ex) {
       
    84             throw new BuildException("Invalid regular expression: " + ex.getMessage(), ex);
       
    85         }
    73     }
    86     }
    74 
    87 
    75     /**
    88     /**
    76      * Helper function to return the regex type
    89      * Helper function to return the regex type
    77      * @return regular expression of this filter
    90      * @return regular expression of this filter
    81     }    
    94     }    
    82 
    95 
    83     /**
    96     /**
    84      * Helper function called by ant to set the description type
    97      * Helper function called by ant to set the description type
    85      * @param desc description associated with filter.
    98      * @param desc description associated with filter.
       
    99      * @ant.required
    86      */
   100      */
    87     public void setDescription(String desc) {
   101     public void setDescription(String desc) {
    88         description = desc;
   102         description = desc;
    89     }
   103     }
    90 
   104 
    95     public String getDescription() {
   109     public String getDescription() {
    96         return description;
   110         return description;
    97     }
   111     }
    98     
   112     
    99     /**
   113     /**
   100      * Internal function to create the pattern
       
   101      * @regex for which the pattern is created.
       
   102      */
       
   103     private void createPattern(String regex) {
       
   104         pattern = Pattern.compile(regex);
       
   105     }
       
   106     
       
   107     /**
       
   108      * Helper function to return the pattern
   114      * Helper function to return the pattern
   109      * @return the pattern of this filter.
   115      * @return the pattern of this filter.
   110      */
   116      */
   111     public Pattern getPattern() {
   117     public Pattern getPattern() {
   112         return pattern;
   118         return pattern;
   113     }
   119     }
       
   120 
       
   121     /**
       
   122      * {@inheritDoc}
       
   123      */
       
   124     public Collection<MetaDataFilter> getAllFilters() {
       
   125         Collection<MetaDataFilter> result = new ArrayList<MetaDataFilter>();
       
   126         if (this.isReference()) {
       
   127             result.add((MetaDataFilter)this.getRefid().getReferencedObject());  
       
   128         } else {
       
   129             result.add(this);
       
   130         }
       
   131         return result;
       
   132     }
   114 }
   133 }
   115 
   134 
   116 
   135