Commit f8ab3000 authored by BenceJanosSzabo's avatar BenceJanosSzabo
Browse files

xsd2ttcn: field names should be prefixed with module name when they are ambiguous (Bug 502221)



Change-Id: I472c0ac7f0397d6aafeda90c695cebac3d736c18
Signed-off-by: default avatarBenceJanosSzabo <bence.janos.szabo@ericsson.com>
parent 890d9eec
/*******************************************************************************
* Copyright (c) 2000-2016 Ericsson Telecom AB
*
* XSD to TTCN-3 Translator version: CRL 113 200/5 R5B01
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
* Contributors:
* Szabo, Bence Janos
*******************************************************************************/
//
// File: www_example_org_pref1_e.ttcn
// Description:
// References:
// Rev:
// Prodnr:
// Updated: Thu Sep 29 08:47:37 2015
// Contact: http://ttcn.ericsson.se
//
////////////////////////////////////////////////////////////////////////////////
// Generated from file(s):
// - www_example_org_perf1_e.xsd
// /* xml version = "1.0" encoding = "UTF-8" */
// /* targetnamespace = "www.example.org/pref1/e" */
////////////////////////////////////////////////////////////////////////////////
// Modification header(s):
//-----------------------------------------------------------------------------
// Modified by:
// Modification date:
// Description:
// Modification contact:
//------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
module www_example_org_pref1_e {
import from XSD all;
import from www_example_org_pref2 all;
import from www_example_org_pref3 all;
type record MyElement_2
{
www_example_org_pref2.MyElement myElement optional,
www_example_org_pref2.MyElement2 myElement2 optional,
XSD.Integer myField,
www_example_org_pref2.MyType myField2,
www_example_org_pref2.MyElement myElement_1,
www_example_org_pref2.MyElement2 myElement2_1
}
with {
variant "name as 'MyElement'";
variant "element";
variant (myElement) "name as capitalized";
variant (myElement) "namespace as 'www.example.org/pref2' prefix 'ns2'";
variant (myElement) "attribute";
variant (myElement2) "name as capitalized";
variant (myElement2) "namespace as 'www.example.org/pref2' prefix 'ns2'";
variant (myElement2) "attribute";
variant (myElement_1) "name as 'MyElement'";
variant (myElement_1) "namespace as 'www.example.org/pref2' prefix 'ns2'";
variant (myElement2_1) "name as 'MyElement2'";
variant (myElement2_1) "namespace as 'www.example.org/pref2' prefix 'ns2'";
};
type www_example_org_pref2.MyElement MyElement
with {
variant "element";
};
type www_example_org_pref2.MyElement2 MyElement_1
with {
variant "name as 'MyElement'";
variant "element";
};
}
with {
encode "XML";
variant "namespace as 'www.example.org/pref1/e' prefix 'ns'";
variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'";
variant "elementFormQualified";
}
/*******************************************************************************
* Copyright (c) 2000-2016 Ericsson Telecom AB
*
* XSD to TTCN-3 Translator version: CRL 113 200/5 R5B01
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
* Contributors:
* Szabo, Bence Janos
*******************************************************************************/
//
// File: www_example_org_pref2_e.ttcn
// Description:
// References:
// Rev:
// Prodnr:
// Updated: Thu Sep 29 08:47:37 2015
// Contact: http://ttcn.ericsson.se
//
////////////////////////////////////////////////////////////////////////////////
// Generated from file(s):
// - www_example_org_pref2_e.xsd
// /* xml version = "1.0" encoding = "UTF-8" */
// /* targetnamespace = "www.example.org/pref2/e" */
////////////////////////////////////////////////////////////////////////////////
// Modification header(s):
//-----------------------------------------------------------------------------
// Modified by:
// Modification date:
// Description:
// Modification contact:
//------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
module www_example_org_pref2 {
import from XSD all;
type MyType MyElement
with {
variant "element";
};
type MyType MyElement2
with {
variant "element";
};
type record MyType
{
XSD.Integer myField
};
}
with {
encode "XML";
variant "namespace as 'www.example.org/pref2/e' prefix 'ns'";
variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'";
}
/*******************************************************************************
* Copyright (c) 2000-2016 Ericsson Telecom AB
*
* XSD to TTCN-3 Translator version: CRL 113 200/5 R5B01
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
* Contributors:
* Szabo, Bence Janos
*******************************************************************************/
//
// File: www_example_org_pref3_e.ttcn
// Description:
// References:
// Rev:
// Prodnr:
// Updated: Thu Sep 29 08:47:37 2015
// Contact: http://ttcn.ericsson.se
//
////////////////////////////////////////////////////////////////////////////////
// Generated from file(s):
// - www_example_org_pref3_e.xsd
// /* xml version = "1.0" encoding = "UTF-8" */
// /* targetnamespace = "www.example.org/pref3/e" */
////////////////////////////////////////////////////////////////////////////////
// Modification header(s):
//-----------------------------------------------------------------------------
// Modified by:
// Modification date:
// Description:
// Modification contact:
//------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
module www_example_org_pref3 {
import from XSD all;
type MyType MyElement2
with {
variant "element";
};
type record MyType
{
XSD.Integer myField
};
}
with {
encode "XML";
variant "namespace as 'www.example.org/pref3/e' prefix 'ns'";
variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'";
}
......@@ -165,6 +165,9 @@
<File path="../xsd/list_complextype.xsd" />
<File path="../xsd/enumeration_restriction3.xsd" />
<File path="../xsd/MyXMLSchema.xsd" />
<File path="../xsd/www_example_org_pref1.xsd" />
<File path="../xsd/www_example_org_pref2.xsd" />
<File path="../xsd/www_example_org_pref3.xsd" />
</File_Group>
<File_Group name="XmlTest_xsds" >
<File path="../XmlTest_xsds/XmlTest_boolean.xsd" />
......@@ -400,6 +403,9 @@
<File path="../XmlTest_expectedTtcns/www_example_org_list_complextype_e.ttcn" />
<File path="../XmlTest_expectedTtcns/www_example_org_enumeration_restriction3_e.ttcn" />
<File path="../XmlTest_expectedTtcns/http_www_example_org_2001_XMLSchema_e.ttcn" />
<File path="../XmlTest_expectedTtcns/www_example_org_pref1_e.ttcn" />
<File path="../XmlTest_expectedTtcns/www_example_org_pref2_e.ttcn" />
<File path="../XmlTest_expectedTtcns/www_example_org_pref3_e.ttcn" />
</File_Group>
<File_Group name="XmlTest_src" >
<File path="xmlTest_Shell.ttcn" />
......
......@@ -1812,6 +1812,23 @@ group ComplexType {
}
}//tc_
testcase tc_ambiguous_type_namespace_prefix() runs on xmlTest_CT {
f_shellCommandWithVerdict(xsd2ttcn_command & " www_example_org_pref1.xsd www_example_org_pref2.xsd www_example_org_pref3.xsd","",c_shell_successWithoutWarningAndError);
if(getverdict==pass) {
f_compareFiles(
"www_example_org_pref1_e.ttcn","www_example_org_pref1.ttcn", c_numOfDiff_headerAndModuleName);
}
if(getverdict==pass) {
f_compareFiles(
"www_example_org_pref2_e.ttcn","www_example_org_pref2.ttcn", c_numOfDiff_headerAndModuleName);
}
if(getverdict==pass) {
f_compareFiles(
"www_example_org_pref3_e.ttcn","www_example_org_pref3.ttcn", c_numOfDiff_headerAndModuleName);
}
}//tc_
//=========================================================================
// tc_complex_any_pos1_encDec
......@@ -2683,6 +2700,7 @@ control {
execute(tc_complex_import_nameCollision2_converter());
execute(tc_complex_any_pos_converter());
execute(tc_imported_type_prefix());
execute(tc_ambiguous_type_namespace_prefix());
execute(tc_complex_any_pos1_encDec()); //Failed, TR: HL37887
execute(tc_complex_any_pos2_encDec());
execute(tc_complex_any_pos3_encDec());//failed, TR:
......
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="www.example.org/pref1"
xmlns:ns="www.example.org/pref1"
xmlns:ns2="www.example.org/pref2"
xmlns:ns3="www.example.org/pref3">
<import namespace="www_example_org_pref2" schemaLocation="www_example_org_pref2.xsd" />
<import namespace="www_example_org_pref3" schemaLocation="www_example_org_pref3.xsd" />
<element name="MyElement">
<complexType>
<sequence>
<element name="myField" type="integer" />
<element name="myField2" type="ns2:MyType"/>
<element ref="ns2:MyElement"/>
<element ref="ns2:MyElement2"/>
</sequence>
<attribute ref="ns2:MyElement"/>
<attribute ref="ns2:MyElement2"/>
</complexType>
</element>
<element name="MyElement" type="ns2:MyElement"/>
<element name="MyElement" type="ns2:MyElement2"/>
</schema>
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="unqualified"
targetNamespace="www.example.org/pref2"
xmlns:ns="www.example.org/pref2">
<element name="MyElement" type="ns:MyType" />
<element name="MyElement2" type="ns:MyType" />
<complexType name="MyType">
<sequence>
<element name="myField" type="integer" />
</sequence>
</complexType>
</schema>
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="unqualified"
targetNamespace="www.example.org/pref3"
xmlns:ns="www.example.org/pref3">
<element name="MyElement2" type="ns:MyType" />
<complexType name="MyType">
<sequence>
<element name="myField" type="integer" />
</sequence>
</complexType>
</schema>
......@@ -1617,6 +1617,7 @@ void ComplexType::resolveAttribute(AttributeType* attr) {
st->addToNameDepList(attr);
}
}
attr->getReference().set_resolved(st);
} else {
printError(module->getSchemaname(), name.convertedValue,
"Reference for a non-defined type: " + attr->getReference().repr());
......
......@@ -729,7 +729,10 @@ int multi(const TTCN3Module *module, ReferenceData const& outside_reference,
RootType * ct = ::lookup1(module, outside_reference.get_val(), outside_reference.get_uri(), obj, want_CT);
if (st || ct) {
multiplicity = 1; // locally defined, no qualif needed
} else for (List<const TTCN3Module*>::iterator it = module->getImportedModules().begin(); it; it = it->Next) {
// means that outside_reference.get_uri() == module->getTargetNamespace())
} else {
// Look for definitions in the imported modules
for (List<const TTCN3Module*>::iterator it = module->getImportedModules().begin(); it; it = it->Next) {
// Artificial lookup
st = ::lookup1(it->Data, outside_reference.get_val(), it->Data->getTargetNamespace(), obj, want_ST);
ct = ::lookup1(it->Data, outside_reference.get_val(), it->Data->getTargetNamespace(), obj, want_CT);
......@@ -737,6 +740,17 @@ int multi(const TTCN3Module *module, ReferenceData const& outside_reference,
++multiplicity;
}
}
// If multiplicity > 1 then the qualif needed
// But if == 1 we need to check this module for a type definition with
// the same name as outsize_reference.get_val()
if (multiplicity == 1) {
st = ::lookup1(module, outside_reference.get_val(), module->getTargetNamespace(), obj, want_ST);
ct = ::lookup1(module, outside_reference.get_val(), module->getTargetNamespace(), obj, want_CT);
if (st || ct) {
++multiplicity;
}
}
}
return multiplicity;
}
......
......@@ -775,18 +775,6 @@ void SimpleType::finalModification() {
}
isOptional = isOptional || (getMinOccurs() == 0 && getMaxOccurs() == 0);
// If the type name is the same as the identifier then we have to prefix it
// with the module identifier.
if (type.convertedValue == name.convertedValue && !outside_reference.empty()) {
List<const TTCN3Module*>::iterator import_module = module->getImportedModules().begin();
for (; import_module; import_module = import_module->Next) {
if (import_module->Data->getTargetNamespace() == outside_reference.get_uri()) {
type.upload(import_module->Data->getModulename() + Mstring(".") + type.convertedValue);
break;
}
}
}
}
bool SimpleType::hasUnresolvedReference() {
......@@ -835,8 +823,8 @@ void SimpleType::printToFile(FILE * file) {
int multiplicity = multi(module, outside_reference, this);
const RootType *type_ref = outside_reference.get_ref();
if ((multiplicity > 1) && type_ref
&& type_ref->getModule() != module) {
if ((multiplicity > 1 && type_ref && type_ref->getModule() != module)
|| name.convertedValue == type.convertedValue) {
fprintf(file, "%s.", type_ref->getModule()->getModulename().c_str());
}
......
......@@ -332,6 +332,10 @@ public:
return outside_reference;
}
ReferenceData& getReference() {
return outside_reference;
}
EnumerationType & getEnumeration() {
return enumeration;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment