Example usage for javax.xml.registry LifeCycleManager CLASSIFICATION_SCHEME

List of usage examples for javax.xml.registry LifeCycleManager CLASSIFICATION_SCHEME

Introduction

In this page you can find the example usage for javax.xml.registry LifeCycleManager CLASSIFICATION_SCHEME.

Prototype

String CLASSIFICATION_SCHEME

To view the source code for javax.xml.registry LifeCycleManager CLASSIFICATION_SCHEME.

Click Source Link

Document

Constant representing the javax.xml.registry.infomodel.ClassificationScheme interface.

Usage

From source file:it.cnr.icar.eric.client.ui.thin.SearchPanelBean.java

public Collection<SelectItem> getObjectTypes() {
    ArrayList<SelectItem> types = new ArrayList<SelectItem>();
    try {//from ww  w.j a  v  a  2 s.  com
        String classSchemeId = CanonicalSchemes.CANONICAL_CLASSIFICATION_SCHEME_LID_ObjectType;

        ClassificationScheme scheme = (ClassificationScheme) RegistryBrowser.getBQM()
                .getRegistryObject(classSchemeId, LifeCycleManager.CLASSIFICATION_SCHEME);
        if (scheme == null) {
            log.warn("Could not get ClassificationScheme: " + classSchemeId);
        } else {
            @SuppressWarnings("unchecked")
            Collection<RegistryObject> concepts = scheme.getChildrenConcepts();
            getQueryComponent().loadTypes(concepts, types, "");
            objectTypes = types;
        }
    } catch (Throwable t) {
        log.error("Could not load ObjectType class scheme", t);
    }
    return types;
}

From source file:JAXRQueryByNAICSClassification.java

/**
     * Searches for organizations corresponding to an NAICS
     * classification and displays data about them.
     *//*from   w  ww .j  a v a 2  s .com*/
    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:JAXRQueryByWSDLClassification.java

/**
     * Searches for organizations using a WSDL
     * classification and displays data about them.
     */*from  w w  w.j a  v  a 2 s . com*/
     * @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  w  w  . j a va  2 s . c  om
     * @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:JAXRSaveClassificationScheme.java

/**
     * Creates a classification scheme and saves it to the
     * registry.//from w w  w . ja v  a2  s.  c om
     *
     * @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:JAXRPublish.java

/**
     * Creates an organization, its classification, and its
     * services, and saves it to the registry.
     */*from w ww .j av  a 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;

        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:JAXRPublishHelloOrg.java

/**
     * Creates an organization, its classification, and its
     * services, and saves it to the registry.
     *//from  w  w  w.ja va 2s  . co m
     * @param username  the username for the registry
     * @param password  the password for the registry
     */
    public void executePublish(String uuidString, String username, String password) {
        RegistryService rs = null;
        BusinessLifeCycleManager blcm = null;
        BusinessQueryManager bqm = 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 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("wsdlorg.name"));
            Organization org = blcm.createOrganization(s);
            s = blcm.createInternationalString(bundle.getString("wsdlorg.description"));
            org.setDescription(s);

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

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

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

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

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

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

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

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

            /*
             * 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.
             */
            Classification wsdlSpecClassification = blcm.createClassification(uddiOrgTypes,
                    blcm.createInternationalString("wsdlSpec"), "wsdlSpec");

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

            // Find the concept by its UUID
            Concept specConcept = (Concept) bqm.getRegistryObject(uuidString, LifeCycleManager.CONCEPT);

            // If we found the concept, we can save the organization
            if (specConcept != null) {
                String name = getName(specConcept);

                Collection links = specConcept.getExternalLinks();

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

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

                // Now set the specification link for the service binding
                SpecificationLink specLink = blcm.createSpecificationLink();
                specLink.setSpecificationObject(specConcept);

                binding.addSpecificationLink(specLink);
                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());
                    }
                }
            } else {
                System.out.println("Specified concept not found, " + "organization not saved");
            }
        } 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./*  ww w .  ja  v  a  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;

        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) {
                }
            }
        }
    }

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

public void reloadModel() {
    final SwingWorker worker = new SwingWorker(this) {
        public Object doNonUILogic() {
            ConceptsTreeModel objectTypesTreeModel = null;
            try {
                objectTypesTreeModel = new ConceptsTreeModel(false);
                //...code that might take a while to execute is here...
                ClassificationScheme objectTypeScheme = null;
                JAXRClient client = RegistryBrowser.getInstance().getClient();
                BusinessQueryManager bqm = client.getBusinessQueryManager();
                objectTypeScheme = (ClassificationScheme) bqm.getRegistryObject(
                        BindingUtility.CANONICAL_CLASSIFICATION_SCHEME_LID_ObjectType,
                        LifeCycleManager.CLASSIFICATION_SCHEME);
                objectTypesTreeModel.setRootTaxonomyElem(objectTypeScheme);
                objectTypesTreeModel.update();
            } catch (JAXRException j) {
                //TODO: SwingBoost: give error
                objectTypesTreeModel = null;
            }/*from w  w w .j av a2 s  .  c o  m*/
            return objectTypesTreeModel;
        }

        public void doUIUpdateLogic() {
            ConceptsTreeModel objectTypesTreeModel = (ConceptsTreeModel) get();
            if (objectTypesTreeModel != null) {
                objectTypeCombo.setModel(objectTypesTreeModel);
                String selectedIndexStr = ProviderProperties.getInstance()
                        .getProperty("jaxr-ebxml.registryBrowser.objectTypeCombo.initialSelectionIndex", "1");
                int index = Integer.parseInt(selectedIndexStr);
                if (index < objectTypeCombo.getItemCount()) {
                    objectTypeCombo.setSelectedIndex(index);
                } else {
                    objectTypeCombo.setSelectedIndex(-1);
                }
            }
            setObjectTypesTreeModel(objectTypesTreeModel);
        }
    };
    worker.start();
}

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

private Collection<?> getStatusTypeConcepts() throws JAXRException {
    Collection<?> statusTypeConcepts = new ArrayList<Object>();

    JAXRClient client = RegistryBrowser.getInstance().getClient();
    BusinessQueryManager bqm = client.getBusinessQueryManager();

    ClassificationScheme statusTypeScheme = (ClassificationScheme) bqm.getRegistryObject(
            CanonicalConstants.CANONICAL_CLASSIFICATION_SCHEME_ID_StatusType,
            LifeCycleManager.CLASSIFICATION_SCHEME);

    statusTypeConcepts = statusTypeScheme.getChildrenConcepts();
    return statusTypeConcepts;
}