#**### params: source, target, elem
#**###----- $target and $source are instances of UMLObject to which $elem is connected
#**###----- they are put into the context of this script by LinkCodeWriter
#**##set( $link = $elem )
#**##set( $path = $link.Expression )
#**##set( $range = $mofutility.nullIfEmpty($link.getRange()) )
#**##set( $reflective = $link.isReflective())
#**###------------------------------------------------------------
#**###if use of field "range" for ordered or qualified assoc, ensure the source and target
#*   *##if($range)
#*      *#	#set( $rangeIsInteger = $mofutility.isInteger($range))
#*      *#	#if( $rangeIsInteger)
#*         *#		## range integer --> ordered?
#*         *#		#set( $roleTemp = $link.getCorrespondingRole($target))
#*         *#		#if(!$mofutility.isOrdered($roleTemp))
#*            *#			#set( $roleTemp = $link.getCorrespondingRole($source))
#*            *#			#if($mofutility.isOrdered($roleTemp))
#*               *#				## source and target must be switched
#*               *#				#set($temp = $source)
#*               *#				#set($source = $target)
#*               *#				#set($target = $temp)
#*            *#			#end
#*         *#		#end
#*      *#	#else
#*         *#		## range not integer --> qualified?
#*         *#		#set( $roleTemp = $link.getCorrespondingRole($target))
#*         *#		#if(!$roleTemp.Qualifier)
#*            *#			#set( $roleTemp = $link.getCorrespondingRole($source))
#*            *#			#if($roleTemp.Qualifier)
#*               *#				## source and target must be switched
#*               *#				#set($temp = $source)
#*               *#				#set($source = $target)
#*               *#				#set($target = $temp)
#*            *#			#else
#*               *#				## range field used with no reason
#*               *#				#set($range = "")
#*            *#			#end
#*         *#		#end
#*      *#	#end
#*   *##end
#*   *###----------------------------------------------
#*   *#
#*   *##set( $linkNegative = $link.Type == 1 )
#*   *##set( $targetNegative = $target.Type == 2 )
#*   *##if( !$path )
#*      *#	#set( $role = $link.getCorrespondingRole($target) )
#*      *#	#set( $ordered = $mofutility.isOrdered($role) )
#*      *#	#set( $targetRoleName = $mofutility.upFirstChar($role.getAttrName()) )
#*      *#	#set( $partnerRole = $role.PartnerRole )
#*      *#	#set( $toOne = $role.card.upperBound == 1 && !$partnerRole.qualifier  )
#*   *##end
#*   *###----------
#*   *##set( $targetName = $target.getObjectName() )
#*   *##set( $fullJavaNameOfTargetType = $mofutility.getQualifiedName($target.InstanceOf))
#*   *###----- BEGIN MOF Facility specific
#*   *#	#set($isTargetTypeReference = "false")
#*   *#	#set($isFullJavaNameOfTargetTypeGiven = "false")
#*   *#	#set($isRepositoryKeyOfTargetTypeGiven = "false")
#*   *#	#set($targetTypeTagCollection = $target.InstanceOf.Type.Adaptee.Tag)
#*   *#	#foreach($actualTag in $targetTypeTagCollection)
#*      *#		#if($actualTag.Name.equals("stereotype") && $actualTag.value.equals("reference"))
#*         *#			#set($isTargetTypeReference = "true")
#*      *#		#elseif($actualTag.Name.equals("reference") && $isFullJavaNameOfTargetTypeGiven == "false")
#*         *#			#set($isFullJavaNameOfTargetTypeGiven = "true")
#*         *#			##----- if a reference-tag is present at the object's type, its value overrides the qualified name
#*         *#			##----- this variable is used in other templates, which parse this template
#*         *#			#set($fullJavaNameOfTargetType = $actualTag.value)
#*      *#		#elseif($actualTag.Name.equals("repositoryKey") && $isRepositoryKeyOfTargetTypeGiven == "false")
#*         *#			#set($isRepositoryKeyOfTargetTypeGiven = "true")
#*         *#			#set($repositoryKeyOfTargetType = $actualTag.value)
#*      *#		#end
#*   *#	#end
#*   *#	#set($isSourceTypeReference = "false")
#*   *#	#set($sourceTypeTagCollection = $source.InstanceOf.Type.Adaptee.Tag)
#*   *#	#foreach($actualTag in $sourceTypeTagCollection)
#*      *#		#if($actualTag.Name.equals("stereotype") && $actualTag.value.equals("reference"))
#*         *#			#set($isSourceTypeReference = "true")
#*      *#		#end
#*   *#	#end
#*   *###----- END MOF Facility specific
#*   *###----------
#*   *##set( $targetType = $target.InstanceOf.Name )
#*   *##set( $targetSet = $target.isSet() )
#*   *##set( $targetOptional = ($target.isOptional() && !$targetSet) )
#*   *##if ( $targetSet )
#*      *#	#set( $collectionName = $targetName )
#*      *#	#set( $targetName = "fujaba__TmpObject$mofutility.upFirstChar($targetName)" )
#*   *##end
#*   *##set( $sourceName = $source.getObjectName() )
#*   *##set( $sourceSet = $source.isSet() )
#*   *##if ( $sourceSet )
#*      *#	#set( $sourceName = "fujaba__TmpObject$mofutility.upFirstChar($sourceName)" )
#*   *##end
#*   *##set( $object = $target )
#*   *### multi link handling
#*   *##set( $targetMulti = $link.RevTargetLink )
#*   *##set( $sourceMulti = $link.RevSourceLink )
#*   *##if ( $targetMulti.ContainerObject.equals($source) )
#*      *#	#if ( $targetMulti.Type == 0 )## FIRST
#*         *#		#set( $first = true )
#*         *#		#if($mofutility.nullIfEmpty($targetRoleName))
#*            *#			#set( $multi = "FirstOf" )
#*         *#		#else
#*            *#			#set( $multi = "First" )
#*         *#		#end
#*      *#	#end
#*   *##elseif ( $sourceMulti.ContainerObject.equals($source) )
#*      *#	#if ( $sourceMulti.Type == 1 )## LAST
#*         *#		#if($mofutility.nullIfEmpty($targetRoleName))
#*            *#			#set( $multi = "LastOf" )
#*         *#		#else
#*            *#			#set( $multi = "Last" )
#*         *#		#end
#*      *#	#end
#*   *##end
#*   *### FMAAssociationEnd.NAVIGABLE:= 100
#*   *### FMAAssociationEnd.NAVIGABLE_COMP:= 101
#*   *##set( $ref = ($role.Adornment == 100) || ($role.Adornment == 101) )
#*   *#
#*   *##set($qualifiedAssocName = $mofutility.getQualifiedName($link.InstanceOf))
#*   *##set($package = $link.InstanceOf.DeclaredInPackage)
#*   *##set($getX = "${sourceName}.get${targetRoleName}()")
#*   *###----- BEGIN MOF Facility specific
#*   *###------
#*   *###----- TODO [fk] this code differs from the one in object/create.vm as links in a MOF project translated
#*   *###----- from a TGG project have MOF associations contained in other projects as types
#*   *###------
#*   *###----- $getX1 has three opening brackets and should be used in conjunction with $getX2, which closes them
#*   *###----- $getXParameter holds the full qualified name of the link's association
#*   *##set($naviPath = $mofutility.getNavigationPath($package))
#*   *##if($naviPath && (! ($isSourceTypeReference == "true" && $isTargetTypeReference == "true"))) ## TODO [fk] must check if the assoc is tagged as reference instead of source and target type 
#*      *#	##----- WORKAROUND [fk] if a navigation path is available and the source and target type are not both references,
#*      *#	##----- we assume that the assoc is a member of our own repository... TODO introduce reference tag to assocs
#*      *#	#set($accessOwnElementsThroughFacility = $mofutility.AccessOwnElementsThroughFacility)
#*      *#	#if( $accessOwnElementsThroughFacility )
#*         *#		##----- due to performance issues even elements of the same repository may be accessed via Facility
#*         *#		#set($facilityInstanceName = $mofutility.FacilityInstanceName)
#*         *#		#set($getX1 = "((${qualifiedAssocName})(${facilityInstanceName}.getAssociation(refOutermostPackage(),")
#*         *#		#set($getXparameter = "${package.FullPackageName}.${link.InstanceOf.Name}")
#*      *#	#else
#*         *#		##----- normal access via JMI reflection
#*         *#		#set($getX1 = "(($qualifiedAssocName)(${naviPath}.refAssociation(")
#*         *#		#set($getXparameter = "$role.Assoc.Name")
#*      *#	#end
#*   *##else
#*      *#	##----- no navigation path is available, or it is a referenced type, so we must use a Facility
#*      *#	#set($facilityInstanceName = $mofutility.FacilityInstanceName)
#*      *#	#if($isRepositoryKeyOfTargetTypeGiven == "true")
#*         *#		#set($getX1 = "((${qualifiedAssocName})(${facilityInstanceName}.getAssociation(${repositoryKeyOfTargetType},")
#*      *#	#else
#*         *#		##----- TODO remove this FIXME after reference tag hsa been introduced to assocs
#*         *#		#if(!$reflective)
#*            *#		// FIXME try to locate type of instance in any registered repository: is this intended?
#*         *#		#end
#*         *#		#set($getX1 = "((${qualifiedAssocName})(${facilityInstanceName}.getAssociation(null,")
#*      *#	#end
#*      *#	#set($getXparameter = "${package.FullPackageName}.${link.InstanceOf.Name}")
#*   *##end
#*   *###----- END MOF Facility specific
#*   *##set($getX2 = "))).get${targetRoleName}($sourceName)")
#*   *#
#**##if ( ${partnerRole.InheritedCodeStyle} ) #set( $style = "${partnerRole.InheritedCodeStyle.Name}:" ) #end
#**##if ( ${role.InheritedCodeStyle} ) #set( $partnerStyle = "${role.InheritedCodeStyle.Name}:" ) #end
