KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > om > Depend


1 package org.tigris.scarab.om;
2
3 /* ================================================================
4  * Copyright (c) 2000-2002 CollabNet. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowlegement: "This product includes
19  * software developed by Collab.Net <http://www.Collab.Net/>."
20  * Alternately, this acknowlegement may appear in the software itself, if
21  * and wherever such third-party acknowlegements normally appear.
22  *
23  * 4. The hosted project names must not be used to endorse or promote
24  * products derived from this software without prior written
25  * permission. For written permission, please contact info@collab.net.
26  *
27  * 5. Products derived from this software may not use the "Tigris" or
28  * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
29  * prior written permission of Collab.Net.
30  *
31  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
32  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34  * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
35  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
37  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
39  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  * ====================================================================
44  *
45  * This software consists of voluntary contributions made by many
46  * individuals on behalf of Collab.Net.
47  */

48
49 // Turbine classes
50
import org.apache.torque.om.Persistent;
51 import org.apache.torque.TorqueException;
52 import org.apache.fulcrum.localization.Localization;
53
54 // Scarab classes
55
import org.tigris.scarab.om.Module;
56 import org.tigris.scarab.tools.localization.L10NKeySet;
57 import org.tigris.scarab.util.ScarabException;
58
59 /**
60  * This class represents a Dependency object from the SCARAB_DEPEND table.
61  *
62  * @author <a HREF="mailto:jmcnally@collab.net">John McNally</a>
63  * @author <a HREF="mailto:jon@collab.net">Jon S. Stevens</a>
64  * @author <a HREF="mailto:elicia@collab.net">Elicia David</a>
65  * @version $Id: Depend.java 9494 2005-03-19 20:18:33Z jorgeuriarte $
66  */

67 public class Depend
68     extends BaseDepend
69     implements Persistent
70 {
71
72     /**
73      * A Module object which represents the default module.
74      */

75     private Module defaultModule = null;
76
77     /**
78      * A Module object which represents the default module.
79      */

80     private String JavaDoc observerUniqueId = null;
81
82     /**
83      * a user based comment about why this dependency is the way it is.
84      */

85     private String JavaDoc description = null;
86
87     /**
88      * A new Depend object
89      * @deprecated See DependManager.getInstance()
90      */

91     public static Depend getInstance()
92         throws TorqueException
93     {
94         return DependManager.getInstance();
95     }
96
97     /**
98      * Sets default module.
99      */

100     public void setDefaultModule(Module me)
101     {
102         this.defaultModule = me;
103     }
104
105     /**
106      * Returns default module.
107      */

108     public Module getDefaultModule()
109     {
110         return defaultModule;
111     }
112
113     /**
114      * Gets the description of the message given
115      * by the user for the reason for this dependency.
116      * Can be null. Saves the attachment to the database if
117      * there is data to be saved.
118      */

119     public Attachment getDescriptionAsAttachment(ScarabUser user, Issue issue)
120         throws Exception JavaDoc
121     {
122         if (description == null || description.length() == 0)
123         {
124             return null;
125         }
126         Attachment comment = AttachmentManager.getInstance();
127         comment.setTextFields(user, issue, Attachment.MODIFICATION__PK);
128         comment.setData(getDescription());
129         comment.setName("modification");
130         comment.save();
131         return comment;
132     }
133
134     /**
135      * Gets the description of the message given
136      * by the user for the reason for this dependency.
137      * Can be null.
138      */

139     public String JavaDoc getDescription()
140     {
141         return this.description;
142     }
143
144     /**
145      * Sets the description of the message given
146      * by the user for the reason for this dependency.
147      * Can be null.
148      */

149     public void setDescription(String JavaDoc description)
150     {
151         this.description = description;
152     }
153
154     /**
155      * Getter method to get observerId as a String
156      */

157     public String JavaDoc getObserverUniqueId()
158          throws Exception JavaDoc
159     {
160          return observerUniqueId;
161     }
162
163     public void setDependType(String JavaDoc type)
164         throws TorqueException
165     {
166         super.setDependType(DependTypeManager.getInstance(type));
167     }
168
169     /**
170      * Setter method which takes a String - the unique id.
171      */

172     public void setObserverUniqueId(String JavaDoc uniqueId)
173          throws Exception JavaDoc
174     {
175         if (getDefaultModule() == null)
176         {
177             throw new ScarabException( L10NKeySet.ExceptionDependInternalWorkflow,
178                                        "setDefaultModule()",
179                                        "setObserverUniqueId()");
180         }
181         Issue childIssue = null;
182         childIssue = IssueManager.getIssueById(uniqueId.trim());
183         if (childIssue == null)
184         {
185            String JavaDoc code = getDefaultModule().getCode();
186            uniqueId = code + uniqueId;
187            childIssue = IssueManager.getIssueById(uniqueId);
188         }
189         super.setObserverId(childIssue.getIssueId());
190     }
191      
192     /**
193      * Copies the properties from the passed in object
194      * onto this object.
195      */

196     public void setProperties(Depend depend)
197         throws TorqueException
198     {
199         this.setObservedId(depend.getObservedId());
200         this.setObserverId(depend.getObserverId());
201         this.setTypeId(depend.getTypeId());
202     }
203
204     /**
205      * Returns phrase describing this dependency's type.
206      */

207     public String JavaDoc getAction()
208     {
209         Integer JavaDoc typeId = getTypeId();
210         String JavaDoc action = null;
211         if (typeId.equals(DependTypePeer.BLOCKING__PK))
212         {
213             action = Localization.getString("depend_blocking");
214         }
215         else if (typeId.equals(DependTypePeer.DUPLICATE__PK))
216         {
217             action = Localization.getString("depend_duplicate");
218         }
219         else
220         {
221             action = Localization.getString("depend_nonblocking");
222         }
223         return action;
224     }
225         
226 }
227
Popular Tags