Example usage for javax.xml.registry RegistryService getBusinessQueryManager

List of usage examples for javax.xml.registry RegistryService getBusinessQueryManager

Introduction

In this page you can find the example usage for javax.xml.registry RegistryService getBusinessQueryManager.

Prototype

BusinessQueryManager getBusinessQueryManager() throws JAXRException;

Source Link

Document

Returns the BusinessQueryManager object implemented by the JAXR provider.

Usage

From source file:it.cnr.icar.eric.client.ui.swing.JAXRClient.java

/**
 * Makes a connection to a JAXR Registry.
 *
 * @param url The URL of the registry./*from   w  ww. j  a  v  a  2  s. c  o m*/
 * @return boolean true if connected, false otherwise.
 */
public synchronized boolean createConnection(String url) {
    try {
        if (!RegistryBrowser.localCall) {
            (new URL(url)).openStream().read();
        }

        Thread.currentThread().setContextClassLoader(RegistryBrowser.getInstance().classLoader);

        ProviderProperties.getInstance().put("javax.xml.registry.queryManagerURL", url);

        ConnectionFactory connFactory = JAXRUtility.getConnectionFactory();

        connection = (it.cnr.icar.eric.client.xml.registry.ConnectionImpl) connFactory.createConnection();
        RegistryService service = connection.getRegistryService();
        bqm = service.getBusinessQueryManager();
        dqm = (it.cnr.icar.eric.client.xml.registry.DeclarativeQueryManagerImpl) service
                .getDeclarativeQueryManager();
        lcm = (it.cnr.icar.eric.client.xml.registry.BusinessLifeCycleManagerImpl) service
                .getBusinessLifeCycleManager();

        lmm = connection.getLoginModuleManager();
        lmm.setParentFrame(RegistryBrowser.getInstance());
        connected = true;
    } catch (final JAXRException e) {
        connected = false;
        String msg = JavaUIResourceBundle.getInstance().getString("message.error.failedConnecting",
                new String[] { url, e.getLocalizedMessage() });
        log.error(msg, e);
        RegistryBrowser.displayError(msg, e);
    } catch (MalformedURLException e) {
        connected = false;
        String msg = JavaUIResourceBundle.getInstance().getString("message.error.failedConnecting",
                new String[] { url, e.getLocalizedMessage() });
        log.error(msg, e);
        RegistryBrowser.displayError(msg, e);
    } catch (IOException e) {
        connected = false;
        String msg = JavaUIResourceBundle.getInstance().getString("message.error.failedConnecting",
                new String[] { url, e.getLocalizedMessage() });
        log.error(msg, e);
        RegistryBrowser.displayError(msg, e);
    }
    return connected;
}

From source file:JAXRGetMyObjects.java

/**
     * Searches for objects owned by the user and
     * displays data about them./*from  w w  w  .  j ava  2  s .  co m*/
     *
     * @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) {
                }
            }
        }
    }

From source file:JAXRQuery.java

/**
     * Searches for organizations containing a string and
     * displays data about them.//from   w w w .  j a  va2  s.  co m
     *
     * @param qString        the string argument
     */
    public void executeQuery(String qString) {
        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");

            // Define find qualifiers and name patterns
            Collection<String> findQualifiers = new ArrayList<String>();
            findQualifiers.add(SORT_BY_NAME_DESC);

            Collection<String> namePatterns = new ArrayList<String>();
            namePatterns.add("%" + qString + "%");

            // Find orgs with names that contain qString
            BulkResponse response = bqm.findOrganizations(findQualifiers, namePatterns, null, null, null, null);
            Collection orgs = response.getCollection();

            // Display information about the organizations found
            int numOrgs = 0;

            if (orgs.isEmpty()) {
                System.out.println("No organizations found");
            } else {
                for (Object o : orgs) {
                    numOrgs++;

                    Organization org = (Organization) o;
                    System.out.println("Org name: " + getName(org));
                    System.out.println("Org description: " + getDescription(org));
                    System.out.println("Org key id: " + getKey(org));

                    // Display primary contact information
                    User pc = org.getPrimaryContact();

                    if (pc != null) {
                        PersonName pcName = pc.getPersonName();
                        System.out.println(" Contact name: " + pcName.getFullName());

                        Collection phNums = pc.getTelephoneNumbers(null);

                        for (Object n : phNums) {
                            TelephoneNumber num = (TelephoneNumber) n;
                            System.out.println("  Phone number: " + num.getNumber());
                        }

                        Collection eAddrs = pc.getEmailAddresses();

                        for (Object a : eAddrs) {
                            EmailAddress eAd = (EmailAddress) a;
                            System.out.println("  Email address: " + eAd.getAddress());
                        }
                    }

                    // Display service and binding information
                    Collection services = org.getServices();

                    for (Object s : services) {
                        Service svc = (Service) s;
                        System.out.println(" Service name: " + getName(svc));
                        System.out.println(" Service description: " + getDescription(svc));

                        Collection serviceBindings = svc.getServiceBindings();

                        for (Object b : serviceBindings) {
                            ServiceBinding sb = (ServiceBinding) b;
                            System.out.println("  Binding description: " + getDescription(sb));
                            System.out.println("  Access URI: " + sb.getAccessURI());
                        }
                    }

                    // Print spacer between organizations
                    System.out.println(" --- ");
                }
            }

            System.out.println("Found " + numOrgs + " organization(s)");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // At end, close connection to registry
            if (connection != null) {
                try {
                    connection.close();
                } catch (JAXRException je) {
                }
            }
        }
    }

From source file:JAXRSaveClassificationScheme.java

/**
     * Creates a classification scheme and saves it to the
     * registry./*from   w  ww.  j  a va 2 s.  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) {
                }
            }
        }
    }

From source file:JAXRQueryByNAICSClassification.java

/**
     * Searches for organizations corresponding to an NAICS
     * classification and displays data about them.
     *//*from   w  w w .j ava2 s  .co m*/
    public void executeQuery() {
        RegistryService rs = null;
        BusinessQueryManager bqm = null;
        BusinessLifeCycleManager blcm = null;

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

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

            // Find using an NAICS classification
            // Set classification scheme to NAICS, using
            // well-known UUID of ntis-gov:naics:1997
            String uuid_naics = "uuid:C0B9FE13-179F-413D-8A5B-5004DB8E5BB2";
            ClassificationScheme cScheme = (ClassificationScheme) bqm.getRegistryObject(uuid_naics,
                    LifeCycleManager.CLASSIFICATION_SCHEME);

            Collection<Classification> classifications = new ArrayList<Classification>();

            if (cScheme != null) {
                // Create and add classification
                InternationalString sn = blcm.createInternationalString(bundle.getString("classification.name"));
                Classification classification = blcm.createClassification(cScheme, sn,
                        bundle.getString("classification.value"));
                classifications.add(classification);
            } else {
                System.out.println("Classification scheme not found");
            }

            BulkResponse response = bqm.findOrganizations(null, null, classifications, null, null, null);
            Collection orgs = response.getCollection();

            // Display information about the organizations found
            int numOrgs = 0;

            if (orgs.isEmpty()) {
                System.out.println("No organizations found");
            } else {
                for (Object o : orgs) {
                    numOrgs++;

                    Organization org = (Organization) o;
                    System.out.println("Org name: " + getName(org));
                    System.out.println("Org description: " + getDescription(org));
                    System.out.println("Org key id: " + getKey(org));

                    // Display primary contact information
                    User pc = org.getPrimaryContact();

                    if (pc != null) {
                        PersonName pcName = pc.getPersonName();
                        System.out.println(" Contact name: " + pcName.getFullName());

                        Collection phNums = pc.getTelephoneNumbers(null);

                        for (Object n : phNums) {
                            TelephoneNumber num = (TelephoneNumber) n;
                            System.out.println("  Phone number: " + num.getNumber());
                        }

                        Collection eAddrs = pc.getEmailAddresses();

                        for (Object a : eAddrs) {
                            EmailAddress eAd = (EmailAddress) a;
                            System.out.println("  Email Address: " + eAd.getAddress());
                        }
                    }

                    // Display classifications
                    Collection classList = org.getClassifications();

                    for (Object cl : classList) {
                        Classification c = (Classification) cl;
                        System.out.println(" Classification name: " + getName(c));
                        System.out.println(" Classification value: " + c.getValue());

                        ClassificationScheme sch = c.getClassificationScheme();
                        System.out.println(" Classification scheme key: " + getKey(sch));
                    }

                    // Print spacer between organizations
                    System.out.println(" --- ");
                }
            }

            System.out.println("Found " + numOrgs + " organization(s)");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // At end, close connection to registry
            if (connection != null) {
                try {
                    connection.close();
                } catch (JAXRException je) {
                }
            }
        }
    }

From source file:JAXRQueryPostal.java

/**
     * Searches for organizations containing a string and
     * displays data about them, including the postal address in
     * either the JAXR PostalAddress format or the Slot format.
     */*w w  w  .j av  a  2  s  . c  o  m*/
     * @param qString        the string argument
     */
    public void executeQuery(String qString) {
        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");

            // Define find qualifiers and name patterns
            Collection<String> findQualifiers = new ArrayList<String>();
            findQualifiers.add(SORT_BY_NAME_DESC);

            Collection<String> namePatterns = new ArrayList<String>();
            namePatterns.add("%" + qString + "%");

            // Find using the name
            BulkResponse response = bqm.findOrganizations(findQualifiers, namePatterns, null, null, null, null);
            Collection orgs = response.getCollection();

            // Display information about the organizations found
            for (Object o : orgs) {
                Organization org = (Organization) o;
                System.out.println("Org name: " + getName(org));
                System.out.println("Org description: " + getDescription(org));
                System.out.println("Org key id: " + getKey(org));

                // Display primary contact information
                User pc = org.getPrimaryContact();

                if (pc != null) {
                    PersonName pcName = pc.getPersonName();
                    System.out.println(" Contact name: " + pcName.getFullName());

                    Collection phNums = pc.getTelephoneNumbers(null);

                    for (Object n : phNums) {
                        TelephoneNumber num = (TelephoneNumber) n;
                        System.out.println("  Phone number: " + num.getNumber());
                    }

                    Collection eAddrs = pc.getEmailAddresses();

                    for (Object a : eAddrs) {
                        EmailAddress eAd = (EmailAddress) a;
                        System.out.println("  Email Address: " + eAd.getAddress());
                    }

                    // Display postal addresses 
                    //   using PostalAddress methods
                    Collection pAddrs = pc.getPostalAddresses();

                    for (Object pa : pAddrs) {
                        PostalAddress pAd = (PostalAddress) pa;
                        System.out.println("  Postal Address (PostalAddress methods):\n    " + pAd.getStreetNumber()
                                + " " + pAd.getStreet() + "\n    " + pAd.getCity() + ", " + pAd.getStateOrProvince()
                                + " " + pAd.getPostalCode() + "\n    " + pAd.getCountry());
                    }

                    // Display postal addresses 
                    //   using Slot methods
                    Collection pAddrs2 = pc.getPostalAddresses();

                    for (Object pa2 : pAddrs2) {
                        PostalAddress pAd = (PostalAddress) pa2;
                        Collection slots = pAd.getSlots();
                        System.out.println("  Postal Address (Slot methods):");

                        for (Object s : slots) {
                            Slot slot = (Slot) s;
                            Collection values = slot.getValues();

                            for (Object v : values) {
                                String line = (String) v;
                                System.out.println("    Line: " + line);
                            }
                        }
                    }
                }

                // Display service and binding information
                Collection services = org.getServices();

                for (Object s : services) {
                    Service svc = (Service) s;
                    System.out.println(" Service name: " + getName(svc));
                    System.out.println(" Service description: " + getDescription(svc));

                    Collection serviceBindings = svc.getServiceBindings();

                    for (Object b : serviceBindings) {
                        ServiceBinding sb = (ServiceBinding) b;
                        System.out.println("  Binding " + "Description: " + getDescription(sb));
                        System.out.println("  Access URI: " + sb.getAccessURI());
                    }
                }

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

From source file:JAXRQueryByWSDLClassification.java

/**
     * Searches for organizations using a WSDL
     * classification and displays data about them.
     */*  w w  w. j  a  va2  s  .c  o m*/
     * @param qString        the string argument
     */
    public void executeQuery(String qString) {
        RegistryService rs = null;
        BusinessQueryManager bqm = null;
        BusinessLifeCycleManager blcm = null;

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

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

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

            // Define name pattern
            Collection<String> namePatterns = new ArrayList<String>();
            namePatterns.add("%" + qString + "%");

            /*
             * Create a classification, specifying the scheme
             *  and the taxonomy name and value defined for WSDL
             *  documents by the UDDI specification.
             */
            Classification wsdlSpecClassification = blcm.createClassification(uddiOrgTypes,
                    blcm.createInternationalString("wsdlSpec"), "wsdlSpec");

            Collection<Classification> classifications = new ArrayList<Classification>();
            classifications.add(wsdlSpecClassification);

            // Find concepts
            BulkResponse br = bqm.findConcepts(null, namePatterns, classifications, null, null);
            Collection specConcepts = br.getCollection();

            // Display information about the concepts found
            int numConcepts = 0;

            if (specConcepts.isEmpty()) {
                System.out.println("No WSDL specification concepts found");
            } else {
                for (Object sc : specConcepts) {
                    numConcepts++;

                    Concept concept = (Concept) sc;

                    String name = getName(concept);

                    Collection links = concept.getExternalLinks();

                    System.out.println("\nSpecification Concept:\n\tName: " + name + "\n\tKey: " + getKey(concept)
                            + "\n\tDescription: " + getDescription(concept));

                    if (links.size() > 0) {
                        ExternalLink link = (ExternalLink) links.iterator().next();
                        System.out.println("\tURL of WSDL document: '" + link.getExternalURI() + "'");
                    }

                    // Find organizations that use this concept
                    Collection<Concept> specConcepts1 = new ArrayList<Concept>();
                    specConcepts1.add(concept);

                    br = bqm.findOrganizations(null, null, null, specConcepts1, null, null);

                    Collection orgs = br.getCollection();

                    // Display information about organizations
                    if (!(orgs.isEmpty())) {
                        System.out.println("Organizations using the '" + name + "' WSDL Specification:");
                    } else {
                        System.out.println("No Organizations using the '" + name + "' WSDL Specification");
                    }

                    for (Object o : orgs) {
                        Organization org = (Organization) o;
                        System.out.println("\tName: " + getName(org) + "\n\tKey: " + getKey(org)
                                + "\n\tDescription: " + getDescription(org));
                    }
                }
            }

            System.out.println("Found " + numConcepts + " concepts");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // At end, close connection to registry
            if (connection != null) {
                try {
                    connection.close();
                } catch (JAXRException je) {
                }
            }
        }
    }

From source file:JAXRPublishConcept.java

/**
     * Creates a concept and saves it to the registry.
     *// w ww  .j  a  va 2 s .c o  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;
        ResourceBundle bundle = ResourceBundle.getBundle("JAXRExamples");

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

            InternationalString s = blcm.createInternationalString(bundle.getString("concept.name"));
            Concept specConcept = blcm.createConcept(null, s, "");
            s = blcm.createInternationalString(bundle.getString("concept.description"));
            specConcept.setDescription(s);

            s = blcm.createInternationalString(bundle.getString("link.description"));

            ExternalLink wsdlLink = blcm.createExternalLink(bundle.getString("link.uri"), s);
            specConcept.addExternalLink(wsdlLink);

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

            /*
             * Create a classification, specifying the scheme
             *  and the taxonomy name and value defined for WSDL
             *  documents by the UDDI specification. Add to
             *  concept.
             */
            Classification wsdlSpecClassification = blcm.createClassification(uddiOrgTypes,
                    blcm.createInternationalString("wsdlSpec"), "wsdlSpec");
            specConcept.addClassification(wsdlSpecClassification);

            // Save the concept and retrieve the key.
            Collection<Concept> concepts = new ArrayList<Concept>();
            concepts.add(specConcept);

            BulkResponse response = blcm.saveConcepts(concepts);
            Collection exceptions = response.getExceptions();

            if (exceptions == null) {
                System.out.println("WSDL Specification Concept saved");

                Collection keys = response.getCollection();

                for (Object k : keys) {
                    Key concKey = (Key) k;

                    String id = concKey.getId();
                    System.out.println("Concept key is " + id);
                    System.out.println("Use this key as the argument " + "to JAXRPublishHelloOrg");
                }
            } else {
                for (Object e : exceptions) {
                    Exception exception = (Exception) e;
                    System.err.println("Exception on save: " + exception.toString());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // At end, close connection to registry
            if (connection != null) {
                try {
                    connection.close();
                } catch (JAXRException je) {
                }
            }
        }
    }

From source file:JAXRPublish.java

/**
     * Creates an organization, its classification, and its
     * services, and saves it to the registry.
     *//  w  w  w.j a  v  a  2s  .c  o 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 organization name and description
            InternationalString s = blcm.createInternationalString(bundle.getString("org.name"));
            Organization org = blcm.createOrganization(s);
            s = blcm.createInternationalString(bundle.getString("org.description"));
            org.setDescription(s);

            // Create primary contact, set name
            User primaryContact = blcm.createUser();
            PersonName pName = blcm.createPersonName(bundle.getString("person.name"));
            primaryContact.setPersonName(pName);

            // Set primary contact phone number
            TelephoneNumber tNum = blcm.createTelephoneNumber();
            tNum.setNumber(bundle.getString("phone.number"));

            Collection<TelephoneNumber> phoneNums = new ArrayList<TelephoneNumber>();
            phoneNums.add(tNum);
            primaryContact.setTelephoneNumbers(phoneNums);

            // Set primary contact email address
            EmailAddress emailAddress = blcm.createEmailAddress(bundle.getString("email.address"));
            Collection<EmailAddress> emailAddresses = new ArrayList<EmailAddress>();
            emailAddresses.add(emailAddress);
            primaryContact.setEmailAddresses(emailAddresses);

            // Set primary contact for organization
            org.setPrimaryContact(primaryContact);

            // Set classification scheme to NAICS, using
            // well-known UUID of ntis-gov:naics:1997
            String uuid_naics = "uuid:C0B9FE13-179F-413D-8A5B-5004DB8E5BB2";
            ClassificationScheme cScheme = (ClassificationScheme) bqm.getRegistryObject(uuid_naics,
                    LifeCycleManager.CLASSIFICATION_SCHEME);

            if (cScheme != null) {
                // Create and add classification
                InternationalString sn = blcm.createInternationalString(bundle.getString("classification.name"));
                Classification classification = blcm.createClassification(cScheme, sn,
                        bundle.getString("classification.value"));
                Collection<Classification> classifications = new ArrayList<Classification>();
                classifications.add(classification);
                org.addClassifications(classifications);
            } else {
                System.out.println("Classification scheme not found, " + "not classifying organization");
            }

            // Create services and service
            Collection<Service> services = new ArrayList<Service>();
            s = blcm.createInternationalString(bundle.getString("service.name"));

            Service service = blcm.createService(s);
            s = blcm.createInternationalString(bundle.getString("service.description"));
            service.setDescription(s);

            // Create service bindings
            Collection<ServiceBinding> serviceBindings = new ArrayList<ServiceBinding>();
            ServiceBinding binding = blcm.createServiceBinding();
            s = blcm.createInternationalString(bundle.getString("svcbinding.description"));
            binding.setDescription(s);

            // Allow us to publish a fictitious URI without an error
            binding.setValidateURI(false);
            binding.setAccessURI(bundle.getString("svcbinding.accessURI"));
            serviceBindings.add(binding);

            // Add service bindings to service
            service.addServiceBindings(serviceBindings);

            // Add service to services, then add services to organization
            services.add(service);
            org.addServices(services);

            // Add organization and submit to registry
            // Retrieve key if successful
            Collection<Organization> orgs = new ArrayList<Organization>();
            orgs.add(org);

            BulkResponse response = blcm.saveOrganizations(orgs);
            Collection exceptions = response.getExceptions();

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

                Collection keys = response.getCollection();

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

From source file:JAXRPublishPostal.java

/**
     * Creates an organization, its classification, and its
     * services, and saves it to the registry.  The primary
     * contact has a postal address./*from  www .  ja  v a2s .  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 organization name and description
            InternationalString s = blcm.createInternationalString(bundle.getString("postal.org.name"));
            Organization org = blcm.createOrganization(s);
            s = blcm.createInternationalString(bundle.getString("org.description"));
            org.setDescription(s);

            // Create primary contact, set name
            User primaryContact = blcm.createUser();
            PersonName pName = blcm.createPersonName(bundle.getString("postal.person.name"));
            primaryContact.setPersonName(pName);

            // Set primary contact phone number
            TelephoneNumber tNum = blcm.createTelephoneNumber();
            tNum.setNumber(bundle.getString("phone.number"));

            Collection<TelephoneNumber> phoneNums = new ArrayList<TelephoneNumber>();
            phoneNums.add(tNum);
            primaryContact.setTelephoneNumbers(phoneNums);

            // Set primary contact email address
            EmailAddress emailAddress = blcm.createEmailAddress(bundle.getString("postal.email.address"));
            Collection<EmailAddress> emailAddresses = new ArrayList<EmailAddress>();
            emailAddresses.add(emailAddress);
            primaryContact.setEmailAddresses(emailAddresses);

            // create postal address for primary contact
            String streetNumber = bundle.getString("postal.streetNumber");
            String street = bundle.getString("postal.street");
            String city = bundle.getString("postal.city");
            String state = bundle.getString("postal.state");
            String country = bundle.getString("postal.country");
            String postalCode = bundle.getString("postal.postalCode");
            String type = bundle.getString("postal.type");
            PostalAddress postAddr = blcm.createPostalAddress(streetNumber, street, city, state, country,
                    postalCode, type);
            Collection<PostalAddress> postalAddresses = new ArrayList<PostalAddress>();
            postalAddresses.add(postAddr);
            primaryContact.setPostalAddresses(postalAddresses);

            // Set primary contact for organization
            org.setPrimaryContact(primaryContact);

            // Set classification scheme to NAICS, using
            // well-known UUID of ntis-gov:naics:1997
            String uuid_naics = "uuid:C0B9FE13-179F-413D-8A5B-5004DB8E5BB2";
            ClassificationScheme cScheme = (ClassificationScheme) bqm.getRegistryObject(uuid_naics,
                    LifeCycleManager.CLASSIFICATION_SCHEME);

            // Create and add classification
            if (cScheme != null) {
                InternationalString sn = blcm.createInternationalString(bundle.getString("classification.name"));
                Classification classification = blcm.createClassification(cScheme, sn,
                        bundle.getString("classification.value"));
                Collection<Classification> classifications = new ArrayList<Classification>();
                classifications.add(classification);
                org.addClassifications(classifications);
            } else {
                System.out.println("Classification scheme not found, " + "not classifying organization");
            }

            // Create services and service
            Collection<Service> services = new ArrayList<Service>();
            s = blcm.createInternationalString(bundle.getString("service.name"));

            Service service = blcm.createService(s);
            s = blcm.createInternationalString(bundle.getString("service.description"));
            service.setDescription(s);

            // Create service bindings; don't validate this fake URL
            Collection<ServiceBinding> serviceBindings = new ArrayList<ServiceBinding>();
            ServiceBinding binding = blcm.createServiceBinding();
            s = blcm.createInternationalString(bundle.getString("svcbinding.description"));
            binding.setDescription(s);

            // Allow us to publish a fictitious URI without an error
            binding.setValidateURI(false);
            binding.setAccessURI(bundle.getString("svcbinding.accessURI"));
            serviceBindings.add(binding);

            // Add service bindings to service
            service.addServiceBindings(serviceBindings);

            // Add service to services, then add services to organization
            services.add(service);
            org.addServices(services);

            // Add organization and submit to registry
            // Retrieve key if successful
            Collection<Organization> orgs = new ArrayList<Organization>();
            orgs.add(org);

            BulkResponse response = blcm.saveOrganizations(orgs);
            Collection exceptions = response.getExceptions();

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

                Collection keys = response.getCollection();

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