1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include <precomp.h> 29 #include <s2_luidl/pe_servi.hxx> 30 31 32 // NOT FULLY DEFINED SERVICES 33 #include <ary/idl/i_gate.hxx> 34 #include <ary/idl/i_service.hxx> 35 #include <ary/idl/i_siservice.hxx> 36 #include <ary/idl/ip_ce.hxx> 37 #include <ary/doc/d_oldidldocu.hxx> 38 #include <s2_luidl/pe_func2.hxx> 39 #include <s2_luidl/pe_property.hxx> 40 #include <s2_luidl/pe_type2.hxx> 41 #include <s2_luidl/tk_keyw.hxx> 42 #include <s2_luidl/tk_ident.hxx> 43 #include <s2_luidl/tk_punct.hxx> 44 45 46 47 namespace csi 48 { 49 namespace uidl 50 { 51 52 53 54 PE_Service::PE_Service() 55 : eState(e_none), 56 sData_Name(), 57 bIsPreDeclaration(false), 58 pCurService(0), 59 pCurSiService(0), 60 nCurService(0), 61 pPE_Property(0), 62 nCurParsed_Property(0), 63 pPE_Type(0), 64 nCurParsed_Type(0), 65 pPE_Constructor(0), 66 bOptionalMember(false) 67 { 68 pPE_Property = new PE_Property(nCurService); 69 pPE_Type = new PE_Type(nCurParsed_Type); 70 pPE_Constructor = new PE_Function(nCurService, PE_Function::constructor); 71 } 72 73 void 74 PE_Service::EstablishContacts( UnoIDL_PE * io_pParentPE, 75 ary::Repository & io_rRepository, 76 TokenProcessing_Result & o_rResult ) 77 { 78 UnoIDL_PE::EstablishContacts(io_pParentPE,io_rRepository,o_rResult); 79 pPE_Property->EstablishContacts(this,io_rRepository,o_rResult); 80 pPE_Type->EstablishContacts(this,io_rRepository,o_rResult); 81 pPE_Constructor->EstablishContacts(this,io_rRepository,o_rResult); 82 } 83 84 PE_Service::~PE_Service() 85 { 86 } 87 88 void 89 PE_Service::ProcessToken( const Token & i_rToken ) 90 { 91 i_rToken.Trigger(*this); 92 } 93 94 95 void 96 PE_Service::Process_MetaType( const TokMetaType & i_rToken ) 97 { 98 switch ( i_rToken.Id() ) 99 { 100 case TokMetaType::mt_service: 101 if (eState == need_name) 102 SetResult(done, stay ); 103 else if (eState == e_std) 104 { 105 SetResult(done, push_sure, pPE_Type.Ptr()); 106 eState = in_service_type; 107 } 108 else 109 On_Default(); 110 break; 111 case TokMetaType::mt_interface: 112 if (eState == e_std) 113 { 114 SetResult(done, push_sure, pPE_Type.Ptr()); 115 eState = in_ifc_type; 116 } 117 else 118 On_Default(); 119 break; 120 case TokMetaType::mt_property: 121 if (eState == e_std) 122 { 123 StartProperty(); 124 } 125 else 126 On_Default(); 127 break; 128 default: 129 // KORR_FUTURE: 130 // Should throw syntax error warning. 131 ; 132 } // end switch 133 } 134 135 void 136 PE_Service::Process_Identifier( const TokIdentifier & i_rToken ) 137 { 138 if (eState == need_name) 139 { 140 sData_Name = i_rToken.Text(); 141 SetResult(done, stay); 142 eState = need_curlbr_open; 143 } 144 else if (eState == e_std_sib) 145 { 146 SetResult(not_done, push_sure, pPE_Constructor.Ptr()); 147 } 148 else 149 On_Default(); 150 } 151 152 void 153 PE_Service::Process_Punctuation( const TokPunctuation & i_rToken ) 154 { 155 switch (i_rToken.Id()) 156 { 157 case TokPunctuation::Colon: 158 if (eState == need_curlbr_open) 159 { 160 SetResult(done, push_sure, pPE_Type.Ptr()); 161 eState = need_base_interface; 162 } 163 else 164 On_Default(); 165 break; 166 167 case TokPunctuation::CurledBracketOpen: 168 if (eState == need_curlbr_open) 169 { 170 pCurService = &Gate().Ces().Store_Service( 171 CurNamespace().CeId(), 172 sData_Name ); 173 nCurService = pCurService->CeId(); 174 PassDocuAt(*pCurService); 175 SetResult(done, stay); 176 eState = e_std; 177 } 178 else if (eState == need_curlbr_open_sib) 179 { 180 SetResult(done, stay); 181 eState = e_std_sib; 182 } 183 else 184 On_Default(); 185 break; 186 case TokPunctuation::CurledBracketClose: 187 if (eState == e_std OR eState == e_std_sib) 188 { 189 SetResult(done, stay); 190 eState = need_finish; 191 } 192 else 193 On_Default(); 194 break; 195 case TokPunctuation::Comma: 196 if (eState == expect_ifc_separator) 197 { 198 SetResult(done, push_sure, pPE_Type.Ptr()); 199 eState = in_ifc_type; 200 } 201 else if (eState == expect_service_separator) 202 { 203 SetResult(done, push_sure, pPE_Type.Ptr()); 204 eState = in_service_type; 205 } 206 else if (eState == e_std) 207 { 208 SetResult(done, stay); 209 } 210 else 211 On_Default(); 212 break; 213 case TokPunctuation::Semicolon: 214 switch (eState) 215 { 216 case need_curlbr_open: 217 sData_Name.clear(); 218 bIsPreDeclaration = true; 219 SetResult(done, pop_success); 220 eState = e_none; 221 break; 222 case need_curlbr_open_sib: 223 SetResult(done, pop_success); 224 eState = e_none; 225 break; 226 case expect_ifc_separator: 227 case expect_service_separator: 228 SetResult(done, stay); 229 eState = e_std; 230 break; 231 case need_finish: 232 SetResult(done, pop_success); 233 eState = e_none; 234 break; 235 case at_ignore: 236 SetResult(done, stay); 237 eState = e_std; 238 break; 239 default: 240 On_Default(); 241 } // end switch 242 break; 243 default: 244 On_Default(); 245 } // end switch 246 } 247 248 void 249 PE_Service::Process_Stereotype( const TokStereotype & i_rToken ) 250 { 251 if (i_rToken.Id() == TokStereotype::ste_optional) 252 { 253 bOptionalMember = true; 254 SetResult(done, stay); 255 } 256 else if ( eState == e_std ) 257 { 258 StartProperty(); 259 } 260 else 261 On_Default(); 262 } 263 264 void 265 PE_Service::Process_Needs() 266 { 267 SetResult(done,stay); 268 eState = at_ignore; 269 } 270 271 void 272 PE_Service::Process_Observes() 273 { 274 SetResult(done,stay); 275 eState = at_ignore; 276 } 277 278 void 279 PE_Service::Process_Default() 280 { 281 On_Default(); 282 } 283 284 285 void 286 PE_Service::On_Default() 287 { 288 if (eState == at_ignore) 289 SetResult(done, stay); 290 else 291 SetResult(not_done, pop_failure); 292 } 293 294 void 295 PE_Service::InitData() 296 { 297 eState = need_name; 298 sData_Name.clear(); 299 bIsPreDeclaration = false; 300 pCurService = 0; 301 pCurSiService = 0; 302 nCurService = 0; 303 nCurParsed_Property = 0; 304 nCurParsed_Type = 0; 305 bOptionalMember = false; 306 } 307 308 void 309 PE_Service::TransferData() 310 { 311 if (NOT bIsPreDeclaration) 312 { 313 csv_assert(sData_Name.size() > 0); 314 csv_assert( (pCurService != 0) != (pCurSiService != 0) ); 315 } 316 317 eState = e_none; 318 } 319 320 void 321 PE_Service::ReceiveData() 322 { 323 switch (eState) 324 { 325 case in_property: 326 eState = e_std; 327 break; 328 case in_ifc_type: 329 if (bOptionalMember) 330 { 331 pPE_Type->SetOptional(); 332 } 333 pCurService->AddRef_SupportedInterface( 334 nCurParsed_Type, 335 pPE_Type->ReleaseDocu()); 336 nCurParsed_Type = 0; 337 eState = expect_ifc_separator; 338 break; 339 case in_service_type: 340 if (bOptionalMember) 341 { 342 pPE_Type->SetOptional(); 343 } 344 pCurService->AddRef_IncludedService( 345 nCurParsed_Type, 346 pPE_Type->ReleaseDocu()); 347 nCurParsed_Type = 0; 348 eState = expect_service_separator; 349 break; 350 case need_base_interface: 351 pCurSiService = &Gate().Ces().Store_SglIfcService( 352 CurNamespace().CeId(), 353 sData_Name, 354 nCurParsed_Type ); 355 nCurService = pCurSiService->CeId(); 356 PassDocuAt(*pCurSiService); 357 358 nCurParsed_Type = 0; 359 eState = need_curlbr_open_sib; 360 break; 361 case e_std_sib: 362 break; 363 default: 364 csv_assert(false); 365 } 366 367 bOptionalMember = false; 368 } 369 370 371 UnoIDL_PE & 372 PE_Service::MyPE() 373 { 374 return *this; 375 } 376 377 void 378 PE_Service::StartProperty() 379 { 380 SetResult(not_done, push_sure, pPE_Property.Ptr()); 381 eState = in_property; 382 383 if (bOptionalMember) 384 { 385 pPE_Property->PresetOptional(); 386 bOptionalMember = false; 387 } 388 } 389 390 391 } // namespace uidl 392 } // namespace csi 393 394