KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > BugProperty


1 /*
2  * FindBugs - Find bugs in Java programs
3  * Copyright (C) 2003-2005 University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package edu.umd.cs.findbugs;
21
22 import java.io.IOException JavaDoc;
23 import java.io.Serializable JavaDoc;
24
25 import edu.umd.cs.findbugs.xml.XMLAttributeList;
26 import edu.umd.cs.findbugs.xml.XMLOutput;
27 import edu.umd.cs.findbugs.xml.XMLWriteable;
28
29 /**
30  * Name/value metadata pair that may be attached to a BugInstance.
31  * These are different from BugAnnotations because they are not
32  * meant to be shown directly to the user.
33  *
34  * @author David Hovemeyer
35  */

36 public class BugProperty implements XMLWriteable, Serializable JavaDoc, Cloneable JavaDoc {
37     private static final long serialVersionUID = 1L;
38
39     // Constants defining some standard bug properties
40

41     /** Boolean property defining whether or not the BugInstance is really a bug. */
42     public static final String JavaDoc IS_BUG = "isBug";
43     
44     /** Integer property defining the warning severity (1=least severe, 5=most severe). */
45     public static final String JavaDoc SEVERITY = "severity";
46
47     // Fields
48
private String JavaDoc name;
49     private String JavaDoc value;
50     private BugProperty next;
51     
52     /**
53      * Constructor.
54      *
55      * @param name name of property
56      * @param value value of property
57      */

58     BugProperty(String JavaDoc name, String JavaDoc value) {
59         this.name = name.intern();
60         this.value = value;
61     }
62     
63     //@Override
64
@Override JavaDoc
65     protected Object JavaDoc clone() {
66         try {
67             return super.clone();
68         } catch (CloneNotSupportedException JavaDoc e) {
69             throw new AssertionError JavaDoc(e);
70         }
71     }
72     
73     /**
74      * Get name of property.
75      *
76      * @return name of property
77      */

78     public String JavaDoc getName() {
79         return name;
80     }
81     
82     /**
83      * Get value of property.
84      *
85      * @return value of property
86      */

87     public String JavaDoc getValue() {
88         return value;
89     }
90     
91     /**
92      * Get value of property as boolean.
93      *
94      * @return value of property as a boolean
95      */

96     public boolean getValueAsBoolean() {
97         return Boolean.valueOf(getValue()).booleanValue();
98     }
99     
100     /**
101      * Get value of property as an integer.
102      *
103      * @return value of property as integer
104      * @throws NumberFormatException if the value cannot be parsed as
105      * an integer
106      */

107     public int getValueAsInt() {
108         return Integer.parseInt(getValue());
109     }
110     
111     /**
112      * Set value of property.
113      *
114      * @param value
115      */

116     public void setValue(String JavaDoc value) {
117         this.value = value;
118     }
119     
120     /**
121      * Set next property in list.
122      *
123      * @param next next property in list
124      */

125     void setNext(BugProperty next) {
126         this.next = next;
127     }
128     
129     /**
130      * Get next property in list.
131      *
132      * @return next property in list
133      */

134     BugProperty getNext() {
135         return next;
136     }
137
138     /* (non-Javadoc)
139      * @see edu.umd.cs.findbugs.xml.XMLWriteable#writeXML(edu.umd.cs.findbugs.xml.XMLOutput)
140      */

141     public void writeXML(XMLOutput xmlOutput) throws IOException JavaDoc {
142         xmlOutput.openCloseTag(
143                 "Property",
144                 new XMLAttributeList()
145                     .addAttribute("name", getName())
146                     .addAttribute("value", getValue())
147         );
148     }
149 }
150
Popular Tags