FileDocCategorySizeDatePackage
Linker.javaAPI DocExample9569Tue Dec 08 01:21:00 GMT 1998oisoft.togetherx.scripts.Rose98Export

Linker

public class Linker extends Object
author
Eugene Belyaev
version
2.1.0

Fields Summary
private long
myID
private long
myRef
private QuidTable
quidTable
private RefTable
refTable
private String
CurrentDiagram
private Optioner
optioner
Constructors Summary
public Linker(UMLElement rootElement, Optioner optioner)


	      
	
		this.optioner = optioner;
		if( rootElement != null )
			visitUMLElement( rootElement );
	
Methods Summary
public java.lang.StringgenID()

		StringBuffer idStr = new StringBuffer( "EB0000000000" );
		String numStr = Long.toString( myID, 16 );
		for( int i = 0; i < numStr.length(); i++ )
			idStr.setCharAt( 12-numStr.length()+i, numStr.charAt(i) );
		myID++;
		return idStr.toString();
	
public java.lang.StringgenRef()

		return Long.toString( myRef++ );
	
public QuidTablegetQuidTable()

		return quidTable;
	
public RefTablegetRefTable()

		return refTable;
	
private voidvisitUMLElement(UMLElement UMLelement)

		String quid, ref;

		/* put the element to the table with quid generated */
		quid = genID();
		quidTable.put( UMLelement.getQualifiedName(), quid );
		Reporter.Info("quid: " + quid + " for " + UMLelement.getQualifiedName());

		/* put the element to the table with ref generated */
		ref = genRef();
		refTable.put( UMLelement.getQualifiedName(), ref );

		if( (UMLelement instanceof UMLClass) || (UMLelement instanceof UMLInterface) ||
		    (UMLelement instanceof UMLState) || (UMLelement instanceof UMLObject) ||
			(UMLelement instanceof UMLUseCase) || (UMLelement instanceof UMLActor))
		{
			/* put the element to the table with ref generated */
			ref = genRef();
			Reporter.Info( CurrentDiagram + "#" + UMLelement.getQualifiedName() + "#View" );
			refTable.put( CurrentDiagram + "#" + UMLelement.getQualifiedName() + "#View" , ref );
		}

		if(UMLelement instanceof UMLInteractionDiagram)
		{
			/* put the element to the table with ref generated */
			ref = genRef();
			Reporter.Info( UMLelement.getQualifiedName() + "#Mechanism" );
			refTable.put( UMLelement.getQualifiedName() + "#Mechanism" , ref );
		}

		if( UMLelement instanceof UMLClassifier && !(UMLelement instanceof UMLActor))
		{

			UMLAssociationEnumeration qae = ((UMLClassifier)UMLelement).getAssociations();
			while( qae.hasMoreElements() )
			{
				UMLAssociation qa = qae.getNextUMLAssociation();
				if( qa != null )
				{
					quid = genID();
					quidTable.put( qa.getQualifiedName(), quid );
					ref = genRef();
					refTable.put( qa.getQualifiedName(), ref );

					UMLAssociationEnd qaend;
					qaend = qa.getSourceAssociationEnd();
					if( qaend != null )
					{
						quid = genID();
						quidTable.put( qa.getQualifiedName() + "#" + qaend.getQualifiedName() + "#Source", quid );
						ref = genRef();
						refTable.put( qa.getQualifiedName() + "#" + qaend.getQualifiedName() + "#Source" , ref );
					}
					qaend = qa.getDestAssociationEnd();
					if( qaend != null )
					{
						quid = genID();
						quidTable.put( qa.getQualifiedName() + "#" + qaend.getQualifiedName() + "#Dest", quid );
						ref = genRef();
						refTable.put( qa.getQualifiedName() + "#" + qaend.getQualifiedName() + "#Dest" , ref );
					}
				}
			}
		}

		if (UMLelement instanceof UMLActor)
		{
			UMLCommunicationEnumeration uce = ((UMLActor)UMLelement).getCommunications();
			while( uce.hasMoreElements() )
			{
				UMLCommunication ucomm = uce.getNextUMLCommunication();
				if( ucomm != null )
				{
					UMLElement linkSource = null;
					UMLElement linkDestination = null;
					linkSource = ucomm.getLinkSource();
					linkDestination = ucomm.getLinkDestination();
					quid = genID();
					quidTable.put( ucomm.getQualifiedName(), quid );
					ref = genRef();
					refTable.put( ucomm.getQualifiedName(), ref );
					if (linkSource != null)
					{
						quid = genID();
						quidTable.put(ucomm.getQualifiedName() + "#Source", quid );
						ref = genRef();
						refTable.put(ucomm.getQualifiedName() + "#Source", ref );
					}
					if (linkDestination != null)
					{
						quid = genID();
						quidTable.put(ucomm.getQualifiedName() + "#Dest", quid );
						ref = genRef();
						refTable.put(ucomm.getQualifiedName() + "#Dest", ref );
					}
				}
			}
		}

		if (UMLelement instanceof UMLUseCase)
		{
			UMLExtendsEnumeration uee = ((UMLUseCase)UMLelement).getExtendsRelationships();
			while (uee.hasMoreElements())
			{
				UMLExtends uext = uee.getNextUMLExtends();
				if( uext != null )
				{
						quid = genID();
						quidTable.put(uext.getQualifiedName(), quid );
						quid = genID();
						quidTable.put(uext.getQualifiedName() + "#Source", quid );
						ref = genRef();
						refTable.put(uext.getQualifiedName() + "#Source", ref );
						quid = genID();
						quidTable.put(uext.getQualifiedName() + "#Dest", quid );
						ref = genRef();
						refTable.put(uext.getQualifiedName() + "#Dest", ref );
				}
			}
			UMLUsesEnumeration uue = ((UMLUseCase)UMLelement).getUsesRelationships();
			while (uue.hasMoreElements())
			{
				UMLUses uuses = uue.getNextUMLUses();
				if( uuses != null )
				{
						quid = genID();
						quidTable.put(uuses.getQualifiedName(), quid );
						quid = genID();
						quidTable.put(uuses.getQualifiedName() + "#Source", quid );
						ref = genRef();
						refTable.put(uuses.getQualifiedName() + "#Source", ref );
						quid = genID();
						quidTable.put(uuses.getQualifiedName() + "#Dest", quid );
						ref = genRef();
						refTable.put(uuses.getQualifiedName() + "#Dest", ref );
				}
			}
			UMLCommunicationEnumeration uce = ((UMLUseCase)UMLelement).getCommunications();
			while( uce.hasMoreElements() )
			{
				UMLCommunication ucomm = uce.getNextUMLCommunication();
				if( ucomm != null )
				{
					UMLElement linkSource = null;
					UMLElement linkDestination = null;
					linkSource = ucomm.getLinkSource();
					linkDestination = ucomm.getLinkDestination();
					quid = genID();
					quidTable.put( ucomm.getQualifiedName(), quid );
					ref = genRef();
					refTable.put( ucomm.getQualifiedName(), ref );
					if (linkSource != null)
					{
						quid = genID();
						quidTable.put(ucomm.getQualifiedName() + "#Source", quid );
						ref = genRef();
						refTable.put(ucomm.getQualifiedName() + "#Source", ref );
					}
					if (linkDestination != null)
					{
						quid = genID();
						quidTable.put(ucomm.getQualifiedName() + "#Dest", quid );
						ref = genRef();
						refTable.put(ucomm.getQualifiedName() + "#Dest", ref );
					}
				}
			}
		}

		if (UMLelement instanceof UMLInteractionDiagram)
		{
			ref = genRef();
			refTable.put(UMLelement.getQualifiedName() + "#Mechanism", ref );
		}

		if (UMLelement instanceof UMLStateDiagram)
		{
			quid = genID();
			quidTable.put(UMLelement.getQualifiedName() + "#State_Machine", quid );
		}

		if (UMLelement instanceof UMLState)
		{
			UMLTransitionEnumeration ute = ((UMLState)UMLelement).getTransitions();
			if( ute.hasMoreElements() )
			{
				while( ute.hasMoreElements() )
				{
					UMLTransition ut = ute.getNextUMLTransition();
					if( ut != null )
					{
						ref = genRef();
						refTable.put(ut.getQualifiedName(), ref );
						//Reporter.Remind("Generated ref for transition: " + ref );
						quid = genID();
						quidTable.put(ut.getQualifiedName(), quid );
					}
				}
			}
			UMLStateEnumeration substates = ((UMLState)UMLelement).getSubstates();
			while (substates.hasMoreElements())
			{
				visitUMLElement( substates.getNextUMLState() );
			}
		}

		if (UMLelement instanceof UMLObject)
		{
			UMLObject obj = (UMLObject)UMLelement;
			UMLLiferectEnumeration qlre = obj.getLiferects();
			while( qlre.hasMoreElements() )
			{
				UMLLiferect qlr = qlre.getNextUMLLiferect();
				if( qlr != null )
				{
					quid = genID();
					quidTable.put(qlr.getQualifiedName(), quid );
					ref = genRef();
					refTable.put(qlr.getQualifiedName(), ref );
					UMLMessageEnumeration qme = qlr.getOutgoingMessages();
					while( qme.hasMoreElements() )
					{
						UMLMessage qm = qme.getNextUMLMessage();
						if (qm != null)
						{
							quid = genID();
							quidTable.put(qm.getQualifiedName(), quid );
							ref = genRef();
							refTable.put(qm.getQualifiedName(), ref );
						}
					}
				}
			}
		}
		/* iterate through the packages */
		if( UMLelement instanceof UMLPackage )
		{
			String oldDiagram = null;
			optioner.packageCount++;
			//if( UMLelement instanceof UMLClassDiagram )
			//{
				oldDiagram = CurrentDiagram;
				//CurrentDiagram = ((UMLClassDiagram)UMLelement).getQualifiedName();
				CurrentDiagram = UMLelement.getQualifiedName();
			//}
			UMLElementEnumeration qee = ((UMLPackage)UMLelement).getAllElements();
			while( qee.hasMoreElements() )
			{
				UMLElement qe = qee.getNextUMLElement();
				if( qe != null )
					visitUMLElement( qe );
			}
			//if( UMLelement instanceof UMLClassDiagram )
				CurrentDiagram = oldDiagram;
		}