- If the controller cannot be found, MR searches for a special rescue "rescues/404...
[castle.git] / MonoRail / Castle.MonoRail.Framework / Internal / JSElementGeneratorBase.cs
blobb06a7efe2d45a4413c1e941055d89cc07d15d295
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 public abstract class JSElementGeneratorBase
21 protected readonly IJSElementGenerator generator;
22 protected readonly IJSGenerator parentGenerator;
24 /// <summary>
25 /// Initializes a new instance of the <see cref="JSElementGeneratorBase"/> class.
26 /// </summary>
27 /// <param name="generator">The generator.</param>
28 public JSElementGeneratorBase(IJSElementGenerator generator)
30 this.generator = generator;
31 parentGenerator = generator.ParentGenerator;
34 protected void InternalGet(string propName)
36 PrototypeHelper.JSGenerator.ReplaceTailByPeriod(parentGenerator);
37 PrototypeHelper.JSGenerator.Record(parentGenerator, propName);
40 protected object InternalInvoke(string method, object[] args)
42 if (method == "set")
44 PrototypeHelper.JSGenerator.RemoveTail(parentGenerator);
46 PrototypeHelper.JSGenerator.Record(parentGenerator, " = " + args[0]);
48 return null;
50 else
52 PrototypeHelper.JSGenerator.ReplaceTailByPeriod(parentGenerator);
53 //TODO: This code is duplicated JSCollectionGeneratorBase line 65
54 DynamicDispatchSupport dispInterface = generator as DynamicDispatchSupport;
55 if (dispInterface == null)
57 throw new MonoRail.Framework.RailsException("JS Generators must inherit DynamicDispatchSupport");
59 if (dispInterface.IsGeneratorMethod(method))
61 dispInterface.Dispatch(method, args);
63 else
65 parentGenerator.Call(method, args);
68 return this;