Release 9.0.0.16429
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / EXaml / LoadEXaml.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.ComponentModel;
20
21 namespace Tizen.NUI.EXaml
22 {
23     internal static class LoadEXaml
24     {
25         internal static void Load(object view, string xaml)
26         {
27             var globalDataList = new GlobalDataList();
28
29             CreateInstanceAction.Root = view;
30
31             int index = 0;
32
33             var createInstance = new CreateInstanceAction(globalDataList, null);
34             var getObjectByProperty = new GetObjectByPropertyAction(globalDataList, null);
35             var addExistInstance = new AddExistInstanceAction(globalDataList, null);
36             var registerXName = new RegisterXNameAction(globalDataList, null);
37             var setProperty = new SetPropertyAction(globalDataList, null);
38             var addToCollectionProperty = new AddToCollectionPropertyAction(globalDataList, null);
39             var addEvent = new AddEventAction(globalDataList, null);
40             var setBindalbeProperty = new SetBindalbePropertyAction(globalDataList, null);
41             var addObject = new CallAddMethodAction(globalDataList, null);
42             var setDynamicResourceAction = new SetDynamicResourceAction(globalDataList, null);
43             var addToResourceDictionaryAction = new AddToResourceDictionaryAction(globalDataList, null);
44             var setBindingAction = new SetBindingAction(globalDataList, null);
45
46             foreach (char c in xaml)
47             {
48                 if (null == currentOp)
49                 {
50                     switch (c)
51                     {
52                         case '<':
53                             if (0 == index)
54                             {
55                                 currentOp = new GatherAssembliesBlock(globalDataList, null);
56                                 currentOp.Init();
57                                 index++;
58                             }
59                             else if (1 == index)
60                             {
61                                 currentOp = new GatherTypesBlock(globalDataList, null);
62                                 currentOp.Init();
63                                 index++;
64                             }
65                             else if (2 == index)
66                             {
67                                 currentOp = new GatherPropertiesBlock(globalDataList, null);
68                                 currentOp.Init();
69                                 index++;
70                             }
71                             else if (3 == index)
72                             {
73                                 currentOp = new GatherEventsBlock(globalDataList, null);
74                                 currentOp.Init();
75                                 index++;
76                             }
77                             else if (4 == index)
78                             {
79                                 currentOp = new GatherMethodsBlock(globalDataList, null);
80                                 currentOp.Init();
81                                 index++;
82                             }
83                             else if (5 == index)
84                             {
85                                 currentOp = new GatherBindablePropertiesBlock(globalDataList, null);
86                                 currentOp.Init();
87                                 index++;
88                             }
89                             break;
90
91                         case '{':
92                             currentOp = createInstance;
93                             currentOp.Init();
94                             break;
95
96                         case '`':
97                             currentOp = getObjectByProperty;
98                             currentOp.Init();
99                             break;
100
101                         case '@':
102                             currentOp = addExistInstance;
103                             currentOp.Init();
104                             break;
105
106                         case '&':
107                             currentOp = registerXName;
108                             currentOp.Init();
109                             break;
110
111                         case '[':
112                             currentOp = setProperty;
113                             currentOp.Init();
114                             break;
115
116                         case '~':
117                             currentOp = addToCollectionProperty;
118                             currentOp.Init();
119                             break;
120
121                         case '#':
122                             currentOp = addEvent;
123                             currentOp.Init();
124                             break;
125
126                         case '!':
127                             currentOp = setBindalbeProperty;
128                             currentOp.Init();
129                             break;
130
131                         case '$':
132                             currentOp = setDynamicResourceAction;
133                             currentOp.Init();
134                             break;
135
136                         case '^':
137                             currentOp = addObject;
138                             currentOp.Init();
139                             break;
140
141                         case '*':
142                             currentOp = addToResourceDictionaryAction;
143                             currentOp.Init();
144                             break;
145
146                         case '%':
147                             currentOp = setBindingAction;
148                             currentOp.Init();
149                             break;
150                     }
151                 }
152                 else
153                 {
154                     currentOp = currentOp.DealChar(c);
155                 }
156             }
157
158             foreach (var op in globalDataList.Operations)
159             {
160                 op.Do();
161             }
162         }
163
164         private static Action currentOp = null;
165     }
166 }