buildframework/helium/sf/java/metadata/src/com/nokia/helium/metadata/ant/types/MetaDataFilter.java
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 587 85df38eb4012
permissions -rw-r--r--
helium_11.0.0-e00f171ca185
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
/*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
* All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
* This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
* which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
* Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
* Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
* Description:  
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
*/
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
package com.nokia.helium.metadata.ant.types;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    21
import java.util.ArrayList;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    22
import java.util.Collection;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    23
import java.util.regex.Pattern;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    24
import java.util.regex.PatternSyntaxException;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    25
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    26
import org.apache.tools.ant.BuildException;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
import org.apache.tools.ant.types.DataType;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
/**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
 * This class provides filter input to the metadata task.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
 * <pre>
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    33
 * &lt;metadatafilter severity=&quot;error&quot; regex=&quot;&quot; description=&quot;&quot; /&gt;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
 * </pre>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
 * @ant.task name="metadatafilter" category="Metadata"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
 */
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    37
public class MetaDataFilter extends DataType implements MetaDataFilterCollection {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    39
    private SeverityEnum.Severity severity;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
    private String regex;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
    private String description;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
    private Pattern pattern;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    46
     * Defines what is the severity level for this pattern
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    47
     * @param severity type of severity for this input.
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
     */
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    49
    @Deprecated
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    50
    public void setPriority(SeverityEnum severity) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    51
        setSeverity(severity);
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    55
     * Defines what is the severity level for this pattern
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    56
     * @param severity type of severity for this input.
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
     */
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    58
    public void setSeverity(SeverityEnum severity) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    59
        this.severity = severity.getSeverity();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    60
    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    61
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    62
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    63
     * Helper function to return the severity type
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    64
     * @return severity type
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    65
     * @ant.required
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    66
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    67
    public SeverityEnum.Severity getSeverity() {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    68
        return severity;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
     * Helper function called by ant to set the regex
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
     * @param regx regular expression of the filter
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    74
     * @ant.required
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
     */
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    76
    public void setRegex(String regex) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    77
        if (regex == null || regex.trim().length() == 0) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    78
            throw new BuildException("Invalid Regular expression: the regex attribute cannot be an empty string.");
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
        }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    80
        this.regex = regex;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    81
        try {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    82
            pattern = Pattern.compile(this.regex);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    83
        } catch (PatternSyntaxException ex) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    84
            throw new BuildException("Invalid regular expression: " + ex.getMessage(), ex);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    85
        }
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
     * Helper function to return the regex type
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
     * @return regular expression of this filter
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
    public String getRegex() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
        return regex;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
    }    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    97
     * Helper function called by ant to set the description type
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    98
     * @param desc description associated with filter.
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    99
     * @ant.required
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
    public void setDescription(String desc) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   102
        description = desc;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   104
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106
     * Helper function to return the description associated with regular expression
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
     * @return description associated with regex.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   108
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   109
    public String getDescription() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   110
        return description;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   111
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   112
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   113
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   114
     * Helper function to return the pattern
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   115
     * @return the pattern of this filter.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   116
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   117
    public Pattern getPattern() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   118
        return pattern;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   119
    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   120
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   121
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   122
     * {@inheritDoc}
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   123
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   124
    public Collection<MetaDataFilter> getAllFilters() {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   125
        Collection<MetaDataFilter> result = new ArrayList<MetaDataFilter>();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   126
        if (this.isReference()) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   127
            result.add((MetaDataFilter)this.getRefid().getReferencedObject());  
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   128
        } else {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   129
            result.add(this);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   130
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   131
        return result;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   132
    }
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   133
}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   134
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   135