Example usage for javax.xml.registry.infomodel User getPostalAddresses

List of usage examples for javax.xml.registry.infomodel User getPostalAddresses

Introduction

In this page you can find the example usage for javax.xml.registry.infomodel User getPostalAddresses.

Prototype

public Collection getPostalAddresses() throws JAXRException;

Source Link

Document

Gets the postal address for this User.

Usage

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

/**
 * DOCUMENT ME!/*w  w  w  .ja  v  a  2  s  . co  m*/
 * 
 * @param user
 *            DOCUMENT ME!
 * 
 * @return DOCUMENT ME!
 * 
 * @throws JAXRException
 *             DOCUMENT ME!
 */
private static String getDNameFromUser(UserRegistrationInfo userRegInfo) throws JAXRException {
    User user = userRegInfo.getUser();
    String dname = "CN=";

    LifeCycleManager lcm = user.getLifeCycleManager();
    Collection<?> addresses = user.getPostalAddresses();
    PostalAddress address;
    PersonName personName = user.getPersonName();

    // CN=Farrukh Najmi, OU=freebxml.org, O=ebxmlrr, L=Islamabad, ST=Punjab,
    // C=PK
    if (personName == null) {
        personName = lcm.createPersonName("firstName", "middleName", "lastName");
    }

    if ((addresses != null) && (addresses.size() > 0)) {
        address = (PostalAddress) (addresses.iterator().next());
    } else {
        address = lcm.createPostalAddress("number", "street", "city", "state", "country", "postalCode",
                "Office");
    }

    String city = address.getCity();

    if ((city == null) || (city.length() == 0)) {
        city = "Unknown";
    }

    String state = address.getStateOrProvince();

    if ((state == null) || (state.length() == 0)) {
        state = "Unknown";
    }

    String country = address.getCountry();

    if ((country == null) || (country.length() == 0)) {
        country = "US";
    }

    if (country.length() > 0) {
        country = country.substring(0, 2);
    }

    String organization = userRegInfo.getOrganization();

    if (organization == null || organization.trim().length() == 0) {
        organization = "Unknown";
    }

    String unit = userRegInfo.getOrganizationUnit();

    if (unit == null || unit.trim().length() == 0) {
        unit = "Unknown";
    }

    // Escape "," in formattedName per section 2.4 of RFC 2253. \u002c is
    // hex code for ","
    String formattedName = ((PersonNameImpl) personName).getFormattedName();
    formattedName = formattedName.replaceAll(",", "\\\\,");

    dname += (formattedName + ", OU=" + unit + ", O=" + organization + ", L=" + city + ", ST=" + state + ", C="
            + country);

    return dname;
}

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.
     *//from  w ww. j  a va 2s  . c om
     * @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:it.cnr.icar.eric.client.ui.thin.RegistrationInfoBean.java

public String doCheckUserDetails() {
    log.trace("doCheckUserDetails started");
    boolean valid = true;
    FacesContext context = FacesContext.getCurrentInstance();
    UserPreferencesBean userPreferenceBean = (UserPreferencesBean) context.getExternalContext().getSessionMap()
            .get("userPreferencesBean");

    User user = (User) RegistryObjectCollectionBean.getInstance().getCurrentRegistryObjectBean()
            .getRegistryObject();// w w w  .j  av  a  2s  .  co m

    try {
        if (user.getPersonName().getFirstName() == null
                || "".equals(user.getPersonName().getFirstName().trim())) {
            String msg = WebUIResourceBundle.getInstance().getString("requiredFieldMissing");
            context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, null));
            valid = false;
        } else if (user.getPersonName().getLastName() == null
                || "".equals(user.getPersonName().getLastName().trim())) {
            String msg = WebUIResourceBundle.getInstance().getString("requiredFieldMissing");
            context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, null));
            valid = false;
        } else if (user.getPostalAddresses() == null || user.getPostalAddresses().size() == 0) {
            String msg = WebUIResourceBundle.getInstance().getString("requiredFieldMissing");
            context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, null));
            valid = false;
        } else {
            PostalAddress address = (PostalAddress) user.getPostalAddresses().iterator().next();
            if (address.getCity() == null || "".equals(address.getCity().trim())
                    || (ProviderProperties.getInstance().getProperty("noStateOrProvince")
                            .indexOf(userPreferenceBean.getContentLocale().getLanguage()) == -1
                            && (address.getStateOrProvince() == null
                                    || "".equals(address.getStateOrProvince().trim())))
                    || address.getCountry() == null || "".equals(address.getCountry().trim())) {
                String msg = WebUIResourceBundle.getInstance().getString("requiredFieldMissing");
                context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, null));
                valid = false;
            } else if (address.getCountry().trim().length() != 2) {
                String msg = WebUIResourceBundle.getInstance().getString("countryDefinedByTwoChars");
                context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, null));
                valid = false;
            }
        }
    } catch (JAXRException e) {
        OutputExceptions.error(log, WebUIResourceBundle.getInstance().getString("message.ExceptionOccured"), e);
        valid = false;
    }

    if (valid) {
        try {
            getX500Bean().setName(user.getPersonName().getFullName());
            if (user.getPostalAddresses() != null && user.getPostalAddresses().size() > 0) {
                PostalAddress address = (PostalAddress) user.getPostalAddresses().iterator().next();
                getX500Bean().setCity(address.getCity());
                getX500Bean().setStateOrProvince(address.getStateOrProvince());
                getX500Bean().setCountry(address.getCountry());
            }
        } catch (JAXRException e) {
            OutputExceptions.error(log, WebUIResourceBundle.getInstance().getString("message.ExceptionOccured"),
                    e);
            valid = false;
        }
    }

    if (valid) {
        doNext();
        return "ok";
    } else {
        return "error";
    }
}

From source file:org.apache.ws.scout.util.ScoutJaxrUddiHelper.java

/**
 *
 * Convert JAXR User Object to UDDI  Contact
 *///from  w w  w  . j  a  v a 2  s.c o  m
public static Contact getContactFromJAXRUser(User user) throws JAXRException {
    Contact ct = objectFactory.createContact();
    if (user == null) {
        return null;
    }

    Address[] addarr = new Address[0];
    Phone[] phonearr = new Phone[0];
    Email[] emailarr = new Email[0];
    try {

        if (user.getPersonName() != null && user.getPersonName().getFullName() != null) {
            ct.setPersonName(user.getPersonName().getFullName());
        }

        if (user.getType() != null) {
            ct.setUseType(user.getType());
        }
        // Postal Address
        Collection<PostalAddress> postc = user.getPostalAddresses();

        addarr = new Address[postc.size()];

        Iterator<PostalAddress> iterator = postc.iterator();
        int addarrPos = 0;
        while (iterator.hasNext()) {
            PostalAddress post = (PostalAddress) iterator.next();
            addarr[addarrPos] = ScoutJaxrUddiHelper.getAddress(post);
            addarrPos++;
        }
        // Phone Numbers
        Collection ph = user.getTelephoneNumbers(null);

        phonearr = new Phone[ph.size()];

        Iterator it = ph.iterator();
        int phonearrPos = 0;
        while (it.hasNext()) {
            TelephoneNumber t = (TelephoneNumber) it.next();
            Phone phone = objectFactory.createPhone();
            String str = t.getNumber();
            log.debug("Telephone=" + str);

            // FIXME: If phone number is null, should the phone 
            // not be set at all, or set to empty string?
            if (str != null) {
                phone.setValue(str);
            } else {
                phone.setValue("");
            }

            phonearr[phonearrPos] = phone;
            phonearrPos++;
        }

        // Email Addresses
        Collection ec = user.getEmailAddresses();

        emailarr = new Email[ec.size()];

        Iterator iter = ec.iterator();
        int emailarrPos = 0;
        while (iter.hasNext()) {
            EmailAddress ea = (EmailAddress) iter.next();
            Email email = objectFactory.createEmail();

            if (ea.getAddress() != null) {
                email.setValue(ea.getAddress());
            }
            // email.setText( ea.getAddress() );

            if (ea.getType() != null) {
                email.setUseType(ea.getType());
            }

            emailarr[emailarrPos] = email;
            emailarrPos++;
        }
        ct.getAddress().addAll(Arrays.asList(addarr));
        ct.getPhone().addAll(Arrays.asList(phonearr));
        ct.getEmail().addAll(Arrays.asList(emailarr));
    } catch (Exception ud) {
        throw new JAXRException("Apache JAXR Impl:", ud);
    }
    return ct;
}

From source file:org.apache.ws.scout.util.ScoutJaxrUddiV3Helper.java

/**
 *
 * Convert JAXR User Object to UDDI  Contact
 */// w w w .  j a  va 2 s. c  o m
public static Contact getContactFromJAXRUser(User user) throws JAXRException {
    Contact ct = objectFactory.createContact();
    if (user == null) {
        return null;
    }

    Address[] addarr = new Address[0];
    Phone[] phonearr = new Phone[0];
    Email[] emailarr = new Email[0];
    try {

        if (user.getPersonName() != null && user.getPersonName().getFullName() != null) {
            org.uddi.api_v3.PersonName pn = new org.uddi.api_v3.PersonName();
            pn.setValue(user.getPersonName().getFullName());
            ct.getPersonName().add(pn);
        }

        if (user.getType() != null) {
            ct.setUseType(user.getType());
        }
        // Postal Address
        Collection<PostalAddress> postc = user.getPostalAddresses();

        addarr = new Address[postc.size()];

        Iterator<PostalAddress> iterator = postc.iterator();
        int addarrPos = 0;
        while (iterator.hasNext()) {
            PostalAddress post = (PostalAddress) iterator.next();
            addarr[addarrPos] = ScoutJaxrUddiV3Helper.getAddress(post);
            addarrPos++;
        }
        // Phone Numbers
        Collection ph = user.getTelephoneNumbers(null);

        phonearr = new Phone[ph.size()];

        Iterator it = ph.iterator();
        int phonearrPos = 0;
        while (it.hasNext()) {
            TelephoneNumber t = (TelephoneNumber) it.next();
            Phone phone = objectFactory.createPhone();
            String str = t.getNumber();
            log.debug("Telephone=" + str);

            // FIXME: If phone number is null, should the phone 
            // not be set at all, or set to empty string?
            if (str != null) {
                phone.setValue(str);
            } else {
                phone.setValue("");
            }

            phonearr[phonearrPos] = phone;
            phonearrPos++;
        }

        // Email Addresses
        Collection ec = user.getEmailAddresses();

        emailarr = new Email[ec.size()];

        Iterator iter = ec.iterator();
        int emailarrPos = 0;
        while (iter.hasNext()) {
            EmailAddress ea = (EmailAddress) iter.next();
            Email email = objectFactory.createEmail();

            if (ea.getAddress() != null) {
                email.setValue(ea.getAddress());
            }
            // email.setText( ea.getAddress() );

            if (ea.getType() != null) {
                email.setUseType(ea.getType());
            }

            emailarr[emailarrPos] = email;
            emailarrPos++;
        }
        ct.getAddress().addAll(Arrays.asList(addarr));
        ct.getPhone().addAll(Arrays.asList(phonearr));
        ct.getEmail().addAll(Arrays.asList(emailarr));
    } catch (Exception ud) {
        throw new JAXRException("Apache JAXR Impl:", ud);
    }
    return ct;
}