1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
;
20 /// Operations related to an element
22 public abstract class JSElementGeneratorBase
25 /// Element generator instance
27 protected readonly IJSElementGenerator generator
;
29 /// Parent Generator instance
31 protected readonly IJSGenerator parentGenerator
;
34 /// Initializes a new instance of the <see cref="JSElementGeneratorBase"/> class.
36 /// <param name="generator">The generator.</param>
37 public JSElementGeneratorBase(IJSElementGenerator generator
)
39 this.generator
= generator
;
40 parentGenerator
= generator
.ParentGenerator
;
44 /// Generates a get statement
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
);
54 /// Dispatches the invocation (late bound)
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
)
63 PrototypeHelper
.JSGenerator
.RemoveTail(parentGenerator
);
65 PrototypeHelper
.JSGenerator
.Record(parentGenerator
, " = " + args
[0]);
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
);
84 parentGenerator
.Call(method
, args
);