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_attri.hxx>
30 
31 
32 // NOT FULLY DEFINED SERVICES
33 #include <ary/idl/i_gate.hxx>
34 #include <ary/idl/i_attribute.hxx>
35 #include <ary/idl/i_service.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/pe_vari2.hxx>
40 #include <s2_luidl/tk_keyw.hxx>
41 #include <s2_luidl/tk_ident.hxx>
42 #include <s2_luidl/tk_punct.hxx>
43 
44 
45 
46 namespace csi
47 {
48 namespace uidl
49 {
50 
51 
52 
53 PE_Attribute::PE_Attribute( const Ce_id & i_rCurOwner )
54     :   eState(e_none),
55         pCurOwner(&i_rCurOwner),
56         pPE_Variable(0),
57         pPE_Exception(0),
58         pCurAttribute(0),
59         nCurParsedType(0),
60         sCurParsedName(),
61         bReadOnly(false),
62         bBound(false)
63 {
64     pPE_Variable    = new PE_Variable(nCurParsedType, sCurParsedName);
65     pPE_Exception   = new PE_Type(nCurParsedType);
66 }
67 
68 void
69 PE_Attribute::EstablishContacts( UnoIDL_PE *                io_pParentPE,
70                                  ary::Repository &		io_rRepository,
71                                  TokenProcessing_Result & 	o_rResult )
72 {
73     UnoIDL_PE::EstablishContacts(io_pParentPE,io_rRepository,o_rResult);
74     pPE_Variable->EstablishContacts(this,io_rRepository,o_rResult);
75     pPE_Exception->EstablishContacts(this,io_rRepository,o_rResult);
76 }
77 
78 PE_Attribute::~PE_Attribute()
79 {
80 }
81 
82 void
83 PE_Attribute::ProcessToken( const Token & i_rToken )
84 {
85     i_rToken.Trigger(*this);
86 }
87 
88 void
89 PE_Attribute::Process_Identifier( const TokIdentifier & i_rToken )
90 {
91     switch (eState)
92     {
93         case e_start:
94             SetResult(not_done, push_sure, pPE_Variable.Ptr());
95             eState = in_variable;
96             break;
97         case in_raise_std:
98             if (strcmp(i_rToken.Text(),"get") == 0)
99             {
100                 SetResult(done, stay);
101                 eState = in_get;
102             }
103             else if (strcmp(i_rToken.Text(),"set") == 0)
104             {
105                 SetResult(done, stay);
106                 eState = in_set;
107             }
108             else
109             {
110                 SetResult(not_done, pop_failure);
111                 eState = e_none;
112             }
113             break;
114         case in_get:
115         case in_set:
116             SetResult(not_done, push_sure, pPE_Exception.Ptr());
117             break;
118         default:
119             SetResult(not_done, pop_failure);
120     }   // end switch
121 }
122 
123 void
124 PE_Attribute::Process_Stereotype( const TokStereotype & i_rToken )
125 {
126     if (eState != e_start)
127     {
128         SetResult(not_done, pop_failure);
129         eState = e_none;
130         return;
131     }
132 
133     switch (i_rToken.Id())
134     {
135         case TokStereotype::ste_readonly:
136             bReadOnly = true;
137             break;
138         case TokStereotype::ste_bound:
139             bBound = true;
140             break;
141         default:
142             SetResult(not_done, pop_failure);
143             eState = e_none;
144             return;
145     }   // end switch
146 
147     SetResult(done, stay);
148 }
149 
150 void
151 PE_Attribute::Process_MetaType( const TokMetaType & i_rToken )
152 {
153     if (eState != e_start OR i_rToken.Id() != TokMetaType::mt_attribute)
154     {
155         SetResult(not_done, pop_failure);
156         eState = e_none;
157         return;
158     }
159 
160     SetResult(done, stay);
161 }
162 
163 void
164 PE_Attribute::Process_Punctuation( const TokPunctuation & i_rToken )
165 {
166     switch (eState)
167     {
168         case e_start:
169             SetResult(done, stay);
170             break;
171         case expect_end:
172             switch(i_rToken.Id())
173             {
174                 case TokPunctuation::Semicolon:
175                     SetResult(done, pop_success);
176                     eState = e_none;
177     		        break;
178     		    case TokPunctuation::Comma:
179                     SetResult(not_done, pop_failure);
180                     Cerr() << "Autodoc does not support comma separated attributes, because those are discouraged by IDL policies." << Endl();
181                     break;
182     		    case TokPunctuation::CurledBracketOpen:
183                     SetResult(done, stay);
184                     eState = in_raise_std;
185                     break;
186         	    default:
187                     SetResult(not_done, pop_failure);
188             }   // end switch
189             break;
190         case in_raise_std:
191             SetResult(done, stay);
192             if (i_rToken.Id() == TokPunctuation::CurledBracketClose)
193             {
194                 eState = expect_end;
195             }
196             break;
197         case in_get:
198         case in_set:
199             SetResult(done, stay);
200             if (i_rToken.Id() == TokPunctuation::Semicolon)
201             {
202                 eState = in_raise_std;
203             }
204             break;
205         default:
206             csv_assert(false);
207     }
208 }
209 
210 void
211 PE_Attribute::Process_Raises()
212 {
213     if (eState == in_get OR eState == in_set)
214     {
215         SetResult(done, stay);
216     }
217     else
218         SetResult(not_done, pop_failure);
219 }
220 
221 void
222 PE_Attribute::Process_Default()
223 {
224     if (eState == e_start)
225     {
226         SetResult(not_done, push_sure, pPE_Variable.Ptr());
227         eState = in_variable;
228     }
229     else if (eState == in_get OR eState == in_set)
230         SetResult(not_done, push_sure, pPE_Exception.Ptr());
231     else
232         SetResult(not_done, pop_failure);
233 }
234 
235 void
236 PE_Attribute::InitData()
237 {
238     eState = e_start;
239 
240     pCurAttribute = 0;
241     nCurParsedType = 0;
242     sCurParsedName = "";
243     bReadOnly = false;
244     bBound = false;
245 }
246 
247 void
248 PE_Attribute::TransferData()
249 {
250     eState = e_none;
251 }
252 
253 void
254 PE_Attribute::ReceiveData()
255 {
256     switch (eState)
257     {
258         case in_variable:
259             csv_assert(pCurOwner->IsValid());
260             pCurAttribute = &Gate().Ces().Store_Attribute(
261                                                     *pCurOwner,
262                                                     sCurParsedName,
263                                                     nCurParsedType,
264                                                     bReadOnly,
265                                                     bBound );
266             PassDocuAt(*pCurAttribute);
267             nCurParsedType = 0;
268             eState = expect_end;
269             break;
270         case in_get:
271             csv_assert(pCurAttribute != 0);
272             pCurAttribute->Add_GetException(nCurParsedType);
273             nCurParsedType = 0;
274             break;
275         case in_set:
276             csv_assert(pCurAttribute != 0);
277             pCurAttribute->Add_SetException(nCurParsedType);
278             nCurParsedType = 0;
279             break;
280         default:
281             csv_assert(false);
282     }   // end switch
283 }
284 
285 
286 UnoIDL_PE &
287 PE_Attribute::MyPE()
288 {
289     return *this;
290 }
291 
292 
293 }   // namespace uidl
294 }   // namespace csi
295