1 package net.sf.quarrel.dot; 2 3 import net.sf.quarrel.uml.Attribute; 4 import net.sf.quarrel.uml.AttributeAggregator; 5 import net.sf.quarrel.uml.Operation; 6 import net.sf.quarrel.uml.OperationAggregator; 7 import net.sf.quarrel.uml.StructuredElement; 8 9 import java.util.Iterator; 10 11 public abstract class StructuredElementRenderer implements DotRenderer { 12 13 public abstract String getDotString(Object subject); 14 15 private String buildOperationsString(OperationAggregator toRender) { 16 17 StringBuffer buffer = new StringBuffer(); 18 19 final Iterator iterator = toRender.operations(); 20 Operation operation; 21 while (iterator.hasNext()) { 22 operation = (Operation) iterator.next(); 23 buffer.append(operation.getName()); 24 buffer.append("//l"); 25 } 26 27 return buffer.toString(); 28 } 29 30 private String buildAttributesString(AttributeAggregator toRender) { 31 32 StringBuffer buffer = new StringBuffer(); 33 34 final Iterator iterator = toRender.attributes(); 35 36 Attribute attribute; 37 38 final AttributeRenderer attributeRenderer = new AttributeRenderer(); 39 40 while (iterator.hasNext()) { 41 attribute = (Attribute) iterator.next(); 42 final String attrStr = attributeRenderer.getDotString(attribute); 43 buffer.append(attrStr); 44 } 45 46 return buffer.toString(); 47 48 } 49 50 String renderElement(StructuredElement se) { 51 52 StringBuffer buffer = new StringBuffer(); 53 54 buffer.append(se.getName()); 55 buffer.append(" "); 56 buffer.append("[shape=record,label="); 57 buffer.append("\""); 58 buffer.append("{"); 59 buffer.append(renderNameCompartment(se)); 60 buffer.append("|"); 61 buffer.append(buildAttributesString(se)); 62 buffer.append("|"); 63 buffer.append(buildOperationsString(se)); 64 buffer.append("}"); 65 buffer.append("\""); 66 buffer.append("];"); 67 68 return buffer.toString(); 69 70 } 71 72 String renderNameCompartment(StructuredElement se) { 73 return se.getName(); 74 } 75 76 }