KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > bugs > scarab > Issue


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.bugs.scarab;
21
22 import java.io.*;
23 import java.net.URL JavaDoc;
24 import java.util.*;
25 import java.util.Date JavaDoc;
26
27 import javax.xml.parsers.SAXParserFactory JavaDoc;
28 import javax.xml.parsers.SAXParser JavaDoc;
29 import javax.xml.parsers.ParserConfigurationException JavaDoc;
30 import org.xml.sax.SAXException JavaDoc;
31
32
33 /** Represents on issue in issuezilla.
34  * Created by {@link Issuezilla#getBug}
35  *
36  *
37  * tor@netbeans.org:
38  * This class is virtually identical to
39  * nbbuild/antsrc/org/netbeans/nbbuild/Issue.java
40  * At first, I inclouded its class file directly as part of
41  * the build. However, treating Issuezilla as a black box
42  * didn't work well because when connections fail (and are
43  * retried), or even during a query, there is no feedback - and
44  * since issuezilla is so slow, it's hard to know in the GUI
45  * that things are working. Therefore, I've modified the java
46  * file to give us a little bit more feedback.
47  * In CVS I stored the original file as the first revision,
48  * so you can easily diff to see what has changed - and generate
49  * a patch which you can then apply to an updated version
50  * of nbbuild/antsrc/ to keep the two in sync.
51  *
52  * serff@netbeans.org:
53  * This class is almost exactally the same as issuezilla.Issue, but modified to
54  * work with bugzilla. I didn't want to call this class Bug because of the
55  * higher level Bug class. If you can think of a better name, please let me know
56  *
57  * @todo think of a better name.
58  *
59  * @author Ivan Bradac, refactored by Jaroslav Tulach
60  */

61 public final class Issue implements Comparable JavaDoc {
62
63     private HashMap attributes = new HashMap (49);
64     
65     static final String JavaDoc ISSUE_TYPE = "issue_type";
66     static final String JavaDoc ISSUE_ID = "issue_id";
67     static final String JavaDoc REPORTER = "created_by";
68     static final String JavaDoc ASSIGNED_TO = "assigned_to";
69     static final String JavaDoc CREATED = "created";
70     static final String JavaDoc SUMMARY = "Summary";
71     static final String JavaDoc STATUS = "Status";
72     static final String JavaDoc PRIORITY = "Priority";
73     static final String JavaDoc COMPONENT = "Component";
74     static final String JavaDoc SUBCOMPONENT = "Subomponent";
75     static final String JavaDoc KEYWORDS = "Keywords";
76     static final String JavaDoc TARGET = "Target";
77     static final String JavaDoc VOTES = "Votes";
78
79     /**
80      * Gets the id as an Integer.
81      *
82      * @return the issue_id as
83      */

84     public String JavaDoc getId() {
85         return string(ISSUE_ID);
86     }
87
88     /** Who is assigned to this bug.
89      * @return name of person assigned to this bug
90      */

91     public String JavaDoc getAssignedTo () {
92         return string (ASSIGNED_TO);
93     }
94
95     /** Who reported the bug.
96      * @return name of the reporter
97      */

98     public String JavaDoc getReportedBy () {
99         return string (REPORTER);
100     }
101
102
103     /** Type of the issue: Bug, Enhancement, Task, etc...
104      * @return textual name of issue type
105      */

106     public String JavaDoc getType () {
107         return string (ISSUE_TYPE);
108     }
109
110     
111     /** A time when this issue has been created.
112      * @return the date or begining of epoch if wrongly defined
113      */

114     public Date JavaDoc getCreated () {
115         Date JavaDoc d = (Date JavaDoc)getAttribute (CREATED);
116         return d == null ? new Date JavaDoc (0) : d;
117     }
118
119     /** Getter to return string for given attribute.
120      */

121     private String JavaDoc string (String JavaDoc name) {
122         Object JavaDoc o = getAttribute (name);
123         return o instanceof String JavaDoc ? (String JavaDoc)o : "";
124     }
125     
126     /** Getter for array of integers.
127      */

128     private int[] ints (String JavaDoc name) {
129         List l = (List)getAttribute (name);
130         if (l == null) {
131             return new int[0];
132         }
133         
134         int[] arr = new int[l.size ()];
135         for (int i = 0; i < arr.length; i++) {
136             arr[i] = Integer.parseInt ((String JavaDoc)l.get (i));
137         }
138         return arr;
139     }
140
141     /** Package private getter, it is expected to add getter for useful
142      * issues.
143      */

144     Object JavaDoc getAttribute(String JavaDoc name) {
145         return attributes.get(name);
146     }
147
148
149     /** Setter of values, package private. */
150     void setAttribute(final String JavaDoc name, final Object JavaDoc value) {
151         attributes.put(name, value);
152     }
153
154     /** Converts the object to textual representation.
155      * @return a text description of the issue
156      */

157     public String JavaDoc toString() {
158         StringBuffer JavaDoc buffer;
159         if (attributes == null) {
160             return java.util.ResourceBundle.getBundle("org/netbeans/modules/tasklist/bugs/scarab/Bundle").getString("Empty_BugBase");
161         }
162         Iterator it = attributes.entrySet().iterator();
163         buffer = new StringBuffer JavaDoc();
164         buffer.append(this.getClass().getName()
165                       + java.util.ResourceBundle.getBundle("org/netbeans/modules/tasklist/bugs/scarab/Bundle").getString("_containing_these_name/value_attribute_pairs:\n"));
166         while (it.hasNext()) {
167             Map.Entry entry = (Map.Entry) it.next();
168             buffer.append(java.util.ResourceBundle.getBundle("org/netbeans/modules/tasklist/bugs/scarab/Bundle").getString("NAME__:_") + entry.getKey() + "\n");
169             buffer.append(java.util.ResourceBundle.getBundle("org/netbeans/modules/tasklist/bugs/scarab/Bundle").getString("VALUE_:_") + entry.getValue() + "\n");
170         }
171         return buffer.toString();
172     }
173
174     /** Compares issues by their ID
175      */

176     public int compareTo (final Object JavaDoc o) {
177         final Issue i = (Issue)o;
178         return getId ().compareTo(i.getId ());
179     }
180
181     public String JavaDoc getSummary()
182     {
183         return string(SUMMARY);
184     }
185
186     String JavaDoc getStatus()
187     {
188         return string(STATUS);
189     }
190
191 }
192
Popular Tags