File: ObjectPersistData.cs

package info (click to toggle)
mono 6.8.0.105%2Bdfsg-3.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,284,512 kB
  • sloc: cs: 11,172,132; xml: 2,850,069; ansic: 671,653; cpp: 122,091; perl: 59,366; javascript: 30,841; asm: 22,168; makefile: 20,093; sh: 15,020; python: 4,827; pascal: 925; sql: 859; sed: 16; php: 1
file content (212 lines) | stat: -rw-r--r-- 6,315 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
//------------------------------------------------------------------------------
// <copyright file="ObjectPersistData.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

namespace System.Web.UI {
    using System.Collections;
    using System.Collections.Specialized;
    using System.Web.Util;
    using System.Security.Permissions;

    public class ObjectPersistData {
        private Type _objectType;

        private bool _isCollection;
        private ArrayList _collectionItems;

        private bool _localize;
        private string _resourceKey;

        private IDictionary _propertyTableByFilter;
        private IDictionary _propertyTableByProperty;
        private ArrayList _allPropertyEntries;

        private ArrayList _eventEntries;

        private IDictionary _builtObjects;


        public ObjectPersistData(ControlBuilder builder, IDictionary builtObjects) {
            _objectType = builder.ControlType;
            _localize = builder.Localize;
            _resourceKey = builder.GetResourceKey();

            _builtObjects = builtObjects;

            if (typeof(ICollection).IsAssignableFrom(_objectType)) {
                _isCollection = true;
            }

            _collectionItems = new ArrayList();
            _propertyTableByFilter = new HybridDictionary(true);
            _propertyTableByProperty = new HybridDictionary(true);
            _allPropertyEntries = new ArrayList();
            _eventEntries = new ArrayList();

            foreach (PropertyEntry entry in builder.SimplePropertyEntries) {
                AddPropertyEntry(entry);
            }

            foreach (PropertyEntry entry in builder.ComplexPropertyEntries) {
                AddPropertyEntry(entry);
            }

            foreach (PropertyEntry entry in builder.TemplatePropertyEntries) {
                AddPropertyEntry(entry);
            }

            foreach (PropertyEntry entry in builder.BoundPropertyEntries) {
                AddPropertyEntry(entry);
            }

            foreach (EventEntry entry in builder.EventEntries) {
                AddEventEntry(entry);
            }
        }


        /// <devdoc>
        /// Get all property entries
        /// </devdoc>
        public ICollection AllPropertyEntries {
            get {
                return _allPropertyEntries;
            }
        }

        public IDictionary BuiltObjects {
            get {
                return _builtObjects;
            }
        }


        public ICollection CollectionItems {
            get {
                return _collectionItems;
            }
        }


        public ICollection EventEntries {
            get {
                return _eventEntries;
            }
        }


        /// <devdoc>
        /// True if this persistence data is for a collection
        /// </devdoc>
        public bool IsCollection {
            get {
                return _isCollection;
            }
        }

        public bool Localize {
            get {
                return _localize;
            }
        }


        /// <devdoc>
        /// The type of the object with these properties.
        /// </devdoc>
        public Type ObjectType {
            get {
                return _objectType;
            }
        }

        public string ResourceKey {
            get {
                return _resourceKey;
            }
        }

        /// <devdoc>
        /// Adds a property to this persistence data, adding it to all necessary
        /// data structures.
        /// </devdoc>
        private void AddPropertyEntry(PropertyEntry entry) {
            if (_isCollection && (entry is ComplexPropertyEntry && ((ComplexPropertyEntry)entry).IsCollectionItem)) {
                _collectionItems.Add(entry);
            }
            else {
                IDictionary filteredProperties = (IDictionary)_propertyTableByFilter[entry.Filter];
                if (filteredProperties == null) {
                    filteredProperties = new HybridDictionary(true);
                    _propertyTableByFilter[entry.Filter] = filteredProperties;
                }

                Debug.Assert((entry.Name != null) && (entry.Name.Length > 0));
                filteredProperties[entry.Name] = entry;

                ArrayList properties = (ArrayList)_propertyTableByProperty[entry.Name];
                if (properties == null) {
                    properties = new ArrayList();
                    _propertyTableByProperty[entry.Name] = properties;
                }

                properties.Add(entry);
            }


            _allPropertyEntries.Add(entry);
        }

        private void AddEventEntry(EventEntry entry) {
            _eventEntries.Add(entry);
        }


        /// <devdov>
        /// </devdoc>
        public void AddToObjectControlBuilderTable(IDictionary table) {
            if (_builtObjects != null) {
                foreach (DictionaryEntry entry in _builtObjects) {
                    table[entry.Key] = entry.Value;
                }
            }
        }


        /// <devdoc>
        /// Gets a PropertyEntry for the specified filter and property name
        /// </devdoc>
        public PropertyEntry GetFilteredProperty(string filter, string name) {
            IDictionary filteredProperties = GetFilteredProperties(filter);
            if (filteredProperties != null) {
                return (PropertyEntry)filteredProperties[name];
            }

            return null;
        }


        /// <devdoc>
        /// Gets all PropertyEntries for the specified filter
        /// </devdoc>
        public IDictionary GetFilteredProperties(string filter) {
            return (IDictionary)_propertyTableByFilter[filter];
        }


        /// <devdoc>
        /// Gets all filtered PropertiesEntries for a specified property (name uses dot-syntax e.g. Font.Bold)
        /// </devdoc>
        public ICollection GetPropertyAllFilters(string name) {
            ICollection properties = (ICollection)_propertyTableByProperty[name];
            if (properties == null) {
                return new ArrayList();
            }

            return properties;
        }
    }

}