View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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.kuali.rice.krms.impl.provider.repository;
17  
18  import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
19  import org.kuali.rice.krms.api.repository.agenda.AgendaDefinition;
20  import org.kuali.rice.krms.framework.engine.AgendaTree;
21  
22  /**
23   * TODO... 
24   * 
25   * @author Kuali Rice Team (rice.collab@kuali.org)
26   *
27   */
28  public final class LazyAgendaTree implements AgendaTree {
29  
30  	private final Object mutex = new Object();
31  	private final AgendaDefinition agendaDefinition;
32  	private final RepositoryToEngineTranslator translator;
33  	
34  	private AgendaTree agendaTree;
35  	
36  	public LazyAgendaTree(AgendaDefinition agendaDefinition, RepositoryToEngineTranslator translator) {
37  		this.agendaDefinition = agendaDefinition;
38  		this.translator = translator;
39  	}
40  
41  	public void execute(ExecutionEnvironment environment) {
42  		initialize();
43  		agendaTree.execute(environment);
44  	}
45  	
46  	public void initialize() {
47  		// could use double-checked locking here for max efficiency
48  		synchronized (mutex) {
49  			if (agendaTree == null) {
50  				agendaTree = translator.translateAgendaDefinitionToAgendaTree(agendaDefinition);
51  			}
52  		}
53  	}
54  
55  }