<#--
   ******************************************************
   *
   *                       NOTICE
   *
   *  THIS SOFTWARE IS THE PROPERTY OF AND CONTAINS
   *  CONFIDENTIAL INFORMATION OF INFOR, 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:
   *
   *  Copyright © 2009 Infor. All rights reserved.
   *  The word and design marks set forth herein are
   *  trademarks and/or registered trademarks of Infor
   *  and/or related affiliates and subsidiaries.
   *  All rights reserved. All other trademarks listed
   *  herein are the property of their respective owners.
   *  www.infor.com.
   *
   ******************************************************
  -->
<@common.checkCancel/>
  
<#if (methodName=="PublishChanges" || methodName=="UnpublishChanges")>
function extern long <@names.SB_DLLCode/>.${methodName}(
					ref xmlNode i.RequestArgument,
					ref xmlNode o.ResponseArgument,
					ref xmlNode o.ResultArgument)
{
	DllUsage
		This method will PublishChanges as requested in
		the XML Request message.
		Errors are put in the XML result message.
	EndDllUsage

	long	Ret

	CHECK_TOOLS_VERSION(o.ResponseArgument, o.ResultArgument)
	
	Ret = <@names.ST_DLLCode/>.set.PublishRequest(i.RequestArgument)

	bl.result = <@names.ST_DLLCode/>.execute.${methodName}()
	if bl.result <> 0 then
		|* Read result from Synchronization Server
		Ret = <@names.ST_DLLCode/>.get.PublishResult(o.ResultArgument)
		if o.ResultArgument = 0 then
			|* Use default Result
			Ret = createResultObject(o.ResultArgument)
		endif
		handle.messages(o.ResponseArgument, o.ResultArgument, true)
		bl.ret = xmlDelete(o.ResponseArgument)
		o.ResponseArgument = 0
		return(bl.result)
	endif

	Ret = <@names.ST_DLLCode/>.get.PublishResponse(o.ResponseArgument)
	Ret = <@names.ST_DLLCode/>.get.PublishResult(o.ResultArgument)

	if o.ResultArgument <> 0 then
		Ret = xmlSetName(o.ResultArgument, "Result")
	endif

	if o.ResultArgument <> 0 then
		return(1)	|* Error occurred in Publish Method
	endif
	return(0)
}
</#if><#--if (methodName=="PublishChanges" || methodName=="Unpublish")-->

<#list object.methodImplementation as methodImplementation>
	<#assign methodName=common.getNameFromMethodImplementation(methodImplementation)>
	<#if methodName != "SubscribeList" && methodName != "SupportsProcessingScope">
		<#if common.isEventMethod(methodName) || methodImplementation.processingOrder == "batch">
			<#if protected.hasMethodAlternativeImplementation(methodName)=="">

function extern long <@names.SB_DLLCode/>.${methodName}(
					ref xmlNode i.RequestArgument,
					ref xmlNode o.ResponseArgument,
					ref xmlNode o.ResultArgument)
{
	DllUsage
		This method processes ${methodName} events as requested in
		the XML Request message.
		If success, the XML Response is filled.
		Errors are put in the XML Result message.
	EndDllUsage

				<#if methodName == "PublishEvent">
					<#if object.businessInterfaceDefinition.idref.type != "bod">
	long	duml

					</#if>
	CHECK_TOOLS_VERSION_PUB_EVENT(o.ResponseArgument, o.ResultArgument)

					<#if object.businessInterfaceDefinition.idref.type == "bod">
	return(<@names.ST_DLLCode/>.execute.${names.businessInterfaceName}.${methodName}(
			i.RequestArgument, o.ResponseArgument, o.ResultArgument))
					<#else><#--BDE-->
	duml = <@names.ST_DLLCode/>.execute.${names.businessInterfaceName}.${methodName}(
			i.RequestArgument, o.ResponseArgument, o.ResultArgument)
	| method always returns 0; do not use handle messages to avoid losing
	| existing dal messages from application
	
	return(0)
					</#if>
				<#else>
	CHECK_TOOLS_VERSION(o.ResponseArgument, o.ResultArgument)

	RETIFNOK2(<@names.ST_DLLCode/>.execute.${names.businessInterfaceName}.${methodName}(
						i.RequestArgument, o.ResponseArgument, o.ResultArgument))

	handle.messages(o.ResponseArgument,
			o.ResultArgument, false) |* put mess in response
	return(0)
				</#if>
}
			</#if><#-- protected.hasMethodAlternativeImplementation(methodName)==""-->
		</#if><#--if common.isEventMethod(methodName)  || methodImplementation.processingOrder == "batch"-->
	</#if><#-- methodName != "SubscribeList" && methodName != "SupportsProcessingScope"-->
</#list><#--list object.methodImplementation as methodImplementation-->

<#if common.methodPresent("PublishEvent")>
	<#if object.businessInterfaceDefinition.idref.type == "bod">
|------------ GetIdentifierName() -----------------------

function extern long <@names.SB_DLLCode/>.GetIdentifierName(
	ref	string	o.name)
{
DllUsage
	This function must only be used by the Tools Add-On package.
	Do not use it in hook code or other libraries.
	Output: The identifier name (for addition of the variation ID).
	Return value: 0 (OK) or an error value.
EndDllUsage

		<#assign nrIdentifiers = 0>
		<#list public.listPublicAttributes("PublishEvent") as a>
			<#if a.componentName == names.businessInterfaceName && common.getIsIdentifier(a.attributeImplementation)>
				<#assign nrIdentifiers = nrIdentifiers + 1>
			</#if>
		</#list>
		<#if nrIdentifiers == 1>
			<#list public.listPublicAttributes("PublishEvent") as a>
				<#if a.componentName == names.businessInterfaceName && common.getIsIdentifier(a.attributeImplementation)>
	o.name = "${a.path}"
				</#if>
			</#list>
	return(0) | OK
		<#else>
			<#if nrIdentifiers != 0>
	| Multiple identifiers found, the Generator cannot determine which one is correct:
				<#list public.listPublicAttributes("PublishEvent") as a>
					<#if a.componentName == names.businessInterfaceName && common.getIsIdentifier(a.attributeImplementation)>
	|  - ${a.path}
					</#if>
				</#list>
			</#if>
	o.name = ""
	return(-1) | Error
		</#if>
}

	</#if><#--if object.businessInterfaceDefinition.idref.type == "bod"-->
	<#list protected.listProtectedComponents() as c>
|------------ GetPublicIdentifiers() for ${c.componentName} ------------

function extern long <@names.SB_DLLCode/>.${c.componentName}.GetPublicIdentifiers(
		ref		long		o.externalData)
{
DllUsage
	This function must only be used by the Tools Add-On package.
	Do not use it in hook code or other libraries.
	Precondition: internal identifiers have been set in the protected layer.
	Return value: 0 (OK) or an error value.
	In case of error a dal error message has been set.
EndDllUsage

#define ERR_IF(condition, component)
^		if condition then
^			dal.set.error.message("tlbctstgen", "PublishEvent", component, "${names.businessInterfaceName}")
^			|* Error occurred in Method '%1$s' on component '%2$s' of Object '%3$s'.
^			return(DALHOOKERROR)
^		endif
#define ERR_IF(condition)	ERR_IF(condition, "")

	long	componentNode	| component instance node
	long	retl			| return value to be checked


	<#list public.listComponentPath(c.componentName) as cpath>
		<#if cpath.componentName == names.businessInterfaceName>
	retl = handle.output.${cpath.componentName}.identifiers(0, componentNode)
	ERR_IF(retl <> 0)
	o.externalData = componentNode
		<#else>
	retl = handle.output.${cpath.componentName}.identifiers(componentNode, componentNode)
	ERR_IF(retl <> 0)
		</#if><#-- cpath.componentName == names.businessInterfaceName -->		
	</#list><#-- list public.listComponentPath(c.componentName) as cpath-->
	
	return(0) | OK
}
	</#list><#-- list protected.listProtectedComponents() as c -->
</#if><#-- common.methodPresent("PublishEvent") -->

<#if common.methodPresent("PublishEvent")>
	<#list protected.listProtectedComponents() as c>
function long handle.output.${c.componentName}.identifiers(
					xmlNode i.Node,
			ref   	xmlNode o.Node)
{
| i.Node is parentNode
| o.Node is current component Node (is child of i.Node)
	string  value(1024)
	boolean	value.isSet
	xmlNode	g.Node

	| Create component node for ${c.componentName}
	NEW.NODE("${c.componentName}", i.Node, o.Node)

	g.node = 0
	value = ""
	value.isSet = false
		<#list public.listPublicAttributes("PublishEvent") as a>
			<#if c.componentName == a.componentName & common.getIsIdentifier(a.attributeImplementation)>
	${c.componentName}.${a.attributeName}.select = true
	g.Node = createGroupNodes(o.Node, "${a.path}", "${a.alias}")
	ASSIGNVAL(${c.componentName}, ${a.attributeName}, ${a.alias})
			</#if><#-- c.componentName == a.componentName & common.getIsIdentifier(a.attributeImplementation)-->
		</#list><#--list public.listPublicAttributes("PublishEvent") as a-->
	return(0)
}

	</#list><#-- list protected.listProtectedComponents() as c -->
</#if><#-- common.methodPresent("PublishEvent") -->
