WS METADATA

Contents


Accessing WS Metadata

This is a recommended way to access WS Metadata:

FileObject fo = ...; // this is a file object from some project (even project directory is possible)
JAXWSSupport support = JAXWSSupport.getJAXWSSupport(fo);
MetadataModel<WebservicesMetadata> wsModel = support.getWebservicesMetadataModel();
if (wsModel!=null) {
    try {
        List<WS> wsList = wsModel.runReadAction(new MetadataModelAction<WebservicesMetadata, List<WS>>() {
            public List<WS> run(WebservicesMetadata metadata) {
                List<WS> result = new ArrayList<WS>();
                Webservices webServices = metadata.getRoot();
                for (WebserviceDescription wsDesc:webServices.getWebserviceDescription()) {
                    WS ws = new WS();
                    ws.setName(wsDesc.getWebserviceDescriptionName());
                    ws.setWsdlFile(wsDesc.getWsdlFile());
                    result.add(ws);
                }
                return result;
            }
        });
        // do whatever you want with wsList      
                  
    } catch (java.io.IOException ex) { ... }
}

private class WS {
    private String name;
    private String wsdlFile;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getWsdlFile() {
        return wsdlFile;
    }

    public void setWsdlFile(String wsdlFile) {
        this.wsdlFile = wsdlFile;
    }
}

Wrong Practices

DO NOT DO THIS!

FileObject fo = ...; // this is a file object from some project (even project directory is possible)
JAXWSSupport support = JAXWSSupport.getJAXWSSupport(implClassFo);
MetadataModel<WebservicesMetadata> wsModel = support.getWebservicesMetadataModel();
if (wsModel!=null) {
    try {
        List<WebserviceDescription> wsList = wsModel.runReadAction(new MetadataModelAction<WebservicesMetadata, List<WebserviceDescription>>() {
            public List<WebserviceDescription> run(WebservicesMetadata metadata) {
                List<WebserviceDescription> result = new ArrayList<WebserviceDescription>();
                Webservices webServices = metadata.getRoot();
                for (WebserviceDescription wsDesc:webServices.getWebserviceDescription()) {
                    result.add(wsDesc);
                }
                return result;
            }
        });
        // do whatever you want with wsList      
                  
    } catch (java.io.IOException ex) { ... }
}

Clients should not hold objects returned from the model outside read access -- similar to the javac API Element's. In the example above, the instances of WebserviceDescription themeselves are not allowed to escape the run() method, thus the following code is incorrect and will cause random bugs at runtime.


See also this document : Java EE metadata model user's guide

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo