001: /*
002: * FindBugs - Find bugs in Java programs
003: * Copyright (C) 2003-2005 University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package edu.umd.cs.findbugs;
021:
022: import java.io.IOException;
023: import java.io.Serializable;
024:
025: import edu.umd.cs.findbugs.xml.XMLAttributeList;
026: import edu.umd.cs.findbugs.xml.XMLOutput;
027: import edu.umd.cs.findbugs.xml.XMLWriteable;
028:
029: /**
030: * Name/value metadata pair that may be attached to a BugInstance.
031: * These are different from BugAnnotations because they are not
032: * meant to be shown directly to the user.
033: *
034: * @author David Hovemeyer
035: */
036: public class BugProperty implements XMLWriteable, Serializable,
037: Cloneable {
038: private static final long serialVersionUID = 1L;
039:
040: // Constants defining some standard bug properties
041:
042: /** Boolean property defining whether or not the BugInstance is really a bug. */
043: public static final String IS_BUG = "isBug";
044:
045: /** Integer property defining the warning severity (1=least severe, 5=most severe). */
046: public static final String SEVERITY = "severity";
047:
048: // Fields
049: private String name;
050: private String value;
051: private BugProperty next;
052:
053: /**
054: * Constructor.
055: *
056: * @param name name of property
057: * @param value value of property
058: */
059: BugProperty(String name, String value) {
060: this .name = name.intern();
061: this .value = value;
062: }
063:
064: @Override
065: protected Object clone() {
066: try {
067: return super .clone();
068: } catch (CloneNotSupportedException e) {
069: throw new AssertionError(e);
070: }
071: }
072:
073: /**
074: * Get name of property.
075: *
076: * @return name of property
077: */
078: public String getName() {
079: return name;
080: }
081:
082: /**
083: * Get value of property.
084: *
085: * @return value of property
086: */
087: public String getValue() {
088: return value;
089: }
090:
091: /**
092: * Get value of property as boolean.
093: *
094: * @return value of property as a boolean
095: */
096: public boolean getValueAsBoolean() {
097: return Boolean.valueOf(getValue()).booleanValue();
098: }
099:
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 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 {
142: xmlOutput.openCloseTag("Property", new XMLAttributeList()
143: .addAttribute("name", getName()).addAttribute("value",
144: getValue()));
145: }
146: }
|