blob: a0d7a1ebff3c0ce4a0dde4fbb91cf0bcc5d594ad (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
package com.c2kernel.lifecycle.instance.predefined.entitycreation;
import java.util.ArrayList;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import com.c2kernel.collection.MembershipException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.property.PropertyDescription;
import com.c2kernel.property.PropertyDescriptionList;
import com.c2kernel.property.PropertyUtility;
import com.c2kernel.utils.CastorHashMap;
import com.c2kernel.utils.KeyValuePair;
public class Dependency implements java.io.Serializable {
public String name;
public boolean isDescription;
public String itemDescriptionPath;
public ArrayList<DependencyMember> dependencyMemberList = new ArrayList<DependencyMember>();
public CastorHashMap props = new CastorHashMap();
Element elem;
public Dependency() {
super();
}
public Dependency(String itemDesc) {
this();
this.itemDescriptionPath = itemDesc;
}
public Dependency(Element dep) {
elem = dep;
name = dep.getAttribute("name");
isDescription = dep.getAttribute("isDescription").equals("true");
NodeList cpnl = dep.getElementsByTagName("CollectionProperty");
for (int k=0; k<cpnl.getLength(); k++) {
Element p = (Element)cpnl.item(k);
props.put(p.getAttribute("name"), ((Text)p.getFirstChild()).getData());
}
NodeList depmemnl = dep.getElementsByTagName("DependencyMember");
for (int k=0; k<depmemnl.getLength(); k++) {
Element p = (Element)depmemnl.item(k);
dependencyMemberList.add(new DependencyMember(p));
}
}
public KeyValuePair[] getKeyValuePairs() {
return props.getKeyValuePairs();
}
public void setKeyValuePairs(KeyValuePair[] pairs) {
props.setKeyValuePairs(pairs);
}
/**
* @return
*/
public com.c2kernel.collection.Dependency create() throws MembershipException, ObjectNotFoundException {
com.c2kernel.collection.Dependency newDep = isDescription?new com.c2kernel.collection.DependencyDescription(name):new com.c2kernel.collection.Dependency(name);
if (itemDescriptionPath != null && itemDescriptionPath.length()>0) {
PropertyDescriptionList propList = PropertyUtility.getPropertyDescriptionOutcome(new DomainPath(itemDescriptionPath).getSysKey());
StringBuffer classProps = new StringBuffer();
for (PropertyDescription pd : propList.list) {
props.put(pd.getName(), pd.getDefaultValue());
if (pd.getIsClassIdentifier())
classProps.append((classProps.length()>0?",":"")).append(pd.getName());
}
newDep.setProperties(props);
newDep.setClassProps(classProps.toString());
}
for (DependencyMember thisMem : dependencyMemberList) {
int syskey = new DomainPath(thisMem.itemPath).getSysKey();
if (syskey == -1)
throw new MembershipException("Cannot find "+thisMem.itemPath+" specified for collection.");
com.c2kernel.collection.DependencyMember newDepMem = newDep.addMember(syskey);
newDepMem.getProperties().putAll(thisMem.props);
}
return newDep;
}
}
|