Example usage for javax.xml.registry BusinessLifeCycleManager saveClassificationSchemes

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

Introduction

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

Prototype

BulkResponse saveClassificationSchemes(Collection schemes) throws JAXRException;

Source Link

Document

Saves the specified ClassificationScheme instances.

Usage

From source file:JAXRSaveClassificationScheme.java

/**
     * Creates a classification scheme and saves it to the
     * registry.// www.  jav a 2s .co  m
     *
     * @param username  the username for the registry
     * @param password  the password for the registry
     */
    public void executePublish(String username, String password) {
        RegistryService rs = null;
        BusinessLifeCycleManager blcm = null;
        BusinessQueryManager bqm = null;

        try {
            rs = connection.getRegistryService();
            blcm = rs.getBusinessLifeCycleManager();
            bqm = rs.getBusinessQueryManager();
            System.out.println("Got registry service, query " + "manager, and life cycle 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");

            ResourceBundle bundle = ResourceBundle.getBundle("JAXRExamples");

            // Create classification scheme
            InternationalString sn = blcm.createInternationalString(bundle.getString("postal.scheme.name"));
            InternationalString sd = blcm.createInternationalString(bundle.getString("postal.scheme.description"));
            ClassificationScheme postalScheme = blcm.createClassificationScheme(sn, sd);

            /*
             * Find the uddi-org:types classification scheme defined
             * by the UDDI specification, using well-known key id.
             */
            String uuid_types = "uuid:C1ACF26D-9672-4404-9D70-39B756E62AB4";
            ClassificationScheme uddiOrgTypes = (ClassificationScheme) bqm.getRegistryObject(uuid_types,
                    LifeCycleManager.CLASSIFICATION_SCHEME);

            if (uddiOrgTypes != null) {
                InternationalString cn = blcm
                        .createInternationalString(bundle.getString("postal.classification.name"));
                Classification classification = blcm.createClassification(uddiOrgTypes, cn,
                        bundle.getString("postal.classification.value"));

                postalScheme.addClassification(classification);

                /*
                 * Set link to location of postal scheme (fictitious)
                 * so others can look it up. If the URI were valid, we
                 * could use the createExternalLink method.
                 */
                ExternalLink externalLink = (ExternalLink) blcm.createObject(LifeCycleManager.EXTERNAL_LINK);
                externalLink.setValidateURI(false);
                externalLink.setExternalURI(bundle.getString("postal.scheme.link"));

                InternationalString is = blcm.createInternationalString(bundle.getString("postal.scheme.linkdesc"));
                externalLink.setDescription(is);
                postalScheme.addExternalLink(externalLink);

                // Add scheme and save it to registry
                // Retrieve key if successful
                Collection<ClassificationScheme> schemes = new ArrayList<ClassificationScheme>();
                schemes.add(postalScheme);

                BulkResponse br = blcm.saveClassificationSchemes(schemes);

                if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
                    System.out.println("Saved PostalAddress " + "ClassificationScheme");

                    Collection schemeKeys = br.getCollection();

                    for (Object k : schemeKeys) {
                        Key key = (Key) k;
                        System.out.println("The postalScheme key is " + key.getId());
                        System.out.println(
                                "Use this key as the scheme uuid " + "in the postalconcepts.xml file\n  and as the "
                                        + "argument to JAXRPublishPostal and " + "JAXRQueryPostal");
                    }
                } else {
                    Collection exceptions = br.getExceptions();

                    for (Object e : exceptions) {
                        Exception exception = (Exception) e;
                        System.err.println("Exception on save: " + exception.toString());
                    }
                }
            } else {
                System.out.println("uddi-org:types not found. Unable to " + "save PostalAddress scheme.");
            }
        } catch (JAXRException jaxe) {
            jaxe.printStackTrace();
        } finally {
            // At end, close connection to registry
            if (connection != null) {
                try {
                    connection.close();
                } catch (JAXRException je) {
                }
            }
        }
    }