xsd2ttcn: fixed error when reading XMLSchema.xsd (Bug 495653)
[deliverable/titan.core.git] / xsdconvert / ComplexType.hh
1 /******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Balasko, Jeno
10 * Godar, Marton
11 * Raduly, Csaba
12 * Szabo, Bence Janos
13 *
14 ******************************************************************************/
15 #ifndef COMPLEXTYPE_H_
16 #define COMPLEXTYPE_H_
17
18 #include "RootType.hh"
19 #include "SimpleType.hh"
20 #include "TTCN3Module.hh"
21 #include "AttributeType.hh"
22
23
24 class AttributeType;
25
26 /**
27 * Type that contains information coming from XSD complexTypes, model group definitions
28 * and attributeGroups
29 *
30 * Source in XSD:
31 *
32 * * <complexType>, <group> and <attributeGroup> element whose parent element is <schema>
33 * * <element> if nillable, or is a child of <complexType>
34 *
35 * Result in TTCN-3:
36 *
37 * * TTCN-3 type
38 *
39 */
40 class ComplexType : public SimpleType {
41 public:
42
43 enum ComplexType_Mode {
44 CT_simpletype_mode,
45 CT_complextype_mode,
46 CT_undefined_mode
47 };
48
49 enum CT_fromST {
50 fromTagUnion,
51 fromTagNillable,
52 fromTagComplexType,
53 fromTagSubstitution,
54 fromTypeSubstitution
55 };
56
57 enum Resolv_State {
58 No,
59 InProgress,
60 Yes
61 };
62
63 private:
64 //If the complextype is a top level component (child of schema)
65 bool top;
66 bool nillable;
67 bool enumerated;
68 bool embed;
69 bool with_union;
70 bool first_child;
71 bool fromAll;
72 unsigned max_alt;
73 int skipback;
74 //Special use: true if an element of a complextype is restricted to a list
75 // in a simpletype
76 bool list;
77 TagName lastType;
78 Mstring actualPath;
79 RootType * actfield;
80 SimpleType * nameDep;
81 RootType * nillable_field;
82 ComplexType * basefield;
83 ComplexType_Mode cmode;
84 Resolv_State resolved;
85 ComplexType * parentTypeSubsGroup;
86
87
88 void applyAttributeRestriction(ComplexType * found_CT);
89 void applyAttributeExtension(ComplexType * found_CT, AttributeType * anyAttr = NULL);
90 void nameConversion_names(const List<NamespaceType> & ns);
91 void nameConversion_types(const List<NamespaceType> & ns);
92 void nameConversion_fields(const List<NamespaceType> & ns);
93 void setFieldPaths(Mstring path);
94 void collectVariants(List<Mstring>& container);
95 void addNameSpaceAsVariant(RootType * type, RootType * other);
96 void setMinMaxOccurs(const unsigned long long min, const unsigned long long max, const bool generate_list_postfix = true);
97 void applyNamespaceAttribute(VariantMode varLabel, const Mstring& ns_list);
98 void applyReference(const SimpleType & other, const bool on_attributes = false);
99 void setParent(ComplexType * par, SimpleType * child);
100 void finalModification2();
101 Mstring findRoot(const BlockValue value, SimpleType * elem, const Mstring& head_type, const bool first);
102
103 //Reference resolving functions
104 void reference_resolving_funtion();
105 void resolveAttribute(AttributeType *attr);
106 void resolveAttributeGroup(SimpleType *st);
107 void resolveGroup(SimpleType *st);
108 void resolveElement(SimpleType *st);
109 void resolveSimpleTypeExtension();
110 void resolveSimpleTypeRestriction();
111 void resolveComplexTypeExtension();
112 void resolveComplexTypeRestriction();
113 void resolveUnion(SimpleType *st);
114 bool hasMatchingFields(const List<ComplexType*>& a, const List<ComplexType*>& b) const;
115
116 void printVariant(FILE * file);
117
118 public:
119 List<ComplexType*> complexfields;
120 List<AttributeType*> attribfields;
121 List<Mstring> enumfields;
122 List<TagName> tagNames;
123
124 ComplexType(XMLParser * a_parser, TTCN3Module * a_module, ConstructType a_construct);
125 ComplexType(ComplexType & other);
126 ComplexType(const SimpleType & other, CT_fromST c);
127 ComplexType(ComplexType * other);
128 ~ComplexType();
129
130 void modifyAttributeParent();
131 void addSubstitution(SimpleType * st);
132 void addTypeSubstitution(SimpleType * st);
133
134 /** Virtual methods
135 * inherited from RootType
136 */
137 void loadWithValues();
138 void addComment(const Mstring& text);
139 void printToFile(FILE * file);
140 void printToFile(FILE * file, const unsigned level, const bool is_union);
141
142 void modifyValues();
143 void referenceResolving();
144 void nameConversion(NameConversionMode mode, const List<NamespaceType> & ns);
145 void finalModification();
146 bool hasUnresolvedReference(){ return resolved == No; }
147 void setNameDep(SimpleType * dep) { nameDep = dep; }
148 void setParentTypeSubsGroup(ComplexType * dep) { parentTypeSubsGroup = dep; }
149
150 void dump(unsigned int depth) const;
151
152 };
153
154 inline bool compareComplexTypeNameSpaces(ComplexType * lhs, ComplexType * rhs) {
155 if (lhs->getModule()->getTargetNamespace() == Mstring("NoTargetNamespace") && rhs->getModule()->getTargetNamespace() == Mstring("NoTargetNamespace")) {
156 return false;
157 } else if (lhs->getModule()->getTargetNamespace() == Mstring("NoTargetNamespace")) {
158 return true;
159 } else if (rhs->getModule()->getTargetNamespace() == Mstring("NoTargetNamespace")) {
160 return false;
161 } else {
162 return lhs->getModule()->getTargetNamespace() <= rhs->getModule()->getTargetNamespace();
163 }
164 }
165
166 inline bool compareTypes(ComplexType * lhs, ComplexType * rhs) {
167 return lhs->getName().convertedValue < rhs->getName().convertedValue;
168 }
169
170
171 #endif /* COMPLEXTYPE_H_ */
172
This page took 0.032974 seconds and 5 git commands to generate.