[Xaml] Support import other xaml as the source of resource dictionary
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / EXaml / Action / RootAction.cs
1 /*
2  * Copyright(c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 using System;
18 using System.Collections.Generic;
19 using System.Text;
20
21 namespace Tizen.NUI.EXaml
22 {
23     internal class RootAction : Action
24     {
25         delegate void CreateOperation(GlobalDataList globalDataList, List<object> operationInfo);
26
27         public RootAction(GlobalDataList globalDataList)
28         {
29             this.globalDataList = globalDataList;
30
31             childAction = new GetValueListAction(')', this);
32             childAction.Init();
33         }
34
35         public Action DealChar(char c)
36         {
37             if ('(' == c)
38             {
39                 childAction.Init();
40                 return childAction;
41             }
42             else if ('\n' == c)
43             {
44                 return this;
45             }
46             else
47             {
48                 throw new Exception($"RootAction must not deal the char {c}");
49             }
50         }
51
52         public void Init()
53         {
54             childAction.Init();
55         }
56
57         public void OnActive()
58         {
59             int opIndex = (int)childAction.ValueList[0];
60             Operations[opIndex].Invoke(globalDataList, childAction.ValueList[1] as List<object>);
61
62             childAction.Init();
63         }
64
65         private GlobalDataList globalDataList;
66         private GetValueListAction childAction;
67
68         private static CreateOperation[] operations;
69
70         private static CreateOperation[] Operations
71         {
72             get
73             {
74                 if (null == operations)
75                 {
76                     InitOperationFactory(out operations);
77                 }
78
79                 return operations;
80             }
81         }
82
83         private static void InitOperationFactory(out CreateOperation[] createOperations)
84         {
85             createOperations = new CreateOperation[(int)EXamlOperationType.MAX];
86
87             createOperations[(int)EXamlOperationType.GatherAssembly] = (GlobalDataList globalDataList, List<object> opInfo) =>
88             {
89                 var operation = new GatherAssembly(globalDataList, opInfo);
90                 globalDataList.PreLoadOperations.Add(operation);
91             };
92
93             createOperations[(int)EXamlOperationType.GatherType] = (GlobalDataList globalDataList, List<object> opInfo) =>
94             {
95                 var operation = new GatherType(globalDataList, opInfo);
96                 globalDataList.PreLoadOperations.Add(operation);
97             };
98
99             createOperations[(int)EXamlOperationType.GatherProperty] = (GlobalDataList globalDataList, List<object> opInfo) =>
100             {
101                 var operation = new GatherProperty(globalDataList, opInfo);
102                 globalDataList.PreLoadOperations.Add(operation);
103             };
104
105             createOperations[(int)EXamlOperationType.GatherEvent] = (GlobalDataList globalDataList, List<object> opInfo) =>
106             {
107                 var operation = new GatherEvent(globalDataList, opInfo);
108                 globalDataList.PreLoadOperations.Add(operation);
109             };
110
111             createOperations[(int)EXamlOperationType.GatherMethod] = (GlobalDataList globalDataList, List<object> opInfo) =>
112             {
113                 var operation = new GatherMethod(globalDataList, opInfo);
114                 globalDataList.PreLoadOperations.Add(operation);
115             };
116
117             createOperations[(int)EXamlOperationType.GatherBindableProperty] = (GlobalDataList globalDataList, List<object> opInfo) =>
118             {
119                 var operation = new GatherBindableProperties(globalDataList, opInfo);
120                 globalDataList.PreLoadOperations.Add(operation);
121             };
122
123             createOperations[(int)EXamlOperationType.CreateObject] = (GlobalDataList globalDataList, List<object> opInfo) =>
124             {
125                 var operation = new CreateObject(globalDataList, opInfo);
126                 globalDataList.Operations.Add(operation);
127             };
128
129             createOperations[(int)EXamlOperationType.CreateArrayObject] = (GlobalDataList globalDataList, List<object> opInfo) =>
130             {
131                 var operation = new CreateArrayObject(globalDataList, opInfo);
132                 globalDataList.Operations.Add(operation);
133             };
134
135             createOperations[(int)EXamlOperationType.CreateDataTemplate] = (GlobalDataList globalDataList, List<object> opInfo) =>
136             {
137                 var operation = new CreateDataTemplate(globalDataList, opInfo);
138                 globalDataList.Operations.Add(operation);
139             };
140
141             createOperations[(int)EXamlOperationType.GetStaticObject] = (GlobalDataList globalDataList, List<object> opInfo) =>
142             {
143                 var operation = new GetStaticObject(globalDataList, opInfo);
144                 globalDataList.Operations.Add(operation);
145             };
146
147             createOperations[(int)EXamlOperationType.GetTypeObject] = (GlobalDataList globalDataList, List<object> opInfo) =>
148             {
149                 var operation = new GetTypeObject(globalDataList, opInfo);
150                 globalDataList.Operations.Add(operation);
151             };
152
153             createOperations[(int)EXamlOperationType.GetObjectConvertedFromString] = (GlobalDataList globalDataList, List<object> opInfo) =>
154             {
155                 var operation = new GetObjectConvertedFromString(globalDataList, opInfo);
156                 globalDataList.Operations.Add(operation);
157             };
158
159             createOperations[(int)EXamlOperationType.GetEnumObject] = (GlobalDataList globalDataList, List<object> opInfo) =>
160             {
161                 var operation = new GetEnumObject(globalDataList, opInfo);
162                 globalDataList.Operations.Add(operation);
163             };
164
165             createOperations[(int)EXamlOperationType.GetObjectByProperty] = (GlobalDataList globalDataList, List<object> opInfo) =>
166             {
167                 var operation = new GetObjectByProperty(globalDataList, opInfo);
168                 globalDataList.Operations.Add(operation);
169             };
170
171             createOperations[(int)EXamlOperationType.SetProperty] = (GlobalDataList globalDataList, List<object> opInfo) =>
172             {
173                 var operation = new SetProperty(globalDataList, opInfo);
174                 globalDataList.Operations.Add(operation);
175             };
176
177             createOperations[(int)EXamlOperationType.SetBindableProperty] = (GlobalDataList globalDataList, List<object> opInfo) =>
178             {
179                 var operation = new SetBindableProperty(globalDataList, opInfo);
180                 globalDataList.Operations.Add(operation);
181             };
182
183             createOperations[(int)EXamlOperationType.SetBinding] = (GlobalDataList globalDataList, List<object> opInfo) =>
184             {
185                 var operation = new SetBinding(globalDataList, opInfo);
186                 globalDataList.Operations.Add(operation);
187             };
188
189             createOperations[(int)EXamlOperationType.SetDynamicResource] = (GlobalDataList globalDataList, List<object> opInfo) =>
190             {
191                 var operation = new SetDynamicResource(globalDataList, opInfo);
192                 globalDataList.Operations.Add(operation);
193             };
194
195             createOperations[(int)EXamlOperationType.AddEvent] = (GlobalDataList globalDataList, List<object> opInfo) =>
196             {
197                 var operation = new AddEvent(globalDataList, opInfo);
198                 globalDataList.Operations.Add(operation);
199             };
200
201             createOperations[(int)EXamlOperationType.AddObject] = (GlobalDataList globalDataList, List<object> opInfo) =>
202             {
203                 var operation = new AddObject(globalDataList, opInfo);
204                 globalDataList.Operations.Add(operation);
205             };
206
207             createOperations[(int)EXamlOperationType.AddToCollectionObject] = (GlobalDataList globalDataList, List<object> opInfo) =>
208             {
209                 var operation = new AddToCollectionObject(globalDataList, opInfo);
210                 globalDataList.Operations.Add(operation);
211             };
212
213             createOperations[(int)EXamlOperationType.AddToCollectionProperty] = (GlobalDataList globalDataList, List<object> opInfo) =>
214             {
215                 var operation = new AddToCollectionProperty(globalDataList, opInfo);
216                 globalDataList.Operations.Add(operation);
217             };
218
219             createOperations[(int)EXamlOperationType.AddToResourceDictionary] = (GlobalDataList globalDataList, List<object> opInfo) =>
220             {
221                 var operation = new AddToResourceDictionary(globalDataList, opInfo);
222                 globalDataList.Operations.Add(operation);
223             };
224
225             createOperations[(int)EXamlOperationType.RegisterXName] = (GlobalDataList globalDataList, List<object> opInfo) =>
226             {
227                 var operation = new RegisterXName(globalDataList, opInfo);
228                 globalDataList.Operations.Add(operation);
229             };
230
231             createOperations[(int)EXamlOperationType.GetLongString] = (GlobalDataList globalDataList, List<object> opInfo) =>
232             {
233                 globalDataList.LongStrings = opInfo[0] as string;
234             };
235
236             createOperations[(int)EXamlOperationType.CreateDPObject] = (GlobalDataList globalDataList, List<object> opInfo) =>
237             {
238                 var operation = new CreateDPObject(globalDataList, opInfo);
239                 globalDataList.Operations.Add(operation);
240             };
241
242             createOperations[(int)EXamlOperationType.CreateResourceDictionary] = (GlobalDataList globalDataList, List<object> opInfo) =>
243             {
244                 var operation = new CreateResourceDictionary(globalDataList, opInfo);
245                 globalDataList.Operations.Add(operation);
246             };
247         }
248     }
249 }