Example usage for javax.xml.registry JAXRResponse STATUS_SUCCESS

List of usage examples for javax.xml.registry JAXRResponse STATUS_SUCCESS

Introduction

In this page you can find the example usage for javax.xml.registry JAXRResponse STATUS_SUCCESS.

Prototype

int STATUS_SUCCESS

To view the source code for javax.xml.registry JAXRResponse STATUS_SUCCESS.

Click Source Link

Document

Status indicating a successful response.

Usage

From source file:JAXRSaveClassificationScheme.java

/**
     * Creates a classification scheme and saves it to the
     * registry./*w w  w .java 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 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:it.cnr.icar.eric.client.ui.swing.JAXRClient.java

/**
 * DOCUMENT ME!/*from   w w w  .j a v a 2 s .com*/
 *
 * @param resp DOCUMENT ME!
 */
public void checkBulkResponse(BulkResponse resp) {
    try {
        if ((resp != null) && (!(resp.getStatus() == JAXRResponse.STATUS_SUCCESS))) {
            Collection<?> exceptions = resp.getExceptions();

            if (exceptions != null) {
                Iterator<?> iter = exceptions.iterator();

                while (iter.hasNext()) {
                    Exception e = (Exception) iter.next();
                    RegistryBrowser.displayError(e);
                }
            }
        }
    } catch (JAXRException e) {
        RegistryBrowser.displayError(e);
    }
}

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

public String doRegister() {
    log.trace("doRegister started");
    String result = "unknown";
    FacesContext context = FacesContext.getCurrentInstance();

    if (!doCheckAuthDetails()) {
        return result;
    }//from  w  w  w  . j  ava2  s  .com

    try {
        User user = (User) RegistryObjectCollectionBean.getInstance().getCurrentRegistryObjectBean()
                .getRegistryObject();
        Collection<?> emails = user.getEmailAddresses();
        ArrayList<EmailAddress> newList = new ArrayList<EmailAddress>();

        Iterator<?> iters = emails.iterator();
        while (iters.hasNext()) {
            EmailAddress email = (EmailAddress) iters.next();
            if (null != email.getAddress() && email.getAddress().length() > 0) {
                newList.add(email);
            }
        }
        user.setEmailAddresses(newList);

        List<User> users = new ArrayList<User>();
        users.add(user);
        BusinessLifeCycleManagerImpl blcm = RegistryBrowser.getBLCM();
        handleAuth();
        log.trace("calling saveObjects()");
        BulkResponse resp = blcm.saveObjects(users);
        log.trace("saveObjects() returned");
        if ((resp != null) && (resp.getStatus() != JAXRResponse.STATUS_SUCCESS)) {
            Collection<?> exceptions = resp.getExceptions();
            if (exceptions != null && !exceptions.isEmpty()) {
                String msg = WebUIResourceBundle.getInstance().getString("errorRegistrationNeeded");
                context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, null));
                log.error(msg);

                Iterator<?> iter = exceptions.iterator();
                while (iter.hasNext()) {
                    Exception e = (Exception) iter.next();
                    OutputExceptions.error(log, e);
                }
            } else {
                String msg = WebUIResourceBundle.getInstance().getString("registrationFailed");
                context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, null));
                log.error(WebUIResourceBundle.getInstance().getString("message.RegistrationFailed"));
            }
            result = "error";
        } else {
            // ??? Is (null == resp) really success?
            result = "registered";
            doNext();
        }
    } catch (Throwable t) {
        OutputExceptions.error(log, WebUIResourceBundle.getInstance().getString("message.RegistrationFailed"),
                WebUIResourceBundle.getInstance().getString("registrationFailed"), t);
        result = "error";
    } finally {
        try {
            RegistryBrowser.getInstance().clearCredentials();
        } catch (Throwable t) {
            // User doesn't need to hear about a cleanup problem
            OutputExceptions.logWarning(log,
                    WebUIResourceBundle.getInstance().getString("message.couldNotClearCredentials"), t);
        }
    }

    return result;
}

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

/**
 * DOCUMENT ME!/*from   w  ww . ja v  a  2s.co  m*/
 */
@SuppressWarnings("unchecked")
protected void removeAction() {
    RegistryBrowser.setWaitCursor();

    int[] selectedIndices = getSelectedRows();

    if (selectedIndices.length >= 1) {
        try {
            ArrayList<?> selectedObjects = getSelectedRegistryObjects();
            ArrayList<Key> removeKeys = new ArrayList<Key>();

            int size = selectedObjects.size();

            for (int i = size - 1; i >= 0; i--) {
                RegistryObject obj = (RegistryObject) selectedObjects.get(i);
                Key key = obj.getKey();
                removeKeys.add(key);
            }

            // Confirm the remove
            boolean confirmRemoves = true;
            // I18N: Do not localize next statement.
            String confirmRemovesStr = ProviderProperties.getInstance()
                    .getProperty("jaxr-ebxml.registryBrowser.confirmRemoves", "true");

            if (confirmRemovesStr.equalsIgnoreCase("false") || confirmRemovesStr.toLowerCase().equals("off")) {
                confirmRemoves = false;
            }

            if (confirmRemoves) {
                int option = JOptionPane.showConfirmDialog(null,
                        resourceBundle.getString("dialog.confirmRemove.text"),
                        resourceBundle.getString("dialog.confirmRemove.title"), JOptionPane.YES_NO_OPTION);

                if (option == JOptionPane.NO_OPTION) {
                    RegistryBrowser.setDefaultCursor();

                    return;
                }
            }

            // cancels the cell editor, if any
            removeEditor();

            JAXRClient client = RegistryBrowser.getInstance().getClient();
            BusinessLifeCycleManager lcm = client.getBusinessLifeCycleManager();
            BulkResponse resp = lcm.deleteObjects(removeKeys);
            client.checkBulkResponse(resp);

            if (resp.getStatus() == JAXRResponse.STATUS_SUCCESS) {
                //Remove from UI model
                @SuppressWarnings("rawtypes")
                ArrayList objects = (ArrayList) ((tableModel.getRegistryObjects()).clone());
                size = selectedIndices.length;

                for (int i = size - 1; i >= 0; i--) {
                    RegistryObject ro = (RegistryObject) dataModel.getValueAt(selectedIndices[i], -1);
                    objects.remove(ro);
                }

                tableModel.setRegistryObjects(objects);
            }
        } catch (JAXRException e) {
            RegistryBrowser.displayError(e);
        }
    } else {
        RegistryBrowser.displayError(resourceBundle.getString("error.removeAction"));
    }

    RegistryBrowser.setDefaultCursor();
}

From source file:it.cnr.icar.eric.client.xml.registry.LifeCycleManagerImpl.java

private void initializeObjectTypesMap() {
    try {// w w  w  . j  a  va 2s .  c  om
        DeclarativeQueryManager dqm = getRegistryService().getDeclarativeQueryManager();
        //         String queryStr = "SELECT children.* FROM ClassificationNode children, ClassificationNode parent where (parent.path LIKE '/"
        //               + BindingUtility.CANONICAL_CLASSIFICATION_SCHEME_LID_ObjectType
        //               + "/RegistryObject%') AND (parent.path NOT LIKE '/"
        //               + BindingUtility.CANONICAL_CLASSIFICATION_SCHEME_LID_ObjectType
        //               + "/RegistryObject/ExtrinsicObject/%') AND parent.id = children.parent";
        //         Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, queryStr);

        Query query = SQLQueryProvider.initializeObjectTypesMap(dqm);

        BulkResponse resp = dqm.executeQuery(query);

        if ((resp != null) && (!(resp.getStatus() == JAXRResponse.STATUS_SUCCESS))) {
            Collection<?> exceptions = resp.getExceptions();

            if (exceptions != null) {
                Iterator<?> iter = exceptions.iterator();

                while (iter.hasNext()) {
                    Exception e = (Exception) iter.next();
                    e.printStackTrace();
                }
            }

            return;
        }

        objectTypesMap = new HashMap<String, Concept>();

        Collection<?> concepts = resp.getCollection();
        Iterator<?> iter = concepts.iterator();

        while (iter.hasNext()) {
            Concept concept = (Concept) iter.next();
            String value = concept.getValue();

            if (value.equals("ClassificationNode")) {
                value = "Concept";
            }

            objectTypesMap.put(value, concept);
        }
    } catch (JAXRException e) {
        e.printStackTrace();
    }
}

From source file:org.apache.ws.scout.registry.BusinessLifeCycleManagerImpl.java

/**
 * Saves one or more Objects to the registry. An object may be a
 * RegistryObject  subclass instance. If an object is not in the registry,
 * it is created in the registry.  If it already exists in the registry
 * and has been modified, then its  state is updated (replaced) in the
 * registry/*from  ww w .  j av a 2s.  c o  m*/
 * <p/>
 * TODO:Check if juddi can provide a facility to store a collection of heterogenous
 * objects
 * <p/>
 * TODO - does this belong here?  it's really an overload of
 * LifecycleManager.saveObjects, but all the help we need
 * like saveOrganization() is up here...
 *
 * @param col
 * @return a BulkResponse containing the Collection of keys for those objects
 *         that were saved successfully and any SaveException that was encountered
 *         in case of partial commit
 * @throws JAXRException
 */
public BulkResponse saveObjects(Collection col) throws JAXRException {

    Iterator iter = col.iterator();

    LinkedHashSet<Object> suc = new LinkedHashSet<Object>();
    Collection<Exception> exc = new ArrayList<Exception>();

    while (iter.hasNext()) {
        RegistryObject reg = (RegistryObject) iter.next();

        BulkResponse br = null;

        Collection<RegistryObject> c = new ArrayList<RegistryObject>();
        c.add(reg);

        if (reg instanceof javax.xml.registry.infomodel.Association) {
            br = saveAssociations(c, true);
        } else if (reg instanceof javax.xml.registry.infomodel.ClassificationScheme) {
            br = saveClassificationSchemes(c);
        } else if (reg instanceof javax.xml.registry.infomodel.Concept) {
            br = saveConcepts(c);
        } else if (reg instanceof javax.xml.registry.infomodel.Organization) {
            br = saveOrganizations(c);
        } else if (reg instanceof javax.xml.registry.infomodel.Service) {
            br = saveServices(c);
        } else if (reg instanceof javax.xml.registry.infomodel.ServiceBinding) {
            br = saveServiceBindings(c);
        } else {
            throw new JAXRException("Delete Operation for " + reg.getClass() + " not implemented by Scout");
        }

        if (br.getCollection() != null) {
            suc.addAll(br.getCollection());
        }

        if (br.getExceptions() != null) {
            exc.addAll(br.getExceptions());
        }
    }

    BulkResponseImpl bulk = new BulkResponseImpl();

    /*
     *  TODO - what is the right status?
     */
    bulk.setStatus(JAXRResponse.STATUS_SUCCESS);

    bulk.setCollection(suc);
    bulk.setExceptions(exc);

    return bulk;
}