<#--
   ******************************************************
   *
   *                       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.
   *
   ******************************************************
  -->

<#-- Check op standard methods en identifiers, doen we niet, iStudio -->

<#list protected.listProtectedComponents() as c>
	<#list c.componentImplementation.attributeImplementation as attributeImplementation>
		<#assign attributeName=common.getAttributeName(attributeImplementation)>
 		<#assign datatype=common.getDatatype(attributeImplementation)>
	<#-- External Attr domains become extern, we do not generate this -->
	    <#assign dimensions=common.getDimensionsForDataType(common.getMandatoryDatatype(attributeImplementation))/>
   		<#if (dimensions?number > 1)>
	domain ${common.getDatatypeName(datatype)} bl.${c.componentName}.${attributeName}(${dimensions})
	boolean bl.${c.componentName}.${attributeName}.set(${dimensions})
    boolean bl.${c.componentName}.${attributeName}.get(${dimensions})    
 		<#else>
	domain ${common.getDatatypeName(datatype)} bl.${c.componentName}.${attributeName}
    boolean bl.${c.componentName}.${attributeName}.set
    boolean bl.${c.componentName}.${attributeName}.get
		</#if><#--if dimensions?number > 1-->
	<#-- Public.Attributes? -->
	</#list><#--list c.componentImplementation.attributeImplementation as attributeImplementation-->
</#list><#--list protected.listProtectedComponents() as c-->
	boolean bl.permission.for.setting.readonly.attributes

	<#-- Reset.Table.List, something of the old generator internals -->
<#assign tables=[]>
<#list protected.listProtectedComponents() as c>
	<#list c.componentImplementation.componentImplementationTable as componentImplementationTable>
		<#assign tableName=componentImplementationTable.table.idref.name>
		<#assign found=false>
		<#list tables as t>
			<#if t.tableName==tableName || componentImplementationTable.table.idref.type == "form">
				<#assign found=true>
				<#break>
			</#if>
		</#list>
		<#if !found>
			<#assign tables=[{"tableName":tableName}]+tables>
		<#-- make sure table is unique -->
			<#if componentImplementationTable.table.idref.type != "form">
	table t${tableName}
			</#if>
		<#-- No Reference table = always true-->
			<#if !componentImplementationTable.isReferentialIntegrityTable>
	boolean bl.${tableName}.set
			</#if>
		</#if>
	</#list><#--list c.componentImplementation.componentImplementationTable as componentImplementationTable-->
</#list><#--list protected.listProtectedComponents() as c-->

<#list protected.listProtectedComponents() as c>
	<#list c.componentImplementation.componentImplementationTable as componentImplementationTable>
		<#if componentImplementationTable.table.idref.type == "form">
			<#assign table=componentImplementationTable.table.idref>
			<#list table.column as tc>
				<#assign first=true>
				<#list tc.name?split(".") as tn>
					<#if first>
						<#assign tableName=tn>
					<#else>
						<#assign fieldMame=tn>
					</#if>
					<#assign first=false>
				</#list>
				<#assign found=false>
				<#list tables as t>
					<#if t.tableName==tableName>
						<#assign found=true>
						<#break>
					</#if>
				</#list>
				<#if !found>
					<#-- Check if this is really a table field -->
					<#-- Length of tableName must be 8. -->
					<#-- Note: The 'matches' operator has been disabled, because it
						gives problems sometimes when generating. Note that the old
						check (including 'matches') was not complete: names like
						"aaaaa000" and "abcde123" were considered as valid table
						names.
					-->
					<#if tableName?length != 8>
						<#assign tables=[{"tableName":tableName}]+tables>
						<#assign found=true><#-- Do not insert-->
					</#if>
				</#if>
				<#if !found>
					<#assign tables=[{"tableName":tableName}]+tables>
		<#-- make sure table is unique -->
	table t${tableName}
		<#-- No Reference table = always true-->
				</#if>
			</#list>
		</#if>
	</#list><#--list c.componentImplementation.componentImplementationTable as componentImplementationTable-->
</#list><#--list protected.listProtectedComponents() as c-->

<#list protected.listProtectedComponents() as c>
	boolean bl.${c.componentName}.initialize
</#list><#--list protected.listProtectedComponents() as c-->

	string  bl.object(99)
	string  bl.bodesc(99)
	string  bl.component(99)
	long    bl.dal.nr.messages
	string  bl.method(${common.MethodLen()})

	long    bl.result
	long    bl.before.initialize
	long    bl.method.result
	long	bl.component.result
	long    bl.ret
<#if common.referenceMethodPresent()>
	string 	bl.refKey(40)
	boolean bl.refKey.set
</#if><#--if common.referenceMethodPresent()-->

	xmlNode	bl.RequestArgument
	xmlNode	bl.ResponseArgument
	xmlNode	bl.ResultArgument

	boolean	bl.SortingExpressionSet

	xmlNode	bl.Filter
	xmlNode	bl.FilteredAttributes
	string	bl.FilterExpression(1024)
	boolean	bl.PostFilter

<#if protected.generateFunctionServer()>
	string	bl.afs.err.mess(256)	mb
	string	bl.afs.session(13)
	<#list protected.listProtectedComponents() as c>
		<#if protected.isFunctionServerComponent(c.componentImplementation)>
	string	bl.${c.componentName}.main.session(13)
	string	bl.${c.componentName}.sync.session(13)
		</#if>
	</#list>
</#if>

#include <bic_dam>
#pragma used dll otlbctdll1000

<#if protected.generateFunctionServer()>
#pragma used dll ottstpapihand
</#if><#--if protected.generateFunctionServer()-->

<#if common.referenceMethodPresent()>
#pragma used dll ottdlldb.extend
</#if><#--if common.referenceMethodPresent()-->

function extern void <@names.ST_DLLCode/>.set.xmlArguments(
					const xmlNode i.RequestArgument,
					const xmlNode i.ResponseArgument,
					const xmlNode i.ResultArgument)
{
	bl.RequestArgument  = i.RequestArgument
	bl.ResponseArgument = i.ResponseArgument
	bl.ResultArgument   = i.ResultArgument
}

<#list protected.listProtectedComponents() as c>
function extern 
void <@names.ST_DLLCode/>.${c.componentName}.initialize()
{
	DllUsage
	EndDllUsage

	long	i
	i = 0

	<#list c.componentImplementation.attributeImplementation as attributeImplementation>
		<#assign attributeName=common.getAttributeName(attributeImplementation)>
 	   <#assign aiDatatype=common.getMandatoryDatatype(attributeImplementation)/>
 	   <#assign dimensions=common.getDimensionsForDataType(aiDatatype)/>
    	<#if (dimensions?number > 1)>
	for i = 1 to ${dimensions?number}
		bl.${c.componentName}.${attributeName}.set(i) = false
		bl.${c.componentName}.${attributeName}.get(i) = false
			<#if common.get_BaanDatatype_from_XMLSchemaDatatype(aiDatatype)=="DB.STRING">
		bl.${c.componentName}.${attributeName}(1,i) = ${protected.getBaanDataInitializers(attributeImplementation)} 
			<#else>
		bl.${c.componentName}.${attributeName}(i) = ${protected.getBaanDataInitializers(attributeImplementation)} 
			</#if><#--if common.get_BaanDatatype_from_XMLSchemaDatatype(aiDatatype)=="DB.STRING"-->
	endfor
		<#else>
	bl.${c.componentName}.${attributeName}.set = false
	bl.${c.componentName}.${attributeName}.get = false
	bl.${c.componentName}.${attributeName} = ${protected.getBaanDataInitializers(attributeImplementation)} 
		</#if><#--if dimensions?number > 1-->
	</#list>

	bl.${c.componentName}.initialize = true
	<#list c.componentImplementation.componentImplementationTable as componentImplementationTable>
		<#if !componentImplementationTable.isReferentialIntegrityTable>
	bl.${componentImplementationTable.table.idref.name}.set = false
		</#if><#--if !componentImplementationTable.isReferentialIntegrityTable-->
	</#list><#--list c.componentImplementation.componentImplementationTable as componentImplementationTable-->
	<#if protected.isFunctionServerComponent(c.componentImplementation)>
	bl.${c.componentName}.main.session = ""
	bl.${c.componentName}.sync.session = ""
	</#if><#--if protected.isFunctionServerComponent(c.componentImplementation)-->
	set.permission.for.readonly.attributes(false)

	<#list protected.listProtectedComponents(c.componentName) as sc>
	<@names.ST_DLLCode/>.${sc.componentName}.initialize()
	</#list>
}

</#list><#--list protected.listProtectedComponents() as c-->

function extern boolean <@names.ST_DLLCode/>.is.business.studio.supported()
{
	| Checks if the needed functionality is present.
	static	boolean	initialized
	static	boolean	supported
	long		dll.id
	
	if not initialized then
		if get.tools.tiv() < 1400 then
			| A check is done if DLL tlbctdll1000 has external function
			| tlbct.dll1000.remove.nillable.attributes().
<#if names.applicationBackendRelease == "BaanIV">
<#-- The DLL_SILENT_ERR parameter for load_dll is not available on Baan IV -->
			dll.id = load_dll("otlbctdll1000")
<#else>
			dll.id = load_dll("otlbctdll1000", DLL_SILENT_ERR)
</#if>
			if dll.id = 0 then
				supported = false
			else
				supported = (get_function(dll.id, "tlbct.dll1000.remove.nillable.attributes") > 0)
			endif
		else
			| ES 8.4.2 or later is used
			supported = true
		endif
		initialized = true
	endif
	return(supported)
}
