summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Dependency.java
blob: 5993f62921b4fb0bc13305dd58b5f1c1dafa4902 (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
package com.c2kernel.lifecycle.instance.predefined.entitycreation;

import java.util.ArrayList;

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;

public class Dependency implements java.io.Serializable {

    public String name;
    public boolean isDescription;
    public String itemDescriptionPath;
    public ArrayList<DependencyMember> dependencyMemberList;

    public Dependency() {
        super();
        dependencyMemberList = new ArrayList<DependencyMember>();
    }

    public Dependency(String itemDesc) {
        this();
        this.itemDescriptionPath = itemDesc;
    }

    /**
     * @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());
            CastorHashMap props = new CastorHashMap(); 
            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.");
            newDep.addMember(syskey);
        }
        return newDep;
    }

}