boolean isNew = false;
if(chainLinkId == 0)
isNew = true;
ChainLink oldChainLink = findChainLinkByClassName(className);
if(oldChainLink != null && isNew)
throw new DuplicatedChainLinkException ("Another chain link already exist in the system with the same class name.");
else if (!isNew && oldChainLink.getCode().getId() != chainLinkId)
throw new DuplicatedChainLinkException ("Another chain link already exist in the system with the same class name.");
ChainLinkCode lcode;
if(!isNew) {
lcode = chainFactory.loadChainLinkCode(chainLinkId);
lcode.setClassName(className);
lcode.setCode(code);
lcode.setLanguage(lang);
} else {
lcode = new ChainLinkCode (className, code, lang);
}
ChainLink ret = instanciateChainLink(lcode);
chainFactory.saveChainLinkCode(lcode);
return ret;
}