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
;
19 public abstract class JSElementGeneratorBase
21 protected readonly IJSElementGenerator generator
;
22 protected readonly IJSGenerator parentGenerator
;
25 /// Initializes a new instance of the <see cref="JSElementGeneratorBase"/> class.
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
)
44 PrototypeHelper
.JSGenerator
.RemoveTail(parentGenerator
);
46 PrototypeHelper
.JSGenerator
.Record(parentGenerator
, " = " + args
[0]);
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
);
65 parentGenerator
.Call(method
, args
);