- Implemented support for view component caching. Just use the attribute
[castle.git] / MonoRail / Castle.MonoRail.Framework / Internal / JSCollectionGeneratorBase.cs
blobd2ba78d101d8de14d888ca9877f177ef5e98e7a5
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MonoRail.Framework.Internal
17 using Castle.MonoRail.Framework.Helpers;
19 /// <summary>
20 /// Collection related generator
21 /// </summary>
22 /// <remarks>
23 /// Not really implemented.
24 /// </remarks>
25 public abstract class JSCollectionGeneratorBase
27 /// <summary>
28 /// Collection generator instance
29 /// </summary>
30 protected readonly IJSCollectionGenerator generator;
31 /// <summary>
32 /// Parent generator instance
33 /// </summary>
34 protected readonly IJSGenerator parentGenerator;
36 /// <summary>
37 /// Initializes a new instance of the <see cref="JSCollectionGeneratorBase"/> class.
38 /// </summary>
39 /// <param name="generator">The generator.</param>
40 public JSCollectionGeneratorBase(IJSCollectionGenerator generator)
42 this.generator = generator;
43 parentGenerator = generator.ParentGenerator;
46 /// <summary>
47 /// Defines the behavior when a property is read
48 /// </summary>
49 /// <param name="propName">Property name.</param>
50 /// <returns>value back to the template</returns>
51 protected void InternalGet(string propName)
53 PrototypeHelper.JSGenerator.ReplaceTailByPeriod(parentGenerator);
54 PrototypeHelper.JSGenerator.Record(parentGenerator, propName);
57 /// <summary>
58 /// Invokes the specified method.
59 /// </summary>
60 /// <param name="method">The method name.</param>
61 /// <param name="args">The method arguments.</param>
62 /// <returns>value back to the template</returns>
63 protected object InternalInvoke(string method, object[] args)
65 if (method == "set")
67 PrototypeHelper.JSGenerator.RemoveTail(parentGenerator);
69 PrototypeHelper.JSGenerator.Record(parentGenerator, " = " + args[0]);
71 return null;
73 else
75 PrototypeHelper.JSGenerator.ReplaceTailByPeriod(parentGenerator);
76 DynamicDispatchSupport dispInterface = generator as DynamicDispatchSupport;
77 if (dispInterface == null)
79 throw new MonoRail.Framework.MonoRailException("JS Generators must inherit DynamicDispatchSupport");
81 if (dispInterface.IsGeneratorMethod(method))
83 dispInterface.Dispatch(method, args);
85 else
87 parentGenerator.Call(method, args);
90 return this;