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 #include <precomp.h>
23 #include "hfi_property.hxx"
24 
25 
26 // NOT FULLY DEFINED SERVICES
27 #include <ary/idl/i_ce.hxx>
28 #include <ary/idl/ik_attribute.hxx>
29 #include <ary/idl/ik_constant.hxx>
30 #include <ary/idl/ik_enumvalue.hxx>
31 #include <ary/idl/ik_property.hxx>
32 #include <ary/idl/ik_structelem.hxx>
33 #include <toolkit/hf_docentry.hxx>
34 #include <toolkit/hf_title.hxx>
35 #include "hfi_typetext.hxx"
36 #include "hfi_doc.hxx"
37 #include "hfi_tag.hxx"
38 #include "hi_env.hxx"
39 #include "hi_ary.hxx"
40 #include "hi_linkhelper.hxx"
41 
42 void
Produce_byData(const client & ce) const43 HF_IdlDataMember::Produce_byData( const client & ce ) const
44 {
45     write_Title(ce);
46     enter_ContentCell();
47     write_Declaration(ce);
48     write_Description(ce);
49     leave_ContentCell();
50 }
51 
HF_IdlDataMember(Environment & io_rEnv,HF_SubTitleTable & o_table)52 HF_IdlDataMember::HF_IdlDataMember( Environment &       io_rEnv,
53                                     HF_SubTitleTable &  o_table )
54     :   HtmlFactory_Idl( io_rEnv,
55                          &(o_table.Add_Row()
56                             >> *new Html::TableCell
57                                 << new Html::ClassAttr(C_sCellStyle_MDetail))
58                        )
59 {
60 }
61 
62 const String sContentBorder("0");
63 const String sContentWidth("96%");
64 const String sContentPadding("5");
65 const String sContentSpacing("0");
66 
67 const String sBgWhite("#ffffff");
68 const String sCenter("center");
69 
70 void
write_Title(const client & i_ce) const71 HF_IdlDataMember::write_Title( const client & i_ce ) const
72 {
73     CurOut()
74         >> *new Html::Label(i_ce.LocalName())
75             << new Html::ClassAttr(C_sMemberTitle)
76             << i_ce.LocalName();
77 }
78 
79 void
write_Description(const client & i_ce) const80 HF_IdlDataMember::write_Description( const client & i_ce ) const
81 {
82     CurOut() << new Html::HorizontalLine;
83     write_Docu(CurOut(), i_ce);
84 }
85 
86 void
enter_ContentCell() const87 HF_IdlDataMember::enter_ContentCell() const
88 {
89 
90     Xml::Element &
91         rContentCell = CurOut()
92                         >> *new Html::Table( sContentBorder,
93                                              sContentWidth,
94                                              sContentPadding,
95                                              sContentSpacing )
96                             << new Html::ClassAttr("table-in-data")
97                             << new Html::BgColorAttr(sBgWhite)
98                             << new Html::AlignAttr(sCenter)
99                             >> *new Html::TableRow
100                                 >> *new Html::TableCell;
101     Out().Enter(rContentCell);
102 }
103 
104 
105 void
leave_ContentCell() const106 HF_IdlDataMember::leave_ContentCell() const
107 {
108     Out().Leave();
109 }
110 
111 
~HF_IdlProperty()112 HF_IdlProperty::~HF_IdlProperty()
113 {
114 }
115 
116 typedef ary::idl::ifc_property::attr    PropertyAttr;
117 
118 void
write_Declaration(const client & i_ce) const119 HF_IdlProperty::write_Declaration( const client & i_ce ) const
120 {
121     if (PropertyAttr::HasAnyStereotype(i_ce))
122     {
123         CurOut() << "[ ";
124         if (PropertyAttr::IsReadOnly(i_ce))
125             CurOut() << "readonly ";
126         if (PropertyAttr::IsBound(i_ce))
127             CurOut() << "bound ";
128         if (PropertyAttr::IsConstrained(i_ce))
129             CurOut() << "constrained ";
130         if (PropertyAttr::IsMayBeAmbiguous(i_ce))
131             CurOut() << "maybeambiguous ";
132         if (PropertyAttr::IsMayBeDefault(i_ce))
133             CurOut() << "maybedefault ";
134         if (PropertyAttr::IsMayBeVoid(i_ce))
135             CurOut() << "maybevoid ";
136         if (PropertyAttr::IsRemovable(i_ce))
137             CurOut() << "removable ";
138         if (PropertyAttr::IsTransient(i_ce))
139             CurOut() << "transient ";
140         CurOut() << "] ";
141     }   // end if
142 
143     HF_IdlTypeText
144         aType( Env(), CurOut(), true );
145     aType.Produce_byData( PropertyAttr::Type(i_ce) );
146 
147     CurOut() << " " >> *new Html::Bold << i_ce.LocalName();
148     CurOut() << ";";
149 }
150 
151 
152 
153 
~HF_IdlAttribute()154 HF_IdlAttribute::~HF_IdlAttribute()
155 {
156 }
157 
158 typedef ary::idl::ifc_attribute::attr    AttributeAttr;
159 
160 void
write_Declaration(const client & i_ce) const161 HF_IdlAttribute::write_Declaration( const client & i_ce ) const
162 {
163     if (AttributeAttr::HasAnyStereotype(i_ce))
164     {
165         CurOut() << "[ ";
166         if (AttributeAttr::IsReadOnly(i_ce))
167             CurOut() << "readonly ";
168         if (AttributeAttr::IsBound(i_ce))
169             CurOut() << "bound ";
170         CurOut() << "] ";
171     }
172 
173     HF_IdlTypeText
174         aType( Env(), CurOut(), true );
175     aType.Produce_byData( AttributeAttr::Type(i_ce) );
176 
177     CurOut()
178         << " "
179         >> *new Html::Bold
180             << i_ce.LocalName();
181 
182     dyn_type_list pGetExceptions;
183     dyn_type_list pSetExceptions;
184     AttributeAttr::Get_GetExceptions(pGetExceptions, i_ce);
185     AttributeAttr::Get_SetExceptions(pSetExceptions, i_ce);
186 
187     bool bGetRaises = (*pGetExceptions).IsValid();
188     bool bSetRaises = (*pSetExceptions).IsValid();
189     bool bRaises = bGetRaises OR bSetRaises;
190     if (bRaises)
191     {
192         HF_DocEntryList aSub(CurOut());
193 
194         if (bGetRaises)
195         {
196             Xml::Element &
197                 rGet = aSub.Produce_Definition();
198             HF_IdlTypeText
199                 aExc(Env(), rGet, true);
200             type_list & itExc = *pGetExceptions;
201 
202             rGet << "get raises (";
203             aExc.Produce_byData(*itExc);
204             for (++itExc; itExc.operator bool(); ++itExc)
205             {
206                 rGet
207                     << ",";
208                 aExc.Produce_byData(*itExc);
209             }   // end for
210             rGet << ")";
211             if (NOT bSetRaises)
212                 rGet << ";";
213         }   // end if (bGetRaises)
214 
215         if (bSetRaises)
216         {
217             Xml::Element &
218                 rSet = aSub.Produce_Definition();
219             HF_IdlTypeText
220                 aExc(Env(), rSet, true);
221             type_list & itExc = *pSetExceptions;
222 
223             rSet << "set raises (";
224             aExc.Produce_byData(*itExc);
225             for (++itExc; itExc.operator bool(); ++itExc)
226             {
227                 rSet
228                     << ",";
229                 aExc.Produce_byData(*itExc);
230             }   // end for
231             rSet << ");";
232         }   // end if (bSetRaises)
233     }
234     else
235     {
236         CurOut() << ";";
237     }
238 }
239 
240 
241 
242 
~HF_IdlEnumValue()243 HF_IdlEnumValue::~HF_IdlEnumValue()
244 {
245 }
246 
247 typedef ary::idl::ifc_enumvalue::attr    EnumValueAttr;
248 
249 void
write_Declaration(const client & i_ce) const250 HF_IdlEnumValue::write_Declaration( const client & i_ce ) const
251 {
252     CurOut()
253         >> *new Html::Bold
254             << i_ce.LocalName();
255 
256     const String &
257         rValue = EnumValueAttr::Value(i_ce);
258     if ( NOT rValue.empty() )
259     {    CurOut() << " " // << " = "    // In the moment this is somehow in the value
260                  << rValue;
261         // CurOut() << ",";             // In the moment this is somehow in the value
262     }
263     else
264         CurOut() << ",";
265 }
266 
267 
~HF_IdlConstant()268 HF_IdlConstant::~HF_IdlConstant()
269 {
270 }
271 
272 typedef ary::idl::ifc_constant::attr    ConstantAttr;
273 
274 void
write_Declaration(const client & i_ce) const275 HF_IdlConstant::write_Declaration( const client & i_ce ) const
276 {
277     CurOut() << "const ";
278     HF_IdlTypeText
279         aType( Env(), CurOut(), true );
280     aType.Produce_byData(ConstantAttr::Type(i_ce));
281     CurOut()
282         << " "
283         >> *new Html::Bold
284             << i_ce.LocalName();
285     const String &
286         rValue = ConstantAttr::Value(i_ce);
287     CurOut() << " "     // << " = "    // In the moment this is somehow in the value
288              << rValue;
289     // << ";";  // In the moment this is somehow in the value
290 }
291 
292 
~HF_IdlStructElement()293 HF_IdlStructElement::~HF_IdlStructElement()
294 {
295 }
296 
297 typedef ary::idl::ifc_structelement::attr    StructElementAttr;
298 
299 void
write_Declaration(const client & i_ce) const300 HF_IdlStructElement::write_Declaration( const client & i_ce ) const
301 {
302     HF_IdlTypeText
303         aType( Env(), CurOut(), true );
304     aType.Produce_byData(StructElementAttr::Type(i_ce));
305     CurOut()
306         << " "
307         >> *new Html::Bold
308             << i_ce.LocalName();
309     CurOut()
310         << ";";
311 }
312 
~HF_IdlCommentedRelationElement()313 HF_IdlCommentedRelationElement::~HF_IdlCommentedRelationElement()
314 {
315 }
316 
317 void
produce_Summary(Environment & io_env,Xml::Element & io_context,const comref & i_commentedRef,const client & i_rScopeGivingCe)318 HF_IdlCommentedRelationElement::produce_Summary( Environment &   io_env,
319                                                  Xml::Element &  io_context,
320                                                  const comref &  i_commentedRef,
321 									             const client &  i_rScopeGivingCe )
322 {
323     csv_assert( i_commentedRef.Info() );
324 
325     const ary::idl::Type_id aType = i_commentedRef.Type();
326     const ce_info &         rDocu = *i_commentedRef.Info();
327 
328     bool bShort = NOT rDocu.Short().IsEmpty();
329     bool bDescr = NOT rDocu.Description().IsEmpty();
330 
331     if ( bShort )
332     {
333         HF_IdlDocuTextDisplay
334                 aDescription(io_env, 0, i_rScopeGivingCe);
335 
336         Xml::Element& rPara = io_context >> *new Html::Paragraph;
337         aDescription.Out().Enter( rPara );
338         rDocu.Short().DisplayAt( aDescription );
339 
340         // if there's more than just the summary - i.e. a description, or usage restrictions, or tags -,
341         // then add a link to the details section
342         if ( bDescr OR rDocu.IsDeprecated() OR rDocu.IsOptional() OR NOT rDocu.Tags().empty() )
343         {
344             StreamLock aLocalLink(100);
345             aLocalLink() << "#" << get_LocalLinkName(io_env, i_commentedRef);
346 
347             aDescription.Out().Out() << "(";
348             aDescription.Out().Out()
349                 >> *new Html::Link( aLocalLink().c_str() )
350                     << "details";
351             aDescription.Out().Out() << ")";
352         }
353 
354         aDescription.Out().Leave();
355     }
356 }
357 
358 void
produce_LinkDoc(Environment & io_env,const client & i_ce,Xml::Element & io_context,const comref & i_commentedRef,const E_DocType i_docType)359 HF_IdlCommentedRelationElement::produce_LinkDoc( Environment &   io_env,
360                                                  const client &  i_ce,
361                                                  Xml::Element &  io_context,
362                                                  const comref &  i_commentedRef,
363                                                  const E_DocType i_docType )
364 {
365     if ( i_commentedRef.Info() != 0 )
366     {
367         if ( i_docType == doctype_complete )
368         {
369             HF_DocEntryList aDocList(io_context);
370             HF_IdlDocu aDocuDisplay(io_env, aDocList);
371 
372             aDocuDisplay.Produce_fromReference(*i_commentedRef.Info(), i_ce);
373         }
374         else
375         {
376             produce_Summary(io_env, io_context, i_commentedRef, i_ce);
377         }
378     }
379     else
380     {
381         HF_DocEntryList aDocList(io_context);
382 
383         const client *
384             pCe = io_env.Linker().Search_CeFromType(i_commentedRef.Type());
385         const ce_info *
386             pShort = pCe != 0
387                         ?   Get_IdlDocu(pCe->Docu())
388                         :   (const ce_info *)(0);
389         if ( pShort != 0 )
390         {
391             aDocList.Produce_NormalTerm("(referenced entity's summary:)");
392             Xml::Element &
393                 rDef = aDocList.Produce_Definition();
394             HF_IdlDocuTextDisplay
395                 aShortDisplay( io_env, &rDef, *pCe);
396             pShort->Short().DisplayAt(aShortDisplay);
397         }   // end if (pShort != 0)
398     }   // endif ( (*i_commentedRef).Info() != 0 ) else
399 }
400 
401 
402 String
get_LocalLinkName(Environment & io_env,const comref & i_commentedRef)403 HF_IdlCommentedRelationElement::get_LocalLinkName( Environment &  io_env,
404                                                    const comref & i_commentedRef )
405 {
406     StringVector        aModules;
407     String              sLocalName;
408     ce_id               nCe;
409 	int                 nSequenceCount = 0;
410 
411     const ary::idl::Type &
412         rType = io_env.Data().Find_Type(i_commentedRef.Type());
413     io_env.Data().Get_TypeText(aModules, sLocalName, nCe, nSequenceCount, rType);
414 
415     // speaking strictly, this is not correct: If we have two interfaces with the same local
416     // name, but in different modules, then the link name will be ambiguous. However, this should
417     // be too seldom a case to really make the link names that ugly by adding the module information.
418     return sLocalName;
419 }
420 
421 void
write_Title(const client &) const422 HF_IdlCommentedRelationElement::write_Title( const client & /*i_ce*/ ) const
423 {
424 
425     Xml::Element &
426         rAnchor = CurOut()
427                     >> *new Html::Label(get_LocalLinkName(Env(), m_relation))
428                         << new Html::ClassAttr(C_sMemberTitle);
429 
430     HF_IdlTypeText
431         aText(Env(), rAnchor, true);
432     aText.Produce_byData(m_relation.Type());
433 }
434 
435 void
write_Declaration(const client &) const436 HF_IdlCommentedRelationElement::write_Declaration( const client & /*i_ce*/ ) const
437 {
438     // nothing to do here - an entity which is a commented relation does not have a declaration
439 }
440 
441 void
write_Description(const client & i_ce) const442 HF_IdlCommentedRelationElement::write_Description( const client & i_ce ) const
443 {
444     produce_LinkDoc( Env(), i_ce, CurOut(), m_relation, doctype_complete );
445 }
446