FileDocCategorySizeDatePackage
PolicyResourceLoader.javaAPI DocExample7925Tue May 29 16:57:40 BST 2007com.sun.xml.ws.policy.testutils

PolicyResourceLoader

public final class PolicyResourceLoader extends Object
This class provides utility methods to load resources and unmarshall policy source model.
author
Marek Potociar

Fields Summary
public static final String
POLICY_UNIT_TEST_RESOURCE_ROOT
private static final XMLInputFactory
inputFactory
public static final String[]
SINGLE_ALTERNATIVE_POLICY
Constructors Summary
private PolicyResourceLoader()

    
      
    
Methods Summary
public static com.sun.xml.ws.policy.PolicyMapgetPolicyMap(java.lang.String resourceName)

        
        WSDLModel model = getWSDLModel(resourceName, true);
        WSDLPolicyMapWrapper wrapper = model.getExtension(WSDLPolicyMapWrapper.class);
        return wrapper.getPolicyMap();
    
public static com.sun.xml.ws.policy.PolicyMapgetPolicyMap(java.lang.String resourceName, boolean isClient)

        
        WSDLModel model = getWSDLModel(resourceName, isClient);
        WSDLPolicyMapWrapper wrapper = model.getExtension(WSDLPolicyMapWrapper.class);
        return wrapper.getPolicyMap();
    
public static java.io.ReadergetResourceReader(java.lang.String resourceName)

        return new InputStreamReader(getResourceStream(resourceName));
    
public static java.io.InputStreamgetResourceStream(java.lang.String resourceName)

        String fullName = POLICY_UNIT_TEST_RESOURCE_ROOT + resourceName;
        InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream(fullName);
        if (input == null) {
            throw new PolicyException("Failed to find resource \"" + fullName + "\"");
        }
        return input;
    
public static java.net.URLgetResourceUrl(java.lang.String resourceName)

        return Thread.currentThread().getContextClassLoader().getResource(POLICY_UNIT_TEST_RESOURCE_ROOT + resourceName);
    
public static com.sun.xml.stream.buffer.XMLStreamBuffergetResourceXmlBuffer(java.lang.String resourceName)

        try {
            return XMLStreamBuffer.createNewBufferFromXMLStreamReader(inputFactory.createXMLStreamReader(getResourceStream(resourceName)));
        } catch (XMLStreamException ex) {
            throw new PolicyException("Failed to create XMLStreamBuffer", ex);
        }
    
public static com.sun.xml.ws.api.model.wsdl.WSDLModelgetWSDLModel(java.lang.String resourceName)

        return getWSDLModel(resourceName, true);        
    
public static com.sun.xml.ws.api.model.wsdl.WSDLModelgetWSDLModel(java.lang.String resourceName, boolean isClient)

        
        URL resourceUrl = getResourceUrl(resourceName);
        XMLStreamBuffer resourceBuffer = getResourceXmlBuffer(resourceName);
        SDDocumentSource doc = SDDocumentSource.create(resourceUrl, resourceBuffer);
        try {
            Parser parser = new Parser(doc);
            WSDLModel model = WSDLModel.WSDLParser.parse(parser, new PolicyConfigResolver(), isClient, new WSDLParserExtension[] {new PolicyWSDLParserExtension()});
            return model;
        } catch (XMLStreamException ex) {
            throw new PolicyException("Failed to parse document", ex);
        } catch (IOException ex) {
            throw new PolicyException("Failed to parse document", ex);
        } catch (SAXException ex) {
            throw new PolicyException("Failed to parse document", ex);
        }
    
public static com.sun.xml.ws.policy.PolicyloadPolicy(java.lang.String resourceName)

        return translateModel(unmarshallModel(resourceName));
    
public static com.sun.xml.ws.policy.PolicytranslateModel(com.sun.xml.ws.policy.sourcemodel.PolicySourceModel model)

        return PolicyModelTranslator.getTranslator().translate(model);
    
public static com.sun.xml.ws.policy.sourcemodel.PolicySourceModelunmarshallModel(java.lang.String resource)

        Reader resourceReader = getResourceReader(resource);
        PolicySourceModel model = PolicyModelUnmarshaller.getXmlUnmarshaller().unmarshalModel(resourceReader);
        resourceReader.close();
        return model;
    
public static com.sun.xml.ws.policy.sourcemodel.PolicySourceModelunmarshallModel(java.io.Reader resourceReader)

        PolicySourceModel model = PolicyModelUnmarshaller.getXmlUnmarshaller().unmarshalModel(resourceReader);
        resourceReader.close();
        return model;