Example usage for javax.xml.registry BusinessLifeCycleManager deleteOrganizations

List of usage examples for javax.xml.registry BusinessLifeCycleManager deleteOrganizations

Introduction

In this page you can find the example usage for javax.xml.registry BusinessLifeCycleManager deleteOrganizations.

Prototype

BulkResponse deleteOrganizations(Collection organizationKeys) throws JAXRException;

Source Link

Document

Deletes the organizations corresponding to the specified Keys.

Usage

From source file:JAXRDelete.java

/**
     * Removes the organization with the specified key value.
     */* ww w.j  av a 2 s. c om*/
     * @param key        the Key of the organization
     * @param username  the username for the registry
     * @param password  the password for the registry
     */
    public void executeRemove(Key key, String username, String password) {
        BusinessLifeCycleManager blcm = null;

        try {
            blcm = rs.getBusinessLifeCycleManager();

            // Get authorization from the registry
            PasswordAuthentication passwdAuth = new PasswordAuthentication(username, password.toCharArray());

            HashSet<PasswordAuthentication> creds = new HashSet<PasswordAuthentication>();
            creds.add(passwdAuth);
            connection.setCredentials(creds);
            System.out.println("Established security credentials");

            String id = key.getId();
            System.out.println("Deleting organization with id " + id);

            Collection<Key> keys = new ArrayList<Key>();
            keys.add(key);

            BulkResponse response = blcm.deleteOrganizations(keys);
            Collection exceptions = response.getExceptions();

            if (exceptions == null) {
                System.out.println("Organization deleted");

                Collection retKeys = response.getCollection();

                for (Object k : retKeys) {
                    Key orgKey = (Key) k;
                    id = orgKey.getId();
                    System.out.println("Organization key was " + id);
                }
            } else {
                for (Object e : exceptions) {
                    Exception exception = (Exception) e;
                    System.err.println("Exception on delete: " + exception.toString());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // At end, close connection to registry
            if (connection != null) {
                try {
                    connection.close();
                } catch (JAXRException je) {
                }
            }
        }
    }