File: DeviceSpecificChoice.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (752 lines) | stat: -rw-r--r-- 29,773 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
//------------------------------------------------------------------------------
// <copyright file="DeviceSpecificChoice.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>                                                                
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Web.Mobile;
using System.Security.Permissions;

namespace System.Web.UI.MobileControls
{

    /*
     * DeviceSpecificChoice object.
     *
     * Copyright (c) 2000 Microsoft Corporation
     */

    /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoice"]/*' />
    [
        ControlBuilderAttribute(typeof(DeviceSpecificChoiceControlBuilder)),
        PersistName("Choice"),
        PersistChildren(false),
    ]
    [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
    public class DeviceSpecificChoice : IParserAccessor, IAttributeAccessor
    {
        private String _deviceFilter = String.Empty;
        private String _argument;
        private String _xmlns;
        private IDictionary _contents;
        private IDictionary _templates;
        private DeviceSpecific _owner;

        private static IComparer _caseInsensitiveComparer =
            new CaseInsensitiveComparer(CultureInfo.InvariantCulture);

        /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoice.Filter"]/*' />
        [
            DefaultValue("")
        ]
        public String Filter  
        {
            get
            {
                Debug.Assert(_deviceFilter != null);
                return _deviceFilter; 
            }
             
            set
            {
                if (value == null)
                {
                    value = String.Empty;
                }
                _deviceFilter = value; 
            }
        }

        /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoice.Argument"]/*' />
        public String Argument  
        {
            get
            {
                return _argument; 
            }
             
            set
            {
                _argument = value; 
            }
        }

        // This property is used by the Designer, and has no runtime effect
        /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoice.Xmlns"]/*' />
        [
            DefaultValue("")
        ]
        public String Xmlns
        {
            get
            {
                return _xmlns;
            }

            set
            {
                _xmlns = value;
            }
        }

        /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoice.Contents"]/*' />
        [
            DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
        ]
        public IDictionary Contents
        {
            get
            {
                if (_contents == null)
                {
                    _contents = new ListDictionary(_caseInsensitiveComparer);
                }
                return _contents;
            }
        }

        /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoice.Templates"]/*' />
        [
            PersistenceMode(PersistenceMode.InnerProperty),
        ]
        public IDictionary Templates
        {
            get
            {
                if (_templates == null)
                {
                    _templates = new ListDictionary(_caseInsensitiveComparer);
                }
                return _templates;
            }
        }

        /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoice.HasTemplates"]/*' />
        [
            DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
        ]
        public bool HasTemplates
        {
            get
            {
                return _templates != null && _templates.Count > 0;
            }
        }

        internal void ApplyProperties()
        {
            IDictionaryEnumerator enumerator = Contents.GetEnumerator();
            while (enumerator.MoveNext())
            {
                Object parentObject = Owner.Owner;
                
                String propertyName = (String)enumerator.Key;
                String propertyValue = enumerator.Value as String;

                // The ID property may not be overridden, according to spec
                // (since it will override the parent's ID, not very useful). 
                if (String.Equals(propertyName, "id", StringComparison.OrdinalIgnoreCase)) {
                    throw new ArgumentException(
                        SR.GetString(SR.DeviceSpecificChoice_InvalidPropertyOverride,
                                     propertyName));
                }
                
                if (propertyValue != null)
                {
                    // Parse through any "-" syntax items.

                    int dash;
                    while ((dash = propertyName.IndexOf("-", StringComparison.Ordinal)) != -1)
                    {   
                        String containingObjectName = propertyName.Substring(0, dash);
                        PropertyDescriptor pd = TypeDescriptor.GetProperties(parentObject).Find(
                                    containingObjectName, true);
                        if (pd == null)
                        {
                            throw new ArgumentException(
                                SR.GetString(SR.DeviceSpecificChoice_OverridingPropertyNotFound,
                                             propertyName));
                        }

                        parentObject = pd.GetValue(parentObject);
                        propertyName = propertyName.Substring(dash + 1);
                    }

                    if (!FindAndApplyProperty(parentObject, propertyName, propertyValue) &&
                        !FindAndApplyEvent(parentObject, propertyName, propertyValue))
                    {
                        // If control supports IAttributeAccessor (which it should)
                        // use it to set a custom attribute.

                        IAttributeAccessor a = parentObject as IAttributeAccessor;
                        if (a != null)
                        {
                            a.SetAttribute(propertyName, propertyValue);
                        }
                        else
                        {
                            throw new ArgumentException(
                                SR.GetString(SR.DeviceSpecificChoice_OverridingPropertyNotFound,
                                         propertyName));
                        }
                    }
                }
            }
        }

        private bool FindAndApplyProperty(Object parentObject, String name, String value)
        {
            PropertyDescriptor pd = TypeDescriptor.GetProperties(parentObject).Find(name, true);
            if (pd == null)
            {
                return false;
            }

            // Make sure the property is declarable.

            if (pd.Attributes.Contains(DesignerSerializationVisibilityAttribute.Hidden)) 
            {
                throw new ArgumentException(
                    SR.GetString(SR.DeviceSpecificChoice_OverridingPropertyNotDeclarable, name));
            }

            Object o;
            Type type = pd.PropertyType;

            if (type.IsAssignableFrom(typeof(String)))
            {
                o = value;
            }
            else if (type.IsAssignableFrom(typeof(int)))
            {
                o = Int32.Parse(value, CultureInfo.InvariantCulture);
            }
            else if (type.IsEnum)
            {
                o = Enum.Parse(type, value, true);
            }
            else if (value.Length == 0)
            {
                o = null;
            }
            else
            {
                TypeConverter converter = pd.Converter;
                if (converter != null)
                {
                    o = converter.ConvertFromInvariantString(value);
                }
                else
                {
                    throw new InvalidCastException(
                        SR.GetString(SR.DeviceSpecificChoice_OverridingPropertyTypeCast, name));
                }
            }
            pd.SetValue(parentObject, o);
            return true;
        }

        private bool FindAndApplyEvent(Object parentObject, String name, String value)
        {
            if (name.Length > 2 &&
                    Char.ToLower(name[0], CultureInfo.InvariantCulture) == 'o' &&
                    Char.ToLower(name[1], CultureInfo.InvariantCulture) == 'n')
            {
                String eventName = name.Substring(2);
                EventDescriptor ed = TypeDescriptor.GetEvents(parentObject).Find(eventName, true);
                if (ed != null)
                {
                    Delegate d = Delegate.CreateDelegate(ed.EventType, Owner.MobilePage, value);
                    ed.AddEventHandler(parentObject, d);
                    return true;
                }
            }
            return false;
        }

        internal DeviceSpecific Owner
        {
            get
            {
                return _owner;
            }

            set
            {
                _owner = value;
            }
        }

        internal bool Evaluate(MobileCapabilities capabilities)
        {
            // Evaluate the <Choice> by first looking to see if it's null, then
            // checking against evaluators defined in code on the page, then by
            // consulting the MobileCapabilities object.
            bool result;
            if (_deviceFilter != null && _deviceFilter.Length == 0) {
                // indicates device-independent <choice> clause
                result = true;
            }
            else if (CheckOnPageEvaluator(capabilities, out result))
            {
                // result already been set through the out-bound parameter
                // above. 
            }
            else
            {
                // The exception message generated by HasCapability() failing is 
                // inappropriate, so we substitute a more specific one.
                try
                {
                    result = capabilities.HasCapability(_deviceFilter, _argument);
                }
                catch
                {
                    throw new ArgumentException(SR.GetString(
                                    SR.DeviceSpecificChoice_CantFindFilter,
                                    _deviceFilter));
                }
                
            }

            return result;
        }

        // Return true if specified evaluator exists on the page with the
        // correct signature.  If it does, return result of invoking it in
        // evaluatorResult. 
        private bool CheckOnPageEvaluator(MobileCapabilities capabilities,
                                          out bool evaluatorResult)
        {
            evaluatorResult = false;
            TemplateControl containingTemplateControl = Owner.ClosestTemplateControl;

            MethodInfo methodInfo =
                containingTemplateControl.GetType().GetMethod(_deviceFilter,
                                                              new Type[]
                                                              {
                                                                  typeof(MobileCapabilities), 
                                                                  typeof(String)
                                                              }
                    );

            if (methodInfo == null || methodInfo.ReturnType != typeof(bool))
            {
                return false;
            }
            else
            {
                evaluatorResult = (bool)
                    methodInfo.Invoke(containingTemplateControl,
                                      new Object[]
                                      {
                                          capabilities,
                                          _argument
                                      }
                                     );

                return true;
            }
        }

        /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoice.IAttributeAccessor.GetAttribute"]/*' />
        /// <internalonly/>
        protected String GetAttribute(String key)
        {
            Object o = Contents[key];
            if (o != null & !(o is String))
            {
                throw new ArgumentException(SR.GetString(
                            SR.DeviceSpecificChoice_PropertyNotAnAttribute));
            }
            return (String)o;
        }

        /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoice.IAttributeAccessor.SetAttribute"]/*' />
        /// <internalonly/>
        protected void SetAttribute(String key, String value)
        {
            Contents[key] = value;
        }

        /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoice.IParserAccessor.AddParsedSubObject"]/*' />
        /// <internalonly/>
        protected void AddParsedSubObject(Object obj)
        {
            DeviceSpecificChoiceTemplateContainer c = obj as DeviceSpecificChoiceTemplateContainer;
            if (c != null)
            {
                Templates[c.Name] = c.Template;
            }
        }

        #region IAttributeAccessor implementation
        String IAttributeAccessor.GetAttribute(String name) {
            return GetAttribute(name);
        }

        void IAttributeAccessor.SetAttribute(String name, String value) {
            SetAttribute(name, value);
        }
        #endregion

        #region IParserAccessor implementation
        void IParserAccessor.AddParsedSubObject(Object obj) {
            AddParsedSubObject(obj);
        }
        #endregion
    }

    // TEMPLATE BAG
    //
    // The following classes are public by necessity (since they are exposed to
    // the framework), but all internal to the DeviceSpecificChoice. They have to do with
    // persistence of arbitrary templates in a choice. Here's a description of what is done:
    //
    // ASP.NET provides no way for an object or control to allow an arbitrary bag of 
    // templates. It only allows one way to define templates - the parent object must have
    // a property, of type ITemplate, with the same name as the template name. For example,
    // the code
    //
    //      <ParentCtl>
    //          <FirstTemplate>....</FirstTemplate>
    //          <SecondTemplate>....</SecondTemplate>
    //          <ThirdTemplate>....</ThirdTemplate>
    //      </ParentCtl>
    //
    // only works if the ParentCtl class exposes ITemplate properties with names FirstTemplate,
    // SecondTemplate, and ThirdTemplate.
    //
    // Because Choices apply to any control, that could potentially require any named template,
    // what we really need is something like a "template bag" that takes arbitrary templates.
    //
    // To work around this, here's what is done. First, at compile time:
    //
    // 1) DeviceSpecificChoice has its own control builder at compile time. When it is given a
    //    sub-object (in GetChildControlType), it returns DeviceSpecificChoiceTemplateType, which
    //    is a marker type similar to that used in ASP.NET. However, it is our own class, and
    //    has DeviceSpecificChoiceTemplateBuilder as its builder.
    // 2) DeviceSpecificChoiceTemplateBuilder inherits from TemplateBuilder, and thus has the same
    //    behavior as TemplateBuilder for parsing and compiling a template. However, it has
    //    an overriden Init method, which changes the tag name (and thus, the template name) 
    //    to a constant, "Template". It also saves the real template name in a property.
    // 3) When parsed, the framework calls the AppendSubBuilder method of the 
    //    DeviceSpecificChoiceBuilder, to add the template builder into it. But this builder
    //    first creates an intermediate builder, for the class DeviceSpecificChoiceTemplateContainer,
    //    adding the template name as a property in the builder's attribute dictionary. It then
    //    adds the intermediate builder into itself, and the template builder into it.
    //
    // All this has the net effect of automatically transforming something like
    //
    //      <Choice>
    //          <ItemTemplate>...</ItemTemplate>
    //          <HeaderTemplate>...</HeaderTemplate>
    //      </Choice>
    // 
    // into
    //
    //      <Choice>
    //          <DeviceSpecificChoiceTemplateContainer Name="ItemTemplate">
    //              <Template>...</Template>
    //          </DeviceSpecificChoiceTemplateContainer>
    //          <DeviceSpecificChoiceTemplateContainer Name="HeaderTemplate">
    //              <Template>...</Template>
    //          </DeviceSpecificChoiceTemplateContainer>
    //      </Choice>
    //
    // Now, at runtime the compiled code creates a DeviceSpecificChoiceTemplateContainer object,
    // and calls the AddParsedSubObject method of the DeviceSpecificChoice with it. This code (above)
    // then extracts the template referred to by the Template property of the object, and 
    // uses the Name property to add it to the template bag. Presto, we have a general template bag.

    /*
     * DeviceSpecificChoice control builder. For more information, see note on "Template Bag" above.
     *
     * Copyright (c) 2000 Microsoft Corporation
     */

    /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoiceControlBuilder"]/*' />
    [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
    public class DeviceSpecificChoiceControlBuilder : ControlBuilder
    {
        private bool _isDeviceIndependent = false;
        internal bool IsDeviceIndependent()
        {
            return _isDeviceIndependent;
        }

        /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoiceControlBuilder.Init"]/*' />
        public override void Init(TemplateParser parser, 
                                  ControlBuilder parentBuilder,
                                  Type type, 
                                  String tagName, 
                                  String id, 
                                  IDictionary attributes) 
        {
            if (!(parentBuilder is DeviceSpecificControlBuilder))
            {
                throw new ArgumentException(
                    SR.GetString(SR.DeviceSpecificChoice_ChoiceOnlyExistInDeviceSpecific));
            }

            _isDeviceIndependent = attributes == null || attributes["Filter"] == null;

            base.Init (parser, parentBuilder, type, tagName, id, attributes);
        }

        /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoiceControlBuilder.AppendLiteralString"]/*' />
        public override void AppendLiteralString(String text)
        {
            // Ignore literal strings.
        }

        /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoiceControlBuilder.GetChildControlType"]/*' />
        public override Type GetChildControlType(String tagName, IDictionary attributes) 
        {
            // Assume children are templates.

            return typeof(DeviceSpecificChoiceTemplateType);
        }

        /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoiceControlBuilder.AppendSubBuilder"]/*' />
        public override void AppendSubBuilder(ControlBuilder subBuilder) 
        {
            DeviceSpecificChoiceTemplateBuilder tplBuilder = 
                subBuilder as DeviceSpecificChoiceTemplateBuilder;
            if (tplBuilder != null)
            {
                // Called to add a template. Insert an intermediate control, 
                // by creating and adding its builder.

                ListDictionary dict = new ListDictionary();

                // Add the template's name as a Name attribute for the control.
                dict["Name"] = tplBuilder.TemplateName;

                // 1 and "xxxx" are bogus filename/line number values.
                ControlBuilder container = ControlBuilder.CreateBuilderFromType(
                                                Parser, this, 
                                                typeof(DeviceSpecificChoiceTemplateContainer),
                                                "Templates",
                                                null, dict, 1, null);
                base.AppendSubBuilder(container);

                // Now, append the template builder into the new intermediate builder.

                container.AppendSubBuilder(subBuilder);
            }
            else
            {
                base.AppendSubBuilder(subBuilder);
            }
        }
    }

    /*
     * DeviceSpecificChoiceTemplateType - marker type for a template that goes inside
     *      a Choice. Used only at compile time, and never instantiated. See note
     *      on "Template Bag" above.
     *
     * Copyright (c) 2000 Microsoft Corporation
     */

    [
        ControlBuilderAttribute(typeof(DeviceSpecificChoiceTemplateBuilder))
    ]
    [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
    internal class DeviceSpecificChoiceTemplateType : Control, IParserAccessor

    {
        private DeviceSpecificChoiceTemplateType()
        {
        }

        void IParserAccessor.AddParsedSubObject(Object o)
        {
        }
    }

    /*
     * DeviceSpecificChoiceTemplateBuilder - builder for a template that goes inside
     *      a Choice. See note on "Template Bag" above.
     *      When a Choice is device-independent, it also parses literal text content.
     *      The code for this is copied from LiteralTextContainerControlBuilder.cs
     *
     * Copyright (c) 2000 Microsoft Corporation
     */

    /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoiceTemplateBuilder"]/*' />
    [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
    public class DeviceSpecificChoiceTemplateBuilder : TemplateBuilder
    {
        private String _templateName;
        private bool _doLiteralText = false;
        private bool _controlsInserted = false;

        internal String TemplateName
        {
            get
            {
                return _templateName;
            }
        }

        CompileLiteralTextParser _textParser = null;
        internal CompileLiteralTextParser TextParser
        {
            get
            {
                if (_textParser == null)
                {
                    _textParser = 
                        new CompileLiteralTextParser(Parser, this, "xxxx", 1);
                    if (_controlsInserted)
                    {
                        _textParser.ResetBreaking();
                        _textParser.ResetNewParagraph();
                    }
                }
                return _textParser;
            }
        }

        /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoiceTemplateBuilder.Init"]/*' />
        public override void Init(TemplateParser parser, 
                                  ControlBuilder parentBuilder,
                                  Type type, 
                                  String tagName,
                                  String id, 
                                  IDictionary attributes) 
        {
            // Save off template name, and always pass the name "Template" to the base
            // class, because the intermediate object has this property as the name.

            _templateName = tagName;
            base.Init(parser, parentBuilder, type, "Template", id, attributes);

            // Are we a device-independent template?

            if (!InDesigner)
            {
                DeviceSpecificChoiceControlBuilder choiceBuilder = 
                    parentBuilder as DeviceSpecificChoiceControlBuilder;
                _doLiteralText = choiceBuilder != null && choiceBuilder.IsDeviceIndependent();
            }
        }

        /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoiceTemplateBuilder.AppendLiteralString"]/*' />
        public override void AppendLiteralString(String text)
        {
            if (_doLiteralText)
            {
                if (LiteralTextParser.IsValidText(text))
                {
                    TextParser.Parse(text);
                }
            }
            else
            {
                base.AppendLiteralString(text);
            }
        }

        /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoiceTemplateBuilder.AppendSubBuilder"]/*' />
        public override void AppendSubBuilder(ControlBuilder subBuilder)
        {
            if (_doLiteralText)
            {
                // The first one is used if ASP.NET is compiled with FAST_DATABINDING off. The second
                // is used if it is compiled with FAST_DATABINDING on. Note: We can't do a type 
                // comparison because CodeBlockBuilder is internal.
                // if (typeof(DataBoundLiteralControl).IsAssignableFrom(subBuilder.ControlType))
                if (subBuilder.GetType().FullName == "System.Web.UI.CodeBlockBuilder")
                {
                    TextParser.AddDataBinding(subBuilder);
                }
                else
                {
                    base.AppendSubBuilder(subBuilder);
                    if (subBuilder.ControlType != typeof(LiteralText))
                    {
                        if (_textParser != null)
                        {
                            _textParser.ResetBreaking();
                        }
                        else
                        {
                            _controlsInserted = true;
                        }
                    }
                }
            }
            else
            {
                base.AppendSubBuilder(subBuilder);
            }
        }
    }

    /*
     * DeviceSpecificChoiceTemplateContainer - "dummy" container object for 
     *      a template that goes inside a Choice. Once the Choice receives and
     *      extracts the information out of it, this object is simply discarded.
     *      See note on "Template Bag" above.
     *
     * Copyright (c) 2000 Microsoft Corporation
     */

    /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoiceTemplateContainer"]/*' />
    [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
    public class DeviceSpecificChoiceTemplateContainer
    {
        private ITemplate _template;
        private String _name;

        /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoiceTemplateContainer.Template"]/*' />
        [
            Filterable(false),
            TemplateContainer(typeof(TemplateContainer)),
        ]
        public ITemplate Template
        {
            get
            {
                return _template;
            }
            set
            {
                _template = value;
            }
        }

        /// <include file='doc\DeviceSpecificChoice.uex' path='docs/doc[@for="DeviceSpecificChoiceTemplateContainer.Name"]/*' />
        public String Name
        {
            get
            {
                return _name;
            }
            set
            {
                _name = value;
            }
        }
    }
}