xref: /trunk/main/xml2cmp/source/xcd/xmltree.cxx (revision ab595ff6)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 
25 #include <xmltree.hxx>
26 
27 
28 // NOT FULLY DEFINED SERVICES
29 #include <cr_html.hxx>
30 #include <cr_index.hxx>
31 
32 
33 char  C_sMODULEDESCRIPTION[] = "module-description";
34 char  C_sCOMPONENTDESCRIPTION[] = "component-description";
35 char  C_sAuthor[] = "author";
36 char  C_sName[] = "name";
37 char  C_sDescription[] = "description";
38 char  C_sReferenceDocu[] = "reference-docu";
39 char  C_sModuleName[] = "module-name";
40 char  C_sLoaderName[] = "loader-name";
41 char  C_sSupportedService[] = "supported-service";
42 char  C_sServiceDependency[] = "service-dependency";
43 char  C_sProjectBuildDependency[] = "project-build-dependency";
44 char  C_sRuntimeModuleDependency[] = "runtime-module-dependency";
45 char  C_sLanguage[] = "language";
46 char  C_sStatus[] = "status";
47 char  C_sType[] = "type";
48 char  C_sAttr_value[] = "value";
49 char  C_sAttr_xl_href[] = "xlink:href";
50 char  C_sAttr_xl_role[] = "xlink:role";
51 char  C_sAttr_xl_title[] = "xlink:title";
52 char  C_sAttr_xmlns[] = "xmlns:xlink";
53 char  C_sAttr_xl_type[] = "xlink:type";
54 char  C_sCompDescrListTitle[] = "Component Descriptions";
55 
56 
57 FreeChoiceElement *	Create_ModuleDescrOptional_Element(
58 						MultipleTextElement * &
59 											o_rTypes,
60 						MultipleTextElement * &
61 											o_rServiceDependencies );
62 FreeChoiceElement *	Create_CompDescrOptional_Element(
63 						MultipleTextElement * &
64 											o_rTypes,
65 						MultipleTextElement * &
66 											o_rServiceDependencies );
67 
68 
69 
ModuleDescription()70 ModuleDescription::ModuleDescription()
71 	:	SequenceElement(C_sMODULEDESCRIPTION),
72 		pModuleName(0),
73 		pCdList(0),
74 		pTypes(0),
75 		pServiceDependencies(0)
76 {
77 	pModuleName = new MdName;
78 	AddChild( *pModuleName );
79 	pCdList = new CompDescrList;
80 	AddChild( *pCdList );
81 	AddChild( *Create_ModuleDescrOptional_Element( pTypes, pServiceDependencies ) );
82 }
83 
84 const Simstr &
ModuleName() const85 ModuleDescription::ModuleName() const
86 {
87 	return pModuleName->Data();
88 }
89 
90 void
Get_SupportedServices(List<const MultipleTextElement * > & o_rServices) const91 ModuleDescription::Get_SupportedServices( List< const MultipleTextElement * > & o_rServices ) const
92 {
93 	o_rServices.push_back(pServiceDependencies);
94 	pCdList->Get_SupportedServices( o_rServices );
95 }
96 
97 void
Get_Types(List<const MultipleTextElement * > & o_rTypes) const98 ModuleDescription::Get_Types( List< const MultipleTextElement * > & o_rTypes ) const
99 {
100 	o_rTypes.push_back(pTypes);
101 	pCdList->Get_Types( o_rTypes );
102 }
103 
104 void
Get_ServiceDependencies(List<const MultipleTextElement * > & o_rServices) const105 ModuleDescription::Get_ServiceDependencies( List< const MultipleTextElement * > & o_rServices ) const
106 {
107 	pCdList->Get_ServiceDependencies( o_rServices );
108 }
109 
ComponentDescription()110 ComponentDescription::ComponentDescription()
111 	:	SequenceElement(C_sCOMPONENTDESCRIPTION,1),
112 		pComponentName(0),
113 		pSupportedServices(0),
114 		pTypes(0),
115 		pServiceDependencies(0)
116 {
117 	AddChild( *new SglTextElement(C_sAuthor, lt_nolink, false) );
118 	pComponentName = new CdName;
119 	AddChild( *pComponentName );
120 	AddChild( *new SglTextElement(C_sDescription, lt_nolink, false) );
121 	AddChild( *new SglTextElement(C_sLoaderName, lt_idl, true) );
122 	AddChild( *new SglTextElement(C_sLanguage, lt_nolink, false) );
123 	AddChild( *new SglAttrElement(C_sStatus, C_sAttr_value) );
124 	pSupportedServices = new SupportedService;
125 	AddChild( *pSupportedServices );
126 	AddChild( *Create_CompDescrOptional_Element( pTypes, pServiceDependencies ) );
127 }
128 
CompDescrList()129 CompDescrList::CompDescrList()
130 	:	ListElement(C_sCOMPONENTDESCRIPTION, 0)
131 {
132 }
133 
134 void
Write2Html(HtmlCreator & io_rHC) const135 CompDescrList::Write2Html( HtmlCreator & io_rHC ) const
136 {
137 	io_rHC.StartBigCell(C_sCompDescrListTitle);
138 	ListElement::Write2Html(io_rHC);
139 	io_rHC.FinishBigCell();
140 }
141 
142 XmlElement *
Create_and_Add_NewElement()143 CompDescrList::Create_and_Add_NewElement()
144 {
145 	ComponentDescription * pCD = new ComponentDescription;
146 	Children().push_back(pCD);
147 	aCDs.push_back(pCD);
148 	return pCD;
149 }
150 
151 void
Get_SupportedServices(List<const MultipleTextElement * > & o_rResult) const152 CompDescrList::Get_SupportedServices( List< const MultipleTextElement * > & o_rResult ) const
153 {
154 	unsigned i_max = aCDs.size();;
155 	for (unsigned i = 0; i < i_max; ++i)
156 	{
157 		o_rResult.push_back(& aCDs[i]->SupportedServices());
158 	}  // end for
159 }
160 
161 void
Get_Types(List<const MultipleTextElement * > & o_rResult) const162 CompDescrList::Get_Types( List< const MultipleTextElement * > & o_rResult ) const
163 {
164 	unsigned i_max = aCDs.size();;
165 	for (unsigned i = 0; i < i_max; ++i)
166 	{
167 		o_rResult.push_back(& aCDs[i]->Types());
168 	}  // end for
169 }
170 
171 void
Get_ServiceDependencies(List<const MultipleTextElement * > & o_rResult) const172 CompDescrList::Get_ServiceDependencies( List< const MultipleTextElement * > & o_rResult ) const
173 {
174 	unsigned i_max = aCDs.size();;
175 	for (unsigned i = 0; i < i_max; ++i)
176 	{
177 		o_rResult.push_back(& aCDs[i]->ServiceDependencies());
178 	}  // end for
179 }
180 
MdName()181 MdName::MdName()
182 	:	SglTextElement(C_sModuleName, lt_html, false)
183 {
184 }
185 
186 void
Write2Html(HtmlCreator & io_rHC) const187 MdName::Write2Html( HtmlCreator & io_rHC ) const
188 {
189 	io_rHC.Write_SglTextElement( *this, true );
190 }
191 
CdName()192 CdName::CdName()
193 	:	SglTextElement(C_sName, lt_html, true)
194 {
195 }
196 
197 void
Write2Html(HtmlCreator & io_rHC) const198 CdName::Write2Html( HtmlCreator & io_rHC ) const
199 {
200 	io_rHC.Write_SglTextElement( *this, true );
201 }
202 
SupportedService()203 SupportedService::SupportedService()
204 	:	MultipleTextElement(C_sSupportedService, lt_idl, true)
205 {
206 }
207 
208 void
Insert2Index(Index & o_rIndex) const209 SupportedService::Insert2Index( Index & o_rIndex ) const
210 {
211 	for ( unsigned i = 0; i < Size(); ++i )
212 	{
213 		o_rIndex.InsertSupportedService( Data(i) );
214 	}
215 }
216 
217 FreeChoiceElement *
Create_ModuleDescrOptional_Element(MultipleTextElement * & o_rTypes,MultipleTextElement * & o_rServiceDependencies)218 Create_ModuleDescrOptional_Element( MultipleTextElement * & o_rTypes,
219 								  MultipleTextElement * & o_rServiceDependencies )
220 {
221 	FreeChoiceElement * ret = Create_CompDescrOptional_Element( o_rTypes, o_rServiceDependencies );
222 
223 	ret->AddChild( *new MultipleTextElement(C_sProjectBuildDependency, lt_nolink, false) );
224 	ret->AddChild( *new MultipleTextElement(C_sRuntimeModuleDependency, lt_nolink, false) );
225 	return ret;
226 }
227 
228 FreeChoiceElement *
Create_CompDescrOptional_Element(MultipleTextElement * & o_rTypes,MultipleTextElement * & o_rServiceDependencies)229 Create_CompDescrOptional_Element( MultipleTextElement * & o_rTypes,
230 								  MultipleTextElement * & o_rServiceDependencies )
231 {
232 	FreeChoiceElement * ret = new FreeChoiceElement;
233 	const unsigned C_sRefDocuAttrNumber = 5;
234 	static const char * C_sRefDocuAttrNames[C_sRefDocuAttrNumber]
235 			= { C_sAttr_xl_href, C_sAttr_xl_role, C_sAttr_xl_title, C_sAttr_xmlns, C_sAttr_xl_type };
236 
237 	ret->AddChild( *new MultipleAttrElement(C_sReferenceDocu, C_sRefDocuAttrNames, C_sRefDocuAttrNumber) );
238 	o_rServiceDependencies = new MultipleTextElement(C_sServiceDependency, lt_idl, true);
239 	ret->AddChild( *o_rServiceDependencies );
240 	o_rTypes = new MultipleTextElement(C_sType, lt_idl, true);
241 	ret->AddChild( *o_rTypes );
242 	return ret;
243 }
244 
245 
246 #if 0
247 
248 const TextElement *
249 ModuleDescription::ServiceDependencies() const
250 {
251 	const unsigned nEarliestPossibleServiceDependenciesIndexInModules = 1;
252 
253 	for ( unsigned i = nEarliestPossibleServiceDependenciesIndexInModules;
254 		  i < Children().size();
255 		  ++i )
256 	{
257 		if ( strcmp(Children()[i]->Name(), C_sServiceDependency) == 0 )
258 			return Children()[i];
259 	}
260 	return 0;
261 }
262 
263 const TextElement &
264 ComponentDescription::SupportedServices() const
265 {
266 	return *Children()[C_nSupportedServicesIndex];
267 }
268 
269 const TextElement *
270 ComponentDescription::ServiceDependencies() const
271 {
272 	for ( unsigned i = C_nEarliestPossibleServiceDependenciesIndex; i < Children().size(); ++i )
273 	{
274 		if ( strcmp(Children()[i]->Name(),C_sServiceDependency) == 0)
275 			return Children()[i];
276 	}
277 	return 0;
278 }
279 
280 #endif
281 
282 
283