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_singl.hxx>
30 
31 
32 // NOT FULLY DEFINED SERVICES
33 #include <ary/idl/i_gate.hxx>
34 #include <ary/idl/i_singleton.hxx>
35 #include <ary/idl/i_sisingleton.hxx>
36 #include <ary/idl/ip_ce.hxx>
37 #include <ary/doc/d_oldidldocu.hxx>
38 #include <s2_luidl/pe_type2.hxx>
39 #include <s2_luidl/tk_keyw.hxx>
40 #include <s2_luidl/tk_ident.hxx>
41 #include <s2_luidl/tk_punct.hxx>
42 
43 
44 
45 namespace csi
46 {
47 namespace uidl
48 {
49 
50 
51 
52 #if 0
53 #ifdef DF
54 #undef DF
55 #endif
56 #define DF 	&PE_Singleton::On_Default
57 
58 
59 PE_Singleton::F_TOK
60 PE_Singleton::aDispatcher[PE_Singleton::e_STATES_MAX][PE_Singleton::tt_MAX] =
61 		{ 	{ DF, DF, DF },  // e_none
62 			{ DF, &PE_Singleton::On_need_name_Identifer,
63 					  DF },  // need_name
64 			{ DF, DF, &PE_Singleton::On_need_curlbr_open_Punctuation,
65 						 },  // need_curlbr_open
66 			{ &PE_Singleton::On_std_GotoService,
67 				  DF, &PE_Singleton::On_std_Punctuation,
68 						 },  // e_std
69 			{ DF, DF, DF },  // in_service
70 			{ DF, DF, &PE_Interface::On_need_finish_Punctuation,
71 						 }   // need_finish
72 		};
73 #endif // 0
74 
75 
76 PE_Singleton::PE_Singleton()
77 	:	eState(e_none),
78 		sData_Name(),
79 		bIsPreDeclaration(false),
80 		pCurSingleton(0),
81         pCurSiSingleton(0),
82 		pPE_Type(0),
83 		nCurParsed_Type(0)
84 {
85 	pPE_Type 		= new PE_Type(nCurParsed_Type);
86 }
87 
88 void
89 PE_Singleton::EstablishContacts( UnoIDL_PE *				io_pParentPE,
90 							   ary::Repository &		io_rRepository,
91 							   TokenProcessing_Result & o_rResult )
92 {
93 	UnoIDL_PE::EstablishContacts(io_pParentPE,io_rRepository,o_rResult);
94 	pPE_Type->EstablishContacts(this,io_rRepository,o_rResult);
95 }
96 
97 PE_Singleton::~PE_Singleton()
98 {
99 }
100 
101 void
102 PE_Singleton::ProcessToken( const Token & i_rToken )
103 {
104 	i_rToken.Trigger(*this);
105 }
106 
107 
108 void
109 PE_Singleton::Process_MetaType( const TokMetaType &	i_rToken )
110 {
111 	switch ( i_rToken.Id() )
112 	{
113 		case TokMetaType::mt_service:
114 					if (eState == e_std)
115 					{
116 						SetResult(done, push_sure, pPE_Type.Ptr());
117 						eState = in_service;
118 					}
119 					else
120 						On_Default();
121 					break;
122 		case TokMetaType::mt_singleton:
123 					if (eState == need_name)
124 						SetResult(done, stay);
125 					else
126 						On_Default();
127 					break;
128         default:
129             // KORR_FUTURE
130             // Should throw syntax error warning
131                     ;
132 
133 	}	// end switch
134 }
135 
136 void
137 PE_Singleton::Process_Identifier( const TokIdentifier & i_rToken )
138 {
139 	if (eState == need_name)
140 	{
141 		sData_Name = i_rToken.Text();
142 		SetResult(done, stay);
143 		eState = need_curlbr_open;
144 	}
145 	else
146 		On_Default();
147 }
148 
149 void
150 PE_Singleton::Process_Punctuation( const TokPunctuation & i_rToken )
151 {
152 	switch (i_rToken.Id())
153 	{
154 		case TokPunctuation::CurledBracketOpen:
155 					if (eState == need_curlbr_open)
156 					{
157                         pCurSingleton = &Gate().Ces().Store_Singleton(
158                                                         CurNamespace().CeId(),
159                                                         sData_Name );
160 						PassDocuAt(*pCurSingleton);
161 						SetResult(done, stay);
162 						eState = e_std;
163 					}
164 					else
165 						On_Default();
166 					break;
167 		case TokPunctuation::CurledBracketClose:
168 					if (eState == e_std)
169 					{
170 						SetResult(done, stay);
171 						eState = need_finish;
172 					}
173 					else
174 						On_Default();
175 					break;
176 		case TokPunctuation::Semicolon:
177 					switch (eState)
178 					{
179 					   case e_std:  SetResult(done, stay);
180 									break;
181 					   case need_finish:
182 									SetResult(done, pop_success);
183 									eState = e_none;
184 									break;
185 					   default:
186 									On_Default();
187 					}	// end switch
188 					break;
189 		case TokPunctuation::Colon:
190 					switch (eState)
191 					{
192 					   case need_curlbr_open:
193 					                SetResult(done, push_sure, pPE_Type.Ptr());
194                                     eState = in_base_interface;
195 									break;
196 					   default:
197 									On_Default();
198 					}	// end switch
199 		            break;
200 		default:
201 					On_Default();
202 	}	// end switch
203 }
204 
205 void
206 PE_Singleton::Process_Default()
207 {
208 	On_Default();
209 }
210 
211 
212 void
213 PE_Singleton::On_Default()
214 {
215     SetResult(not_done, pop_failure);
216 }
217 
218 void
219 PE_Singleton::InitData()
220 {
221 	eState = need_name;
222 	sData_Name.clear();
223 	bIsPreDeclaration = false;
224 	pCurSingleton = 0;
225     pCurSiSingleton = 0;
226 	nCurParsed_Type = 0;
227 }
228 
229 void
230 PE_Singleton::TransferData()
231 {
232 	if (NOT bIsPreDeclaration)
233 	{
234 		csv_assert(sData_Name.size() > 0);
235 		csv_assert( (pCurSingleton != 0) != (pCurSiSingleton != 0) );
236 	}
237 
238 	eState = e_none;
239 }
240 
241 void
242 PE_Singleton::ReceiveData()
243 {
244     switch (eState)
245     {
246         case in_service:
247                     pCurSingleton->Set_Service(nCurParsed_Type);
248 					nCurParsed_Type = 0;
249 					eState = e_std;
250                     break;
251         case in_base_interface:
252                     pCurSiSingleton = &Gate().Ces().Store_SglIfcSingleton(
253                                                     CurNamespace().CeId(),
254                                                     sData_Name,
255                                                     nCurParsed_Type );
256 					PassDocuAt(*pCurSiSingleton);
257 					nCurParsed_Type = 0;
258 					eState = need_finish;
259                     break;
260         default:
261             csv_assert(false);
262     }   // end switch
263 }
264 
265 UnoIDL_PE &
266 PE_Singleton::MyPE()
267 {
268 	return *this;
269 }
270 
271 }   // namespace uidl
272 }   // namespace csi
273