private MetadataCompoundAttribute get(XmlSchemaElement element, List<string> parents, string internalXPath, string externalXPath)
{
//Debug.Writeline("element :" + element.Name);
XmlSchemaComplexType ct = XmlSchemaUtility.GetComplextType(element);
string nameOfType = "";
if (ct.Name != null)
nameOfType = ct.Name;
else
nameOfType = GetTypeOfName(element.Name);
MetadataCompoundAttribute metadataCompountAttr = getExistingMetadataCompoundAttribute(nameOfType);
string currentInternalXPath = internalXPath + "/" + element.Name + "/" + nameOfType;
string currentExternalXPath = externalXPath + "/" + element.Name;
// create and map
if (metadataCompountAttr == null)
{
if (ct.Name != null)
{
metadataCompountAttr = createMetadataCompoundAttribute(ct);
}
else
{
metadataCompountAttr = createMetadataCompoundAttribute(element);
}
List<XmlSchemaElement> childrens = XmlSchemaUtility.GetAllElements(element, false, Elements);
parents.Add(element.Name);
foreach (XmlSchemaElement child in childrens)
{
//Debug.Writeline("child :" + child.Name);
// simple element
if (XmlSchemaUtility.IsSimpleType(child))
{
metadataCompountAttr = addMetadataAttributeToMetadataCompoundAttribute(
metadataCompountAttr, child, currentInternalXPath, currentExternalXPath);
}
//complex element
else
{
XmlSchemaComplexType complexTypeOfChild = XmlSchemaUtility.GetComplextType(child);
if (ct.Name == null || complexTypeOfChild.Name == null)
{
//--> create compountAttribute
MetadataCompoundAttribute compoundAttributeChild = get(child, parents,
currentInternalXPath, currentExternalXPath);
// add compound to compount
metadataCompountAttr =
addUsageFromMetadataCompoundAttributeToMetadataCompoundAttribute(
metadataCompountAttr, compoundAttributeChild, child);
}
else
{
if (ct.Name != null && complexTypeOfChild.Name != null)
{
if (!ct.Name.Equals(complexTypeOfChild.Name))
{
//--> create compountAttribute
MetadataCompoundAttribute compoundAttributeChild = get(child, parents,
currentInternalXPath, currentExternalXPath);
// add compound to compount
metadataCompountAttr =
addUsageFromMetadataCompoundAttributeToMetadataCompoundAttribute(
metadataCompountAttr, compoundAttributeChild, child);
}
}
}
}
}
if (metadataAttributeManager.MetadataCompoundAttributeRepo.Get().Where(m => m.Name.Equals(metadataCompountAttr.Name)).Count() > 0)
{
metadataAttributeManager.Update(metadataCompountAttr);
}
else
{
metadataCompountAttr = metadataAttributeManager.Create(metadataCompountAttr);
createdCompoundsDic.Add(metadataCompountAttr.Id, metadataCompountAttr.Name);
}
}
//only map
else
{
// if its there need to map
List<XmlSchemaElement> childrens = XmlSchemaUtility.GetAllElements(element, false, Elements);
parents.Add(element.Name);
foreach (XmlSchemaElement child in childrens)
{
//Debug.Writeline("child :" + child.Name);
if (XmlSchemaUtility.IsSimpleType(child))
{
//add existing Simple elements to mappingFile
addMetadataAttributeToMappingFile(metadataCompountAttr, child, currentInternalXPath, currentExternalXPath);
}
else
{
XmlSchemaComplexType complexTypeOfChild = XmlSchemaUtility.GetComplextType(child);
if (ct.Name == null || complexTypeOfChild.Name == null)
{
MetadataCompoundAttribute compoundAttributeChild = get(child, parents, currentInternalXPath, currentExternalXPath);
}
else
{
if (ct.Name != null && complexTypeOfChild.Name != null)
{
if (!ct.Name.Equals(complexTypeOfChild.Name))
{
MetadataCompoundAttribute compoundAttributeChild = get(child, parents, currentInternalXPath, currentExternalXPath);
}
}
}
}
}
}
return metadataCompountAttr;
}