|
1 /* |
|
2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 package com.nokia.helium.metadata.ant.types; |
|
18 |
|
19 import org.apache.tools.ant.BuildException; |
|
20 import org.apache.tools.ant.types.EnumeratedAttribute; |
|
21 |
|
22 /** |
|
23 * Defines an Ant enumerated type for the severity. |
|
24 */ |
|
25 public class SeverityEnum extends EnumeratedAttribute { |
|
26 |
|
27 /** |
|
28 * Defines a list of enumerated severities. |
|
29 */ |
|
30 public enum Severity { |
|
31 FATAL("FATAL"), ERROR("ERROR"), CRITICAL("CRITICAL"), WARNING("WARNING"), REMARK( |
|
32 "REMARK"), INFO("INFO"), NONE("NONE"); |
|
33 |
|
34 private final String value; |
|
35 |
|
36 Severity(String value) { |
|
37 this.value = value; |
|
38 } |
|
39 |
|
40 public String toString() { |
|
41 return this.value; |
|
42 } |
|
43 } |
|
44 |
|
45 private static String[] values; |
|
46 |
|
47 static { |
|
48 // Let's support upper case and lower case string. |
|
49 values = new String[Severity.values().length * 2]; |
|
50 int i = 0; |
|
51 for (Severity severity : Severity.values()) { |
|
52 values[i++] = severity.toString(); |
|
53 values[i++] = severity.toString().toLowerCase(); |
|
54 } |
|
55 } |
|
56 |
|
57 /** |
|
58 * Get the list of supported severity types. |
|
59 * @return List of supported severity types. |
|
60 */ |
|
61 @Override |
|
62 public String[] getValues() { |
|
63 return values; |
|
64 } |
|
65 |
|
66 /** |
|
67 * Get the severity as a Severity enum. |
|
68 * @return The severity value. |
|
69 */ |
|
70 public Severity getSeverity() { |
|
71 for (Severity severity : Severity.values()) { |
|
72 if (severity.toString().equalsIgnoreCase(getValue())) { |
|
73 return severity; |
|
74 } |
|
75 } |
|
76 throw new BuildException("Invalid severity: " + getValue()); |
|
77 } |
|
78 |
|
79 } |