KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > sourcecontrols > ClearCaseModification


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2001, ThoughtWorks, Inc.
4  * 651 W Washington Ave. Suite 600
5  * Chicago, IL 60661 USA
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * + Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * + Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  *
20  * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21  * names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior
23  * written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  ********************************************************************************/

37
38 package net.sourceforge.cruisecontrol.sourcecontrols;
39
40 import org.apache.log4j.Logger;
41 import org.jdom.Element;
42
43 import java.text.DateFormat JavaDoc;
44 import java.util.HashMap JavaDoc;
45 import java.util.Iterator JavaDoc;
46 import java.util.List JavaDoc;
47 import java.util.Map JavaDoc;
48 import java.util.Vector JavaDoc;
49
50 import net.sourceforge.cruisecontrol.Modification;
51
52 /**
53  * data structure for holding data about a single modification
54  * to a source control tool.
55  *
56  * @author <a HREF="mailto:alden@thoughtworks.com">alden almagro</a>
57  */

58 public class ClearCaseModification extends Modification {
59     private static final String JavaDoc TAGNAME_LABEL = "label";
60     private static final String JavaDoc TAGNAME_ATTRIBUTE = "attribute";
61     private static final String JavaDoc TAGNAME_ATTRIBUTE_NAME = "name";
62
63     private static final Logger LOG = Logger.getLogger(Modification.class);
64
65     public List JavaDoc labels = null;
66     public Map JavaDoc attributes = null;
67
68     public ClearCaseModification() {
69         super("clearcase");
70     }
71
72     public Element toElement(DateFormat JavaDoc formatter) {
73         Element modificationElement = super.toElement(formatter);
74
75         if (labels != null) {
76             for (Iterator JavaDoc it = labels.iterator(); it.hasNext(); ) {
77                 Element labelElement = new Element(TAGNAME_LABEL);
78                 labelElement.addContent((String JavaDoc) it.next());
79                 modificationElement.addContent(labelElement);
80             }
81         }
82
83         if (attributes != null) {
84             for (Iterator JavaDoc it = attributes.keySet().iterator(); it.hasNext(); ) {
85                 String JavaDoc attName = (String JavaDoc) it.next();
86                 String JavaDoc attValue = (String JavaDoc) attributes.get(attName);
87                 Element attElement = new Element(TAGNAME_ATTRIBUTE);
88                 attElement.setAttribute(TAGNAME_ATTRIBUTE_NAME, attName);
89                 attElement.addContent(attValue);
90                 modificationElement.addContent(attElement);
91             }
92         }
93
94         return modificationElement;
95     }
96
97     public String JavaDoc toString() {
98         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(super.toString());
99
100         for (Iterator JavaDoc it = labels.iterator(); it.hasNext(); ) {
101             sb.append("Tag: ").append(it.next()).append('\n');
102         }
103
104         for (Iterator JavaDoc it = attributes.keySet().iterator(); it.hasNext(); ) {
105             String JavaDoc attName = (String JavaDoc) it.next();
106             String JavaDoc attValue = (String JavaDoc) attributes.get(attName);
107             sb.append("Attribute: ").append(attName).append(" = ").append(attValue).append('\n');
108         }
109
110         return sb.toString();
111     }
112
113     public void log(DateFormat JavaDoc formatter) {
114         if (LOG.isDebugEnabled()) {
115             super.log(formatter);
116
117             if (labels != null) {
118                 for (Iterator JavaDoc it = labels.iterator(); it.hasNext(); ) {
119                     LOG.debug("Tag: " + it.next());
120                 }
121             }
122
123             if (attributes != null) {
124                 for (Iterator JavaDoc it = attributes.keySet().iterator(); it.hasNext(); ) {
125                     String JavaDoc attName = (String JavaDoc) it.next();
126                     String JavaDoc attValue = (String JavaDoc) attributes.get(attName);
127                     LOG.debug("Attribute: " + attName + " = " + attValue);
128                 }
129             }
130
131             LOG.debug("");
132             LOG.debug("");
133         }
134     }
135
136     public void fromElement(Element modification, DateFormat JavaDoc formatter) {
137         super.fromElement(modification, formatter);
138
139         List JavaDoc modLabels = modification.getChildren(TAGNAME_LABEL);
140         if (modLabels != null && modLabels.size() > 0) {
141             labels = new Vector JavaDoc();
142             Iterator JavaDoc it = modLabels.iterator();
143             while (it.hasNext()) {
144                 Element label = (Element) it.next();
145                 labels.add(label.getText());
146             }
147         }
148
149         List JavaDoc modAttrs = modification.getChildren(TAGNAME_ATTRIBUTE);
150         if (modAttrs != null && modAttrs.size() > 0) {
151             attributes = new HashMap JavaDoc();
152             Iterator JavaDoc it = modAttrs.iterator();
153             while (it.hasNext()) {
154                 Element att = (Element) it.next();
155                 String JavaDoc attName = att.getAttributeValue(TAGNAME_ATTRIBUTE_NAME);
156                 String JavaDoc attValue = att.getText();
157                 attributes.put(attName, attValue);
158             }
159         }
160     }
161 }
162
Popular Tags