1 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 ; 44 import java.util.HashMap ; 45 import java.util.Iterator ; 46 import java.util.List ; 47 import java.util.Map ; 48 import java.util.Vector ; 49 50 import net.sourceforge.cruisecontrol.Modification; 51 52 58 public class ClearCaseModification extends Modification { 59 private static final String TAGNAME_LABEL = "label"; 60 private static final String TAGNAME_ATTRIBUTE = "attribute"; 61 private static final String TAGNAME_ATTRIBUTE_NAME = "name"; 62 63 private static final Logger LOG = Logger.getLogger(Modification.class); 64 65 public List labels = null; 66 public Map attributes = null; 67 68 public ClearCaseModification() { 69 super("clearcase"); 70 } 71 72 public Element toElement(DateFormat formatter) { 73 Element modificationElement = super.toElement(formatter); 74 75 if (labels != null) { 76 for (Iterator it = labels.iterator(); it.hasNext(); ) { 77 Element labelElement = new Element(TAGNAME_LABEL); 78 labelElement.addContent((String ) it.next()); 79 modificationElement.addContent(labelElement); 80 } 81 } 82 83 if (attributes != null) { 84 for (Iterator it = attributes.keySet().iterator(); it.hasNext(); ) { 85 String attName = (String ) it.next(); 86 String attValue = (String ) 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 toString() { 98 StringBuffer sb = new StringBuffer (super.toString()); 99 100 for (Iterator it = labels.iterator(); it.hasNext(); ) { 101 sb.append("Tag: ").append(it.next()).append('\n'); 102 } 103 104 for (Iterator it = attributes.keySet().iterator(); it.hasNext(); ) { 105 String attName = (String ) it.next(); 106 String attValue = (String ) 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 formatter) { 114 if (LOG.isDebugEnabled()) { 115 super.log(formatter); 116 117 if (labels != null) { 118 for (Iterator it = labels.iterator(); it.hasNext(); ) { 119 LOG.debug("Tag: " + it.next()); 120 } 121 } 122 123 if (attributes != null) { 124 for (Iterator it = attributes.keySet().iterator(); it.hasNext(); ) { 125 String attName = (String ) it.next(); 126 String attValue = (String ) 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 formatter) { 137 super.fromElement(modification, formatter); 138 139 List modLabels = modification.getChildren(TAGNAME_LABEL); 140 if (modLabels != null && modLabels.size() > 0) { 141 labels = new Vector (); 142 Iterator it = modLabels.iterator(); 143 while (it.hasNext()) { 144 Element label = (Element) it.next(); 145 labels.add(label.getText()); 146 } 147 } 148 149 List modAttrs = modification.getChildren(TAGNAME_ATTRIBUTE); 150 if (modAttrs != null && modAttrs.size() > 0) { 151 attributes = new HashMap (); 152 Iterator it = modAttrs.iterator(); 153 while (it.hasNext()) { 154 Element att = (Element) it.next(); 155 String attName = att.getAttributeValue(TAGNAME_ATTRIBUTE_NAME); 156 String attValue = att.getText(); 157 attributes.put(attName, attValue); 158 } 159 } 160 } 161 } 162 | Popular Tags |