1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include <precomp.h>
29*cdf0e10cSrcweir #include <s2_luidl/pe_attri.hxx>
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir // NOT FULLY DEFINED SERVICES
33*cdf0e10cSrcweir #include <ary/idl/i_gate.hxx>
34*cdf0e10cSrcweir #include <ary/idl/i_attribute.hxx>
35*cdf0e10cSrcweir #include <ary/idl/i_service.hxx>
36*cdf0e10cSrcweir #include <ary/idl/ip_ce.hxx>
37*cdf0e10cSrcweir #include <ary/doc/d_oldidldocu.hxx>
38*cdf0e10cSrcweir #include <s2_luidl/pe_type2.hxx>
39*cdf0e10cSrcweir #include <s2_luidl/pe_vari2.hxx>
40*cdf0e10cSrcweir #include <s2_luidl/tk_keyw.hxx>
41*cdf0e10cSrcweir #include <s2_luidl/tk_ident.hxx>
42*cdf0e10cSrcweir #include <s2_luidl/tk_punct.hxx>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir namespace csi
47*cdf0e10cSrcweir {
48*cdf0e10cSrcweir namespace uidl
49*cdf0e10cSrcweir {
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir PE_Attribute::PE_Attribute( const Ce_id & i_rCurOwner )
54*cdf0e10cSrcweir     :   eState(e_none),
55*cdf0e10cSrcweir         pCurOwner(&i_rCurOwner),
56*cdf0e10cSrcweir         pPE_Variable(0),
57*cdf0e10cSrcweir         pPE_Exception(0),
58*cdf0e10cSrcweir         pCurAttribute(0),
59*cdf0e10cSrcweir         nCurParsedType(0),
60*cdf0e10cSrcweir         sCurParsedName(),
61*cdf0e10cSrcweir         bReadOnly(false),
62*cdf0e10cSrcweir         bBound(false)
63*cdf0e10cSrcweir {
64*cdf0e10cSrcweir     pPE_Variable    = new PE_Variable(nCurParsedType, sCurParsedName);
65*cdf0e10cSrcweir     pPE_Exception   = new PE_Type(nCurParsedType);
66*cdf0e10cSrcweir }
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir void
69*cdf0e10cSrcweir PE_Attribute::EstablishContacts( UnoIDL_PE *                io_pParentPE,
70*cdf0e10cSrcweir                                  ary::Repository &		io_rRepository,
71*cdf0e10cSrcweir                                  TokenProcessing_Result & 	o_rResult )
72*cdf0e10cSrcweir {
73*cdf0e10cSrcweir     UnoIDL_PE::EstablishContacts(io_pParentPE,io_rRepository,o_rResult);
74*cdf0e10cSrcweir     pPE_Variable->EstablishContacts(this,io_rRepository,o_rResult);
75*cdf0e10cSrcweir     pPE_Exception->EstablishContacts(this,io_rRepository,o_rResult);
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir PE_Attribute::~PE_Attribute()
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir }
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir void
83*cdf0e10cSrcweir PE_Attribute::ProcessToken( const Token & i_rToken )
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir     i_rToken.Trigger(*this);
86*cdf0e10cSrcweir }
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir void
89*cdf0e10cSrcweir PE_Attribute::Process_Identifier( const TokIdentifier & i_rToken )
90*cdf0e10cSrcweir {
91*cdf0e10cSrcweir     switch (eState)
92*cdf0e10cSrcweir     {
93*cdf0e10cSrcweir         case e_start:
94*cdf0e10cSrcweir             SetResult(not_done, push_sure, pPE_Variable.Ptr());
95*cdf0e10cSrcweir             eState = in_variable;
96*cdf0e10cSrcweir             break;
97*cdf0e10cSrcweir         case in_raise_std:
98*cdf0e10cSrcweir             if (strcmp(i_rToken.Text(),"get") == 0)
99*cdf0e10cSrcweir             {
100*cdf0e10cSrcweir                 SetResult(done, stay);
101*cdf0e10cSrcweir                 eState = in_get;
102*cdf0e10cSrcweir             }
103*cdf0e10cSrcweir             else if (strcmp(i_rToken.Text(),"set") == 0)
104*cdf0e10cSrcweir             {
105*cdf0e10cSrcweir                 SetResult(done, stay);
106*cdf0e10cSrcweir                 eState = in_set;
107*cdf0e10cSrcweir             }
108*cdf0e10cSrcweir             else
109*cdf0e10cSrcweir             {
110*cdf0e10cSrcweir                 SetResult(not_done, pop_failure);
111*cdf0e10cSrcweir                 eState = e_none;
112*cdf0e10cSrcweir             }
113*cdf0e10cSrcweir             break;
114*cdf0e10cSrcweir         case in_get:
115*cdf0e10cSrcweir         case in_set:
116*cdf0e10cSrcweir             SetResult(not_done, push_sure, pPE_Exception.Ptr());
117*cdf0e10cSrcweir             break;
118*cdf0e10cSrcweir         default:
119*cdf0e10cSrcweir             SetResult(not_done, pop_failure);
120*cdf0e10cSrcweir     }   // end switch
121*cdf0e10cSrcweir }
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir void
124*cdf0e10cSrcweir PE_Attribute::Process_Stereotype( const TokStereotype & i_rToken )
125*cdf0e10cSrcweir {
126*cdf0e10cSrcweir     if (eState != e_start)
127*cdf0e10cSrcweir     {
128*cdf0e10cSrcweir         SetResult(not_done, pop_failure);
129*cdf0e10cSrcweir         eState = e_none;
130*cdf0e10cSrcweir         return;
131*cdf0e10cSrcweir     }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir     switch (i_rToken.Id())
134*cdf0e10cSrcweir     {
135*cdf0e10cSrcweir         case TokStereotype::ste_readonly:
136*cdf0e10cSrcweir             bReadOnly = true;
137*cdf0e10cSrcweir             break;
138*cdf0e10cSrcweir         case TokStereotype::ste_bound:
139*cdf0e10cSrcweir             bBound = true;
140*cdf0e10cSrcweir             break;
141*cdf0e10cSrcweir         default:
142*cdf0e10cSrcweir             SetResult(not_done, pop_failure);
143*cdf0e10cSrcweir             eState = e_none;
144*cdf0e10cSrcweir             return;
145*cdf0e10cSrcweir     }   // end switch
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir     SetResult(done, stay);
148*cdf0e10cSrcweir }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir void
151*cdf0e10cSrcweir PE_Attribute::Process_MetaType( const TokMetaType & i_rToken )
152*cdf0e10cSrcweir {
153*cdf0e10cSrcweir     if (eState != e_start OR i_rToken.Id() != TokMetaType::mt_attribute)
154*cdf0e10cSrcweir     {
155*cdf0e10cSrcweir         SetResult(not_done, pop_failure);
156*cdf0e10cSrcweir         eState = e_none;
157*cdf0e10cSrcweir         return;
158*cdf0e10cSrcweir     }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir     SetResult(done, stay);
161*cdf0e10cSrcweir }
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir void
164*cdf0e10cSrcweir PE_Attribute::Process_Punctuation( const TokPunctuation & i_rToken )
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir     switch (eState)
167*cdf0e10cSrcweir     {
168*cdf0e10cSrcweir         case e_start:
169*cdf0e10cSrcweir             SetResult(done, stay);
170*cdf0e10cSrcweir             break;
171*cdf0e10cSrcweir         case expect_end:
172*cdf0e10cSrcweir             switch(i_rToken.Id())
173*cdf0e10cSrcweir             {
174*cdf0e10cSrcweir                 case TokPunctuation::Semicolon:
175*cdf0e10cSrcweir                     SetResult(done, pop_success);
176*cdf0e10cSrcweir                     eState = e_none;
177*cdf0e10cSrcweir     		        break;
178*cdf0e10cSrcweir     		    case TokPunctuation::Comma:
179*cdf0e10cSrcweir                     SetResult(not_done, pop_failure);
180*cdf0e10cSrcweir                     Cerr() << "Autodoc does not support comma separated attributes, because those are discouraged by IDL policies." << Endl();
181*cdf0e10cSrcweir                     break;
182*cdf0e10cSrcweir     		    case TokPunctuation::CurledBracketOpen:
183*cdf0e10cSrcweir                     SetResult(done, stay);
184*cdf0e10cSrcweir                     eState = in_raise_std;
185*cdf0e10cSrcweir                     break;
186*cdf0e10cSrcweir         	    default:
187*cdf0e10cSrcweir                     SetResult(not_done, pop_failure);
188*cdf0e10cSrcweir             }   // end switch
189*cdf0e10cSrcweir             break;
190*cdf0e10cSrcweir         case in_raise_std:
191*cdf0e10cSrcweir             SetResult(done, stay);
192*cdf0e10cSrcweir             if (i_rToken.Id() == TokPunctuation::CurledBracketClose)
193*cdf0e10cSrcweir             {
194*cdf0e10cSrcweir                 eState = expect_end;
195*cdf0e10cSrcweir             }
196*cdf0e10cSrcweir             break;
197*cdf0e10cSrcweir         case in_get:
198*cdf0e10cSrcweir         case in_set:
199*cdf0e10cSrcweir             SetResult(done, stay);
200*cdf0e10cSrcweir             if (i_rToken.Id() == TokPunctuation::Semicolon)
201*cdf0e10cSrcweir             {
202*cdf0e10cSrcweir                 eState = in_raise_std;
203*cdf0e10cSrcweir             }
204*cdf0e10cSrcweir             break;
205*cdf0e10cSrcweir         default:
206*cdf0e10cSrcweir             csv_assert(false);
207*cdf0e10cSrcweir     }
208*cdf0e10cSrcweir }
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir void
211*cdf0e10cSrcweir PE_Attribute::Process_Raises()
212*cdf0e10cSrcweir {
213*cdf0e10cSrcweir     if (eState == in_get OR eState == in_set)
214*cdf0e10cSrcweir     {
215*cdf0e10cSrcweir         SetResult(done, stay);
216*cdf0e10cSrcweir     }
217*cdf0e10cSrcweir     else
218*cdf0e10cSrcweir         SetResult(not_done, pop_failure);
219*cdf0e10cSrcweir }
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir void
222*cdf0e10cSrcweir PE_Attribute::Process_Default()
223*cdf0e10cSrcweir {
224*cdf0e10cSrcweir     if (eState == e_start)
225*cdf0e10cSrcweir     {
226*cdf0e10cSrcweir         SetResult(not_done, push_sure, pPE_Variable.Ptr());
227*cdf0e10cSrcweir         eState = in_variable;
228*cdf0e10cSrcweir     }
229*cdf0e10cSrcweir     else if (eState == in_get OR eState == in_set)
230*cdf0e10cSrcweir         SetResult(not_done, push_sure, pPE_Exception.Ptr());
231*cdf0e10cSrcweir     else
232*cdf0e10cSrcweir         SetResult(not_done, pop_failure);
233*cdf0e10cSrcweir }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir void
236*cdf0e10cSrcweir PE_Attribute::InitData()
237*cdf0e10cSrcweir {
238*cdf0e10cSrcweir     eState = e_start;
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir     pCurAttribute = 0;
241*cdf0e10cSrcweir     nCurParsedType = 0;
242*cdf0e10cSrcweir     sCurParsedName = "";
243*cdf0e10cSrcweir     bReadOnly = false;
244*cdf0e10cSrcweir     bBound = false;
245*cdf0e10cSrcweir }
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir void
248*cdf0e10cSrcweir PE_Attribute::TransferData()
249*cdf0e10cSrcweir {
250*cdf0e10cSrcweir     eState = e_none;
251*cdf0e10cSrcweir }
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir void
254*cdf0e10cSrcweir PE_Attribute::ReceiveData()
255*cdf0e10cSrcweir {
256*cdf0e10cSrcweir     switch (eState)
257*cdf0e10cSrcweir     {
258*cdf0e10cSrcweir         case in_variable:
259*cdf0e10cSrcweir             csv_assert(pCurOwner->IsValid());
260*cdf0e10cSrcweir             pCurAttribute = &Gate().Ces().Store_Attribute(
261*cdf0e10cSrcweir                                                     *pCurOwner,
262*cdf0e10cSrcweir                                                     sCurParsedName,
263*cdf0e10cSrcweir                                                     nCurParsedType,
264*cdf0e10cSrcweir                                                     bReadOnly,
265*cdf0e10cSrcweir                                                     bBound );
266*cdf0e10cSrcweir             PassDocuAt(*pCurAttribute);
267*cdf0e10cSrcweir             nCurParsedType = 0;
268*cdf0e10cSrcweir             eState = expect_end;
269*cdf0e10cSrcweir             break;
270*cdf0e10cSrcweir         case in_get:
271*cdf0e10cSrcweir             csv_assert(pCurAttribute != 0);
272*cdf0e10cSrcweir             pCurAttribute->Add_GetException(nCurParsedType);
273*cdf0e10cSrcweir             nCurParsedType = 0;
274*cdf0e10cSrcweir             break;
275*cdf0e10cSrcweir         case in_set:
276*cdf0e10cSrcweir             csv_assert(pCurAttribute != 0);
277*cdf0e10cSrcweir             pCurAttribute->Add_SetException(nCurParsedType);
278*cdf0e10cSrcweir             nCurParsedType = 0;
279*cdf0e10cSrcweir             break;
280*cdf0e10cSrcweir         default:
281*cdf0e10cSrcweir             csv_assert(false);
282*cdf0e10cSrcweir     }   // end switch
283*cdf0e10cSrcweir }
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir UnoIDL_PE &
287*cdf0e10cSrcweir PE_Attribute::MyPE()
288*cdf0e10cSrcweir {
289*cdf0e10cSrcweir     return *this;
290*cdf0e10cSrcweir }
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir }   // namespace uidl
294*cdf0e10cSrcweir }   // namespace csi
295