// verbatim.beh // Last modified - Jun 12 '98 // Author - Not Applicable // last modified by Binoy // This is the pure java code for the classes involved in apstudio //*******************UGraph ********************************/ UGraph { (@ // Graph management and utility functions public int getSize(){return nameToIdVertexTable.size();} public void initialize() { set_idToVertexTable(new Hashtable()); set_idToEdgeTable(new Hashtable()); set_nameToIdVertexTable(new Hashtable()); } /** Remove all the nodes from this NetList. */ public void removeAll() { nameToIdVertexTable.clear(); idToVertexTable.clear(); idToEdgeTable.clear(); } public void clearTags() { for(Enumeration enum = idToVertexTable.elements();enum.hasMoreElements();) { UVertex uv = (UVertex)enum.nextElement(); uv.set_vdeco(new Decorator (new Integer(0) , new Vector())); } for(Enumeration enum = idToEdgeTable.elements();enum.hasMoreElements();) { UEdge ue = (UEdge)enum.nextElement(); ue.set_edeco(new Decorator (new Integer(0) , new Vector())); } } //add a UVertex into the UVertex_List public void add_uvertex(UVertex uvertex) { if(get_vertices() != null ) { Nonempty_UVertex_List newlist = new Nonempty_UVertex_List( uvertex , get_vertices().get_first()); get_vertices().set_first(newlist); //get a UVertexList, get a Nonempty_UvertexList , replace // old one with new one, it=uvertex , next = old_Ne_V_L } else { Nonempty_UVertex_List newlist = new Nonempty_UVertex_List( uvertex , null); set_vertices(new UVertex_List(newlist)); } } //add a UEdge into the UEdge_Lis public void add_uedge(UEdge uedge) { if(get_edges() != null ) { Nonempty_UEdge_List newlist = new Nonempty_UEdge_List( uedge , get_edges().get_first()); get_edges().set_first(newlist); //get a UEdgeList, get its Nonempty_UEdgeList , replace // old one with new one, it=uedge , next = old_Ne_V_L } else { Nonempty_UEdge_List newlist = new Nonempty_UEdge_List( uedge , null); set_edges(new UEdge_List(newlist)); } } // Underlying assumption in using hashtables as well as the way it is // implemented is that node/arc managements are infrequent. // Vertex/Node management below public void addNode(UVertex n) { String name = n.get_vertexname().get_name().toString(); UID id = n.get_vid(); // maps name and id. helpes to get id while knowing name in case of subgraph computation. nameToIdVertexTable.put(name,id); // archives the node idToVertexTable.put(id,n); } public UVertex getNode(UID id) { return (UVertex)idToVertexTable.get(id); } public void removeNode(UID id) { UVertex u = getNode(id); String name = u.get_vertexname().get_name().toString(); nameToIdVertexTable.remove(name); idToVertexTable.remove(id); } public Enumeration vertexEnum(){return idToVertexTable.elements();} public void modifyVertexName(String newName,UID id) { UVertex u=getNode(id); nameToIdVertexTable.remove(u.get_vertexname().get_name().toString()); u.set_vertexname(new UVertexName(new Ident(newName))); nameToIdVertexTable.put(newName,id); } public boolean checkThisOut(String name) { return nameToIdVertexTable.containsKey(name); } public UID nameToUID(String name) { return (UID)nameToIdVertexTable.get(name); } // Edge/Arc management below public void addArc(UEdge n) { idToEdgeTable.put(n.get_eid(),n); if(n instanceof UConstEdge) { if(((UConstEdge)n).get_edgename()!=null) { UID fromVertex = n.get_fromVertex(); String edgeLabel = ((UConstEdge)n).get_edgename().get_name().toString(); ((UConstOrAltVertex)getNode(fromVertex)).addEdgeName(edgeLabel); } } else { UID toVertex = n.get_toVertex(); getNode(toVertex).setMulInheritance(true); } } public UEdge getArc(UID id) { return (UEdge)idToEdgeTable.get(id); } /** Remove an arc by removing its entry from the connected vertices This methos is called from ArcPerspective#dispose*/ public void removeArc(UID id) { UEdge ue=getArc(id); UID fromVertex = ue.get_fromVertex(); UID toVertex = ue.get_toVertex(); getNode(fromVertex).removeOutArc(id); getNode(toVertex).removeInArc(id); if( ue instanceof UConstEdge) { if(((UConstEdge)ue).get_edgename() != null) { String edgeLabel = ((UConstEdge)ue).get_edgename().get_name().toString(); ((UConstOrAltVertex)getNode(fromVertex)).removeEdgeName(edgeLabel); } } else getNode(toVertex).setMulInheritance(false); idToEdgeTable.remove(id); } public Enumeration edgeEnum(){return idToEdgeTable.elements();} public void modifyEdgeName(String newName,UID id) { UEdge u=getArc(id); UID fromVertex = getArc(id).get_fromVertex(); String oldName = null; if(((UConstEdge)u).get_edgename() != null) oldName = ((UConstEdge)u).get_edgename().get_name().toString(); if( oldName!= null) { ((UConstOrAltVertex)getNode(fromVertex)).removeEdgeName(oldName); } if(newName!=null) { ((UConstEdge)u).set_edgename(new UEdgeName(new Ident(newName))); ((UConstOrAltVertex)getNode(fromVertex)).addEdgeName(newName); } else ((UConstEdge)u).set_edgename(null); } @) } //******************end class UGraph************************************/ //******************UVertex **************************************/ UVertex { (@ public static final int CONSTVERT = 0; public static final int ALTVERT = 1; public static final int INTERFACE = 2; public static final int TERM_CONST = 3; public static final int TERM_INTERFACE = 4; private boolean mulInheritance = false; public Rectangle getBoundingBox(){return get_persp().getBoundingBox();} public void setMulInheritance(boolean status) { mulInheritance = status; } public boolean isMultipleAlternation() { return mulInheritance; } /* public boolean isMultipleAlternation(Document d) { if(inArcList.size()<1) return false; else { for(Enumeration e=inArcList.elements();e.hasMoreElements();) { UEdge ue=d.net().getArc((UID)e.nextElement()); if(ue.get_persp().get_figure() instanceof FigAltEdge) return true; } return false; } } */ public void set_label(Document d,String name) { d.net().modifyVertexName(name,vid); } public void dispose(Document d) { System.out.println("Vertex disposing: " + toString()); d.net().removeNode(vid); } /** Add an arc by adding its entry into the connected vertices This methos is called from UEdge#connect*/ public void addInArc(UID in) { inArcIdList.addElement(in); } public void addOutArc(UID out) { outArcIdList.addElement(out); } /** Remove an arc by removing its entry from the connected vertices This methos is called from ArcPerspective#dispose*/ public void removeOutArc(UID id) { outArcIdList.removeElement(id); } public void removeInArc(UID id) { inArcIdList.removeElement(id); } /** Usually when nodes are created it is done through newInstance * and there is no chance to supply a default node or to connect * this node to some other application level object. So after a * node is constructed initialize is called to supply that * information.

* * Needs-More-Work: what is the class protocol design here? */ public void initialize(UVertex default_node,String name,Document d,Point p){} public void initialize(VertexInfo model,Document d,UID id) { } /** Add a perspective to my list of predefined perspectives. */ public void set_Perspective(Perspective p) {set_persp(p);} /** By default the zeroth perspective will be used */ public Perspective get_Perspective() { return get_persp();} UVertex(Ident name , UID _vid ) { set_vid( _vid); set_vertexname(new UVertexName(name)); //magic numbers 600 & 400 = screen x y max set_position(new Coordinates(new X(new Integer((int)(600 * Math.random()))),new Y(new Integer((int)(400 * Math.random()))))); set_incoming(new IEdge_List()); set_outgoing(new OEdge_List()); } //add a incoming UID into the UVetex::IEdge_List public void add_incoming(UID _uid) { UID uid = new UID(_uid.get_id()); if(get_incoming() != null ) {/* Nonempty_IEdge_List newlist = new Nonempty_IEdge_List ( uid , get_incoming().get_first()); get_incoming().set_first(newlist); */ //replace above code w/ line below get_incoming().addElement(uid); } else { Nonempty_IEdge_List newlist = new Nonempty_IEdge_List( uid , null); set_incoming(new IEdge_List(newlist)); } } public boolean delete_incoming(UID id) { if (get_incoming() ==null) return false; Nonempty_IEdge_List current = get_incoming().get_first(); Nonempty_IEdge_List prev=null; do { if(current.get_it().equals(id)) { if(prev==null) set_incoming(null); else prev.set_next(current.get_next()); return true; } prev=current; current=current.get_next(); }while(current!=null); return false; } //add a outgoing UID into the UVertex::OEdge_List public void add_outgoing(UID _uid) { UID uid = new UID(_uid.get_id()); if(get_outgoing() != null ) { /* Nonempty_OEdge_List newlist = new Nonempty_OEdge_List ( uid , get_outgoing().get_first()); get_outgoing().set_first(newlist); */ //replace above code w/ line below get_outgoing().addElement(uid); } else { Nonempty_OEdge_List newlist = new Nonempty_OEdge_List( uid , null); set_outgoing(new OEdge_List(newlist)); } } public boolean delete_outgoing(UID id) { if (get_outgoing() ==null) return false; Nonempty_OEdge_List current = get_outgoing().get_first(); Nonempty_OEdge_List prev=null; do { if(current.get_it().equals(id)) { if(prev==null) set_outgoing(null); else prev.set_next(current.get_next()); return true; } prev=current; current=current.get_next(); }while(current!=null); return false; } @) boolean isMarked() to Decorator { before Decorator(@ return_val = host.isMarked(); @) } } //******************end class UVertex **********************************/ //*********************** UConstOrAltVertex*****************************/ UConstOrAltVertex { (@ UConstOrAltVertex(Ident name , UID _vid , boolean bParse) { super(name,_vid); if(bParse) parse = new YaParse(); else parse = new NopParse(); } public void addEdgeName(String name) { outEdgeNameList.addElement(name); } public void removeEdgeName(String name) { outEdgeNameList.removeElement(name); } public boolean checkThisOut(String name) { return outEdgeNameList.contains(name); } @) } //*****************end class UconstOrAltVertex ***********************/ //******************UAltVertex************************************/ UAltVertex { (@ int insertion_pointer = 0; public void addAlternationVertex(UID eid) { outArcIdList.insertElementAt(eid,insertion_pointer++); } public void initialize(UVertex deft, String labelname,Document d,Point click) { set_vid(d.nextId()); buildPerspective(click.x,click.y,labelname,d); } public void initialize(VertexInfo vertexinfo,Document d,UID id) { String name = vertexinfo.get_name(); int x = vertexinfo.get_position().x; int y = vertexinfo.get_position().y; set_vid(id); buildPerspective(x,y,name,d); } private void buildPerspective(int x,int y,String name,Document d) { set_inArcIdList(new Vector()); set_outArcIdList(new Vector()); set_outEdgeNameList(new Vector()); setMulInheritance(false); int width,height; width=d.vertexSize().x; height=d.vertexSize().y; //Graphics g = d.getGraphics(); //g.setFont(d.getFont()); //FontMetrics fm =g.getFontMetrics(); int shoulder = 4; int colorBand = 15; FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(new Font("Times Roman",Font.ITALIC,12)); //width=Math.max(width,fm.stringWidth("<>")+shoulder); int stringWidth = fm.stringWidth(name)+shoulder; width = Math.max(width,stringWidth); int letterHeight = fm.getHeight(); //height = Math.max(height,2*letterHeight + colorBand + 2); height = Math.max(height,letterHeight + colorBand + 2); Integer x1 = new Integer(x); Integer y1 = new Integer(y); Integer x2 = new Integer(width); Integer y2 = new Integer(height); Color fill = (Color)d.getGraphicAttribute("FillColor"); Color border = (Color)d.getGraphicAttribute("LineColor"); Fig obj1 = new FigAltVert(x1, y1, x2, y2, border,fill, name); Perspective pers1 = new Perspective(this, obj1); pers1.position(x,y); set_persp(pers1); } UAltVertex(Name name , UID _vid , boolean bParse) { super(new Ident(name.toString()) , _vid , bParse); } @) } //******************end class UAltVertex*****************************/ //******************UInterface************************************/ UInterface { (@ // public void initialize(UVertex deft, String labelname,Document d,Point click) // { // set_vid(d.nextId()); // buildPerspective(click.x,click.y,labelname,d); // } // public void initialize(VertexInfo vertexinfo,Document d,UID id) // { // String name = vertexinfo.get_name(); // int x = vertexinfo.get_position().x; // int y = vertexinfo.get_position().y; // set_vid(id); // buildPerspective(x,y,name,d); // } // private void buildPerspective(int x,int y,String name,Document d) // { // set_inArcIdList(new Vector()); // set_outArcIdList(new Vector()); // set_outEdgeNameList(new Vector()); // setMulInheritance(false); // int width,height; // width=d.vertexSize().x; // height=d.vertexSize().y; // Graphics g = d.getGraphics(); // g.setFont(d.getFont()); // FontMetrics fm =g.getFontMetrics(); // // int shoulder = 4; // int colorBand = 15; // width=Math.max(width,fm.stringWidth("<>")+shoulder); // int stringWidth = fm.stringWidth(name)+shoulder; // // width = Math.max(width,stringWidth); // int letterHeight = fm.getHeight(); // height = Math.max(height,2*letterHeight + colorBand + 2); // // Integer x1 = new Integer(x); // Integer y1 = new Integer(y); // Integer x2 = new Integer(width); // Integer y2 = new Integer(height); // // Color fill = (Color)d.getGraphicAttribute("FillColor"); // Color border = (Color)d.getGraphicAttribute("LineColor"); // // Fig obj1 = new FigAltVert(x1, y1, x2, y2, border,fill, name); // Perspective pers1 = new Perspective(this, obj1); // pers1.position(x,y); // set_persp(pers1); // } // UInterface(Ident name , UID _vid) { super(name , _vid); } UInterface(Name name , UID _vid) { super(new Ident(name.toString()) , _vid); } @) } //******************end class UInterface*****************************/ //******************UConstVertex**********************************/ UConstVertex { (@ public boolean isBreakingRepetition() { // This is called when a new edge is being drawn if(get_outArcIdList().size() - get_outEdgeNameList().size() == 1) return true; return false; } public boolean isCrackingRepetition() { // This is called when user tries to modify the cardinality to 0..* or 1..* // If there are 2 or more outgoing edges then none of them can have multiple cardinality if(get_outArcIdList().size() >=2) return true; return false; } public void initialize(UVertex deft, String name,Document d,Point click) { set_vid(d.nextId()); buildPerspective(click.x,click.y,name,d); } public void initialize(VertexInfo vertexinfo,Document d,UID id) { int x = vertexinfo.get_position().x; int y = vertexinfo.get_position().y; String name = vertexinfo.get_name(); set_vid(id); buildPerspective(x,y,name,d); } private void buildPerspective(int x,int y,String name,Document d) { set_inArcIdList(new Vector()); set_outArcIdList(new Vector()); set_outEdgeNameList(new Vector()); setMulInheritance(false); int width,height; width=d.vertexSize().x; height=d.vertexSize().y; Graphics g = d.getGraphics(); g.setFont(d.getFont()); int maxnooflines, nooflines, letterHeight,stringWidth; FontMetrics fm =g.getFontMetrics(); int shoulder = 4; int colorBand = 15; stringWidth = fm.stringWidth(name)+shoulder; letterHeight = fm.getHeight(); width = Math.max(width,stringWidth); height = Math.max(height,letterHeight + colorBand + 2); Integer x2 = new Integer(width); Integer y2 = new Integer(height); Color fill = (Color)d.getGraphicAttribute("FillColor"); Color border = (Color)d.getGraphicAttribute("LineColor"); Integer x1=new Integer(x); Integer y1=new Integer(y); Fig obj1 = new FigConstVert(x1, y1, x2, y2, border, fill, name); Perspective pers1 = new Perspective(this, obj1); pers1.position(x,y); set_persp(pers1); } public void set_beforeSyntax(String s) { if(s==null) set_beFore(null); else set_beFore(new UBefore(new String(s))); } public void set_afterSyntax(String s) { if(s==null) set_afTer(null); else set_afTer(new UAfter(new String(s))); } public String get_beforeSyntax() { if(get_beFore()==null) return null; else return get_beFore().get_syntax(); } public String get_afterSyntax() { if(get_afTer()==null) return null; else return get_afTer().get_syntax(); } UConstVertex(Name name , UID _vid , boolean bParse) { super(new Ident(name.toString()) , _vid , bParse); } @) } //******************end class UConstVertex******************************/ //******************UTerm****************************************/ UTerm { (@ UTerm(Ident name , UID _vid) { super(name , _vid); } @) } //******************end class UTerm*************************************/ //******************UTermConstVertex****************************************/ UTermConstVertex { (@ UTermConstVertex(Name name , UID _vid) { super(new Ident(name.toString()) , _vid); } UTermConstVertex(Ident name , UID _vid) { super(name , _vid); } @) } //******************end class UTerm*************************************/ //******************UEdge**************************************/ UEdge { (@ public Rectangle getBoundingBox(){return get_persp().getBoundingBox();} public void set_label(Document d,String name) { d.net().modifyEdgeName(name,eid); } public Perspective get_sourcePerspective(Document d) { UVertex nn=d.net().getNode(fromVertex); return nn.get_Perspective(); } public Perspective get_destPerspective(Document d) { UVertex nn=d.net().getNode(toVertex); return nn.get_Perspective(); } /** Connect the source and destination ports, iff they agree to * being connected (i.e., canConnectTo() returns true). Reply true * on success. This method is normally called after a new arc * instance is made. Maybe this behavior should be in a constructor, * but I want to use Class#newInstancel so constructors do not get * any arguments. */ public void connect(UVertex s, UVertex d) { set_fromVertex(s.get_vid()); set_toVertex(d.get_vid()); s.addOutArc(eid); d.addInArc(eid); } public void connectAlternation(UVertex s, UVertex d) { set_fromVertex(s.get_vid()); set_toVertex(d.get_vid()); ((UAltVertex)s).addAlternationVertex(eid); d.addInArc(eid); } /** Remove this NetArc from the underlying connected graph model. */ public void dispose(Document d) { System.out.println("Arc disposing: " + toString()); if (get_fromVertex() != null && get_toVertex() != null) d.net().removeArc(eid); } UEdge(UID source_id , UID dest_id) { set_eid( UniqueIDGenerator.get_NextUnique() ); set_fromVertex(source_id); set_toVertex(dest_id); } @) boolean isMarked() to Decorator { before Decorator(@ return_val = host.isMarked(); @) } } //******************end class UEdge**********************************/ //******************UConstEdge************************************/ UConstEdge { (@ public void set_beforeSyntax(String s) { if(s==null) set_beFore(null); else set_beFore(new UBefore(new String(s))); } public void set_afterSyntax(String s) { if(s==null) set_afTer(null); else set_afTer(new UAfter(new String(s))); } public String get_beforeSyntax() { if(get_beFore()==null) return null; else return get_beFore().get_syntax(); } public String get_afterSyntax() { if(get_afTer()==null) return null; else return get_afTer().get_syntax(); } UConstEdge(UID source_id , UID dest_id , Ident partname ) { super( source_id , dest_id ); if(partname == null) partname = new Ident(" "); set_edgename(new UEdgeName(partname)); } @) } //******************end class UConstEdge********************************/ //******************USuperEdge**************************************/ USuperEdge { (@ USuperEdge(UID source_id , UID dest_id) { super( source_id , dest_id ); } @) } //******************end class USuperEdge**********************************/ //******************UAltEdge**************************************/ UAltEdge { (@ UAltEdge(UID source_id , UID dest_id) { super( source_id , dest_id ); } @) } //******************end class UAltEdge**********************************/ //******************UExtendEdge**************************************/ UExtendEdge { (@ UExtendEdge(UID source_id , UID dest_id) { super( source_id , dest_id ); } @) } //******************end class UExtendEdge**********************************/ //******************UImplEdge**************************************/ UImplEdge { (@ UImplEdge(UID source_id , UID dest_id) { super( source_id , dest_id ); } @) } //******************end class UImplEdge**********************************/ //******************UID**********************************/ UID { (@ public boolean equals(Object uid) { return this.get_id().equals(((UID)uid).get_id()); } public int hashCode() { return this.get_id().intValue(); } @) } //******************end class UID**********************************/ //******************UniqueIDGenerator**********************/ UniqueIDGenerator { (@ static UID uidgen = new UID(new Integer (0)); public static UID get_NextUnique() { UID olduid = uidgen ; uidgen = new UID (new Integer( uidgen.get_id().intValue() + 1 )); return olduid ; } @) } //******************end class UniqueIDGenerator**********************/ //******************IndependantTraversal**********************/ //IndependantTraversal //{ // (@ // public void add_bypassing(UID id) // { // if(get_bypassings() != null ) // { // Nonempty_UID_List newlist = new Nonempty_UID_List( id , get_bypassings().get_first()); // get_bypassings().set_first(newlist); // } // else // { // Nonempty_UID_List newlist = new Nonempty_UID_List( id , null); // set_bypassings(new UID_List(newlist)); // } // } // public void add_source(UID id) // { // SUID suid = new SUID(id); // if(get_sourceid() != null ) // { // Nonempty_SUID_List newlist = new Nonempty_SUID_List( suid ,get_sourceid().get_first()); // get_sourceid().set_first(newlist); // } // else // { // Nonempty_SUID_List newlist = new Nonempty_SUID_List( suid , null); // set_sourceid(new SUID_List(newlist)); // } // } // public void add_dest(UID id) // { // DUID duid=new DUID(id); // if(get_destid() != null ) // { // Nonempty_DUID_List newlist = new Nonempty_DUID_List( duid , get_destid().get_first()); // get_destid().set_first(newlist); // } // else // { // Nonempty_DUID_List newlist = new Nonempty_DUID_List( duid , null); // set_destid(new DUID_List(newlist)); // } // } // @) //} //******************end class IndependantTraversal**********************/ //*********************Coordinates************************************/ Coordinates { (@ Coordinates (int _x , int _y) { set_x(new X(new Integer(_x))); set_y(new Y(new Integer(_y))); } int get_xvalue() { return x.get_x().intValue(); } int get_yvalue() { return y.get_y().intValue(); } @) } //**************************end class Coordinates********************************************/ //*******************Decorator**********************/ Decorator { (@ boolean isSet(boolean flag) { if(flag) { if(travtag.equals(new Integer(1))) return true; } else { if(travtag.equals(new Integer(2)) || travtag.equals(new Integer(3))) return true; } return false; } void setMarked(int i) { switch(i) { case 0: case 1: case 2: case 3: travtag = new Integer(i); travtaglist = new Vector(); break; default :System.out.println("error value in decorator"); } } boolean isMarked() { return isSet(false); } void setMark(boolean flag) { if(flag) { travtag = new Integer(1); } else { switch(travtag.intValue()) { case 0 : case 2 :travtag = new Integer(2);break; case 1 : case 3 :travtag = new Integer(3);break; default :System.out.println("error value in decorator"); } } } @) } //******************end class Decorator*******************/ //******************ClassName PartName**********************************/ {ClassName , PartName, Name, UVertexName, UEdgeName} { (@ public boolean equals(Object cn) { return this.toString().equals(cn.toString()); } public int hashCode() { return this.toString().hashCode(); } @) } ClassName{ (@ public ClassName(Ident iname){ name = Name.parse(iname.toString()); } public String toString() { return this.get_name().toString(); } @) } PartName{ (@ public PartName(Ident iname){ name = new OtherIdent(iname); } @) public String toString() to OtherIdent { before OtherIdent(@ return_val = host.get_id().toString(); @) } } //******************end class ClassName PartName**********************************/ //***************************toString()**********************************/ { PackageName, Name } { public String toString() (@ return first.toString(); @) } { Nonempty_PackageName, Nonempty_Name } { public String toString() (@ return it + (next == null ? "" : "." + next); @) } OtherIdent { public String toString() (@ return id.toString(); @) } { UVertexName, UEdgeName } { public String toString() (@ return name.toString(); @) } //******************end toString()**********************************/