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