final HashMap<WsdlBindingSubject, Collection<Policy>> subjectToPolicies = new HashMap<WsdlBindingSubject, Collection<Policy>>();
for (PolicySubject subject: policySubjects) {
final Object actualSubject = subject.getSubject();
if (actualSubject instanceof WsdlBindingSubject) {
final WsdlBindingSubject wsdlSubject = (WsdlBindingSubject) actualSubject;
final Collection<Policy> subjectPolicies = new LinkedList<Policy>();
subjectPolicies.add(subject.getEffectivePolicy(MERGER));
final Collection<Policy> existingPolicies = subjectToPolicies.put(wsdlSubject, subjectPolicies);
if (existingPolicies != null) {
subjectPolicies.addAll(existingPolicies);
}
}
}
final PolicyMapKeyConverter converter = new PolicyMapKeyConverter(serviceName, portName);
for (WsdlBindingSubject wsdlSubject : subjectToPolicies.keySet()) {
final PolicySubject newSubject = new PolicySubject(wsdlSubject, subjectToPolicies.get(wsdlSubject));
PolicyMapKey mapKey = converter.getPolicyMapKey(wsdlSubject);
if (wsdlSubject.isBindingSubject()) {
policyMap.putSubject(ScopeType.ENDPOINT, mapKey, newSubject);
}
else if (wsdlSubject.isBindingOperationSubject()) {
policyMap.putSubject(ScopeType.OPERATION, mapKey, newSubject);
}
else if (wsdlSubject.isBindingMessageSubject()) {
switch (wsdlSubject.getMessageType()) {
case INPUT:
policyMap.putSubject(ScopeType.INPUT_MESSAGE, mapKey, newSubject);
break;
case OUTPUT:
policyMap.putSubject(ScopeType.OUTPUT_MESSAGE, mapKey, newSubject);