1 25 package classycle.renderer; 26 27 import java.text.MessageFormat ; 28 29 import classycle.graph.AtomicVertex; 30 import classycle.graph.NameAttributes; 31 import classycle.graph.StrongComponent; 32 33 39 public abstract class XMLAtomicVertexRenderer implements AtomicVertexRenderer 40 { 41 46 public String render(AtomicVertex vertex, StrongComponent cycle, 47 int layerIndex) 48 { 49 StringBuffer result = new StringBuffer (); 50 result.append(getVertexRenderer().render(vertex, cycle, layerIndex)); 51 MessageFormat format = new MessageFormat (" <" + getRefElement() 52 + " name=\"{0}\"" + " type=\"{1}\"/>\n"); 53 String [] values = new String [2]; 54 for (int i = 0, n = vertex.getNumberOfIncomingArcs(); i < n; i++) 55 { 56 values[0] = ((NameAttributes) vertex.getTailVertex(i).getAttributes()) 57 .getName(); 58 values[1] = "usedBy"; 59 format.format(values, result, null); 60 } 61 for (int i = 0, n = vertex.getNumberOfOutgoingArcs(); i < n; i++) 62 { 63 values[0] = ((NameAttributes) vertex.getHeadVertex(i).getAttributes()) 64 .getName(); 65 values[1] = ((AtomicVertex) vertex.getHeadVertex(i)).isGraphVertex() 66 ? "usesInternal" : "usesExternal"; 67 format.format(values, result, null); 68 } 69 result.append(" </").append(getElement()).append(">\n"); 70 return new String (result); 71 } 72 73 protected abstract AtomicVertexRenderer getVertexRenderer(); 74 75 protected abstract String getElement(); 76 77 protected abstract String getRefElement(); 78 } | Popular Tags |