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 /// Collection related generator
23 /// Not really implemented.
25 public abstract class JSCollectionGeneratorBase
28 /// Collection generator instance
30 protected readonly IJSCollectionGenerator generator
;
32 /// Parent generator instance
34 protected readonly IJSGenerator parentGenerator
;
37 /// Initializes a new instance of the <see cref="JSCollectionGeneratorBase"/> class.
39 /// <param name="generator">The generator.</param>
40 public JSCollectionGeneratorBase(IJSCollectionGenerator generator
)
42 this.generator
= generator
;
43 parentGenerator
= generator
.ParentGenerator
;
47 /// Defines the behavior when a property is read
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
);
58 /// Invokes the specified method.
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
)
67 PrototypeHelper
.JSGenerator
.RemoveTail(parentGenerator
);
69 PrototypeHelper
.JSGenerator
.Record(parentGenerator
, " = " + args
[0]);
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
);
87 parentGenerator
.Call(method
, args
);