Example usage for javax.xml.registry BusinessQueryManager getRegistryObjects

List of usage examples for javax.xml.registry BusinessQueryManager getRegistryObjects

Introduction

In this page you can find the example usage for javax.xml.registry BusinessQueryManager getRegistryObjects.

Prototype

public BulkResponse getRegistryObjects() throws JAXRException;

Source Link

Document

Gets the RegistryObjects owned by the caller.

Usage

From source file:JAXRGetMyObjects.java

/**
     * Searches for objects owned by the user and
     * displays data about them.// w w w .  ja va 2s. c  om
     *
     * @param username  the username for the registry
     * @param password  the password for the registry
     */
    public void executeQuery(String username, String password) {
        RegistryService rs = null;
        BusinessQueryManager bqm = null;

        try {
            // Get registry service and query manager
            rs = connection.getRegistryService();
            bqm = rs.getBusinessQueryManager();
            System.out.println("Got registry service and " + "query manager");

            // 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");

            // Get all objects owned by me
            BulkResponse response = bqm.getRegistryObjects();
            Collection objects = response.getCollection();

            // Display information on the objects found
            if (objects.isEmpty()) {
                System.out.println("No objects found");
            } else {
                for (Object o : objects) {
                    RegistryObject obj = (RegistryObject) o;
                    System.out.println("Object key id: " + getKey(obj));
                    System.out.println("Object name is: " + getName(obj));
                    System.out.println("Object description is: " + getDescription(obj));

                    // Print spacer between objects
                    System.out.println(" --- ");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // At end, close connection to registry
            if (connection != null) {
                try {
                    connection.close();
                } catch (JAXRException je) {
                }
            }
        }
    }