<#import "common.ftl" as common/>  
<#--
     Generate the type-safe Java proxy for a BusinessInterfaceDefinition
     - object is an instance of BusinessInterfaceDefinition
     - properties is a HashMap generated by PropertiesHelper.getInstance() - it provides access to the
       named GeneratorProperty elements in ApplicationControlData.
  -->
<@common.copyright/>
 *  Component Name: ${object.name?cap_first}
 * <#if object.versionID?has_content> Component Version: ${object.versionID}</#if>
 * <#if object.description?has_content> Component Description: ${object.description}</#if>
 *  BID: ${common.getBIDName(object)}
 *****************************************************/
<#assign bdeName>
	<@common.toName name="${object.name?cap_first}"/>
</#assign>
<#assign noOfAttrs=0>
<#assign noOfPKeys=0>
<#list object.attribute as attribute>
	<#if !attribute.isHidden && attribute.isIdentifier>
		<#assign noOfPKeys = noOfPKeys + 1>
	</#if>
	<#if !attribute.isHidden && !common.isUsedInComplexOrGroup(object, attribute)>	
		<#assign noOfAttrs = noOfAttrs + 1>
	</#if>		
</#list>

using System;
using OpenWorld.Adapter.BdeImpl;

<#if properties.namespace?has_content>namespace ${properties.namespace}
{
</#if>
	/// <summary>
	/// Generated typesafe BDE component proxy ${object.name?cap_first}.
	/// <br>This ${object.name?cap_first}Manager extends com.ssaglobal.bdeimpl.java.BusinessDataEntity.<br>
	/// Identifying attributes: ${common.identifyingAttributes(object)}<br>
	/// Mandatory attributes  : ${common.mandatoryAttributes(object)}<br>
	/// Component Name: ${object.name?cap_first}<br>
	/// <#if object.versionID?has_content>Component Version: ${object.versionID}<br></#if>
	/// <#if object.description?has_content>Component Description: ${object.description}<br></#if>
	/// </summary>
	public class ${bdeName} : BusinessDataEntity
	{
<#if common.getBIDName(object)=object.name>	
		/// <summary>
		///Constructor for creating a 'empty' ${bdeName}.
		/// <br>Depending on the action you want to perform identifying or mandatory attributes may be required.
		/// This can be used if a ${bdeName} can be created without identifying attributes (created by backend)
		/// </summary>
		public ${bdeName}() : base(s_metaData[0][ITEM_NAME])
		{
		}
<#else>
		internal ${bdeName}() : base(s_metaData[0][ITEM_NAME])
		{
		}
</#if>

<#if common.countPrimKeys(object) != 0 >
		/// <summary>	
		/// Create ${bdeName} with identifying attributes.
		/// </summary>	
		public ${bdeName}(${common.primkeys_types_and_names(object)}) : base(s_metaData[0][ITEM_NAME])  
		{
<#list object.attribute as attribute>		
	<#if attribute.isIdentifier && !common.isUsedInComplexOrGroup(object, attribute)>
			set${attribute.name?cap_first}(p_${attribute.name});
	</#if>
</#list>
		}	
</#if>
	
<#if object.relationship?has_content>
<#list object.relationship as relations>
	<#assign subComponent = common.getSubComponent(relations)>	
	<#assign relationComponentName = subComponent.name?cap_first >	
	<#if relations.type = "aggregation">
		<#if !subComponent.isHidden>

		/// <summary>
		/// List ${relationComponentName} currently present in this local ${bdeName}.
		/// returns ${relationComponentName}Iterator
		/// throws BdeException If an error occurs	 
		/// </summary>
		public ${relationComponentName}Iterator List${relationComponentName}()
		{
			return (${relationComponentName}Iterator) listComponents(${noOfAttrs+relations_index+1});
		}

		/// <summary>
		/// Add a new ${relationComponentName} to this local ${bdeName} for create.
		/// <br>The method arguments are the identifying attributes for this new ${relationComponentName}.
		/// The mandatory attributes are not filled.
		/// Executing the Change on the ${common.getBIDName(object)} does the actual create of this ${relationComponentName} on the backend.
		/// returns ${bdeName} proxy object, which can be used to set more (mandatory) attributes.
		/// throws BdeException If an error occurs	 
		/// </summary>
		public ${relationComponentName} Create${relationComponentName}(${common.primkeys_types_and_names(relations.component)})	
		{
			${relationComponentName} newComponent = new ${relationComponentName}(${common.primkeys_names(relations.component)});
			createComponent((BusinessDataEntity) newComponent);
			return newComponent;
		}
	
		/// <summary>
	 	/// Add a new ${relationComponentName} to this local ${bdeName} for create.
	 	/// The identifying and mandatory attributes are not filled.
	 	/// Executing the Change on the ${common.getBIDName(object)} does the actual create of this ${relationComponentName} on the backend.
	 	/// @return ${bdeName} proxy object, which can be used to set mandatory or identifying attributes.
	 	/// @throws BdeException If an error occurs	 
		/// </summary>	 	
		public ${relationComponentName} Create${relationComponentName}()
		{
			${relationComponentName} newComponent = new ${relationComponentName}();
			createComponent((BusinessDataEntity) newComponent);
			return newComponent;
		}

		/// <summary>	
		/// Add a new ${relationComponentName} to this local ${bdeName} for change.
	 	/// Executing the Change on the ${common.getBIDName(object)} does the actual change of this ${relationComponentName} on the backend.
	 	/// @return ${bdeName} proxy object, which can be used to set more (mandatory or identifying) attributes.
	 	/// @throws BdeException If an error occurs	 
		/// </summary>
		public ${relationComponentName} Change${relationComponentName}(${common.primkeys_types_and_names(relations.component)}) 
		{
			${relationComponentName} newComponent = new ${relationComponentName}(${common.primkeys_names(relations.component)});
			changeComponent((BusinessDataEntity) newComponent);
			return newComponent;
		}
	
		/// <summary>
	 	/// Add a new ${relationComponentName} to this local ${bdeName} for delete.
	 	/// The new ${relationComponentName} is based on the identifying attributes.
	 	/// Executing the Change on the ${common.getBIDName(object)} does the actual delete of this ${relationComponentName} on the backend.	 
	 	/// @throws BdeException If an error occurs	 
		/// </summary>	 	
		public void Delete${relationComponentName}(${common.primkeys_types_and_names(relations.component)})	
		{
			${relationComponentName} newComponent = new ${relationComponentName}(${common.primkeys_names(relations.component)});
			deleteComponent((BusinessDataEntity) newComponent);
		}

		/// <summary>
	 	/// Add a ${relationComponentName} to this local ${bdeName} for delete.
	 	/// Executing the Change on the ${common.getBIDName(object)} does the actual delete of this ${relationComponentName} on the backend.	 
	 	/// @throws BdeException If an error occurs	 
		/// </summary>	 	
		public void Delete${relationComponentName}(${relationComponentName} componentToDelete) 
		{
			deleteExistingComponent(componentToDelete);
		}
	
		</#if>
	<#else>
		// found associated component '${relationComponentName}' not generating code for associations.
	
	</#if>
</#list>
</#if>
<#--
	This #list loop below generates the following methods: 
	get<Component>
	set<Component>
	has<Component>
	unset<Component>
-->
<#assign attributeIndex=0>
<#list object.attribute as attribute>
	<#if !attribute.isHidden && !common.isUsedInComplexOrGroup(object, attribute)>
		<#assign attributeIndex	= attributeIndex+1/>
		<#switch attribute.type>
		  	<#case "simple">
				<#assign dataType = common.getdotnetdt(attribute.datatype.idref.primitiveDatatype)>		  	
				<#assign functionType = common.getFunctiondt(attribute.datatype.idref.primitiveDatatype)>		  	
			<#break>
			<#case "group">
				<#assign dataType = attribute.name?cap_first>
			<#break>
			<#case "complex">
				<#assign dataType = attribute.datatype.idref.name?cap_first>			
			<#break>	
		</#switch>  

		/// <summary>
		/// Get <@common.printAttributeInfo _attr=attribute/>
		/// <@common.printAttributeDescription _attr=attribute/>
		/// </summary>	
		public ${dataType} Get${attribute.name?cap_first}()
	   	{
		<#if attribute.type = "simple">
			return get${functionType?cap_first}Value(${attributeIndex});
		<#else>
			${dataType} new${dataType} = new ${dataType}();
			getComplexValue(${attributeIndex}, new${dataType});
			return new${dataType};
		</#if>
   		}
    
		<#if attribute.isIdentifier>
	   	/*package private */ void set${attribute.name?cap_first}(${dataType} value)
	   	{
		<#if attribute.type = "simple">
			set${functionType?cap_first}Value(${attributeIndex}, value);
		<#else>
			setComplexValue(${attributeIndex}, value);
		</#if>
   		}

		<#else>
		/// <summary>		
		/// Set <@common.printAttributeInfo _attr=attribute/>
		/// <@common.printAttributeDescription _attr=attribute/>
		/// </summary>			
   		public void Set${attribute.name?cap_first}(${dataType} value)
   		{
		<#if attribute.type = "simple">
			set${functionType?cap_first}Value(${attributeIndex}, value);
		<#else>
			setComplexValue(${attributeIndex}, value);
		</#if>
   		}

		/// <summary>	   		
		/// Has <@common.printAttributeInfo _attr=attribute/>
		/// <@common.printAttributeDescription _attr=attribute/>
		/// </summary>			
   		public bool Has${attribute.name?cap_first}()
   		{
	       	return hasValue(${attributeIndex});
	   	}	
   	
		/// <summary>	   		
		/// Unset <@common.printAttributeInfo _attr=attribute/>
		/// <@common.printAttributeDescription _attr=attribute/>
		/// </summary>	   		
	   	public void Unset${attribute.name?cap_first}()
	   	{
       		unsetValue(${attributeIndex});
   		}	  
		</#if>       
	</#if>       	 	
</#list>

		private static String [][] s_metaData = 
		{
<#--
	This #list loop below creates the following:
	{"<BDEName>"},
	{"<FieldName>", TYPE_<dataTypeUPPERCASE>,"<FacetInformation>"},
	etc...
-->		
			new string[]{"${object.name}"}
<#list object.attribute as attribute>		
	<#if !attribute.isHidden && !common.isUsedInComplexOrGroup(object, attribute)>
		<#switch attribute.type>
		  	<#case "simple">
			,new string[]{"${attribute.name}", "${common.getSchemadt(attribute.datatype.idref.primitiveDatatype)}"<#list attribute.datatype.idref.facet as facet><#if facet_index = 0>,</#if><#break></#list><#list attribute.datatype.idref.facet as facet>"${facet.type}:${facet.value?j_string}"<#if facet_has_next>,</#if></#list>}
			<#break>
			<#case "group">
			,new string[]{"${attribute.name}", "group"}
			<#break>
			<#case "complex">
			,new string[]{"${attribute.name}", "complex"}
			<#break>	
		</#switch>  
	</#if>
</#list>
<#if object.relationship?has_content>
	<#list object.relationship as relations>
		<#if relations.type = "aggregation">
				<#assign subComponent = common.getSubComponent(relations)>			
				<#if !subComponent.isHidden>
			,new string[]{"${subComponent.name}", "Comp"}
				</#if>
		</#if>
	</#list>
</#if>
		};
	
	
	
	<@GenerateAttributeIdentifier sName="_ALL_"  sValue="${object.name}.*"/>
<#list object.attribute as attribute>	
	<#if !attribute.isHidden && !common.isUsedInComplexOrGroup(object, attribute)>
		<#switch attribute.type>
			<#case "simple">
			<@GenerateAttributeIdentifier sName="${attribute.name}"  sValue="${object.name}.${attribute.name}"/>
				<#break>
			<#case "group">			
			<#case "complex">
			<@createComplexAttributeIdentifiers iCompleteName="" iAttribute=attribute iAttributeRelation=""/>
				<#break>
		</#switch>  
	</#if>
</#list>
	
		protected override BdeIterator _createComponentIterator(int index)
		{
<#if object.relationship?has_content>
			switch (index)
			{
		<#list object.relationship as relations>
			<#if relations.type = "aggregation">
				<#assign subComponent = common.getSubComponent(relations)>	
				<#if !subComponent.isHidden>
				case(${noOfAttrs+1+relations_index}):
				return new ${subComponent.name}Iterator();
				</#if>
			</#if>		
		</#list>
				default:
					return null;		
  			}
  			
<#else>
			return null;
</#if>			
		}

		protected override String getMetaData(int ItemIndex, int ProperyIndex)
		{
			try
    	    {
        	    return s_metaData[ItemIndex][ProperyIndex];
	        }
    	    catch (Exception) 
	        {
    	        return null;
       		}
		}
	
		internal static String _getPrimaryKeys(String sParentName)
		{
			String sb = "";

<#list object.attribute as attribute>
	<#if !attribute.isHidden && attribute.isIdentifier>
		<#switch attribute.type>
			<#case "simple">
			sb = sb + sParentName + ${attribute.name?upper_case} + ";";
				<#break>
		</#switch>  
	</#if>
</#list>	
<#if object.relationship?has_content>
	<#list object.relationship as relations>
		<#if relations.type = "aggregation">
			<#assign subComponent = common.getSubComponent(relations)>	
			<#if !subComponent.isHidden>
			sb = sb + ${subComponent.name}._getPrimaryKeys(s_metaData[0][ITEM_NAME] + ".");
			</#if>
		</#if>		
	</#list>
</#if>			return sb;
		}
	}
<#if properties.namespace?has_content>}</#if>
<#macro createComplexAttributeIdentifiers iCompleteName iAttribute iAttributeRelation>
	<#if !iAttribute.isHidden>
	<#switch iAttribute.type>
		<#case "simple">
		<@GenerateAttributeIdentifier sName = "${iCompleteName}${iAttributeRelation.name}" sValue="${object.name}.${iCompleteName}${iAttributeRelation.name}"/>
			<#break>
		<#case "group">
		<@GenerateAttributeIdentifier sName = "${iCompleteName}${iAttribute.name}._ALL_" sValue="${object.name}${iCompleteName}.${iAttribute.name}.*"/>		
			<#list iAttribute.attributeRelationship as ar>
 				<@createComplexAttributeIdentifiers iCompleteName = iCompleteName+iAttribute.name+"." iAttribute=ar.attribute.idref iAttributeRelation=ar/>
			</#list>
			<#break>
		<#case "complex">		
				<#if iAttributeRelation?has_content>
		<@GenerateAttributeIdentifier sName = "${iCompleteName}${iAttributeRelation.name}._ALL_" sValue="${object.name}.${iCompleteName}${iAttributeRelation.name}.*"/>						
				<#else>
		<@GenerateAttributeIdentifier sName = "${iCompleteName}${iAttribute.name}._ALL_" sValue="${object.name}.${iCompleteName}${iAttribute.name}.*"/>		
				</#if>
			<#list iAttribute.attributeRelationship as ar>
				<#if iAttributeRelation?has_content>
					<@createComplexAttributeIdentifiers iCompleteName = iCompleteName+iAttributeRelation.name+"." iAttribute=ar.attribute.idref iAttributeRelation=ar/>
				<#else>
					<@createComplexAttributeIdentifiers iCompleteName = iCompleteName+iAttribute.name+"." iAttribute=ar.attribute.idref iAttributeRelation=ar/>				
				</#if>
			</#list>
			<#break>
	</#switch>  
	</#if>
</#macro>
<#macro GenerateAttributeIdentifier sName sValue>
		public static String ${sName?upper_case?replace(".","_")}  = "${sValue}";
</#macro>