List of usage examples for java.beans PropertyDescriptor getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.gbif.portal.registration.UDDIUtils.java
/** * Creates a Provider detail from the business defined by the given key * /* ww w . j av a 2s .co m*/ * A username is provided so that the primary user is not added to the * secondary contacts list. * * @param uuid To get the business for * @param primaryContactName To NOT add to the secondary contacts * @return The provider details for the given business or null * @throws TransportException On comms error * @throws UDDIException On corrupt data, or invalid key */ @SuppressWarnings("unchecked") public ProviderDetail createProviderFromUDDI(String uuid, String primaryContactName) throws UDDIException, TransportException { BusinessDetail detail = getUddiProxy().get_businessDetail(uuid); Vector businessEntityVector = detail.getBusinessEntityVector(); BusinessEntity business = (BusinessEntity) businessEntityVector.get(0); ProviderDetail provider = new ProviderDetail(); provider.setBusinessKey(business.getBusinessKey()); provider.setBusinessName(business.getDefaultNameString()); provider.setBusinessDescription(business.getDefaultDescriptionString()); CategoryBag metadata = business.getCategoryBag(); Vector keyedMetadata = metadata.getKeyedReferenceVector(); for (int i = 0; i < keyedMetadata.size(); i++) { KeyedReference kr = (KeyedReference) keyedMetadata.get(i); if (CATEGORY_BAG_KEY_COUNTRY.equals(kr.getKeyName())) { provider.setBusinessCountry(kr.getKeyValue()); } else if (CATEGORY_BAG_KEY_LOGO_URL.equals(kr.getKeyName())) { provider.setBusinessLogoURL(kr.getKeyValue()); } } //initialise the primary contact Contacts contacts = business.getContacts(); if (contacts.size() > 0) { Contact uddiContact = contacts.get(0); ProviderDetail.Contact primaryContact = provider.getBusinessPrimaryContact(); setContactDetailsFromUDDI(uddiContact, primaryContact); } addSecondaryContactsToModel(primaryContactName, business, provider); // add the resource data Vector names = new Vector(); names.add(new Name("%")); ServiceList serviceList = getUddiProxy().find_service(uuid, names, null, null, null, 10000); if (serviceList != null) { ServiceInfos serviceInfos = serviceList.getServiceInfos(); if (serviceInfos.size() > 0) { Vector<ServiceInfo> serviceInfosVector = serviceInfos.getServiceInfoVector(); for (ServiceInfo serviceInfo : serviceInfosVector) { ServiceDetail serviceDetail = getUddiProxy().get_serviceDetail(serviceInfo.getServiceKey()); Vector<BusinessService> businessServiceVector = serviceDetail.getBusinessServiceVector(); // there should only be one but... for (BusinessService bs : businessServiceVector) { logger.info("Adding a resource"); ResourceDetail resource = new ResourceDetail(); resource.setName(bs.getDefaultNameString()); resource.setServiceKey(bs.getServiceKey()); resource.setDescription(bs.getDefaultDescriptionString()); BindingTemplates bindingTemplates = bs.getBindingTemplates(); if (bindingTemplates != null && bindingTemplates.size() > 0) { BindingTemplate bt = bindingTemplates.get(0); AccessPoint ap = bt.getAccessPoint(); if (ap != null) { resource.setAccessPoint(ap.getText()); resource.setResourceType(bt.getDefaultDescriptionString()); } } CategoryBag cb = bs.getCategoryBag(); if (cb != null) { Vector<KeyedReference> keyedReferences = cb.getKeyedReferenceVector(); for (KeyedReference kr : keyedReferences) { try { PropertyDescriptor pd = org.springframework.beans.BeanUtils .getPropertyDescriptor(ResourceDetail.class, kr.getKeyName()); if (pd != null) { Object theProperty = (Object) pd.getReadMethod().invoke(resource, (Object[]) null); logger.debug(pd.getClass()); if (theProperty instanceof List) { List propertyList = (List) theProperty; if (propertyList != null) { propertyList.add(kr.getKeyValue()); } } else if (pd.getPropertyType().equals(Date.class)) { SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy"); try { Date theDate = sdf.parse(kr.getKeyValue()); BeanUtils.setProperty(resource, kr.getKeyName(), theDate); } catch (Exception e) { logger.debug(e.getMessage(), e); } } else { BeanUtils.setProperty(resource, kr.getKeyName(), kr.getKeyValue()); } } } catch (Exception e) { logger.error(e.getMessage(), e); } } } provider.getBusinessResources().add(resource); } } } } if (logger.isDebugEnabled()) { logger.debug("Provider detail retrieved: " + provider); } return provider; }