View Javadoc

1   package net.sf.msplice.model;
2   
3   import java.util.Dictionary;
4   import java.util.Hashtable;
5   
6   import org.apache.commons.lang.StringUtils;
7   
8   public abstract class CompositeElement {
9   
10  	protected Dictionary<String, BusinessProperty> childBusinessProps = null;
11  
12  	// --------------------------------------------------------------------------------
13  	// ctors
14  	// --------------------------------------------------------------------------------
15  
16  	public CompositeElement() {
17  		childBusinessProps = new Hashtable<String, BusinessProperty>();
18  	}
19  
20  	// --------------------------------------------------------------------------------
21  	//  
22  	// --------------------------------------------------------------------------------
23  
24  	public BusinessProperty getBusinessProperty(String key) {
25  		return childBusinessProps.get(key);
26  	}
27  
28  	public void addBusinessProperty(BusinessProperty businessProperty) {
29  
30  		// preconditions
31  		//
32  		if (StringUtils.isEmpty(businessProperty.getName())) {
33  			throw new ModelRuntimeException(
34  					"BusinessProperty name must not be empty");
35  		}
36  
37  		// action
38  		//		
39  		String name = businessProperty.getName();
40  		BusinessProperty preempted = putBusinessProperty(name, businessProperty);
41  
42  		// postconditions
43  		//
44  		if (preempted != null) {
45  			throw new ModelRuntimeException(
46  					"BusinessProperty name clash for name: " + name);
47  		}
48  	}
49  
50  	// --------------------------------------------------------------------------------
51  	// private helpers
52  	// --------------------------------------------------------------------------------
53  
54  	private BusinessProperty putBusinessProperty(String key,
55  			BusinessProperty businessProperty) {
56  		return childBusinessProps.put(key, businessProperty);
57  	}
58  }