FileDocCategorySizeDatePackage
UseCaseExporter.javaAPI DocExample21403Tue Dec 08 01:21:00 GMT 1998oisoft.togetherx.scripts.Rose98Export

UseCaseExporter

public class UseCaseExporter extends Object
author
Eugene Belyaev
version
2.1.0

Fields Summary
private Optioner
optioner
private Writer
o
Constructors Summary
public UseCaseExporter(Optioner optioner)

		this.optioner = optioner;
		this.o = optioner.writer;
	
Methods Summary
public voidcreateStateDiagramAnchor(UMLStateDiagram usd)
creates an empty usecase to be an anchor for the hanging state diagram

			StateExporter se = new StateExporter(optioner);
			boolean wasVisual = optioner.isVisual;
			o.out( "(object UseCase " + o.makeString( usd.getName() + "_Anchor" ) );
			o.advance();
			o.out( "quid" + o.tab() + o.makeString( optioner.linker.genID() ) );
			optioner.isVisual = false;
			se.visitStateDiagram(usd);
			optioner.isVisual = true;
			se.visitStateDiagram(usd);
			optioner.isVisual = wasVisual;
			o.retreat();
			o.out( ")" );
	
private voidvisitActor(UMLActor ua)

		String quid = (String)optioner.linker.getQuidTable().get( ua.getQualifiedName() );
		String ref = (String)optioner.linker.getRefTable().get( optioner.CurrentDiagram + "#" + ua.getQualifiedName() + "#View" );
		java.awt.Rectangle rect = ua.getRectangle();
		int x = 0, y = 0;
		if( rect != null )
		{
			x = ( rect.x + rect.width / 2 ) * 3;
			y = ( rect.y + rect.height / 2 ) * 3;
		}
		if( optioner.isVisual )
		{
			if( optioner.isClassViewMode )
			{
				o.out( "(object ClassView " + o.makeString( "Class" ) + " " + o.makeString( o.makeRose98StyleQualifiedName( ua.getQualifiedName() ) ) + " @" + ref );
				o.advance();
				o.out( "IncludeAttribute" + o.tab() + o.makeBooleanString(true) );
				o.out( "IncludeOperation" + o.tab() + o.makeBooleanString(true) );
				o.out( "location" + o.tab() + "(" + x + ", " + y + ")" );
				o.out( "quidu" + o.tab() + o.makeString( quid ) );
				o.out( "annotation" + o.tab() + "8" );
				o.out( "autoResize" + o.tab() + o.makeBooleanString(true) );
				o.retreat();
				o.out( ")" ); // close ClassView
			} else
			{
				UMLCommunicationEnumeration uce = ua.getCommunications();
				while( uce.hasMoreElements() )
				{
					UMLCommunication ucomm = uce.getNextUMLCommunication();
					if( ucomm != null )
					{
						String ucommname = null;
						if( ucomm.getProperty("label") != null )
							ucommname = ucomm.getProperty("label");
						else
						ucommname = ucomm.getName();
						String assref = optioner.linker.getRefTable().get( ucomm.getQualifiedName() );
						UMLElement linkSource = ucomm.getLinkSource();
						String linkSourceQuid = optioner.linker.getQuidTable().get(linkSource.getQualifiedName());
						String linkSourceRoleQuid = optioner.linker.getQuidTable().get(ucomm.getQualifiedName() + "#Source" );
						UMLElement linkDest = ucomm.getLinkDestination();
						String linkDestQuid = optioner.linker.getQuidTable().get(linkDest.getQualifiedName());
						String linkDestRoleQuid = optioner.linker.getQuidTable().get(ucomm.getQualifiedName() + "#Dest" );
						o.out( "(object AssociationViewNew " + o.makeString( ucommname ) + " @" + assref );
						o.advance();
						String assQuid = (String)optioner.linker.getQuidTable().get( ucomm.getQualifiedName() );
						o.out( "quidu" + o.tab() + o.makeString( assQuid ) );
						o.out( "roleview_list" + o.tab() + "(list RoleViews" );
						o.advance();
						o.out( "(object RoleView " + o.makeString( linkSource.getName() ) + " @" + optioner.linker.genRef() );
						o.advance();
						o.out( "Parent_View" + o.tab() + "@" + assref );
						o.out( "quidu" + o.tab() + o.makeString( linkSourceRoleQuid ) );
						o.out( "client" + o.tab() + "@" + assref );
						String supplierRef = (String)optioner.linker.getRefTable().get( optioner.CurrentDiagram + "#" + linkSource.getQualifiedName() + "#View" );
						o.out( "supplier" + o.tab() + "@" + supplierRef );
						visitPoints( ucomm.getPoints() );
						o.out( "line_style" + o.tab() + "0" );
						o.retreat();
						o.out( ")" ); // close RoleView

						o.out( "(object RoleView " + o.makeString( linkDest.getName() ) + " @" + optioner.linker.genRef() );
						o.advance();
						o.out( "Parent_View" + o.tab() + "@" + assref );
						o.out( "quidu" + o.tab() + o.makeString( linkDestRoleQuid ) );
						o.out( "client" + o.tab() + "@" + assref );
						supplierRef = (String)optioner.linker.getRefTable().get( optioner.CurrentDiagram + "#" + linkDest.getQualifiedName() + "#View" );
						o.out( "supplier" + o.tab() + "@" + supplierRef );
						visitPoints( ucomm.getPoints() );
						o.out( "line_style" + o.tab() + "0" );
						o.retreat();
						o.out( ")" ); // close RoleView

						o.retreat();
						o.out( ")" ); // close roleview_list
						o.retreat();
						o.out( ")" ); // close AssociationViewNew
					}
				}
			}
		} else
		{
			if( ua.getProperty("alias") != null )
				o.out( "(object Class " + o.makeString( ua.getProperty("alias") ) );
			else
				o.out( "(object Class " + o.makeString( ua.getName() ) );
			o.advance();
			o.out( "quid" + o.tab() + o.makeString( quid ) );
			if( ua.getProperty("Documentation")!=null )
				o.out( "documentation" + o.tab() + o.makeLongString( ua.getProperty("Documentation") ) );
			else if( ua.getProperty(null)!=null )
				o.out( "documentation" + o.tab() + o.makeLongString( ua.getProperty(null) ) );
			o.out( "stereotype" + o.tab() + o.makeString( "Actor" ) );
			o.retreat();
			o.out( ")" );               // close Actor
			UMLCommunicationEnumeration uce = ua.getCommunications();
			while( uce.hasMoreElements() )
			{
				UMLCommunication ucomm = uce.getNextUMLCommunication();
				if( ucomm != null )
				{
					String ucommname = null;
					if( ucomm.getProperty("label") != null )
						ucommname = ucomm.getProperty("label");
					else
						ucommname = ucomm.getName();
					UMLElement linkSource = ucomm.getLinkSource();
					String linkSourceQuid = optioner.linker.getQuidTable().get(linkSource.getQualifiedName());
					String linkSourceRoleQuid = optioner.linker.getQuidTable().get(ucomm.getQualifiedName() + "#Source" );
					UMLElement linkDest = ucomm.getLinkDestination();
					String linkDestQuid = optioner.linker.getQuidTable().get(linkDest.getQualifiedName());
					String linkDestRoleQuid = optioner.linker.getQuidTable().get(ucomm.getQualifiedName() + "#Dest" );
					String assquid = (String)optioner.linker.getQuidTable().get( ucomm.getQualifiedName() );

					o.out( "(object Association " + o.makeString( ucommname ) );
					o.advance();
					o.out( "quid" + o.tab() + o.makeString( assquid ) );
					o.out( "roles" + o.tab() + "(list role_list" );
					o.advance();

					/* Source End */
					o.out( "(object Role " + o.makeString(null) );
					o.advance();
					o.out( "quid" + o.tab() + o.makeString( linkSourceRoleQuid ) );
					o.out( "quidu" + o.tab() + o.makeString( linkSourceQuid ) );
					o.retreat();
					o.out( ")" ); // close Role

					/* Dest End */
					o.out( "(object Role " + o.makeString(null) );
					o.advance();
					o.out( "quid" + o.tab() + o.makeString( linkDestRoleQuid ) );
					o.out( "quidu" + o.tab() + o.makeString( linkDestQuid ) );
					o.out( "is_navigable" + o.tab() + o.makeBooleanString(true) );
					o.retreat();
					o.out( ")" ); // close Role

					o.retreat();
					o.out( ")" ); // close roles
					o.retreat();
					o.out( ")" ); // close Association
				}
			}
		}
	
private voidvisitPoints(UMLPointEnumeration points)

		if( points.hasMoreElements() )
		{
			o.out( "vertices" + o.tab() + "(list Points" );
			o.advance();
			while( points.hasMoreElements() )
			{
				java.awt.Point point = points.getNextPoint();
				o.out( "(" + (point.x * 3) + ", " + (point.y * 3) + ")" );
			}
			o.retreat();
			o.out( ")" );
		}
 	
private voidvisitUseCase(UMLUseCase uuc)

		String quid = optioner.linker.getQuidTable().get( uuc.getQualifiedName() );
		String usecaseName = "";
		String ref = optioner.linker.getRefTable().get( optioner.CurrentDiagram + "#" + uuc.getQualifiedName() + "#View" );
		java.awt.Rectangle rect = uuc.getRectangle();
		int x = 0, y = 0, w = 225, h = 125;
		if( rect != null )
		{
			x = ( rect.x + rect.width / 2 ) * 3;
			y = ( rect.y + rect.height / 2 ) * 3;
		}

		if( uuc.getProperty("alias") != null )
			usecaseName = uuc.getProperty("alias");
		else
			usecaseName = uuc.getName();
		if( optioner.isVisual )
		{
			if( optioner.isClassViewMode )
			{
				o.out( "(object UseCaseView " + o.makeString(usecaseName) + " @" + ref );
				o.advance();
				o.out( "location" + o.tab() + "(" + x + ", " + y + ")" );
				o.out( "quidu" + o.tab() + o.makeString(quid) );
				o.out( "autoResize" + o.tab() + o.makeBooleanString(true) );
				o.retreat();
				o.out( ")" ); 			// close UseCaseView
			} else
			{
				UMLExtendsEnumeration uee = uuc.getExtendsRelationships();
				while( uee.hasMoreElements() )
				{
					UMLExtends uext = uee.getNextUMLExtends();
					if( uext != null )
					{
						UMLElement linkSource = uext.getLinkSource();
						UMLElement linkDest = uext.getLinkDestination();
						String supername = linkDest.getQualifiedName();
						String inhViewRef = optioner.linker.genRef();
						o.out( "(object InheritView " + o.makeString(null) + " @" + inhViewRef );
						o.advance();
						String inhQuidu = (String)optioner.linker.getQuidTable().get( uext.getQualifiedName() );
						o.out( "quidu" + o.tab() + o.makeString( inhQuidu ) );
						o.out( "stereotype" + o.tab() + "(object SegLabel @" + optioner.linker.genRef() );
						o.advance();
						o.out( "Parent_View" + o.tab() + "@" + inhViewRef );
						o.out( "label" + o.tab() + o.makeString("<<Extends>>") );
						o.retreat();
						o.out( ")" );
						o.out( "client" + o.tab() + "@" + ref );
						String supplier = (String)optioner.linker.getRefTable().get( optioner.CurrentDiagram + "#" + supername + "#View" );
						o.out( "supplier" + o.tab() + "@" + supplier );
						visitPoints( uext.getPoints() );
						o.out( "line_style" + o.tab() + "0" );
						o.retreat();
						o.out( ")" ); // close InheritView
					}
				}
				UMLUsesEnumeration uue = uuc.getUsesRelationships();
				while( uue.hasMoreElements() )
				{
					UMLUses uuses = uue.getNextUMLUses();
					if( uuses != null )
					{
						UMLElement linkSource = uuses.getLinkSource();
						UMLElement linkDest = uuses.getLinkDestination();
						String supername = linkDest.getQualifiedName();
						String inhViewRef = optioner.linker.genRef();
						o.out( "(object InheritView " + o.makeString(null) + " @" + inhViewRef );
						o.advance();
						String inhQuidu = (String)optioner.linker.getQuidTable().get( uuses.getQualifiedName() );
						o.out( "quidu" + o.tab() + o.makeString( inhQuidu ) );
						o.out( "stereotype" + o.tab() + "(object SegLabel @" + optioner.linker.genRef() );
						o.advance();
						o.out( "Parent_View" + o.tab() + "@" + inhViewRef );
						o.out( "label" + o.tab() + o.makeString("<<Uses>>") );
						o.retreat();
						o.out( ")" );
						o.out( "client" + o.tab() + "@" + ref );
						String supplier = (String)optioner.linker.getRefTable().get( optioner.CurrentDiagram + "#" + supername + "#View" );
						o.out( "supplier" + o.tab() + "@" + supplier );
						visitPoints( uuses.getPoints() );
						o.out( "line_style" + o.tab() + "0" );
						o.retreat();
						o.out( ")" ); // close InheritView
					}
				}

				UMLCommunicationEnumeration uce = uuc.getCommunications();
				if( uce != null )
				while( uce.hasMoreElements() )
				{
					UMLCommunication ucomm = uce.getNextUMLCommunication();
					if( ucomm != null )
					{
						String ucommname = null;
						if( ucomm.getProperty("label") != null )
							ucommname = ucomm.getProperty("label");
						else
							ucommname = ucomm.getName();
						String assref = optioner.linker.getRefTable().get( ucomm.getQualifiedName() );
						UMLElement linkSource = ucomm.getLinkSource();
						String linkSourceQuid = optioner.linker.getQuidTable().get(linkSource.getQualifiedName());
						String linkSourceRoleQuid = optioner.linker.getQuidTable().get(ucomm.getQualifiedName() + "#Source" );
						UMLElement linkDest = ucomm.getLinkDestination();
						String linkDestQuid = optioner.linker.getQuidTable().get(linkDest.getQualifiedName());
						String linkDestRoleQuid = optioner.linker.getQuidTable().get(ucomm.getQualifiedName() + "#Dest" );
						o.out( "(object AssociationViewNew " + o.makeString( ucommname ) + " @" + assref );
						o.advance();
						String assQuid = (String)optioner.linker.getQuidTable().get( ucomm.getQualifiedName() );
						o.out( "quidu" + o.tab() + o.makeString( assQuid ) );
						o.out( "roleview_list" + o.tab() + "(list RoleViews" );
						o.advance();
						o.out( "(object RoleView " + o.makeString( linkSource.getName() ) + " @" + optioner.linker.genRef() );
						o.advance();
						o.out( "Parent_View" + o.tab() + "@" + assref );
						o.out( "quidu" + o.tab() + o.makeString( linkSourceRoleQuid ) );
						o.out( "client" + o.tab() + "@" + assref );
						String supplierRef = (String)optioner.linker.getRefTable().get( optioner.CurrentDiagram + "#" + linkSource.getQualifiedName() + "#View" );
						o.out( "supplier" + o.tab() + "@" + supplierRef );
						visitPoints( ucomm.getPoints() );
						o.out( "line_style" + o.tab() + "0" );
						o.retreat();
						o.out( ")" ); // close RoleView

						o.out( "(object RoleView " + o.makeString( linkDest.getName() ) + " @" + optioner.linker.genRef() );
						o.advance();
						o.out( "Parent_View" + o.tab() + "@" + assref );
						o.out( "quidu" + o.tab() + o.makeString( linkDestRoleQuid ) );
						o.out( "client" + o.tab() + "@" + assref );
						supplierRef = (String)optioner.linker.getRefTable().get( optioner.CurrentDiagram + "#" + linkDest.getQualifiedName() + "#View" );
						o.out( "supplier" + o.tab() + "@" + supplierRef );
						visitPoints( ucomm.getPoints() );
						o.out( "line_style" + o.tab() + "0" );
						o.retreat();
						o.out( ")" ); // close RoleView

						o.retreat();
						o.out( ")" ); // close roleview_list
						o.retreat();
						o.out( ")" ); // close AssociationViewNew
					}
				}
			}
		} else {
			o.out( "(object UseCase " + o.makeString( usecaseName ) );
			o.advance();
			o.out( "quid" + o.tab() + o.makeString( quid ) );
			if( uuc.getProperty("Documentation")!=null )
				o.out( "documentation" + o.tab() + o.makeLongString( uuc.getProperty("Documentation") ) );
			else if( uuc.getProperty(null)!=null )
				o.out( "documentation" + o.tab() + o.makeLongString( uuc.getProperty(null) ) );
			if ( uuc.getProperty("stereotype")!=null ) {
				o.out( "stereotype" + o.tab() + o.makeString( uuc.getProperty("stereotype") ) );
			}

			UMLExtendsEnumeration uee = uuc.getExtendsRelationships();
			UMLUsesEnumeration uue = uuc.getUsesRelationships();

			boolean superclassesadded = false;

			if( uee.hasMoreElements() || uue.hasMoreElements() )
			{
				o.out( "superclasses" + o.tab() + "(list inheritance_relationship_list" );
				o.advance();
				superclassesadded = true;
			}
			while( uee.hasMoreElements() )
			{
				UMLExtends uext = uee.getNextUMLExtends();
				if( uext != null )
				{
					o.out( "(object Inheritance_Relationship" );
					o.advance();
					String inhQuid = optioner.linker.getQuidTable().get( uext.getQualifiedName() );
					o.out( "quid" + o.tab() + o.makeString( inhQuid ) );
					o.out( "quidu" + o.tab() + o.makeString( (String)optioner.linker.getQuidTable().get( uext.getLinkDestination().getQualifiedName() ) ) );
					o.out( "stereotype" + o.tab() + o.makeString("Extends") );
					o.retreat();
					o.out( ")" ); // close Inheritance_Relationship
				}
			}
			while( uue.hasMoreElements() )
			{
				UMLUses uuses = uue.getNextUMLUses();
				if( uuses != null )
				{
					o.out( "(object Inheritance_Relationship" );
					o.advance();
					String inhQuid = optioner.linker.getQuidTable().get( uuses.getQualifiedName() );
					o.out( "quid" + o.tab() + o.makeString( inhQuid ) );
					o.out( "quidu" + o.tab() + o.makeString( (String)optioner.linker.getQuidTable().get( uuses.getLinkDestination().getQualifiedName() ) ) );
					o.out( "stereotype" + o.tab() + o.makeString("Uses") );
					o.retreat();
					o.out( ")" ); // close Inheritance_Relationship
				}
			}
			if (superclassesadded)
			{
				o.retreat();
				o.out( ")" );
			}
			o.retreat();
			o.out( ")" ); // close UseCase
			UMLCommunicationEnumeration uce = uuc.getCommunications();
			while( uce.hasMoreElements() )
			{
				UMLCommunication ucomm = uce.getNextUMLCommunication();
				if( ucomm != null )
				{
					String ucommname = null;
					if( ucomm.getProperty("label") != null )
						ucommname = ucomm.getProperty("label");
					else
						ucommname = ucomm.getName();
					UMLElement linkSource = ucomm.getLinkSource();
					String linkSourceQuid = optioner.linker.getQuidTable().get(linkSource.getQualifiedName());
					String linkSourceRoleQuid = optioner.linker.getQuidTable().get(ucomm.getQualifiedName() + "#Source" );
					UMLElement linkDest = ucomm.getLinkDestination();
					String linkDestQuid = optioner.linker.getQuidTable().get(linkDest.getQualifiedName());
					String linkDestRoleQuid = optioner.linker.getQuidTable().get(ucomm.getQualifiedName() + "#Dest" );
					String assquid = (String)optioner.linker.getQuidTable().get( ucomm.getQualifiedName() );

					o.out( "(object Association " + o.makeString( ucommname ) );
					o.advance();
					o.out( "quid" + o.tab() + o.makeString( assquid ) );
					o.out( "roles" + o.tab() + "(list role_list" );
					o.advance();

					/* Source End */
					o.out( "(object Role " + o.makeString(null) );
					o.advance();
					o.out( "quid" + o.tab() + o.makeString( linkSourceRoleQuid ) );
					o.out( "quidu" + o.tab() + o.makeString( linkSourceQuid ) );
					o.retreat();
					o.out( ")" ); // close Role

					/* Dest End */
					o.out( "(object Role " + o.makeString(null) );
					o.advance();
					o.out( "quid" + o.tab() + o.makeString( linkDestRoleQuid ) );
					o.out( "quidu" + o.tab() + o.makeString( linkDestQuid ) );
					o.out( "is_navigable" + o.tab() + o.makeBooleanString(true) );
					o.retreat();
					o.out( ")" ); // close Role

					o.retreat();
					o.out( ")" ); // close roles
					o.retreat();
					o.out( ")" ); // close Association
				}
			}
		}
	
public voidvisitUseCaseDiagram(UMLUseCaseDiagram uucd)

		optioner.CurrentDiagram = uucd.getQualifiedName();
		String diagramName = "";
		String quid = optioner.linker.getQuidTable().get( uucd.getQualifiedName() );
		if( uucd.getProperty("alias") != null )
		{
			diagramName = uucd.getProperty("alias");
		} else
		{
			diagramName = uucd.getName();
		}
		if( optioner.isVisual )
		{
			o.out( "(object UseCaseDiagram " + o.makeString( diagramName ) );
			o.advance();
			o.out( "quid" + o.tab() + o.makeString( optioner.linker.genID() ) );
			if( uucd.getProperty("Documentation")!=null )
				o.out( "documentation" + o.tab() + o.makeLongString( uucd.getProperty("Documentation") ) );
			else if( uucd.getProperty(null)!=null )
				o.out( "documentation" + o.tab() + o.makeLongString( uucd.getProperty(null) ) );
			o.out( "items" +o.tab() + "(list diagram_item_list" );
			o.advance();

			/* class views (actor views) */
			optioner.isClassViewMode = true;
			UMLActorEnumeration uae = uucd.getActors();
			while( uae.hasMoreElements() )
			{
				UMLActor ua = uae.getNextUMLActor();
					visitActor( ua );
			}

			/* UseCase views */
			optioner.isClassViewMode = true;
			UMLUseCaseEnumeration uuce = uucd.getUseCases();
			while( uuce.hasMoreElements() ) {
				UMLUseCase uuc = uuce.getNextUMLUseCase();
				if( uuc != null )
				{
					visitUseCase( uuc );
				}
			}

			/* actor links */
			optioner.isClassViewMode = false;
			uae = uucd.getActors();
			while( uae.hasMoreElements() )
			{
				UMLActor ua = uae.getNextUMLActor();
					visitActor( ua );
			}

			/* usecase links */
			optioner.isClassViewMode = false;
			uuce = uucd.getUseCases();
			while( uuce.hasMoreElements() )
			{
				UMLUseCase uuc = uuce.getNextUMLUseCase();
				if( uuc != null )
				{
					visitUseCase( uuc );
				}
			}

			o.retreat();
			o.out( ")" ); // close items
			o.retreat();
			o.out( ")" ); // close ClassDiagram

		} else
		{
			UMLUseCaseEnumeration uuce = uucd.getUseCases();
			while( uuce.hasMoreElements() )
			{
				UMLUseCase uuc = uuce.getNextUMLUseCase();
				if( uuc != null )
				{
					visitUseCase( uuc );
				}
			}

			UMLActorEnumeration uae = uucd.getActors();
			while( uae.hasMoreElements() )
			{
				UMLActor ua = uae.getNextUMLActor();
				if( ua != null )
				{
					visitActor( ua );
				}
			}
		}