View Javadoc
1   /*
2    * Copyright (C) 2007-2012 Argeo GmbH
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.argeo.slc.core.execution.generator;
17  
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.List;
21  import java.util.Map;
22  
23  /**
24   * Default implementation of <code>RunnableDataNode</code>
25   *
26   */
27  public class DefaultRunnableDataNode implements RunnableDataNode {
28  
29  	private List<RunnableDataNode> children = new ArrayList<RunnableDataNode>();
30  	
31  	private RunnableDataNode parent;
32  	
33  	/**
34  	 * Data of the RunnableDataNode. Does not contain
35  	 * parent data.
36  	 */
37  	private Map<String, Object> properData = new HashMap<String, Object>();
38  	
39  	private String path;
40  	
41  	private String beanName;
42  
43  	public boolean isLeaf() {
44  		return children.size() == 0;
45  	}
46  	
47  	public List<RunnableDataNode> getChildren() {
48  		return children;
49  	}
50  
51  	public void addChild(RunnableDataNode child) {
52  		child.setParent(this);
53  		children.add(child);
54  	}
55  	
56  	public Map<String, Object> getData() {
57  		Map<String, Object> data = new HashMap<String, Object>();
58  		if(parent != null) {
59  			Map<String, Object> parentData = parent.getData();
60  			if(parentData != null) {
61  				data.putAll(parentData);
62  			}
63  		}
64  		// entries defined in parentData can be overridden
65  		// in properData
66  		if(properData != null) {
67  			data.putAll(properData);
68  		}
69  		return data;
70  	}
71  
72  	public Map<String, Object> getProperData() {
73  		return properData;
74  	}
75  
76  	public void setProperData(Map<String, Object> properData) {
77  		this.properData = properData;
78  	}
79  
80  	public String getPath() {
81  		return path;
82  	}
83  
84  	public void setPath(String path) {
85  		this.path = path;
86  	}
87  
88  	public String getBeanName() {
89  		return beanName;
90  	}
91  
92  	public void setBeanName(String beanName) {
93  		this.beanName = beanName;
94  	}
95  
96  	public void setParent(RunnableDataNode parent) {
97  		this.parent = parent;
98  	}
99  
100 	public RunnableDataNode getParent() {
101 		return parent;
102 	}
103 
104 }