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_property.hxx>
30 
31 
32 // NOT FULLY DEFINED SERVICES
33 #include <ary/idl/i_gate.hxx>
34 #include <ary/idl/i_property.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_vari2.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 PE_Property::PE_Property( const Ce_id & i_rCurOwner )
53     :   eState(e_none),
54         pCurOwner(&i_rCurOwner),
55         pPE_Variable(0),
56         nCurParsedType(0),
57         sCurParsedName(),
58         bIsOptional(false),
59         aStereotypes()
60 {
61     pPE_Variable    = new PE_Variable(nCurParsedType, sCurParsedName);
62 }
63 
64 void
65 PE_Property::EstablishContacts( UnoIDL_PE *                io_pParentPE,
66                                 ary::Repository &		io_rRepository,
67                                 TokenProcessing_Result & 	o_rResult )
68 {
69     UnoIDL_PE::EstablishContacts(io_pParentPE,io_rRepository,o_rResult);
70     pPE_Variable->EstablishContacts(this,io_rRepository,o_rResult);
71 }
72 
73 PE_Property::~PE_Property()
74 {
75 }
76 
77 void
78 PE_Property::ProcessToken( const Token & i_rToken )
79 {
80     i_rToken.Trigger(*this);
81 }
82 
83 void
84 PE_Property::Process_Stereotype( const TokStereotype & i_rToken )
85 {
86     switch (i_rToken.Id())
87     {
88         case TokStereotype::ste_optional:
89             bIsOptional = true;
90             break;
91         case TokStereotype::ste_readonly:
92             aStereotypes.Set_Flag(Stereotypes::readonly);
93             break;
94         case TokStereotype::ste_bound:
95             aStereotypes.Set_Flag(Stereotypes::bound);
96             break;
97         case TokStereotype::ste_constrained:
98             aStereotypes.Set_Flag(Stereotypes::constrained);
99             break;
100         case TokStereotype::ste_maybeambiguous:
101             aStereotypes.Set_Flag(Stereotypes::maybeambiguous);
102             break;
103         case TokStereotype::ste_maybedefault:
104             aStereotypes.Set_Flag(Stereotypes::maybedefault);
105             break;
106         case TokStereotype::ste_maybevoid:
107             aStereotypes.Set_Flag(Stereotypes::maybevoid);
108             break;
109         case TokStereotype::ste_removable:
110             aStereotypes.Set_Flag(Stereotypes::removable);
111             break;
112         case TokStereotype::ste_transient:
113             aStereotypes.Set_Flag(Stereotypes::transient);
114             break;
115 
116         default:
117             SetResult(not_done, pop_failure);
118             eState = e_none;
119             return;
120     }
121 
122     SetResult(done, stay);
123 }
124 
125 void
126 PE_Property::Process_MetaType( const TokMetaType & i_rToken )
127 {
128     if (eState == e_start)
129     {
130         if ( i_rToken.Id() == TokMetaType::mt_property )
131     	{
132             SetResult(done, stay);
133             eState = expect_variable;
134             return;
135     	}
136     }   // endif (eState == e_start)
137 
138     SetResult(not_done, pop_failure);
139     eState = e_none;
140 }
141 
142 void
143 PE_Property::Process_Punctuation( const TokPunctuation & i_rToken )
144 {
145     switch (eState)
146     {
147         case e_start:
148             SetResult(done, stay);
149             break;
150         case expect_variable:
151             if (i_rToken.Id() == TokPunctuation::Semicolon)
152     		{
153                 SetResult(done, pop_success);
154                 eState = e_none;
155     		}
156             else if (i_rToken.Id() == TokPunctuation::Comma)
157                 SetResult(done, stay);
158         	else
159                 SetResult(not_done, pop_failure);
160             break;
161         default:
162             csv_assert(false);
163     }
164 }
165 
166 void
167 PE_Property::Process_Default()
168 {
169     if (eState == expect_variable)
170     {
171         SetResult(not_done, push_sure, pPE_Variable.Ptr());
172         eState = in_variable;
173     }
174     else
175         SetResult(not_done, pop_failure);
176 }
177 
178 void
179 PE_Property::InitData()
180 {
181     eState = e_start;
182 
183     nCurParsedType = 0;
184     sCurParsedName = "";
185 
186     // bIsOptional and
187     // aStereotypes
188     //   may be preset by the PE_Service-(or PE_Interface-)parent
189     //   with PresetOptional() or
190     //   PresetStereotype()
191     //   - therefore it must not be set here!
192 }
193 
194 void
195 PE_Property::TransferData()
196 {
197     if (bIsOptional)
198     {
199         SetOptional();
200         bIsOptional = false;
201     }
202 
203     ary::idl::CodeEntity *
204         pCe = 0;
205     csv_assert(pCurOwner->IsValid());
206 
207     pCe = &Gate().Ces().Store_Property( *pCurOwner,
208                                         sCurParsedName,
209                                         nCurParsedType,
210                                         aStereotypes );
211 
212     csv_assert(pCe != 0);
213     PassDocuAt(*pCe);
214 
215     nCurParsedType = 0;
216     sCurParsedName.clear();
217     aStereotypes = Stereotypes();
218 
219     eState = e_none;
220 }
221 
222 void
223 PE_Property::ReceiveData()
224 {
225     eState = expect_variable;
226 }
227 
228 
229 UnoIDL_PE &
230 PE_Property::MyPE()
231 {
232     return *this;
233 }
234 
235 
236 }   // namespace uidl
237 }   // namespace csi
238 
239