UGraph { traversal ReadAllVertices(ReadVertexVisitor rvv) { bypassing -> *,edges,* to { UConstVertex, UAltVertex, UTerm}; } (@ public String PrintVertices() { ReadVertexVisitor rvv= new ReadVertexVisitor(this, new String(), new Integer(0), new Integer(0)); this.ReadAllVertices(rvv); String temp = rvv.get_graphstring(); if (rvv.get_uppervalue().intValue() == 1) { temp = temp + "\nList(S)\t~ {S} .\n"; } return temp; } public String FindVertex(Integer vertexid) { ReadVertexVisitor rvv= new ReadVertexVisitor(this, new String(), vertexid, new Integer(0)); this.ReadAllVertices(rvv); return rvv.get_graphstring(); } @) traversal ReadAllEdges(ReadEdgeVisitor rev) { bypassing -> *,vertices,* to {UConstEdge, UAltEdge}; } (@ public String FindEdge(Integer vertexid, String fromvertextype) { // We will use this string fromvertextype to differentiate // if this function was called from an alt or a const vertex // The Integers are for the pipeswitch and the listswitch.. ReadEdgeVisitor rev= new ReadEdgeVisitor(this, new String(), new String(), vertexid, fromvertextype, new Integer(0), new Integer(0)); this.ReadAllEdges(rev); String tmp = new String(); // if the vertex called this as a card type, we'll just return // whether or not the upper cardinality is a *.. if (fromvertextype.equals("card")) { if (rev.get_listswitch().intValue() == 1) { tmp = "1"; } else { tmp = "0"; } return tmp; } tmp = rev.get_graphstring(); if ( ! rev.get_commonstring().equals("") ) { tmp = tmp + "\n\t\t*common*\n\t\t" + rev.get_commonstring(); } return tmp; } @) } ReadVertexVisitor { before UConstVertex (@ // if lookupvid is 0 then this traversal was called by PrintVertices if (lookupvid.intValue() == 0) { graphstring = graphstring + host.get_vertexname().get_name() + " "; graphstring = graphstring + "\t= " ; graphstring = graphstring + thegraph.FindEdge(host.get_vid().get_id(), new String("const") ); graphstring = graphstring + ".\n"; // this finds out if we need to insert a List(S) ~ {S}. at the bottom.. if (thegraph.FindEdge(host.get_vid().get_id(), new String("card")).equals("1")) { set_uppervalue(new Integer(1)); } // else this traversal was called by the EdgeVisitor } else if (host.get_vid().get_id().intValue() == lookupvid.intValue()){ graphstring = graphstring + host.get_vertexname().get_name(); } @) before UAltVertex (@ // if lookupvid is 0 then this traversal was called by PrintVertices if (lookupvid.intValue() == 0) { graphstring = graphstring + host.get_vertexname().get_name() + " "; graphstring = graphstring + "\t: " ; graphstring = graphstring + thegraph.FindEdge(host.get_vid().get_id(), new String("alt") ); graphstring = graphstring + ".\n"; // else this traversal was called by the EdgeVisitor } else if (host.get_vid().get_id().intValue() == lookupvid.intValue()){ graphstring = graphstring + host.get_vertexname().get_name() + " "; } @) } ReadEdgeVisitor { before UConstEdge (@ if (host.get_fromVertex().get_id().intValue() == lookupvid.intValue() ) { String wholevertex = new String(); String tovertex_st = new String(); // if coming from an alt class we need the *common* construct if (fromtype.equals("alt") ) { commonstring = commonstring + "<" + host.get_edgename().get_name() + "> " ; commonstring = commonstring + thegraph.FindVertex(host.get_toVertex().get_id()); } else { // we set the tovertex_st string to the vertex's name.. tovertex_st = thegraph.FindVertex(host.get_toVertex().get_id()); // then if the upper cardinality is "*", we enclose it in List().. if ( host.get_card().get_upper() != null && host.get_card().get_upper().get_u().equals("*") ) { wholevertex = "List(" + tovertex_st + ")"; // this switch lets the ReadVertexVisitor know it has to insert // a List(S) ~ {S} . at the end of the cd.. if (get_listswitch().intValue() == 0 ) { set_listswitch(new Integer(1) ); } } else { // otherwise, no List().. wholevertex = tovertex_st; } wholevertex = "<" + host.get_edgename().get_name() + "> " + wholevertex ; // if the lower cardinality is 0, we enclose the vertex in brackets.. if (host.get_card().get_lower().get_l().intValue() == 0) { wholevertex = "[" + wholevertex + "]"; } graphstring = graphstring + wholevertex + " "; } } @) before UAltEdge (@ if (host.get_fromVertex().get_id().intValue() == lookupvid.intValue() ) { if (this.get_pipeswitch().intValue() == 0 ) { set_pipeswitch(new Integer(1) ); } else { graphstring = graphstring + " | "; } graphstring = graphstring + thegraph.FindVertex(host.get_toVertex().get_id()); } @) } Main { (@ public static void main(String args[]) throws Exception { FileInputStream fi=new FileInputStream("uml.input"); UGraph graph = UGraph.parse(fi); System.out.println(graph.PrintVertices()); } @) }