2afc6881a8190a1284959df00c4164e1d00ab6c7
[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                 //Console.Write(c);
49                 if (null == currentOp)
50                 {
51                     switch (c)
52                     {
53                         case '<':
54                             if (0 == index)
55                             {
56                                 currentOp = new GatherAssembliesBlock(globalDataList, null);
57                                 currentOp.Init();
58                                 index++;
59                             }
60                             else if (1 == index)
61                             {
62                                 currentOp = new GatherTypesBlock(globalDataList, null);
63                                 currentOp.Init();
64                                 index++;
65                             }
66                             else if (2 == index)
67                             {
68                                 currentOp = new GatherPropertiesBlock(globalDataList, null);
69                                 currentOp.Init();
70                                 index++;
71                             }
72                             else if (3 == index)
73                             {
74                                 currentOp = new GatherEventsBlock(globalDataList, null);
75                                 currentOp.Init();
76                                 index++;
77                             }
78                             else if (4 == index)
79                             {
80                                 currentOp = new GatherMethodsBlock(globalDataList, null);
81                                 currentOp.Init();
82                                 index++;
83                             }
84                             else if (5 == index)
85                             {
86                                 currentOp = new GatherBindablePropertiesBlock(globalDataList, null);
87                                 currentOp.Init();
88                                 index++;
89                             }
90                             break;
91
92                         case '{':
93                             currentOp = createInstance;
94                             currentOp.Init();
95                             break;
96
97                         case '`':
98                             currentOp = getObjectByProperty;
99                             currentOp.Init();
100                             break;
101
102                         case '@':
103                             currentOp = addExistInstance;
104                             currentOp.Init();
105                             break;
106
107                         case '&':
108                             currentOp = registerXName;
109                             currentOp.Init();
110                             break;
111
112                         case '[':
113                             currentOp = setProperty;
114                             currentOp.Init();
115                             break;
116
117                         case '~':
118                             currentOp = addToCollectionProperty;
119                             currentOp.Init();
120                             break;
121
122                         case '#':
123                             currentOp = addEvent;
124                             currentOp.Init();
125                             break;
126
127                         case '!':
128                             currentOp = setBindalbeProperty;
129                             currentOp.Init();
130                             break;
131
132                         case '$':
133                             currentOp = setDynamicResourceAction;
134                             currentOp.Init();
135                             break;
136
137                         case '^':
138                             currentOp = addObject;
139                             currentOp.Init();
140                             break;
141
142                         case '*':
143                             currentOp = addToResourceDictionaryAction;
144                             currentOp.Init();
145                             break;
146
147                         case '%':
148                             currentOp = setBindingAction;
149                             currentOp.Init();
150                             break;
151                     }
152                 }
153                 else
154                 {
155                     currentOp = currentOp.DealChar(c);
156                 }
157             }
158
159             foreach (var op in globalDataList.Operations)
160             {
161                 op.Do();
162             }
163         }
164
165         private static Action currentOp = null;
166     }
167 }