{
binding.setQName(new QName(binding.getQName().getNamespaceURI(), getName()));
}
if (getRefName() != null)
{
PortType portType = getPortType();
binding.setEPortType(portType);
if (portType == null)
{
//The model doesn't reconile with it's Element properly when we're setting a null for it's PortType
binding.getElement().setAttribute("type", "");
}
}
List bindingOperations = binding.getEBindingOperations();
PortType portType = binding.getEPortType();
if (!getOverwrite())
{
// Don't Overwrite
if (portType == null)
{
return binding;
}
else
{
List operations = portType.getOperations();
/*******************************************************************************
* Determine which Operations require new a new corresponding BindingOperations
*******************************************************************************/
List newBindingOpsNeeded = new ArrayList();
for (int index = 0; index < operations.size(); index++)
{
Operation operation = (Operation)operations.get(index);
boolean foundMatch = false;
Iterator bindingOperationsIt = bindingOperations.iterator();
while (bindingOperationsIt.hasNext())
{
BindingOperation bindingOperation = (BindingOperation)bindingOperationsIt.next();
if (namesEqual(bindingOperation.getName(), operation.getName()))
{
foundMatch = true;
break;
}
}
if (!foundMatch)
{
newBindingOpsNeeded.add(operation);
}
}
// newBindingOpsNeeded is the List of Operations needing new corresponding
// BindingOperation's
List newBindingOps = createNewBindingOperations(newBindingOpsNeeded);
// don't add required namespace if nothing is really being added
if (!newBindingOps.isEmpty()) {
addRequiredNamespaces(binding);
}
// Generate the contents of the new BindingOperation's
Iterator newBindingOpsIt = newBindingOps.iterator();
while (newBindingOpsIt.hasNext())
{
BindingOperation newBindingOp = (BindingOperation)newBindingOpsIt.next();
generateBindingOperation(newBindingOp);
generateBindingOperationContent(newBindingOp);
}
}
generateBindingContent(binding);
}
else
{
// Overwrite
if (portType == null)
{
// We need to blow away everything under the Binding. No PortType associated with this Binding
bindingOperations.clear();
return binding;
}
else
{
addRequiredNamespaces(binding);
List operations = portType.getOperations();
/******************************************************
* Compare the Operations
******************************************************/
// Remove any BindingOperations which are no longer used