FileDocCategorySizeDatePackage
PolicyConfigParser.javaAPI DocExample15995Tue May 29 16:56:36 BST 2007com.sun.xml.ws.policy.jaxws

PolicyConfigParser

public final class PolicyConfigParser extends Object
Reads a policy configuration file and returns the WSDL model generated from it.
author
Marek Potociar (marek.potociar at sun.com)

Fields Summary
private static final com.sun.xml.ws.policy.privateutil.PolicyLogger
LOGGER
private static final String
SERVLET_CONTEXT_CLASSNAME
private static final String
JAR_PREFIX
private static final String
WAR_PREFIX
Constructors Summary
Methods Summary
public static com.sun.xml.ws.policy.PolicyMapextractPolicyMap(com.sun.xml.ws.api.model.wsdl.WSDLModel model)
Utility method that tries to retrieve a {@link PolicyMap} object from a given {@link WSDLModel}. When succesfull, {@link PolicyMap} instance is returned, otherwise result is {@code null}.

param
model A {@link WSDLModel} (possibly) with a {@link PolicyMap} object populated with information read from the WSIT config file. May be {@code null}; in that case, {@code null} is returned as a result of this function call.
return
{@link PolicyMap} instance retrieved from a given {@link WSDLModel} if successful, {@code null} otherwise.

        LOGGER.entering(model);
        PolicyMap result = null;
        try {
            if (model != null) {
                final WSDLPolicyMapWrapper wrapper = model.getExtension(WSDLPolicyMapWrapper.class);
                
                if (wrapper != null) {
                    result = wrapper.getPolicyMap();
                }
            }
            return result;
        } finally {
            LOGGER.exiting(result);
        }
    
public static com.sun.xml.ws.policy.PolicyMapparse(java.lang.String configFileIdentifier, com.sun.xml.ws.api.server.Container container, com.sun.xml.ws.policy.PolicyMapMutator mutators)
This is a helper method that returns directly {@link PolicyMap} instance populated from information in WSIT config file. For more details on the whole process see {@link #parseModel(String, Container, PolicyMapMutator[]) parseModel} method.

param
configFileIdentifier base of WSIT config file name (web service name for WSIT service config file or "client" for WSIT client configuration). Must not be {@code null}.
param
container if the application is run inside a web container, the container instance should be passed into this function, in order to get access to the servlet context that is used to load config file stored in {@code WEB-INF} directory of the application. May be {@code null}.
param
mutators to be registered with the populated {@link PolicyMap} object. May be ommited if user does not plan to modify the {@link PolicyMap} instance.
return
A {@link WSDLModel} with a {@link PolicyMap} object populated with information read from the WSIT config file.
throws
PolicyException in case of any problems that may occur while reading WSIT config file and constructing the {@link WSDLModel} object or populating {@link PolicyMap} instance.

    
                                                                                                                                                                                                                                           
                   
        LOGGER.entering(configFileIdentifier, container, mutators);
        PolicyMap map = null;
        try {
            return map = extractPolicyMap(parseModel(configFileIdentifier, container, mutators));
        } finally {
            LOGGER.exiting(map);
        }
    
public static com.sun.xml.ws.policy.PolicyMapparse(java.net.URL configFileUrl, boolean isClient, com.sun.xml.ws.policy.PolicyMapMutator mutators)
This is a helper method that returns directly {@link PolicyMap} instance populated from information in WSIT config file. For more details on the whole process see {@link #parseModel(URL, boolean, PolicyMapMutator[]) parseModel} method.

param
configFileUrl {@link URL} of the config file resource that should be parsed. Must not be {@code null}.
param
isClient must be {@code true} if this method is invoked to parse client configuration, {@code false} otherwise
param
mutators to be registered with the populated {@link PolicyMap} object. May be ommited if user does not plan to modify the {@link PolicyMap} instance.
return
A {@link WSDLModel} with a {@link PolicyMap} object populated with information read from the WSIT config file.
throws
PolicyException in case of any problems that may occur while reading WSIT config file and constructing the {@link WSDLModel} object or populating {@link PolicyMap} instance.
throws
IllegalArgumentException in case {@code configFileUrl} parameter is {@code null}.

        LOGGER.entering(configFileUrl, isClient, mutators);
        PolicyMap map = null;
        try {
            return map = extractPolicyMap(parseModel(configFileUrl, isClient, mutators));
        } finally {
            LOGGER.exiting(map);
        }
    
public static com.sun.xml.ws.api.model.wsdl.WSDLModelparseModel(java.lang.String configFileIdentifier, com.sun.xml.ws.api.server.Container container, com.sun.xml.ws.policy.PolicyMapMutator mutators)
The function uses {@code configFileIdentifier} parameter to construct a WSIT config file name according to following pattern:

wsit-[configFileIdentifier].xml

After constructing the WSIT config file name, the function tries to find the WSIT config file and read it from the following locations:

  • {@code WEB-INF} - for servlet-based web service implementations
  • {@code META-INF} - for EJB-based web service implementations
  • {@code classpath} - for web service clients
If the file is found it is parsed and resulting {@link WSDLModel} object containig the populated {@link PolicyMap} instance is returned. If config file is not found, warning message is logged and {@code null} is returned as a result of this function call. In case of any other problems that may occur while reading the WSIT config file, a {@link PolicyException} is thrown.

Since {@link PolicyMap} object is immutable as such, this function gives you also a chance to register your own {@link PolicyMapMutator} objects so that you are able to modify the {@link PolicyMap} object later if needed.

param
configFileIdentifier base of WSIT config file name (web service name for WSIT service config file or "client" for WSIT client configuration). Must not be {@code null}.
param
container if the application is run inside a web container, the container instance should be passed into this function, in order to get access to the servlet context that is used to load config file stored in {@code WEB-INF} directory of the application. May be {@code null}.
param
mutators to be registered with the populated {@link PolicyMap} object. May be ommited if user does not plan to modify the {@link PolicyMap} instance.
return
A {@link WSDLModel} with a {@link PolicyMap} object populated with information read from the WSIT config file.
throws
PolicyException in case of any problems that may occur while reading WSIT config file and constructing the {@link WSDLModel} object or populating {@link PolicyMap} instance.

        LOGGER.entering(configFileIdentifier, container, mutators);
        WSDLModel model = null;
        try {
            final String configFileName = PolicyUtils.ConfigFile.generateFullName(configFileIdentifier);
            LOGGER.finest(LocalizationMessages.WSP_1037_CONFIG_FILE_IS(configFileName));
            
            Object context = null;
            if (container != null) {
                try {
                    final Class<?> contextClass = Class.forName(SERVLET_CONTEXT_CLASSNAME);
                    context = container.getSPI(contextClass);
                } catch (ClassNotFoundException e) {
                    LOGGER.fine(LocalizationMessages.WSP_1043_CAN_NOT_FIND_CLASS(SERVLET_CONTEXT_CLASSNAME));
                }
                LOGGER.finest(LocalizationMessages.WSP_1036_CONTEXT_IS(context));
                
            }
            
            URL configFileUrl = null;
            final boolean isClientConfig = PolicyConstants.CLIENT_CONFIGURATION_IDENTIFIER.equals(configFileIdentifier);
            String examinedPath;
            if (context == null || isClientConfig) {
                examinedPath = JAR_PREFIX + configFileName;
                configFileUrl = PolicyUtils.ConfigFile.loadFromClasspath(examinedPath);
                if (configFileUrl == null && isClientConfig) {
                    examinedPath = examinedPath + File.pathSeparator + " " + configFileName;
                    configFileUrl = PolicyUtils.ConfigFile.loadFromClasspath(configFileName);
                }
            } else {
                examinedPath = WAR_PREFIX + configFileName;
                configFileUrl = PolicyUtils.ConfigFile.loadFromContext(examinedPath, context);
            }
            
            if (configFileUrl == null) {
                LOGGER.config(LocalizationMessages.WSP_1035_COULD_NOT_LOCATE_WSIT_CFG_FILE(configFileIdentifier, examinedPath));
            } else {
                model = parseModel(configFileUrl, isClientConfig, mutators);
                LOGGER.info(LocalizationMessages.WSP_1049_LOADED_WSIT_CFG_FILE(configFileUrl.toExternalForm()));
            }
            
            return model;
        } finally {
            LOGGER.exiting(model);
        }
    
public static com.sun.xml.ws.api.model.wsdl.WSDLModelparseModel(java.net.URL configFileUrl, boolean isClient, com.sun.xml.ws.policy.PolicyMapMutator mutators)
Reads the WSIT config from a file denoted by {@code configFileUrl} parameter. If the file exists it is parsed and resulting {@link WSDLModel} object containig the populated {@link PolicyMap} instance is returned. If config file for given {@link URL} does not exist or in case of any other problems that may occur while reading the WSIT config file, a {@link PolicyException} is thrown.

param
configFileUrl {@link URL} of the config file resource that should be parsed. Must not be {@code null}.
param
isClient must be {@code true} if this method is invoked to parse client configuration, {@code false} otherwise
param
mutators to be registered with the populated {@link PolicyMap} object. May be ommited if user does not plan to modify the {@link PolicyMap} instance.
return
A {@link WSDLModel} with a {@link PolicyMap} object populated with information read from the WSIT config file.
throws
PolicyException in case of any problems that may occur while reading WSIT config file and constructing the {@link WSDLModel} object or populating {@link PolicyMap} instance.
throws
IllegalArgumentException in case {@code configFileUrl} parameter is {@code null}.

        LOGGER.entering(configFileUrl, isClient, mutators);
        WSDLModel model = null;
        try {
            if (null == configFileUrl) {
                throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_1028_FAILED_TO_READ_NULL_WSIT_CFG()));
            }
            
            final SDDocumentSource doc = SDDocumentSource.create(configFileUrl);
            final XMLEntityResolver.Parser parser =  new XMLEntityResolver.Parser(doc);
            model = WSDLModel.WSDLParser.parse(
                    parser,
                    new PolicyConfigResolver(),
                    isClient,
                    new WSDLParserExtension[] { new PolicyWSDLParserExtension(true, mutators) }
            );
            
            return model;
        } catch (XMLStreamException ex) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_1002_WSIT_CFG_FILE_PROCESSING_FAILED(configFileUrl.toString()), ex));
        } catch (IOException ex) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_1002_WSIT_CFG_FILE_PROCESSING_FAILED(configFileUrl.toString()), ex));
        } catch (SAXException ex) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_1002_WSIT_CFG_FILE_PROCESSING_FAILED(configFileUrl.toString()), ex));
        } finally {
            LOGGER.exiting(model);
        }