Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Table of Contents
maxLevel3
minLevel3

...

styleborder:1
locationtop
typeflat
separatorpipe

...

Info
titleNote

Please follow the documentation on how to create a client-side connection to use the Governance API before following these examples.

Adding a new Service

Assuming that the governanceRegistry variable refers to a valid governanceRegistry object, you can create a new service and and save it using the following code.

Code Block

import org.wso2.carbon.governance.api.services.ServiceManager;
import org.wso2.carbon.governance.api.services.dataobjects.Service;

ServiceManager serviceManager = new ServiceManager(governanceRegistry);
Service service = serviceManager.newService(new QName("http://my.service.ns1", "MyService"));
// you can do the changes to the service instance (like setting/unsettings attributes) in here.
serviceManager.addService(service);

...

After you have made additional changes to the service (after adding attributes), call updateService to update the service.

Code Block

service.addAttribute("Owner", "Financial Department");
serviceManager.updateService(service);

...

In order to remove a service, you should have the reference to the service ID, which can be retrieved from service.getId();

Code Block

String serviceId = service.getId();
serviceManager.removeService(serviceId);

...

Info
titleTip

This method can only be used if you have the reference to the service ID. If you do not have any reference to the service ID, you can use the #discovery methods to retrieve services.

Code Block

Service service = serviceManager.getService(serviceId);

...

  • key - Owner.
  • value - Financial Department.
Code Block

Service[] services = serviceManager.findServices(new ServiceFilter() {
        public boolean matches(Service service) throws GovernanceException {
            String attributeVal = service.getAttribute("Owner");
            ifreturn (attributeVal != null && attributeVal.equals("Financial Department") {
                return true;
            }
            return false);
        }
    });

...

Attaching a WSDL to a Service

...

To attach any Governance artifact, use the attach method which the Service class inherits from the GovernanceArtifact class.

Code Block

service.attach(governanceArtifact);

Or use the Service specific method to attach WSDLs, schemas, policies, and Endpoints.

Code Block

service.attachWsdl(wsdl);
service.attachSchema(schema);
service.attachPolicy(poliyc);
service.attachWndpoint(endpoint);

 

...

Retrieving Dependents and Dependencies

The GovernanceArtifact class has the getDependents() and getDependencies() methods that are inherited by Service, Policy, Schema and Wsdl.

Code Block

GovernanceArtifact[] dependents = service.getDependents();
GovernanceArtifact[] dependencies = service.getDependencies();
Excerpt
hidden-true
hidden-true

Instructions on how to manage services using the Governance API.