1 package net.sf.msplice.model;
2
3 import java.util.ArrayList;
4 import java.util.Dictionary;
5 import java.util.Enumeration;
6 import java.util.Hashtable;
7 import java.util.List;
8
9 import net.sf.msplice.SpliceException;
10 import net.sf.msplice.visitor.IVisitor;
11
12 import org.apache.commons.lang.StringUtils;
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15
16 public class BusinessProperty extends CompositeElement {
17
18 private final static Log LOG = LogFactory.getLog(BusinessProperty.class);
19
20 private Dictionary<String, ViewProperty> viewProperties = null;
21
22 private String name = null;
23
24
25
26
27
28 public BusinessProperty() {
29 viewProperties = new Hashtable<String, ViewProperty>();
30 }
31
32
33
34
35
36 public Object accept(IVisitor visitor) throws SpliceException {
37
38
39
40 List<Object> resultBusinessChildList = new ArrayList<Object>();
41 for (Enumeration<BusinessProperty> enumeration = childBusinessProps
42 .elements(); enumeration.hasMoreElements();) {
43
44 Object result = enumeration.nextElement().accept(visitor);
45 resultBusinessChildList.add(result);
46
47 LOG.debug("Result of the BusinessElement visit: " + result);
48 }
49
50
51
52
53 List<Object> resultViewPropertyList = new ArrayList<Object>();
54 for (Enumeration<BusinessProperty> enumeration = childBusinessProps
55 .elements(); enumeration.hasMoreElements();) {
56
57 Object result = enumeration.nextElement().accept(visitor);
58 resultViewPropertyList.add(result);
59
60 LOG.debug("Result of the BusinessElement visit: " + result);
61 }
62
63 return null;
64 }
65
66
67
68
69
70 public ViewProperty getViewProperty(String key) {
71 return viewProperties.get(key);
72 }
73
74 public void addViewProperty(ViewProperty viewProperty) {
75
76
77
78 if (StringUtils.isEmpty(viewProperty.getName())) {
79 throw new ModelRuntimeException(
80 "ViewProperty name must not be empty");
81 }
82
83
84
85 String name = viewProperty.getName();
86 ViewProperty preempted = putViewProperty(name, viewProperty);
87
88
89
90 if (preempted != null) {
91 throw new ModelRuntimeException(
92 "ViewProperty name clash for name: " + name);
93 }
94
95 }
96
97
98
99
100
101 public String getName() {
102 return name;
103 }
104
105 public void setName(String name) {
106 this.name = name;
107 }
108
109
110
111
112
113 private ViewProperty putViewProperty(String key, ViewProperty viewProperty) {
114 return viewProperties.put(key, viewProperty);
115 }
116
117 }