Fix the build.
[castle.git] / MonoRail / Castle.MonoRail.Framework / Internal / JSElementGeneratorBase.cs
blobbcc7350015adf772f94faf627cd9732dea3fa1c4
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 /// Operations related to an element
21 /// </summary>
22 public abstract class JSElementGeneratorBase
24 /// <summary>
25 /// Element generator instance
26 /// </summary>
27 protected readonly IJSElementGenerator generator;
28 /// <summary>
29 /// Parent Generator instance
30 /// </summary>
31 protected readonly IJSGenerator parentGenerator;
33 /// <summary>
34 /// Initializes a new instance of the <see cref="JSElementGeneratorBase"/> class.
35 /// </summary>
36 /// <param name="generator">The generator.</param>
37 public JSElementGeneratorBase(IJSElementGenerator generator)
39 this.generator = generator;
40 parentGenerator = generator.ParentGenerator;
43 /// <summary>
44 /// Generates a get statement
45 /// </summary>
46 /// <param name="propName">Name of the prop.</param>
47 protected void InternalGet(string propName)
49 PrototypeHelper.JSGenerator.ReplaceTailByPeriod(parentGenerator);
50 PrototypeHelper.JSGenerator.Record(parentGenerator, propName);
53 /// <summary>
54 /// Dispatches the invocation (late bound)
55 /// </summary>
56 /// <param name="method">The method.</param>
57 /// <param name="args">The args.</param>
58 /// <returns></returns>
59 protected object InternalInvoke(string method, object[] args)
61 if (method == "set")
63 PrototypeHelper.JSGenerator.RemoveTail(parentGenerator);
65 PrototypeHelper.JSGenerator.Record(parentGenerator, " = " + args[0]);
67 return null;
69 else
71 PrototypeHelper.JSGenerator.ReplaceTailByPeriod(parentGenerator);
72 //TODO: This code is duplicated JSCollectionGeneratorBase line 65
73 DynamicDispatchSupport dispInterface = generator as DynamicDispatchSupport;
74 if (dispInterface == null)
76 throw new MonoRail.Framework.RailsException("JS Generators must inherit DynamicDispatchSupport");
78 if (dispInterface.IsGeneratorMethod(method))
80 dispInterface.Dispatch(method, args);
82 else
84 parentGenerator.Call(method, args);
87 return this;