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_excp.hxx>
30 
31 
32 // NOT FULLY DECLARED SERVICES
33 #include <ary/idl/i_exception.hxx>
34 #include <ary/idl/i_gate.hxx>
35 #include <ary/idl/i_structelem.hxx>
36 #include <ary/idl/ip_ce.hxx>
37 #include <ary/doc/d_oldidldocu.hxx>
38 #include <s2_luidl/tk_ident.hxx>
39 #include <s2_luidl/tk_punct.hxx>
40 #include <s2_luidl/tk_keyw.hxx>
41 #include <s2_luidl/pe_type2.hxx>
42 #include <s2_luidl/pe_selem.hxx>
43 
44 
45 
46 namespace csi
47 {
48 namespace uidl
49 {
50 
51 
52 PE_Exception::PE_Exception()
53 	// :	aWork,
54 	//      pStati
55 {
56 	pStati = new S_Stati(*this);
57 }
58 
59 void
60 PE_Exception::EstablishContacts( UnoIDL_PE *				io_pParentPE,
61 							  ary::Repository &			io_rRepository,
62 							  TokenProcessing_Result & 	o_rResult )
63 {
64 	UnoIDL_PE::EstablishContacts(io_pParentPE,io_rRepository,o_rResult);
65 	Work().pPE_Element->EstablishContacts(this,io_rRepository,o_rResult);
66 	Work().pPE_Type->EstablishContacts(this,io_rRepository,o_rResult);
67 }
68 
69 PE_Exception::~PE_Exception()
70 {
71 }
72 
73 void
74 PE_Exception::ProcessToken( const Token & i_rToken )
75 {
76 	i_rToken.Trigger(*Stati().pCurStatus);
77 }
78 
79 
80 void
81 PE_Exception::InitData()
82 {
83 	Work().InitData();
84 	Stati().pCurStatus = &Stati().aWaitForName;
85 }
86 
87 void
88 PE_Exception::TransferData()
89 {
90 	if (NOT Work().bIsPreDeclaration)
91 	{
92 		csv_assert(Work().sData_Name.size() > 0);
93 		csv_assert(Work().nCurStruct.IsValid());
94 	}
95 	Stati().pCurStatus = &Stati().aNone;
96 }
97 
98 void
99 PE_Exception::ReceiveData()
100 {
101 	Stati().pCurStatus->On_SubPE_Left();
102 }
103 
104 PE_Exception::S_Work::S_Work()
105 	:	sData_Name(),
106 		bIsPreDeclaration(false),
107 		nCurStruct(0),
108 		pPE_Element(0),
109 		nCurParsed_ElementRef(0),
110 		pPE_Type(0),
111 		nCurParsed_Base(0)
112 
113 {
114 	pPE_Element = new PE_StructElement(nCurParsed_ElementRef,nCurStruct);
115 	pPE_Type = new PE_Type(nCurParsed_Base);
116 }
117 
118 void
119 PE_Exception::S_Work::InitData()
120 {
121 	sData_Name.clear();
122 	bIsPreDeclaration = false;
123 	nCurStruct = 0;
124 
125     nCurParsed_ElementRef = 0;
126     nCurParsed_Base = 0;
127 }
128 
129 void
130 PE_Exception::S_Work::Prepare_PE_QualifiedName()
131 {
132 	nCurParsed_ElementRef = 0;
133 }
134 
135 void
136 PE_Exception::S_Work::Prepare_PE_Element()
137 {
138 	nCurParsed_Base = 0;
139 }
140 
141 void
142 PE_Exception::S_Work::Data_Set_Name( const char * i_sName )
143 {
144 	sData_Name = i_sName;
145 }
146 
147 PE_Exception::S_Stati::S_Stati(PE_Exception & io_rStruct)
148 	:	aNone(io_rStruct),
149 		aWaitForName(io_rStruct),
150 		aGotName(io_rStruct),
151 		aWaitForBase(io_rStruct),
152 		aGotBase(io_rStruct),
153 		aWaitForElement(io_rStruct),
154 		aWaitForFinish(io_rStruct),
155 		pCurStatus(0)
156 {
157 	pCurStatus = &aNone;
158 }
159 
160 
161 //***********************		Stati		***************************//
162 
163 
164 UnoIDL_PE &
165 PE_Exception::PE_StructState::MyPE()
166 {
167 	return rStruct;
168 }
169 
170 
171 void
172 PE_Exception::State_WaitForName::Process_Identifier( const TokIdentifier & i_rToken )
173 {
174 	Work().Data_Set_Name(i_rToken.Text());
175 	MoveState( Stati().aGotName );
176 	SetResult(done,stay);
177 }
178 
179 void
180 PE_Exception::State_GotName::Process_Punctuation( const TokPunctuation & i_rToken )
181 {
182 	if ( i_rToken.Id() != TokPunctuation::Semicolon )
183     {
184 		switch (i_rToken.Id())
185 		{
186 			case TokPunctuation::Colon:
187 				MoveState( Stati().aWaitForBase );
188 				SetResult(done,push_sure,Work().pPE_Type.Ptr());
189 				Work().Prepare_PE_QualifiedName();
190 				break;
191 			case TokPunctuation::CurledBracketOpen:
192 			    PE().store_Exception();
193 				MoveState( Stati().aWaitForElement );
194 				SetResult(done,stay);
195 				break;
196 			default:
197 				SetResult(not_done,pop_failure);
198 		}	// end switch
199 	}
200 	else
201 	{
202 		Work().sData_Name.clear();
203 		SetResult(done,pop_success);
204 	}
205 }
206 
207 void
208 PE_Exception::State_WaitForBase::On_SubPE_Left()
209 {
210 	MoveState(Stati().aGotBase);
211 }
212 
213 void
214 PE_Exception::State_GotBase::Process_Punctuation( const TokPunctuation & i_rToken )
215 {
216 	if ( i_rToken.Id() == TokPunctuation::CurledBracketOpen )
217 	{
218 	    PE().store_Exception();
219 		MoveState( Stati().aWaitForElement );
220 		SetResult(done,stay);
221 	}
222 	else
223 	{
224 		SetResult(not_done,pop_failure);
225 	}
226 }
227 
228 void
229 PE_Exception::State_WaitForElement::Process_Identifier( const TokIdentifier & )
230 {
231 	SetResult( not_done, push_sure, Work().pPE_Element.Ptr() );
232 	Work().Prepare_PE_Element();
233 }
234 
235 void
236 PE_Exception::State_WaitForElement::Process_NameSeparator()
237 {
238 	SetResult( not_done, push_sure, Work().pPE_Element.Ptr());
239 	Work().Prepare_PE_Element();
240 }
241 
242 void
243 PE_Exception::State_WaitForElement::Process_BuiltInType( const TokBuiltInType & )
244 {
245 	SetResult( not_done, push_sure, Work().pPE_Element.Ptr());
246 	Work().Prepare_PE_Element();
247 }
248 
249 void
250 PE_Exception::State_WaitForElement::Process_TypeModifier(const TokTypeModifier & )
251 {
252 	SetResult( not_done, push_sure, Work().pPE_Element.Ptr());
253 	Work().Prepare_PE_Element();
254 }
255 
256 void
257 PE_Exception::State_WaitForElement::Process_Punctuation( const TokPunctuation & i_rToken )
258 {
259 	if ( i_rToken.Id() == TokPunctuation::CurledBracketClose )
260 	{
261 		MoveState( Stati().aWaitForFinish );
262 		SetResult( done, stay );
263 	}
264 	else
265 	{
266 		SetResult( not_done, pop_failure );
267 	}
268 }
269 
270 void
271 PE_Exception::State_WaitForFinish::Process_Punctuation( const TokPunctuation & i_rToken )
272 {
273 	if (i_rToken.Id() == TokPunctuation::Semicolon)
274 	{
275 		MoveState( Stati().aNone );
276 		SetResult( done, pop_success );
277 	}
278 	else
279 	{
280 		SetResult( not_done, pop_failure );
281 	}
282 }
283 
284 void
285 PE_Exception::store_Exception()
286 {
287     ary::idl::Exception &
288         rCe = Gate().Ces().Store_Exception(
289 						    CurNamespace().CeId(),
290 						    Work().sData_Name,
291                             Work().nCurParsed_Base );
292     PassDocuAt(rCe);
293     Work().nCurStruct = rCe.Id();
294 }
295 
296 
297 }   // namespace uidl
298 }   // namespace csi
299