<#--
	******************************************************
	*
	*                       NOTICE
	*
	*  THIS SOFTWARE IS THE PROPERTY OF AND CONTAINS
	*  CONFIDENTIAL INFORMATION OF INFOR INC., AND SHALL
	*  NOT BE COPIED, USED, NOR DISCLOSED WITHOUT EXPRESS 
	*  WRITTEN AUTHORIZATION. ALTHOUGH PUBLICATION IS NOT 
	*  INTENDED, IN THE EVENT OF PUBLICATION, THE FOLLOWING 
	*  NOTICE IS APPLICABLE:
	*
	*  (c) COPYRIGHT 2006 INFOR, INC.
	*
	******************************************************
 -->
 
<#--
	Returns a sequence with all methods from the business interface definition with
	the exception of the PublishEvent method, which is an internal method only.
	
	@return      a sequence with all public methods
-->
<#function listPublicMethods>
	<#local methodList=[]>
	<#list object.method as m>
		<#if m.name!="PublishEvent">
			<#local methodList=methodList+[m]>
		</#if>
	</#list>
	<#return methodList>
</#function>

<#--
	Returns a method object from a specific businessInterfaceDefinition based
	upon the method name.
	
	@param		iBusinessInterfaceDefinition	a businessInterfaceDefinition object
	@param		iMethodName						a method name
	@return		a method object
-->
<#function getPublicMethod iBusinessInterfaceDefinition iMethodName>
	<#list iBusinessInterfaceDefinition.method as m>
		<#if m.name==iMethodName>
			<#return m>
		</#if>
	</#list>
	<#return "">
</#function>

<#--
	Is used to check whether there are actual input or output attribute-arguments
	specified for a certain method. It checks all levels of the component
	hierarchy.
	
	@param	iMethod		a method object
	@param	iInput		a boolean indicating whether the check is for input or output arguments
	@return      		a sequence with all public method objects
-->
<#function hasPublicAttributes iMethod iInput>
	<#return hasPublicAttributesAA(iMethod, object, iInput)>
</#function>

<#--private-->
<#function hasPublicAttributesAA iMethod iComponent iInput>
	<#if listPublicAttributes(iMethod, iComponent, iInput)?size==0>	
		<#list iComponent.relationship as r>
			<#if r.type=="aggregation">
				<#return hasPublicAttributesAA(iMethod, r.component, iInput)/>
			</#if>
		</#list>
		<#return false>
	</#if>
	<#return true>
</#function>

<#--
	Is used to check whether a certain attribute is used in the method.
	
	@param	iMethod		a method object
	@param	iComponent	a component object
	@param	iAttribute	an attribute object
	@param	iInput		a boolean indicating whether the check is for input or output arguments
	@return      		a boolean indicating whether the specified attribute is used in the method or not.
-->
<#function isUsedInMethod iMethod iComponent iAttribute iInput>
	<#switch iAttribute.type>
		<#case "simple">
		<#case "qualifier">
			<#local ma=getMethodArgumentFromAttribute(iMethod, iComponent, iAttribute)>
			<#if ma!="">
				<#if (iInput==true && (ma.scope=="in" || ma.scope="inout")) || (iInput==false && (ma.scope=="out" || ma.scope="inout"))>
					<#return true>
				</#if>
			</#if>
			<#break>	
		<#case "group">			
		<#case "complex">
			<#list iAttribute.attributeRelationship as ar>
				<#if isUsedInMethod(iMethod, iComponent, ar.attribute.idref, iInput)>
					<#return true>
				</#if>
			</#list>
			<#break>
	</#switch>									
	<#return false>
</#function>

<#--
	Returns a sequence with all input or output arguments from a certain method
	and component.
	
	@param	iMethod		a method object
	@param	iComponent	a component object
	@param	iInput		a boolean indicating whether to return all input or output method arguments
	@return      		a sequence with all public method argument objects
-->
<#function listPublicAttributes iMethod iComponent iInput>
	<#local attributeList=[]>
	<#list iComponent.attribute as a>
		<#if !a.parentAttribute?has_content>
			<#if isUsedInMethod(iMethod, iComponent, a, iInput)>
				<#local attributeList=attributeList+[a]>
			</#if>
		</#if>
	</#list>
	<#return attributeList>
</#function>

<#--
	Is used to check whether there are actual input or output specific controlling
	attributes for a certain method.
	
	@param	iMethod		a method object
	@param	iInput		a boolean indicating whether the check is for input or output arguments
	@return      		a boolean indicating whether there are specific controllingn attributes
-->
<#function hasControllingAttributes iMethod iInput=true>
	<#if iInput>
		<#switch iMethod.name>
			<#case "List">
			<#case "Show">
			<#case "Create">
			<#case "Change">
			<#case "Delete">
			<#case "DeleteRef">
			<#case "SubscribeList">
			<#case "SubscribeEvent">
			<#case "unSubscribeEvent">
			<#case "PublishEvent">
			<#case "OnEvent">
			<#default>
				<#return true>
				<#break>
			<#case "CreateRef">
			<#case "SupportsReferentialIntegrity">
			<#case "SupportsProcessingScope">
				<#return listSpecificControllingAttributes(iMethod,true)?size!=0>
				<#break>
		</#switch>
	<#else>
		<#switch iMethod.name>
			<#case "List">
			<#case "Show">
			<#case "CreateRef">
			<#case "SupportsReferentialIntegrity">
			<#case "SupportsProcessingScope">
				<#return true>
				<#break>
			<#case "Create">
			<#case "Change">
			<#case "Delete">
			<#case "DeleteRef">
			<#case "SubscribeList">
			<#case "SubscribeEvent">
			<#case "unSubscribeEvent">
			<#case "PublishEvent">
			<#case "OnEvent">
			<#default>
				<#return listSpecificControllingAttributes(iMethod,false)?size!=0>
				<#break>
		</#switch>
	</#if>
	<#return false>
</#function>

<#--
	Returns a sequence with all input or output specific controlling attributes from 
	a certain method.
	
	@param	iMethod		a method object
	@param	iInput		a boolean indicating whether to return all input or output method arguments
	@return      		a sequence with all public method argument objects
-->
<#function listSpecificControllingAttributes iMethod iInput>
	<#local specificControllingAttributeList=[]>
	<#list iMethod.methodArgument as methodArgument>
		<#if !methodArgument.attribute?has_content>
			<#if (iInput==true && (methodArgument.scope=="in" || methodArgument.scope=="inout")) || (iInput==false && (methodArgument.scope=="out" || methodArgument.scope=="inout"))>
				<#local specificControllingAttributeList=specificControllingAttributeList+[methodArgument]>
			</#if>
		</#if>
	</#list>
	<#return specificControllingAttributeList>
</#function>

<#--
	Returns the method argument from a certain attribute.
	
	@param	iMethod		a method object
	@param	iComponent	a component object
	@param	iAttribute 	an attribute object
	@return      		a method argument object
-->
<#function getMethodArgumentFromAttribute iMethod iComponent iAttribute>
	<#list iMethod.methodArgument as ma>
		<#if ma.attribute?exists && (ma.component.idref.name==iComponent.name && ma.attribute.idref.name==iAttribute.name)>
			<#return ma>
		</#if>
	</#list>
	<#return "">
</#function>

<#--
	Returns the datatype from a certain method argument. If the method
	argument has no datatype specified, the datatype from the attribute
	will be returned.
	
	@param	iMethodArgument		a method argument object
	@return      				a datatype object
	@throws						error if datatype cannot be found
-->
<#function getDatatypeFromMethodArgument iMethodArgument>
	<#if iMethodArgument.datatype?exists>
		<#return iMethodArgument.datatype.idref>
	<#elseif iMethodArgument.attribute?exists>
		<#if iMethodArgument.attribute.idref.datatype?exists>
			<#return iMethodArgument.attribute.idref.datatype.idref>
		</#if>
	</#if>
</#function>		

<#--
	Returns the default value from a certain method argument. The create method
	cam have a default value specified in either the method argument or in the
	attributes themselves. If the method is create and the method argument has 
	no default value specified, the default value will be taken form the attribute.
	
	@param	iMethod				a method object
	@param	iMethodArgument		a method argument object
	@return      				a default value
-->
<#function getDefaultValueFromMethodArgument iMethod iMethodArgument>
	<#if iMethodArgument.defaultValue?exists>
		<#return iMethodArgument.defaultValue>
	<#else>
		<#if iMethod.name=="Create" && iMethodArgument.attribute?exists>
			<#if iMethodArgument.attribute.idref.defaultValue?exists>
				<#return iMethodArgument.attribute.idref.defaultValue>
			</#if>
		</#if>
	</#if>
	<#return "">
</#function>		

<#--
	Returns whether an attribute is mandatory.
	
	@param	iMethod			a method object
	@param	iComponent		a component object
	@param	iAttribute		an attribute object
	@return      			a boolean indicating whether the attribute is grouped
-->
<#function getIsMandatory iMethod iComponent iAttribute>
	<#local ma="">
	<#switch iAttribute.type>
		<#case "simple">
		<#case "qualifier">
			<#local ma=getMethodArgumentFromAttribute(iMethod, iComponent, iAttribute)>
			<#if ma!="">
				<#return ma.isMandatory>
			</#if>
			<#break>
		<case <"complex">
		<case <"group">
			<#list iAttribute.attributeRelationship as ar>
				<#if getIsMandatory(iMethod, iComponent, ar.attribute.idref)>
					<#return true>
				</#if>
			</#list>				
			<#break>
	</#switch>
	<#return false>
</#function>

<#--
	Returns the default value of an attribute.
	
	@param	iMethod			a method object
	@param	iComponent		a component object
	@param	iAttribute		an attribute object
	@return      			a boolean indicating whether the attribute is grouped
-->
<#function getDefaultValue iMethod iComponent iAttribute>
	<#local ma="">
	<#if (iAttribute.type=="simple" || iAttribute.type=="qualifier")>
		<#local ma=getMethodArgumentFromAttribute(iMethod, iComponent, iAttribute)>
		<#if ma!="">
			<#return getDefaultValueFromMethodArgument(iMethod, ma)>
		</#if>
	</#if>
	<#return "">

</#function>

<#--
	Returns a sequence with all input or output qualifiers from a component
	from a certain method
	
	@param	iMethod		a method object
	@param	iComponent	a component object
	@param	iInput		a boolean indicating whether to return all input or output method arguments
	@return      		a sequence with all public method argument objects
-->
<#function listPublicComponentQualifiers iMethod iComponent iInput>
	<#local qualifierList=[]>
	<#list iComponent.attribute as a>
		<#if a.type=="qualifier">
			<#if !a.parentAttribute?has_content>
				<#if isUsedInMethod(iMethod, iComponent, a, iInput)>
					<#local qualifierList=qualifierList+[a]>
				</#if>
			</#if>
		</#if>
	</#list>
	<#return qualifierList>
</#function>

<#--
	Returns a sequence with all input or output qualifiers from an attribute
	from a certain method
	
	@param	iMethod		a method object
	@param	iComponent	a component object
	@param	iAttribute	an attribute object
	@param	iInput		a boolean indicating whether to return all input or output method arguments
	@return      		a sequence with all public method argument objects
-->
<#function listPublicAttributeQualifiers iMethod iComponent iAttribute iInput>
	<#local qualifierList=[]>
	<#list iAttribute.attributeRelationship as ar>
		<#local a=ar.attribute.idref/>
		<#if a.type=="qualifier">
			<#if isUsedInMethod(iMethod, iComponent, a, iInput)>
				<#local qualifierList=qualifierList+[{
					"attribute":a,
					"attributeRelationship":ar
				}]>
			</#if>
		</#if>
	</#list>
	<#return qualifierList>
</#function>
