View Javadoc

1   /*
2    * Copyright 2006 Outsource Cafe, Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the 'License')
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an 'AS IS' BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.javagen.agile.core.emitter.context;
17  
18  import org.javagen.agile.core.context.ContextHolderStack;
19  import org.javagen.agile.core.context.DefaultContext;
20  import org.javagen.agile.core.emitter.Emitter;
21  import org.javagen.agile.core.emitter.template.NanoTemplateCallback;
22  import org.javagen.agile.core.model.Model;
23  import org.javagen.agile.core.context.Keys;
24  
25  /***
26   * Adds a local context to the context stack providing a place to put a standard set of
27   * values from the current model, including:
28   * <ul>
29   * <li><code>model</code> = the current model instance</li>
30   * <li><code>modelName</code> = the current model name</li>
31   * <li><code>nanoTemplate</code> - a NanoTemplate callback instance</li>
32   * </ul>
33   * TODO the ooNamingService provides most of the NanoTemplate functionality - can we refactor NanoTemplate out of the templates?
34   * 
35   * @author Richard Easterling
36   */
37  public class EmitterLocalContextLoader extends EmitterContextStackLoader {
38  	
39  	public void pushAll(ContextHolderStack context, Model currentModel, Emitter emitterContextHolder) {
40  		super.pushAll(context, currentModel, emitterContextHolder);
41  		DefaultContext localContext = new DefaultContext();
42          localContext.put(Keys.MODEL.toString(), currentModel);
43          localContext.put(Keys.MODEL_NAME.toString(), currentModel.getName());
44  		localContext.put(Keys.NANO_TEMPLATE.toString(), new NanoTemplateCallback(context));
45  		context.push(localContext); //local context
46  	}
47  	
48  	public void popAll(ContextHolderStack context, Model modelTree, Emitter emitterContextHolder) {
49  		context.pop(); //local context
50  		super.popAll(context, modelTree, emitterContextHolder);
51  	}
52  
53  }