//if this is the last binding for this service, and
if (service.getBindingTemplates().getBindingTemplate().size()==1 && isRemoveServiceIfNoTemplates) {
clerk.unRegisterService(serviceKey);
FindTModel findTmodelForProcessName = createFindTModelForProcessName(serviceName);
TModelList tModelList = clerk.findTModel(findTmodelForProcessName);
if (tModelList!=null && tModelList.getTModelInfos()!=null && tModelList.getTModelInfos().getTModelInfo()!=null) {
TModelInfo tModelInfo = tModelList.getTModelInfos().getTModelInfo().get(0);
String bpel4WSTModelKey = tModelInfo.getTModelKey();
clerk.unRegisterTModel(bpel4WSTModelKey);
// now use this key to find the portType TModels
GetTModelDetail findAllPortTypesForProcess = createFindAllPortTypesForProcess_1(bpel4WSTModelKey);
TModelDetail tModelDetail = clerk.getTModelDetail(findAllPortTypesForProcess);
if (tModelDetail!=null) {
List<TModel> tModelPortTypeList = tModelDetail.getTModel();
if (tModelPortTypeList!=null && tModelPortTypeList.size()>0) {
TModel bpel4WSTModel = tModelPortTypeList.get(0);
CategoryBag categoryBag = bpel4WSTModel.getCategoryBag();
if (categoryBag!=null && categoryBag.getKeyedReference()!=null) {
List<KeyedReference> portTypeTModelKeys = new ArrayList<KeyedReference>();
KeyedReference namespaceRef = null;
for (KeyedReference keyedReference : categoryBag.getKeyedReference()) {
if ("uddi:uddi.org:wsdl:porttypereference".equals(keyedReference.getTModelKey()) ) {
portTypeTModelKeys.add(keyedReference);
}
if ("uddi:uddi.org:xml:namespace".equals(keyedReference.getTModelKey()) ) {
namespaceRef = keyedReference;
}
}
String namespace = null;
if (namespaceRef!=null) namespace = namespaceRef.getKeyValue();
//find the bindingTModel
for (KeyedReference keyedReference : portTypeTModelKeys) {
FindTModel findBindingTModel = WSDL2UDDI.createFindBindingTModelForPortType(keyedReference.getKeyValue(), namespace);
TModelList bindingTmodels = clerk.findTModel(findBindingTModel);
if (bindingTmodels!=null && bindingTmodels.getTModelInfos()!=null && bindingTmodels.getTModelInfos().getTModelInfo()!=null) {
for (TModelInfo bindingTModelInfo : bindingTmodels.getTModelInfos().getTModelInfo()) {
//delete the Binding TModel
clerk.unRegisterTModel(bindingTModelInfo.getTModelKey());
}
}
//delete the PortType TModel