001: /********************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2001, ThoughtWorks, Inc.
004: * 200 E. Randolph, 25th Floor
005: * Chicago, IL 60601 USA
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * + Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * + Redistributions in binary form must reproduce the above
016: * copyright notice, this list of conditions and the following
017: * disclaimer in the documentation and/or other materials provided
018: * with the distribution.
019: *
020: * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
021: * names of its contributors may be used to endorse or promote
022: * products derived from this software without specific prior
023: * written permission.
024: *
025: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
026: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
027: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
028: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
029: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
030: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
031: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
032: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
033: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
034: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
035: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
036: ********************************************************************************/package net.sourceforge.cruisecontrol.sourcecontrols;
037:
038: import org.apache.log4j.Logger;
039: import org.jdom.Element;
040:
041: import java.text.DateFormat;
042: import java.util.HashMap;
043: import java.util.Iterator;
044: import java.util.List;
045: import java.util.Map;
046: import java.util.Vector;
047:
048: import net.sourceforge.cruisecontrol.Modification;
049:
050: /**
051: * data structure for holding data about a single modification
052: * to a source control tool.
053: *
054: * @author <a href="mailto:alden@thoughtworks.com">alden almagro</a>
055: */
056: public class ClearCaseModification extends Modification {
057: private static final String TAGNAME_LABEL = "label";
058: private static final String TAGNAME_ATTRIBUTE = "attribute";
059: private static final String TAGNAME_ATTRIBUTE_NAME = "name";
060:
061: private static final Logger LOG = Logger
062: .getLogger(Modification.class);
063:
064: public List labels = null;
065: public Map attributes = null;
066:
067: public ClearCaseModification() {
068: super ("clearcase");
069: }
070:
071: public Element toElement(DateFormat formatter) {
072: Element modificationElement = super .toElement(formatter);
073:
074: if (labels != null) {
075: for (Iterator it = labels.iterator(); it.hasNext();) {
076: Element labelElement = new Element(TAGNAME_LABEL);
077: labelElement.addContent((String) it.next());
078: modificationElement.addContent(labelElement);
079: }
080: }
081:
082: if (attributes != null) {
083: for (Iterator it = attributes.keySet().iterator(); it
084: .hasNext();) {
085: String attName = (String) it.next();
086: String attValue = (String) attributes.get(attName);
087: Element attElement = new Element(TAGNAME_ATTRIBUTE);
088: attElement
089: .setAttribute(TAGNAME_ATTRIBUTE_NAME, attName);
090: attElement.addContent(attValue);
091: modificationElement.addContent(attElement);
092: }
093: }
094:
095: return modificationElement;
096: }
097:
098: public String toString() {
099: StringBuffer sb = new StringBuffer(super .toString());
100:
101: for (Iterator it = labels.iterator(); it.hasNext();) {
102: sb.append("Tag: ").append(it.next()).append('\n');
103: }
104:
105: for (Iterator it = attributes.keySet().iterator(); it.hasNext();) {
106: String attName = (String) it.next();
107: String attValue = (String) attributes.get(attName);
108: sb.append("Attribute: ").append(attName).append(" = ")
109: .append(attValue).append('\n');
110: }
111:
112: return sb.toString();
113: }
114:
115: public void log(DateFormat formatter) {
116: if (LOG.isDebugEnabled()) {
117: super .log(formatter);
118:
119: if (labels != null) {
120: for (Iterator it = labels.iterator(); it.hasNext();) {
121: LOG.debug("Tag: " + it.next());
122: }
123: }
124:
125: if (attributes != null) {
126: for (Iterator it = attributes.keySet().iterator(); it
127: .hasNext();) {
128: String attName = (String) it.next();
129: String attValue = (String) attributes.get(attName);
130: LOG.debug("Attribute: " + attName + " = "
131: + attValue);
132: }
133: }
134:
135: LOG.debug("");
136: LOG.debug("");
137: }
138: }
139:
140: public void fromElement(Element modification, DateFormat formatter) {
141: super .fromElement(modification, formatter);
142:
143: List modLabels = modification.getChildren(TAGNAME_LABEL);
144: if (modLabels != null && modLabels.size() > 0) {
145: labels = new Vector();
146: Iterator it = modLabels.iterator();
147: while (it.hasNext()) {
148: Element label = (Element) it.next();
149: labels.add(label.getText());
150: }
151: }
152:
153: List modAttrs = modification.getChildren(TAGNAME_ATTRIBUTE);
154: if (modAttrs != null && modAttrs.size() > 0) {
155: attributes = new HashMap();
156: Iterator it = modAttrs.iterator();
157: while (it.hasNext()) {
158: Element att = (Element) it.next();
159: String attName = att
160: .getAttributeValue(TAGNAME_ATTRIBUTE_NAME);
161: String attValue = att.getText();
162: attributes.put(attName, attValue);
163: }
164: }
165: }
166: }
|