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_method.hxx"
24 
25 
26 // NOT FULLY DEFINED SERVICES
27 #include <ary/idl/i_exception.hxx>
28 #include <ary/idl/i_param.hxx>
29 #include <toolkit/hf_docentry.hxx>
30 #include <toolkit/hf_funcdecl.hxx>
31 #include "hfi_doc.hxx"
32 #include "hfi_globalindex.hxx"
33 #include "hfi_typetext.hxx"
34 
35 
36 
37 
38 
HF_IdlMethod(Environment & io_rEnv,Xml::Element & o_cell)39 HF_IdlMethod::HF_IdlMethod( Environment &           io_rEnv,
40                             Xml::Element &          o_cell)
41     :   HtmlFactory_Idl(io_rEnv,&o_cell)
42 {
43 }
44 
45 
~HF_IdlMethod()46 HF_IdlMethod::~HF_IdlMethod()
47 {
48 }
49 
50 
51 void
Produce_byData(const String & i_sName,type_id i_nReturnType,param_list & i_rParams,type_list & i_rExceptions,bool i_bOneway,bool i_bEllipse,const client & i_ce) const52 HF_IdlMethod::Produce_byData( const String &      i_sName,
53                               type_id             i_nReturnType,
54                               param_list &        i_rParams,
55                               type_list &         i_rExceptions,
56                               bool                i_bOneway,
57                               bool                i_bEllipse,
58                               const client &      i_ce ) const
59 {
60     CurOut()
61         >> *new Html::Label(i_sName)
62             << new Html::ClassAttr(C_sMemberTitle)
63             << i_sName;
64     enter_ContentCell();
65     write_Declaration( i_sName,
66                        i_nReturnType,
67                        i_rParams,
68                        i_rExceptions,
69                        i_bOneway,
70                        i_bEllipse );
71     CurOut() << new Html::HorizontalLine;
72     write_Docu(CurOut(), i_ce);
73     leave_ContentCell();
74 }
75 
76 #if 0 // old
77 void
78 HF_IdlMethod::write_Declaration( const String &      i_sName,
79                                  type_id             i_nReturnType,
80                                  param_list &        i_rParams,
81                                  type_list &         i_rExceptions,
82                                  bool                i_bOneway,
83                                  bool				 i_bEllipse ) const
84 {
85     HF_FunctionDeclaration
86         aDecl(CurOut()) ;
87     Xml::Element &
88         front = aDecl.Add_ReturnLine();
89 
90     // Front:
91     if (i_bOneway)
92         front << "[oneway] ";
93     if (i_nReturnType.IsValid())
94     {   // Normal function, but not constructors:
95         HF_IdlTypeText
96             aReturn(Env(), front, true);
97         aReturn.Produce_byData(i_nReturnType);
98         front
99             << new Html::LineBreak;
100 
101     }
102     front
103         >> *new Html::Bold
104             << i_sName;
105 
106     //  Main line:
107     Xml::Element &
108         types = aDecl.Types();
109     Xml::Element &
110         names = aDecl.Names();
111     bool bParams = i_rParams.operator bool();
112     if (bParams)
113     {
114         front
115             << "(";
116         HF_IdlTypeText
117             aType( Env(), types, true );
118 
119         write_Param( aType, names, (*i_rParams) );
120 
121         for (++i_rParams; i_rParams; ++i_rParams)
122         {
123             types
124                 << new Html::LineBreak;
125             names
126                 << ","
127                 << new Html::LineBreak;
128             write_Param( aType, names, (*i_rParams) );
129         }   // end for
130 
131         if (i_bEllipse)
132         {
133             names
134                 << " ...";
135         }
136         names
137             << " )";
138     }
139     else
140         front
141             << "()";
142 
143 
144     if ( i_rExceptions.operator bool() )
145     {
146         Xml::Element &
147             rExcOut = aDecl.Add_RaisesLine("raises", NOT bParams);
148         HF_IdlTypeText
149             aExc(Env(), rExcOut, true);
150         aExc.Produce_byData(*i_rExceptions);
151 
152         for (++i_rExceptions; i_rExceptions; ++i_rExceptions)
153         {
154             rExcOut
155                 << ","
156                 << new Html::LineBreak;
157             aExc.Produce_byData(*i_rExceptions);
158         }   // end for
159 
160         rExcOut << " );";
161     }
162     else
163     {
164         if (bParams)
165             aDecl.Names() << ";";
166         else
167             aDecl.Front() << ";";
168     }
169 }
170 #endif   // 0  old
171 
172 void
write_Declaration(const String & i_sName,type_id i_nReturnType,param_list & i_rParams,type_list & i_rExceptions,bool i_bOneway,bool i_bEllipse) const173 HF_IdlMethod::write_Declaration( const String &      i_sName,
174                                  type_id             i_nReturnType,
175                                  param_list &        i_rParams,
176                                  type_list &         i_rExceptions,
177                                  bool                i_bOneway,
178                                  bool				 i_bEllipse ) const
179 {
180     HF_FunctionDeclaration
181         aDecl(CurOut(), "raises") ;
182     Xml::Element &
183         rReturnLine = aDecl.ReturnCell();
184 
185     // Return line:
186     if (i_bOneway)
187         rReturnLine << "[oneway] ";
188     if (i_nReturnType.IsValid())
189     {   // Normal function, but not constructors:
190         HF_IdlTypeText
191             aReturn(Env(), rReturnLine, true);
192         aReturn.Produce_byData(i_nReturnType);
193     }
194 
195     //  Main line:
196     Xml::Element &
197         rNameCell = aDecl.NameCell();
198     rNameCell
199         >> *new Html::Bold
200             << i_sName;
201 
202     Xml::Element *
203         pParamEnd  = 0;
204 
205     bool bParams = i_rParams.operator bool();
206     if (bParams)
207     {
208         rNameCell
209             << "(";
210 
211         pParamEnd  = write_Param( aDecl, *i_rParams );
212         for (++i_rParams; i_rParams; ++i_rParams)
213         {
214             *pParamEnd << ",";
215             pParamEnd  = write_Param( aDecl, *i_rParams );
216         }   // end for
217 
218         if (i_bEllipse)
219         {
220             Xml::Element &
221                 rParamType = aDecl.NewParamTypeCell();
222             rParamType
223                 << " ...";
224             pParamEnd = &rParamType;
225         }
226         *pParamEnd
227             << " )";
228     }
229     else
230     {
231         rNameCell
232             << "()";
233     }
234 
235     if ( i_rExceptions.operator bool() )
236     {
237         Xml::Element &
238             rExcOut = aDecl.ExceptionCell();
239         HF_IdlTypeText
240             aExc(Env(), rExcOut, true);
241         aExc.Produce_byData(*i_rExceptions);
242 
243         for (++i_rExceptions; i_rExceptions; ++i_rExceptions)
244         {
245             rExcOut
246                 << ","
247                 << new Html::LineBreak;
248             aExc.Produce_byData(*i_rExceptions);
249         }   // end for
250 
251         rExcOut << " );";
252     }
253     else if (bParams)
254     {
255         *pParamEnd << ";";
256     }
257     else
258     {
259         rNameCell << ";";
260     }
261 }
262 
263 #if 0   // old
264 void
265 HF_IdlMethod::write_Param( HF_IdlTypeText &             o_type,
266                            Xml::Element &               o_names,
267                            const ary::idl::Parameter &  i_param ) const
268 {
269     switch ( i_param.Direction() )
270     {
271         case ary::idl::param_in:
272                     o_type.CurOut() << "[in] ";
273                     break;
274         case ary::idl::param_out:
275                     o_type.CurOut() << "[out] ";
276                     break;
277         case ary::idl::param_inout:
278                     o_type.CurOut() << "[inout] ";
279                     break;
280     }   // end switch
281 
282     o_type.Produce_byData( i_param.Type() );
283     o_names
284         << i_param.Name();
285 }
286 #endif  // 0   old
287 
288 Xml::Element *
write_Param(HF_FunctionDeclaration & o_decl,const ary::idl::Parameter & i_param) const289 HF_IdlMethod::write_Param( HF_FunctionDeclaration &     o_decl,
290                            const ary::idl::Parameter &  i_param ) const
291 {
292     Xml::Element &
293         rTypeCell  = o_decl.NewParamTypeCell();
294     Xml::Element &
295         rNameCell  = o_decl.ParamNameCell();
296 
297     switch ( i_param.Direction() )
298     {
299         case ary::idl::param_in:
300                     rTypeCell << "[in] ";
301                     break;
302         case ary::idl::param_out:
303                     rTypeCell << "[out] ";
304                     break;
305         case ary::idl::param_inout:
306                     rTypeCell << "[inout] ";
307                     break;
308     }   // end switch
309 
310     HF_IdlTypeText
311         aTypeWriter(Env(), rTypeCell, true);
312     aTypeWriter.Produce_byData( i_param.Type() );
313 
314     rNameCell
315         << i_param.Name();
316     return &rNameCell;
317 }
318 
319 const String sContentBorder("0");
320 const String sContentWidth("96%");
321 const String sContentPadding("5");
322 const String sContentSpacing("0");
323 
324 const String sBgWhite("#ffffff");
325 const String sCenter("center");
326 
327 void
enter_ContentCell() const328 HF_IdlMethod::enter_ContentCell() const
329 {
330 
331     Xml::Element &
332         rContentCell = CurOut()
333                         >> *new Html::Table( sContentBorder,
334                                              sContentWidth,
335                                              sContentPadding,
336                                              sContentSpacing )
337                             << new Html::ClassAttr("table-in-method")
338                             << new Html::BgColorAttr(sBgWhite)
339                             << new Html::AlignAttr(sCenter)
340                             >> *new Html::TableRow
341                                 >> *new Html::TableCell;
342     Out().Enter(rContentCell);
343 }
344 
345 
346 void
leave_ContentCell() const347 HF_IdlMethod::leave_ContentCell() const
348 {
349     Out().Leave();
350 }
351 
352