FileDocCategorySizeDatePackage
PolicyWSDLParserExtension.javaAPI DocExample62645Thu Jul 12 10:19:06 BST 2007com.sun.xml.ws.policy.jaxws

PolicyWSDLParserExtension

public final class PolicyWSDLParserExtension extends com.sun.xml.ws.api.wsdl.parser.WSDLParserExtension
author
Jakub Podlesak (jakub.podlesak at sun.com)

Fields Summary
private static final com.sun.xml.ws.policy.privateutil.PolicyLogger
LOGGER
private static final StringBuffer
AnonymnousPolicyIdPrefix
private int
anonymousPoliciesCount
private boolean
isForConfigFile
private PolicyRecord
expandQueueHead
private Map
policyRecordsPassedBy
private Map
anonymousPolicyModels
private List
unresolvedUris
final Set
urlsRead
private final LinkedList
urisNeeded
private final Map
modelsNeeded
private Map
handlers4ServiceMap
private Map
handlers4PortMap
private Map
handlers4PortTypeMap
private Map
handlers4BindingMap
private Map
handlers4BoundOperationMap
private Map
handlers4OperationMap
private Map
handlers4MessageMap
private Map
handlers4InputMap
private Map
handlers4OutputMap
private Map
handlers4FaultMap
private Map
handlers4BindingInputOpMap
private Map
handlers4BindingOutputOpMap
private Map
handlers4BindingFaultOpMap
private PolicyMapBuilder
policyBuilder
private com.sun.xml.ws.policy.PolicyMapMutator[]
externalMutators
Constructors Summary
public PolicyWSDLParserExtension()
Creates a new instance of PolicyWSDLParserExtension

        this(false, (PolicyMapMutator[])null);
    
public PolicyWSDLParserExtension(com.sun.xml.ws.policy.PolicyMapMutator externalMutators)
Creates a new instance of PolicyWSDLParserExtension. Allows you to register several instances of {@link com.sun.xml.ws.policy.PolicyMapMutator} to the newly populated {@link com.sun.xml.ws.policy.PolicyMap} to make changes to the map later.

        this(false, externalMutators);
    
public PolicyWSDLParserExtension(boolean isForConfigFile, com.sun.xml.ws.policy.PolicyMapMutator externalMutators)
Creates a new instance of PolicyWSDLParserExtension

        this.isForConfigFile = isForConfigFile;
        if (null != externalMutators) {
            this.externalMutators = new PolicyMapMutator[externalMutators.length];
            System.arraycopy(externalMutators, 0, this.externalMutators, 0, externalMutators.length);
        }
    
Methods Summary
private voidaddHandlerToMap(java.util.Map map, com.sun.xml.ws.api.model.wsdl.WSDLObject key, com.sun.xml.ws.policy.jaxws.PolicyWSDLParserExtension$PolicyRecordHandler handler)

        if (map.containsKey(key)) {
            map.get(key).add(handler);
        } else {
            final Collection<PolicyRecordHandler> newSet = new LinkedList<PolicyRecordHandler>();
            newSet.add(handler);
            map.put(key,newSet);
        }
    
private voidaddNewPolicyNeeded(java.lang.String policyUri, com.sun.xml.ws.policy.sourcemodel.PolicySourceModel policyModel)

        if (!modelsNeeded.containsKey(policyUri)) {
            modelsNeeded.put(policyUri, policyModel);
            urisNeeded.addFirst(policyUri);
        }
    
public voidbindingAttributes(com.sun.xml.ws.api.model.wsdl.WSDLBoundPortType binding, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        processAttributes(binding, reader, getHandlers4BindingMap());
        LOGGER.exiting();
    
public booleanbindingElements(com.sun.xml.ws.api.model.wsdl.WSDLBoundPortType binding, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        final boolean result = processSubelement(binding, reader, getHandlers4BindingMap());
        LOGGER.exiting();
        return result;
    
public voidbindingOperationAttributes(com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation boundOperation, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        processAttributes(boundOperation, reader, getHandlers4BoundOperationMap());
        LOGGER.exiting();
    
public booleanbindingOperationElements(com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation boundOperation, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        final boolean result = processSubelement(boundOperation, reader, getHandlers4BoundOperationMap());
        LOGGER.exiting();
        return result;
    
public voidbindingOperationFaultAttributes(com.sun.xml.ws.api.model.wsdl.WSDLBoundFault fault, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        processAttributes(fault, reader, getHandlers4BindingFaultOpMap());
        LOGGER.exiting();
    
public booleanbindingOperationFaultElements(com.sun.xml.ws.api.model.wsdl.WSDLBoundFault fault, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        final boolean result = processSubelement(fault, reader, getHandlers4BindingFaultOpMap());
        LOGGER.exiting(result);
        return result;
    
public voidbindingOperationInputAttributes(com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation operation, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        processAttributes(operation, reader, getHandlers4BindingInputOpMap());
        LOGGER.exiting();
    
public booleanbindingOperationInputElements(com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation operation, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        final boolean result = processSubelement(operation, reader, getHandlers4BindingInputOpMap());
        LOGGER.exiting();
        return result;
    
public voidbindingOperationOutputAttributes(com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation operation, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        processAttributes(operation, reader, getHandlers4BindingOutputOpMap());
        LOGGER.exiting();
    
public booleanbindingOperationOutputElements(com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation operation, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        final boolean result = processSubelement(operation, reader, getHandlers4BindingOutputOpMap());
        LOGGER.exiting();
        return result;
    
public booleandefinitionsElements(javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        if (PolicyConstants.POLICY.equals(reader.getName())) {     // Only "Policy" element interests me
            readSinglePolicy(
                    skipPolicyElement(
                    reader,
                    (null == reader.getLocation().getSystemId()) ? // baseUrl
                        "" : reader.getLocation().getSystemId()),
                    false);
            LOGGER.exiting();
            return true;
        }
        LOGGER.exiting();
        return false;
    
public voidfinished(com.sun.xml.ws.api.wsdl.parser.WSDLParserExtensionContext context)

        LOGGER.entering();
        // need to make sure proper beginning order of internal policies within unresolvedUris list
        if (null != expandQueueHead) { // any policies found
            final List<String> externalUris = getUnresolvedUris(false); // protect list of possible external policies
            getUnresolvedUris(true); // cleaning up the list only
            final LinkedList<String> baseUnresolvedUris = new LinkedList<String>();
            for (PolicyRecord currentRec = expandQueueHead ; null != currentRec ; currentRec = currentRec.next) {
                baseUnresolvedUris.addFirst(currentRec.uri);
            }
            getUnresolvedUris(false).addAll(baseUnresolvedUris);
            expandQueueHead = null; // cut the queue off
            getUnresolvedUris(false).addAll(externalUris);
        }
//        final Set<String> urlsRead = new HashSet<String>();
//        urlsRead.add("");
        while (!getUnresolvedUris(false).isEmpty()) {
            final List<String> urisToBeSolvedList = getUnresolvedUris(false);
            getUnresolvedUris(true); // just cleaning up the list
            for (String currentUri : urisToBeSolvedList) {
                if (!isPolicyProcessed(currentUri)) {
                    final PolicyRecord prefetchedRecord = getPolicyRecordsPassedBy().get(currentUri);
                    if (null == prefetchedRecord) {
                        if (urlsRead.contains(getBaseUrl(currentUri))) { // big problem --> unresolvable policy
                            LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_1042_CAN_NOT_FIND_POLICY(currentUri)));
                        } else {
                            if (readExternalFile(getBaseUrl(currentUri))) {
                                getUnresolvedUris(false).add(currentUri);
                            }
                        }
                    } else { // policy has not been yet passed by
                        if (null != prefetchedRecord.unresolvedURIs) {
                            getUnresolvedUris(false).addAll(prefetchedRecord.unresolvedURIs);
                        } // end-if null != prefetchedRecord.unresolvedURIs
                        addNewPolicyNeeded(currentUri, prefetchedRecord.policyModel);
                    }
                } // end-if policy already processed
            } // end-foreach unresolved uris
        }
        final PolicySourceModelContext modelContext = PolicySourceModelContext.createContext();
        for (String policyUri : urisNeeded) {
            final PolicySourceModel sourceModel = modelsNeeded.get(policyUri);
            try {
                sourceModel.expand(modelContext);
                modelContext.addModel(new URI(policyUri), sourceModel);
            } catch (URISyntaxException e) {
                LOGGER.logSevereException(e);
            } catch (PolicyException e) {
                LOGGER.logSevereException(e);
            }
        }
        
        // Start-preparation of policy map builder
        // iterating over all services and binding all the policies read before
        try {
            // messageSet holds the handlers for all wsdl:message elements. There
            // may otherwise be multiple entries for policies that are contained
            // by fault messages.
            HashSet<BuilderHandlerMessageScope> messageSet = new HashSet<BuilderHandlerMessageScope>();
            for (WSDLService service : context.getWSDLModel().getServices().values()) {
                if (getHandlers4ServiceMap().containsKey(service)) {
                    getPolicyMapBuilder().registerHandler(new BuilderHandlerServiceScope(
                            getPolicyURIs(getHandlers4ServiceMap().get(service),modelContext)
                            ,getPolicyModels()
                            ,service
                            ,service.getName()));
                }
                // end service scope
                
                for (WSDLPort port : service.getPorts()) {
                    if (getHandlers4PortMap().containsKey(port)) {
                        getPolicyMapBuilder().registerHandler(
                                new BuilderHandlerEndpointScope(
                                getPolicyURIs(getHandlers4PortMap().get(port),modelContext)
                                ,getPolicyModels()
                                ,port
                                ,port.getOwner().getName()
                                ,port.getName()));
                    }
                    if ( // port.getBinding may not be null, but in case ...
                            null != port.getBinding()) {
                        if ( // handler for binding
                                getHandlers4BindingMap().containsKey(port.getBinding())) {
                            getPolicyMapBuilder()
                            .registerHandler(
                                    new BuilderHandlerEndpointScope(
                                    getPolicyURIs(getHandlers4BindingMap().get(port.getBinding()),modelContext)
                                    ,getPolicyModels()
                                    ,port.getBinding()
                                    ,service.getName()
                                    ,port.getName()));
                        } // endif handler for binding
                        if ( // handler for port type
                                getHandlers4PortTypeMap().containsKey(port.getBinding().getPortType())) {
                            getPolicyMapBuilder()
                            .registerHandler(
                                    new BuilderHandlerEndpointScope(
                                    getPolicyURIs(getHandlers4PortTypeMap().get(port.getBinding().getPortType()),modelContext)
                                    ,getPolicyModels()
                                    ,port.getBinding().getPortType()
                                    ,service.getName()
                                    ,port.getName()));
                        } // endif handler for port type
                        // end endpoint scope
                        
                        for (WSDLBoundOperation boundOperation : port.getBinding().getBindingOperations()) {

                            final WSDLOperation operation = boundOperation.getOperation();
                            if ( // handler for operation scope -- by boundOperation
                                    getHandlers4BoundOperationMap().containsKey(boundOperation)) {
                                getPolicyMapBuilder()
                                .registerHandler(
                                        new BuilderHandlerOperationScope(
                                        getPolicyURIs(getHandlers4BoundOperationMap().get(boundOperation),modelContext)
                                        ,getPolicyModels()
                                        ,boundOperation
                                        ,service.getName()
                                        ,port.getName()
                                        ,operation.getName()));
                            } // endif handler for binding:operation scope
                            if ( // handler for operation scope -- by operation map
                                    getHandlers4OperationMap().containsKey(operation)) {
                                getPolicyMapBuilder()
                                .registerHandler(
                                        new BuilderHandlerOperationScope(
                                        getPolicyURIs(getHandlers4OperationMap().get(operation),modelContext)
                                        ,getPolicyModels()
                                        ,operation
                                        ,service.getName()
                                        ,port.getName()
                                        ,operation.getName()));
                            } // endif for portType:operation scope
                            // end operation scope

                            final WSDLInput input = operation.getInput();
                            if (null!=input) {
                                WSDLMessage inputMsg = input.getMessage();
                                if (inputMsg != null && getHandlers4MessageMap().containsKey(inputMsg)) {
                                    messageSet.add(new BuilderHandlerMessageScope(
                                        getPolicyURIs(
                                            getHandlers4MessageMap().get(inputMsg), modelContext)
                                            ,getPolicyModels()
                                            ,inputMsg
                                            ,BuilderHandlerMessageScope.Scope.InputMessageScope
                                            ,service.getName()
                                            ,port.getName()
                                            ,operation.getName()
                                            ,null)
                                    );
                                }
                            }
                            if ( // binding op input msg
                                    getHandlers4BindingInputOpMap().containsKey(boundOperation)) {
                                getPolicyMapBuilder()
                                .registerHandler(
                                        new BuilderHandlerMessageScope(
                                        getPolicyURIs(getHandlers4BindingInputOpMap().get(boundOperation),modelContext)
                                        ,getPolicyModels()
                                        ,boundOperation
                                        ,BuilderHandlerMessageScope.Scope.InputMessageScope
                                        ,service.getName()
                                        ,port.getName()
                                        ,operation.getName()
                                        ,null));
                            } // endif binding op input msg
                            if ( null != input    // portType op input msg
                                    && getHandlers4InputMap().containsKey(input)) {
                                getPolicyMapBuilder()
                                .registerHandler(
                                        new BuilderHandlerMessageScope(
                                        getPolicyURIs(getHandlers4InputMap().get(input),modelContext)
                                        ,getPolicyModels()
                                        ,input
                                        ,BuilderHandlerMessageScope.Scope.InputMessageScope
                                        ,service.getName()
                                        ,port.getName()
                                        ,operation.getName()
                                        ,null));
                            } // endif portType op input msg
                            // end input message scope
                            
                            final WSDLOutput output = operation.getOutput();
                            if (null!=output) {
                                WSDLMessage outputMsg = output.getMessage();
                                if (outputMsg != null && getHandlers4MessageMap().containsKey(outputMsg)) {
                                    messageSet.add(new BuilderHandlerMessageScope(
                                        getPolicyURIs(
                                            getHandlers4MessageMap().get(outputMsg),modelContext)
                                            ,getPolicyModels()
                                            ,outputMsg
                                            ,BuilderHandlerMessageScope.Scope.OutputMessageScope
                                            ,service.getName()
                                            ,port.getName()
                                            ,operation.getName()
                                            ,null)
                                    );
                                }
                            }
                            if ( // binding op output msg
                                    getHandlers4BindingOutputOpMap().containsKey(boundOperation)) {
                                getPolicyMapBuilder()
                                .registerHandler(
                                        new BuilderHandlerMessageScope(
                                        getPolicyURIs(getHandlers4BindingOutputOpMap().get(boundOperation),modelContext)
                                        ,getPolicyModels()
                                        ,boundOperation
                                        ,BuilderHandlerMessageScope.Scope.OutputMessageScope
                                        ,service.getName()
                                        ,port.getName()
                                        ,operation.getName()
                                        ,null));
                            } // endif binding op output msg
                            if ( null != output // portType op output msg
                                    && getHandlers4OutputMap().containsKey(output)) {
                                getPolicyMapBuilder()
                                .registerHandler(
                                        new BuilderHandlerMessageScope(
                                        getPolicyURIs(getHandlers4OutputMap().get(output),modelContext)
                                        ,getPolicyModels()
                                        ,output
                                        ,BuilderHandlerMessageScope.Scope.OutputMessageScope
                                        ,service.getName()
                                        ,port.getName()
                                        ,operation.getName()
                                        ,null));
                            } // endif portType op output msg
                            // end output message scope
                            
                            for (WSDLBoundFault boundFault : boundOperation.getFaults()) {
                                final QName faultName = new QName(boundOperation.getName().getNamespaceURI(), boundFault.getName());
                                final WSDLFault fault = boundFault.getFault();
                                final WSDLMessage faultMessage = fault.getMessage();
                                if (faultMessage != null && getHandlers4MessageMap().containsKey(faultMessage)) {
                                    messageSet.add(
                                        new BuilderHandlerMessageScope(
                                            getPolicyURIs(getHandlers4MessageMap().get(faultMessage), modelContext)
                                            ,getPolicyModels()
                                            ,new WSDLBoundFaultContainer(boundFault, boundOperation)
                                            ,BuilderHandlerMessageScope.Scope.FaultMessageScope
                                            ,service.getName()
                                            ,port.getName()
                                            ,operation.getName()
                                            ,faultName)
                                        );
                                }
                                if (fault != null && getHandlers4FaultMap().containsKey(fault)) {
                                    messageSet.add(
                                        new BuilderHandlerMessageScope(
                                            getPolicyURIs(getHandlers4FaultMap().get(fault), modelContext)
                                            ,getPolicyModels()
                                            ,new WSDLBoundFaultContainer(boundFault, boundOperation)
                                            ,BuilderHandlerMessageScope.Scope.FaultMessageScope
                                            ,service.getName()
                                            ,port.getName()
                                            ,operation.getName()
                                            ,faultName)
                                        );
                                }
                                if (getHandlers4BindingFaultOpMap().containsKey(boundFault)) {
                                    messageSet.add(
                                        new BuilderHandlerMessageScope(
                                            getPolicyURIs(getHandlers4BindingFaultOpMap().get(boundFault), modelContext)
                                            ,getPolicyModels()
                                            ,new WSDLBoundFaultContainer(boundFault, boundOperation)
                                            ,BuilderHandlerMessageScope.Scope.FaultMessageScope
                                            ,service.getName()
                                            ,port.getName()
                                            ,operation.getName()
                                            ,faultName)
                                        );
                                }
                            } // end foreach binding operation fault msg
                            // end fault message scope
                            
                        } // end foreach boundOperation in port
                    } // endif port.getBinding() != null
                } // end foreach port in service
            } // end foreach service in wsdl
            // Add handlers for wsdl:message elements
            for (BuilderHandlerMessageScope scopeHandler : messageSet) {
                getPolicyMapBuilder().registerHandler(scopeHandler);
            }
        } catch(PolicyException e) {
            LOGGER.logSevereException(e);
        }
        // End-preparation of policy map builder
        
        // finally register a wrapper for getting WSDL policy map
        
        final EffectivePolicyModifier modifier = EffectivePolicyModifier.createEffectivePolicyModifier();
        final PolicyMapExtender extender = PolicyMapExtender.createPolicyMapExtender();
        
        try {
            if (null != externalMutators && externalMutators.length > 0) {
                PolicyMapMutator[] mutators = new PolicyMapMutator[externalMutators.length+2];
                mutators[0] = modifier;
                mutators[1] = extender;
                System.arraycopy(externalMutators, 0, mutators, 2, externalMutators.length);
                context.getWSDLModel().addExtension(new WSDLPolicyMapWrapper(policyBuilder.getPolicyMap(mutators), modifier, extender));
            } else {
                context.getWSDLModel().addExtension(new WSDLPolicyMapWrapper(policyBuilder.getPolicyMap(modifier, extender), modifier, extender));
            }
        } catch(PolicyException e) {
            LOGGER.logSevereException(e);
            throw LOGGER.logSevereException(new WebServiceException(LocalizationMessages.WSP_1018_POLICY_EXCEPTION_WHILE_FINISHING_PARSING_WSDL(), e));
        }
        
        LOGGER.exiting();
    
private java.util.MapgetAnonymousPolicyModels()

        if (null==anonymousPolicyModels) {
            anonymousPolicyModels = new HashMap<String,PolicySourceModel>();
        }
        return anonymousPolicyModels;
    
private java.lang.StringgetBaseUrl(java.lang.String policyUri)

        if (null == policyUri) {
            return null;
        }
        // TODO: encoded urls (escaped characters) might be a problem ?
        final int fragmentIdx = policyUri.indexOf('#");
        return (fragmentIdx == -1) ? policyUri : policyUri.substring(0, fragmentIdx);
    
private java.util.MapgetHandlers4BindingFaultOpMap()

        if (null==handlers4BindingFaultOpMap) {
            handlers4BindingFaultOpMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
        }
        return handlers4BindingFaultOpMap;
    
private java.util.MapgetHandlers4BindingInputOpMap()

        if (null==handlers4BindingInputOpMap) {
            handlers4BindingInputOpMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
        }
        return handlers4BindingInputOpMap;
    
private java.util.MapgetHandlers4BindingMap()

        if (null==handlers4BindingMap) {
            handlers4BindingMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
        }
        return handlers4BindingMap;
    
private java.util.MapgetHandlers4BindingOutputOpMap()

        if (null==handlers4BindingOutputOpMap) {
            handlers4BindingOutputOpMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
        }
        return handlers4BindingOutputOpMap;
    
private java.util.MapgetHandlers4BoundOperationMap()

        if (null==handlers4BoundOperationMap) {
            handlers4BoundOperationMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
        }
        return handlers4BoundOperationMap;
    
private java.util.MapgetHandlers4FaultMap()

        if (null==handlers4FaultMap) {
            handlers4FaultMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
        }
        return handlers4FaultMap;
    
private java.util.MapgetHandlers4InputMap()

        if (null==handlers4InputMap) {
            handlers4InputMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
        }
        return handlers4InputMap;
    
private java.util.MapgetHandlers4MessageMap()

        if (null==handlers4MessageMap) {
            handlers4MessageMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
        }
        return handlers4MessageMap;
    
private java.util.MapgetHandlers4OperationMap()

        if (null==handlers4OperationMap) {
            handlers4OperationMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
        }
        return handlers4OperationMap;
    
private java.util.MapgetHandlers4OutputMap()

        if (null==handlers4OutputMap) {
            handlers4OutputMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
        }
        return handlers4OutputMap;
    
private java.util.MapgetHandlers4PortMap()

        if (null==handlers4PortMap) {
            handlers4PortMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
        }
        return handlers4PortMap;
    
private java.util.MapgetHandlers4PortTypeMap()

        if (null==handlers4PortTypeMap) {
            handlers4PortTypeMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
        }
        return handlers4PortTypeMap;
    
private java.util.MapgetHandlers4ServiceMap()

        if (null==handlers4ServiceMap) {
            handlers4ServiceMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
        }
        return handlers4ServiceMap;
    
private PolicyMapBuildergetPolicyMapBuilder()

        if (null == policyBuilder) {
            policyBuilder = new PolicyMapBuilder();
        }
        return policyBuilder;
    
private java.util.MapgetPolicyModels()

        return modelsNeeded;
    
private java.util.MapgetPolicyRecordsPassedBy()

        if (null==policyRecordsPassedBy) {
            policyRecordsPassedBy = new HashMap<String,PolicyRecord>();
        }
        return policyRecordsPassedBy;
    
private java.util.CollectiongetPolicyURIs(java.util.Collection handlers, com.sun.xml.ws.policy.sourcemodel.PolicySourceModelContext modelContext)

        final Collection<String> result = new ArrayList<String>(handlers.size());
        String policyUri;
        for (PolicyRecordHandler handler : handlers) {
            policyUri = handler.handler;
            if (HandlerType.AnonymousPolicyId == handler.type) {
                final PolicySourceModel policyModel = getAnonymousPolicyModels().get(policyUri);
                policyModel.expand(modelContext);
                while (getPolicyModels().containsKey(policyUri)) {
                    policyUri = AnonymnousPolicyIdPrefix.append(anonymousPoliciesCount++).toString();
                }
                getPolicyModels().put(policyUri,policyModel);
            }
            result.add(policyUri);
        }
        return result;
    
private java.lang.String[]getPolicyURIsFromAttr(javax.xml.stream.XMLStreamReader reader)
Reads policy reference URIs from PolicyURIs attribute and returns them as a String array returns null if there is no such attribute

        final String policyURIs = reader.getAttributeValue(
                PolicyConstants.POLICY_URIs.getNamespaceURI(),
                PolicyConstants.POLICY_URIs.getLocalPart());
        return (null == policyURIs) ? null : policyURIs.split("[\\n ]+");
    
private java.util.ListgetUnresolvedUris(boolean emptyListNeeded)

        if ((null == unresolvedUris) || emptyListNeeded) {
            unresolvedUris = new LinkedList<String>();
        }
        return unresolvedUris;
    
private booleanisPolicyProcessed(java.lang.String policyUri)

    
         
        return modelsNeeded.containsKey(policyUri);
    
public voidmessageAttributes(com.sun.xml.ws.api.model.wsdl.WSDLMessage msg, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        processAttributes(msg, reader, getHandlers4MessageMap());
        LOGGER.exiting();
    
public booleanmessageElements(com.sun.xml.ws.api.model.wsdl.WSDLMessage msg, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        final boolean result = processSubelement(msg, reader, getHandlers4MessageMap());
        LOGGER.exiting();
        return result;
    
private voidpolicyRecToExpandQueue(com.sun.xml.ws.policy.jaxws.PolicyWSDLParserExtension$PolicyRecord policyRec)

        if (null==expandQueueHead) {
            expandQueueHead = policyRec;
        } else {
            expandQueueHead = expandQueueHead.insert(policyRec);
        }
    
public voidportAttributes(com.sun.xml.ws.api.model.wsdl.WSDLPort port, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        processAttributes(port, reader, getHandlers4PortMap());
        LOGGER.exiting();
    
public booleanportElements(com.sun.xml.ws.api.model.wsdl.WSDLPort port, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        final boolean result = processSubelement(port, reader, getHandlers4PortMap());
        LOGGER.exiting();
        return result;
    
public voidportTypeAttributes(com.sun.xml.ws.api.model.wsdl.WSDLPortType portType, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        processAttributes(portType, reader, getHandlers4PortTypeMap());
        LOGGER.exiting();
    
public booleanportTypeElements(com.sun.xml.ws.api.model.wsdl.WSDLPortType portType, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        final boolean result = processSubelement(portType, reader, getHandlers4PortTypeMap());
        LOGGER.exiting();
        return result;
    
public voidportTypeOperationAttributes(com.sun.xml.ws.api.model.wsdl.WSDLOperation operation, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        processAttributes(operation, reader, getHandlers4OperationMap());
        LOGGER.exiting();
    
public booleanportTypeOperationElements(com.sun.xml.ws.api.model.wsdl.WSDLOperation operation, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        final boolean result = processSubelement(operation, reader, getHandlers4OperationMap());
        LOGGER.exiting();
        return result;
    
public voidportTypeOperationFaultAttributes(com.sun.xml.ws.api.model.wsdl.WSDLFault fault, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        processAttributes(fault, reader, getHandlers4FaultMap());
        LOGGER.exiting();
    
public booleanportTypeOperationFaultElements(com.sun.xml.ws.api.model.wsdl.WSDLFault fault, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        final boolean result = processSubelement(fault, reader, getHandlers4FaultMap());
        LOGGER.exiting();
        return result;
    
public voidportTypeOperationInputAttributes(com.sun.xml.ws.api.model.wsdl.WSDLInput input, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        processAttributes(input, reader, getHandlers4InputMap());
        LOGGER.exiting();
    
public booleanportTypeOperationInputElements(com.sun.xml.ws.api.model.wsdl.WSDLInput input, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        final boolean result = processSubelement(input, reader, getHandlers4InputMap());
        LOGGER.exiting();
        return result;
    
public voidportTypeOperationOutputAttributes(com.sun.xml.ws.api.model.wsdl.WSDLOutput output, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        processAttributes(output, reader, getHandlers4OutputMap());
        LOGGER.exiting();
    
public booleanportTypeOperationOutputElements(com.sun.xml.ws.api.model.wsdl.WSDLOutput output, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        final boolean result = processSubelement(output, reader, getHandlers4OutputMap());
        LOGGER.exiting();
        return result;
    
public voidpostFinished(com.sun.xml.ws.api.wsdl.parser.WSDLParserExtensionContext context)

        LOGGER.entering();
        final WSDLPolicyMapWrapper mapWrapper = context.getWSDLModel().getExtension(WSDLPolicyMapWrapper.class);
        if (mapWrapper != null) {
            if (context.isClientSide() && (!isForConfigFile)) {
                try {
                    final PolicyMap clientPolicyMap = PolicyConfigParser.parse(PolicyConstants.CLIENT_CONFIGURATION_IDENTIFIER, null);
                    if (clientPolicyMap != null) {
                        mapWrapper.addClientConfigToMap(PolicyConstants.CLIENT_CONFIGURATION_IDENTIFIER, clientPolicyMap);
                    } else {
                        LOGGER.config(LocalizationMessages.WSP_1040_CLIENT_CONFIG_PROCESSING_SKIPPED());
                    }
                } catch (PolicyException e) {
                    throw LOGGER.logSevereException(new WebServiceException(LocalizationMessages.WSP_1017_ERROR_WHILE_PROCESSING_CLIENT_CONFIG(), e));
                }
                
                LOGGER.fine(LocalizationMessages.WSP_1024_INVOKING_CLIENT_POLICY_ALTERNATIVE_SELECTION());
                try {
                    mapWrapper.doAlternativeSelection();
                } catch (PolicyException e) {
                    throw LOGGER.logSevereException(new WebServiceException(LocalizationMessages.WSP_1003_VALID_POLICY_ALTERNATIVE_NOT_FOUND(), e));
                }
            } else if (!context.isClientSide() && !isForConfigFile) { // not client side and not config file => server side
                try {
                    mapWrapper.validateServerSidePolicies();
                } catch (PolicyException e) {
                    throw LOGGER.logSevereException(new WebServiceException(LocalizationMessages.WSP_1050_SERVER_SIDE_POLICY_VALIDATION_FAILED(), e));
                }
            }
            mapWrapper.configureModel(context.getWSDLModel());
        }
        LOGGER.exiting();
    
private voidprocessAttributes(com.sun.xml.ws.api.model.wsdl.WSDLObject element, javax.xml.stream.XMLStreamReader reader, java.util.Map map)

        final String[] uriArray = getPolicyURIsFromAttr(reader);
        if (null != uriArray) {
            for (String policyUri : uriArray) {
                processReferenceUri(policyUri, element, reader, map);
            }
        }
    
private voidprocessReferenceUri(java.lang.String policyUri, com.sun.xml.ws.api.model.wsdl.WSDLObject element, javax.xml.stream.XMLStreamReader reader, java.util.Map map)

        
        if (null == policyUri) {
            return;
        }
        if ('#" != policyUri.charAt(0)) { // external uri (already)
            getUnresolvedUris(false).add(policyUri);
        }
        
        addHandlerToMap(map, element,
                new PolicyRecordHandler(
                HandlerType.PolicyUri,
                relativeToAbsoluteUrl(policyUri, reader.getLocation().getSystemId())));
    
private booleanprocessSubelement(com.sun.xml.ws.api.model.wsdl.WSDLObject element, javax.xml.stream.XMLStreamReader reader, java.util.Map map)

        if (PolicyConstants.POLICY_REFERENCE.equals(reader.getName())) {     // "PolicyReference" element interests us
            processReferenceUri(readPolicyReferenceElement(reader), element, reader, map);
            return true;
        } else if (PolicyConstants.POLICY.equals(reader.getName())) {   // policy could be defined here
            final PolicyRecordHandler handler =
                    readSinglePolicy(
                    skipPolicyElement(
                    reader,
                    (null == reader.getLocation().getSystemId()) ? // baseUrl
                        "" : reader.getLocation().getSystemId()),
                    true);
            if (null != handler) {           // only policies with an Id can work for us
                addHandlerToMap(map, element, handler);
            } // endif null != handler
            return true; // element consumed
        }//end if Policy element found
        return false;
    
private booleanreadExternalFile(java.lang.String fileUrl)

        InputStream ios = null;
        XMLStreamReader reader = null;
        try {
            final URL xmlURL = new URL(fileUrl);
            ios = xmlURL.openStream();
            reader = XMLInputFactory.newInstance().createXMLStreamReader(ios);
            while (reader.hasNext()) {
                if (reader.isStartElement() && PolicyConstants.POLICY.equals(reader.getName())) {
                    readSinglePolicy(skipPolicyElement(reader, fileUrl), false);
                }
                reader.next();
            }
            return true;
        } catch (IOException ioe) {
            return false;
        } catch (XMLStreamException xmlse) {
            return false;
        } finally {
            PolicyUtils.IO.closeResource(reader);
            PolicyUtils.IO.closeResource(ios);
        }
    
private java.lang.StringreadPolicyReferenceElement(javax.xml.stream.XMLStreamReader reader)
Reads policy reference element and returns referenced policy URI as String

        try {
            if (PolicyConstants.POLICY_REFERENCE.equals(reader.getName())) {     // "PolicyReference" element interests me
                for (int i = 0; i < reader.getAttributeCount(); i++) {
                    if (PolicyConstants.POLICY_URI.getLocalPart().equals(reader.getAttributeName(i).getLocalPart())) {
                        final String uriValue = reader.getAttributeValue(i);
                        reader.next();
                        return uriValue;
                    }
                }
            }
            reader.next();
            return null;
        } catch(XMLStreamException e) {
            throw LOGGER.logSevereException(new WebServiceException(LocalizationMessages.WSP_1001_XML_EXCEPTION_WHEN_PROCESSING_POLICY_REFERENCE(), e));
        }
    
private com.sun.xml.ws.policy.jaxws.PolicyWSDLParserExtension$PolicyRecordHandlerreadSinglePolicy(com.sun.xml.ws.policy.jaxws.PolicyWSDLParserExtension$PolicyRecord policyRec, boolean inner)

        PolicyRecordHandler handler = null;
        String policyId = policyRec.policyModel.getPolicyId();
        if (policyId == null) {
            policyId = policyRec.policyModel.getPolicyName();
        }
        if (policyId != null) {           // policy id defined, keep the policy
            handler = new PolicyRecordHandler(HandlerType.PolicyUri,policyRec.uri);
            getPolicyRecordsPassedBy().put(policyRec.uri, policyRec);
            policyRecToExpandQueue(policyRec);
        } else if (inner) { // no id given to the policy --> keep as an annonymous policy model
            final String anonymousId = AnonymnousPolicyIdPrefix.append(anonymousPoliciesCount++).toString();
            handler = new PolicyRecordHandler(HandlerType.AnonymousPolicyId,anonymousId);
            getAnonymousPolicyModels().put(anonymousId, policyRec.policyModel);
            if (null != policyRec.unresolvedURIs) {
                getUnresolvedUris(false).addAll(policyRec.unresolvedURIs);
            }
        }
        return handler;
    
private java.lang.StringrelativeToAbsoluteUrl(java.lang.String relativeUri, java.lang.String baseUri)

        if ('#" != relativeUri.charAt(0)) {  // TODO: escaped char could be an issue?
            return relativeUri; // absolute already
        }
        return (null == baseUri) ? relativeUri : baseUri + relativeUri;
    
public voidserviceAttributes(com.sun.xml.ws.api.model.wsdl.WSDLService service, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        processAttributes(service, reader, getHandlers4ServiceMap());
        LOGGER.exiting();
    
public booleanserviceElements(com.sun.xml.ws.api.model.wsdl.WSDLService service, javax.xml.stream.XMLStreamReader reader)

        LOGGER.entering();
        final boolean result = processSubelement(service, reader, getHandlers4ServiceMap());
        LOGGER.exiting();
        return result;
    
private com.sun.xml.ws.policy.jaxws.PolicyWSDLParserExtension$PolicyRecordskipPolicyElement(javax.xml.stream.XMLStreamReader reader, java.lang.String baseUrl)
skips current element (should be in START_ELEMENT state) and returns its content as String

        if ((null == reader) || (!reader.isStartElement())) {
            return null;
        }
        final StringBuffer elementCode = new StringBuffer();
        final PolicyRecord policyRec = new PolicyRecord();
        final QName elementName = reader.getName();
        boolean insidePolicyReferenceAttr;
        int depth = 0;
        try{
            do {
                switch (reader.getEventType()) {
                    case XMLStreamConstants.START_ELEMENT:  // process start of next element
                        QName curName = reader.getName();
                        insidePolicyReferenceAttr = PolicyConstants.POLICY_REFERENCE.equals(curName);
                        if (elementName.equals(curName)) {  // it is our element !
                            depth++;                        // we are then deeper
                        }
                        final StringBuffer xmlnsCode = new StringBuffer();    // take care about namespaces as well
                        final Set<String> tmpNsSet = new HashSet<String>();
                        if ((null == curName.getPrefix()) || ("".equals(curName.getPrefix()))) {           // no prefix
                            elementCode
                                    .append('<")                     // start tag
                                    .append(curName.getLocalPart());
                            xmlnsCode
                                    .append(" xmlns=\"")
                                    .append(curName.getNamespaceURI())
                                    .append('"");
                            
                        } else {                                    // prefix presented
                            elementCode
                                    .append('<")                     // start tag
                                    .append(curName.getPrefix())
                                    .append(':")
                                    .append(curName.getLocalPart());
                            xmlnsCode
                                    .append(" xmlns:")
                                    .append(curName.getPrefix())
                                    .append("=\"")
                                    .append(curName.getNamespaceURI())
                                    .append('"");
                            tmpNsSet.add(curName.getPrefix());
                        }
                        final int attrCount = reader.getAttributeCount();     // process element attributes
                        final StringBuffer attrCode = new StringBuffer();
                        for (int i=0; i < attrCount; i++) {
                            boolean uriAttrFlg = false;
                            if (insidePolicyReferenceAttr && "URI".equals(
                                    reader.getAttributeName(i).getLocalPart())) { // PolicyReference found
                                uriAttrFlg = true;
                                if (null == policyRec.unresolvedURIs) { // first such URI found
                                    policyRec.unresolvedURIs = new HashSet<String>(); // initialize URIs set
                                }
                                policyRec.unresolvedURIs.add(  // add the URI
                                        relativeToAbsoluteUrl(reader.getAttributeValue(i), baseUrl));
                            } // end-if PolicyReference attribute found
                            if ("xmlns".equals(reader.getAttributePrefix(i)) && tmpNsSet.contains(reader.getAttributeLocalName(i))) {
                                continue; // do not append already defined ns
                            }
                            if ((null == reader.getAttributePrefix(i)) || ("".equals(reader.getAttributePrefix(i)))) {  // no attribute prefix
                                attrCode
                                        .append(' ")
                                        .append(reader.getAttributeLocalName(i))
                                        .append("=\"")
                                        .append(uriAttrFlg ? relativeToAbsoluteUrl(reader.getAttributeValue(i), baseUrl) : reader.getAttributeValue(i))
                                        .append('"");
                            } else {                                        // prefix`presented
                                attrCode
                                        .append(' ")
                                        .append(reader.getAttributePrefix(i))
                                        .append(':")
                                        .append(reader.getAttributeLocalName(i))
                                        .append("=\"")
                                        .append(uriAttrFlg ? relativeToAbsoluteUrl(reader.getAttributeValue(i), baseUrl) : reader.getAttributeValue(i))
                                        .append('"");
                                if (!tmpNsSet.contains(reader.getAttributePrefix(i))) {
                                    xmlnsCode
                                            .append(" xmlns:")
                                            .append(reader.getAttributePrefix(i))
                                            .append("=\"")
                                            .append(reader.getAttributeNamespace(i))
                                            .append('"");
                                    tmpNsSet.add(reader.getAttributePrefix(i));
                                } // end if prefix already processed
                            }
                        } // end foreach attr
                        elementCode
                                .append(xmlnsCode)          // complete the start element tag
                                .append(attrCode)
                                .append('>");
                        break;
                        //case XMLStreamConstants.ATTRIBUTE:   Unreachable (I hope ;-)
                        //    break;
                        //case XMLStreamConstants.NAMESPACE:   Unreachable (I hope ;-)
                        //    break;
                    case XMLStreamConstants.END_ELEMENT:
                        curName = reader.getName();
                        if (elementName.equals(curName)) {  // it is our element !
                            depth--;                        // go up
                        }
                        elementCode
                                .append("</")                     // append appropriate XML code
                                .append("".equals(curName.getPrefix())?"":curName.getPrefix()+':")
                                .append(curName.getLocalPart())
                                .append('>");                        // complete the end element tag
                        break;
                    case XMLStreamConstants.CHARACTERS:
                        elementCode.append(reader.getText());           // append text data
                        break;
                    case XMLStreamConstants.CDATA:
                        elementCode
                                .append("<![CDATA[")                // append CDATA delimiters
                                .append(reader.getText())
                                .append("]]>");
                        break;
                    case XMLStreamConstants.COMMENT:    // Ignore any comments
                        break;
                    case XMLStreamConstants.SPACE:      // Ignore spaces as well
                        break;
                }
                if (reader.hasNext() && depth>0) {
                    reader.next();
                }
            } while (XMLStreamConstants.END_DOCUMENT!=reader.getEventType() && depth>0);
            policyRec.policyModel = PolicyModelUnmarshaller.getXmlUnmarshaller().unmarshalModel(
                    new StringReader(elementCode.toString()));
            if (null != policyRec.policyModel.getPolicyId()) {
                policyRec.uri = baseUrl + "#" + policyRec.policyModel.getPolicyId();
            } else if (policyRec.policyModel.getPolicyName() != null) {
                policyRec.uri = policyRec.policyModel.getPolicyName();
            }
        } catch(Exception e) {
            throw LOGGER.logSevereException(new WebServiceException(LocalizationMessages.WSP_1033_EXCEPTION_WHEN_READING_POLICY_ELEMENT(elementCode.toString()), e));
        }
        urlsRead.add(baseUrl);
        return policyRec;