/** The Arc class represents a connection between two locations, based on the XArc spec.
* Note that Arcs are 'smashed flat' - it's up to the Link class to 'resolve' link sets into individual arcs and add them to LinkSet objects.
* @version 0.12 - Last Modified 12/18/98
* Copyright 1998 Simon St.Laurent
* Information on XArc is at http://www.jfinity.com/xarc/
* Information at: http://www.simonstl.com/projects/xlinkfilter/
* This code is licensed by Simon St.Laurent under the Mozilla Public License.
* See http://www.mozilla.org/MPL/ for details.
* No warranty provided - use at your own risk */

/* Modification history
* 12/15/98 - Created Arc as a simplification of Link.  Link will now extend Arc. - Simon St.Laurent
* 12/16/98 - Added setFrom and setTo methods (to provide greater support of transformed trees) and convenience getOriginURL-getDestLoc methods. -SSL
* 12/16/98 - Moved role and title information to resources.  Supported old versions of that functionality, however. -SSL
* 12/18/98 - Added lots of set methods I'd forgotten. Fixed two-argument constructor. -SSL
* 12/18/98 - Added element name to Arc, provided equality tests with and without element name having importance. -SSL
*/

package com.simonstl.sax.xlink;

public class Arc {
/* from and to identify resources connected by Arc */
	protected XResource from, to;
/* other values provide Arc description */
	protected String declaringElement, 
			destShow,
			destActuate,
			destBehavior,
			type, originalType;

/**empty constructor
will need to use set method calls.
*/

public Arc() {

}

/**short constructor
Note that all Arcs using this version are assumed to have no show, actuate, or behavior.
*/
public Arc(XResource from, XResource to, String element) {
		this.from=from;
		this.to=to;
		this.declaringElement=element;
		this.destShow=null;
		this.destActuate=null;
		this.destBehavior=null;
		this.type="arc";
		this.originalType="arc";
	}

/**long constructor
This version provides access to all fields of the Arc class and is the version used by the XLinkFilter and Link classes.
*/
	public Arc(XResource from, XResource to,  String element,
		String destShow, String destActuate,
		String destBehavior) {
		
		this.from=from;
		this.to=to;
		this.declaringElement=element;
		
		this.destShow=destShow;
		this.destActuate=destActuate;
		this.destBehavior=destBehavior;
		this.type="arc";
		this.originalType="arc";
		
    	}

	public XResource getFrom() {return from;}
	
	public XResource getTo() {return to;}
	
	public void setFrom(XResource newFrom) {
	    from=newFrom;
	}
	
	public void setTo(XResource newTo) {
	    to=newTo;
	}	

	public String getDeclElement() {return declaringElement;}
	
	public void setDeclElement(String elementName) {
	    declaringElement=elementName;
	}

	public String getDestShow() {return destShow;}
	
	public void  setDestShow(String newShow) {
	    destShow=newShow;
	}

	public String getDestActuate() {return destActuate;}

	public void  setDestActuate(String newActuate) {
	    destActuate=newActuate;
	}

	public String getDestBehavior() {return destBehavior;}
	
	public void setDestBehavior(String newBehavior) {
		    destBehavior=newBehavior;
	}

	public String getType() {return type;}
	
	public void setType(String newType) {
	    type=newType;
	}
	
	public String getOriginalType() {return originalType;}
	
	public void setOriginalType(String newOriginalType) {
	    originalType=newOriginalType;
	}
	
/*The following methods are convenience methods so that calling applications don't need to know about the XResource
object if they don't want to.
*/
	public String getOriginURL() {return from.getURL();}

	public String getOriginConnect() {return from.getConnect();}

	public String getOriginLoc() {return from.getLoc();}
	
	public String getDestURL() {return to.getURL();}

	public String getDestConnect() {return to.getConnect();}
	
	public String getDestLoc() {return to.getLoc();}
	
	public String getOriginContentTitle() {return from.getTitle();}

	public String getOriginContentRole() {return from.getRole();}

	public void setOriginContentTitle(String newTitle) {from.setTitle(newTitle);}

	public void setOriginContentRole(String newRole) {from.setRole(newRole);}
	
	public String getDestRole() {return to.getTitle();}

	public String getDestTitle() {return to.getRole();}

	public void setDestContentTitle(String newTitle) {to.setTitle(newTitle);}

	public void setDestContentRole(String newRole) {to.setRole(newRole);}

	public boolean equals (Arc compareArc) {
	    XResource thatFrom, thatTo;
	    String thatFromURL, thatToURL, thisFromURL, thisToURL;
	    thatFrom=compareArc.getFrom();
	    thatTo=compareArc.getTo();
	    
	    if ((from.equals(thatFrom)) &&
	        (to.equals(thatTo)) &&
		(compareArc.getDestShow().equals(destShow)) &&
		(compareArc.getDestActuate().equals(destActuate)) &&
		(compareArc.getDestBehavior().equals(destBehavior)) &&	
		(compareArc.getType().equals(type)))
	    {
		return true;
	    }
	    else {
		return false;
	    }
	}

	public boolean equals (Arc compareArc, boolean elementMatters) {
	    if ( 
		(this.equals(compareArc)) && 
		(  (compareArc.getDeclElement().equals(declaringElement)) || (!(elementMatters))  )
		)
	    {	
		return true;
	    
	    }
	    else {
		return false;
	    }
	}

    public LinkSet resolve() {
	LinkSet tempLinkSet=new LinkSet();
	tempLinkSet.addArc(this);
	return tempLinkSet;
    }
	
//utility methods
	public void print() {
System.out.println("Origin URL:"+from.getFullURL());
System.out.println("Declaring Element Name:"+declaringElement);

System.out.println("Origin Content-Role:"+getOriginContentRole());
System.out.println("Origin Content-Title:"+getOriginContentTitle());

System.out.println("Dest URL:"+to.getFullURL());
System.out.println("Dest Role:"+getDestRole());
System.out.println("Dest Title:"+getDestTitle());

System.out.println("Dest Show:"+destShow);
System.out.println("Dest Actuate:"+destActuate);
System.out.println("Dest Behavior:"+destBehavior);

System.out.println("Type:"+type);
System.out.println("------------------------");
	}
}