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; import com.c2kernel.utils.KeyValuePair; import com.c2kernel.utils.Logger; public class Dependency implements java.io.Serializable { public String name; public boolean isDescription; public String itemDescriptionPath; public ArrayList dependencyMemberList = new ArrayList(); public CastorHashMap props = new CastorHashMap(); public Dependency() { super(); } public Dependency(String name) { this(); this.name = name; } 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) { Logger.debug(itemDescriptionPath); 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; } }