private ArtistDto artistToDto(Artist artist) { ArtistDto artistDto = new ArtistDto(); PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); try { propertyUtilsBean.copyProperties(artistDto, artist); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException("Can not create artist Data Transfer Object", e); } String slug = slugService.getSlugForArtist(artist); artistDto.setSlug(slug); if (artist.getBeginDate() != null) { artistDto.setBeginDateDay(artist.getBeginDate().toDate()); } if (artist.getEndDate() != null) { artistDto.setEndDateDay(artist.getEndDate().toDate()); } return artistDto; }
private Artist dtoToArtist(ArtistDto artistDto) { Artist artist = new Artist(); PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); try { propertyUtilsBean.copyProperties(artist, artistDto); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException("Can not create Artist from Data Transfer Object", e); } if (artistDto.getAlbums() != null) { List<Album.ShortInfo> albums = artistDto.getAlbums().stream() .map(this::albumDtoToShortInfo) .collect(Collectors.toList()); artist.setAlbums(albums); } if (artistDto.getBeginDateDay() != null) { artist.setBeginDate(new ODate(artistDto.getBeginDateDay())); } if (artistDto.getEndDateDay() != null) { artist.setEndDate(new ODate(artistDto.getEndDateDay())); } return artist; }
private AlbumDto albumToDto(Album album) { AlbumDto albumDto = new AlbumDto(); PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); try { propertyUtilsBean.copyProperties(albumDto, album); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException("Can not create album Data Transfer Object", e); } String slug = slugService.getSlugForAlbum(album); albumDto.setSlug(slug); if (album.getArtists() != null && !album.getArtists().isEmpty()) { List<ArtistDto> artistDtoList = album.getArtists().stream() .map(this::artistShortInfoToDto) .collect(toList()); albumDto.setArtistList(artistDtoList); } return albumDto; }
@Override public void afterPropertiesSet() throws Exception { beanContext = new BackendBeanContext(beanFactory); BeanContextBean.getInstance().setBeanContext(beanContext); VenusBeanUtilsBean.setInstance(new BackendBeanUtilsBean(new ConvertUtilsBean(), new PropertyUtilsBean(), beanContext)); AthenaExtensionResolver.getInstance().resolver(); CodeMapScanner.getCodeMap(); List<ServiceConfig> serviceConfigList = new ArrayList<ServiceConfig>(); Map<String, InterceptorMapping> interceptors = new HashMap<String, InterceptorMapping>(); Map<String, InterceptorStackConfig> interceptorStacks = new HashMap<String, InterceptorStackConfig>(); loadVenusService(serviceConfigList, interceptors, interceptorStacks); loadMonitorService(interceptors, interceptorStacks); loadRegistryService(interceptors, interceptorStacks); initMonitor(serviceConfigList, interceptors, interceptorStacks); }
/** * JAVADOC Method Level Comments * * @param workflowDefinitionId JAVADOC. * @param placeId JAVADOC. * @param entity JAVADOC. * * @return JAVADOC. */ @Override public Collection<String> listPermittedTransitions(String workflowDefinitionId, String placeId, PersistableEntity entity) { Assert.notNull(entity); Map<String, Object> map; try { map = new PropertyUtilsBean().describe(entity); } catch (Exception e) { throw new RuntimeException("Failure to convert object to map", e); } return listPermittedTransitions(workflowDefinitionId, placeId, entity.getApplicationType(), map); }
protected Type getPropertyType(Object instance, String propertyName) { try { if (instance != null) { Field field = instance.getClass().getField(propertyName); return field.getGenericType(); } else { // instance is null for anonymous class, use default type } } catch (NoSuchFieldException e1) { try { BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance(); PropertyUtilsBean propertyUtils = beanUtilsBean.getPropertyUtils(); PropertyDescriptor propertyDescriptor = propertyUtils.getPropertyDescriptor(instance, propertyName); return propertyDescriptor.getReadMethod().getGenericReturnType(); } catch (Exception e2) { // nothing } } catch (Exception e) { // ignore other exceptions } // return Object class type by default return Object.class; }
@SuppressWarnings("unchecked") @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { long clusterId = 0; try { clusterId = Long.parseLong(request.getParameter("clusterId").trim()); } catch (Exception e) { throw new IllegalArgumentException("parameter 'clusterId' is invalid:" + request.getParameter("clusterId")); } ClusterDO cluster = xmlAccesser.getClusterDAO().getClusterById(clusterId); Map<String, Object> clusterMap = new PropertyUtilsBean().describe(cluster); clusterMap.remove("class"); clusterMap.remove("name"); clusterMap.remove("deployDesc"); clusterMap.put("name", CobarStringUtil.htmlEscapedString(cluster.getName())); clusterMap.put("deployDesc", CobarStringUtil.htmlEscapedString(cluster.getDeployDesc())); return new ModelAndView("m_editCluster", new FluenceHashMap<String, Object>().putKeyValue("cluster", clusterMap)); }
/** * Fills the bean with the default values, by calling all the getters and setting the returned value. * @param bean * @return * @throws IllegalAccessException * @throws NoSuchMethodException * @throws InvocationTargetException */ public static DiffableBean fillBeanDefaults(DiffableBean bean) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { BeanMap map = new BeanMap(bean); PropertyUtilsBean propUtils = new PropertyUtilsBean(); for (Object propNameObject : map.keySet()) { String propertyName = (String) propNameObject; Object property1 = propUtils.getProperty(bean, propertyName); if(property1 == null || !DiffableBean.class.isAssignableFrom(property1.getClass())) { if(property1 != null) { // System.out.println(propertyName + ": " + property1.toString()); org.apache.commons.beanutils.BeanUtils.setProperty(bean, propertyName, property1); } } else { // System.out.println("RECURSIVE: " + propertyName); property1 = fillBeanDefaults((DiffableBean) property1); org.apache.commons.beanutils.BeanUtils.setProperty(bean, propertyName, property1); } } return bean; }
/** * Updates a oldBean with all non-null values in the newBean. * @param cls * @param ignoreProperties * @param oldBean * @param newBean * @param <T> * @return * @throws IllegalAccessException * @throws InvocationTargetException * @throws NoSuchMethodException * @throws FloraOnException * @throws InstantiationException */ public static <T extends DiffableBean> T updateBean(Class<T> cls, Collection<String> ignoreProperties, T oldBean, T newBean) throws IllegalAccessException , InvocationTargetException, NoSuchMethodException, FloraOnException, InstantiationException { BeanMap propertyMap = new BeanMap(oldBean); // we assume beans are the same class! so we take the first as a model PropertyUtilsBean propUtils = new PropertyUtilsBean(); BeanUtilsBean bub = createBeanUtilsNull(); T out = cls.newInstance(); for (Object propNameObject : propertyMap.keySet()) { String propertyName = (String) propNameObject; if(ignoreProperties != null && ignoreProperties.contains(propertyName)) continue; System.out.println("PROP: " + propertyName); Object newProperty; newProperty = propUtils.getProperty(newBean, propertyName); if(newProperty == null) bub.setProperty(out, propertyName, propUtils.getProperty(oldBean, propertyName)); else bub.setProperty(out, propertyName, newProperty); // TODO: nested beans } return out; }
@SuppressWarnings("unchecked") @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { long clusterId = 0; try { clusterId = Long.parseLong(request.getParameter("clusterId").trim()); } catch (Exception e) { throw new IllegalArgumentException("parameter 'clusterId' is invalid:" + request.getParameter("clusterId")); } ClusterDO cluster = xmlAccesser.getClusterDAO().getClusterById(clusterId); Map<String, Object> clusterMap = new PropertyUtilsBean().describe(cluster); clusterMap.remove("class"); clusterMap.remove("name"); clusterMap.remove("deployDesc"); clusterMap.put("name", CobarStringUtil.htmlEscapedString(cluster.getName())); clusterMap.put("deployDesc", CobarStringUtil.htmlEscapedString(cluster.getDeployDesc())); return new ModelAndView( "m_editCluster", new FluenceHashMap<String, Object>().putKeyValue("cluster", clusterMap)); }
public void addNonDefaultAttribute(XmlBuilder senderXml, ISender sender, String attribute) { try { PropertyUtilsBean pub = new PropertyUtilsBean(); if (pub.isReadable(sender,attribute) && pub.isWriteable(sender,attribute)) { String value = BeanUtils.getProperty(sender,attribute); Object defaultSender; Class[] classParm = null; Object[] objectParm = null; Class cl = sender.getClass(); java.lang.reflect.Constructor co = cl.getConstructor(classParm); defaultSender = co.newInstance(objectParm); String defaultValue = BeanUtils.getProperty(defaultSender,attribute); if (value!=null && !value.equals(defaultValue)) { senderXml.addAttribute(attribute,value); } } } catch (Exception e) { log.error("cannot retrieve attribute ["+attribute+"] from sender ["+ClassUtils.nameOf(sender)+"]"); } }
@Override public String lookup(String key) { if (this.map == null) { return null; } else { int dotIndex = key.indexOf("."); Object obj = this.map.get(key.substring(0, dotIndex < 0 ? key.length() : dotIndex)); if (obj instanceof Map) { return new MapOfMapStrLookup(((Map) obj)).lookup(key.substring(key.indexOf(".") + 1)); } else if (obj != null && !(obj instanceof String) && key.contains(".")) { final String subkey = key.substring(key.indexOf(".") + 1); for (PropertyDescriptor descriptor : new PropertyUtilsBean().getPropertyDescriptors(obj)) { if (descriptor.getName().equals(subkey)) { try { return descriptor.getReadMethod().invoke(obj).toString(); } catch (Exception ex) { continue; } } } } return obj == null ? "" : obj.toString(); } }
private AlbumDto albumToDto(Album album) { AlbumDto albumDto = new AlbumDto(); PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); try { propertyUtilsBean.copyProperties(albumDto, album); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException("Can not create album Data Transfer Object", e); } String slug = slugService.getSlugForAlbum(album); albumDto.setSlug(slug); if (album.getTrackList() != null && !album.getTrackList().isEmpty()) { List<TrackDto> trackDtoList = album.getTrackList().stream() .map(this::trackToDto) .collect(toList()); albumDto.setTrackList(trackDtoList); } if (album.getArtists() != null && !album.getArtists().isEmpty()) { List<ArtistDto> artistDtoList = album.getArtists().stream() .map(this::artistShortInfoToDto) .collect(toList()); albumDto.setArtistList(artistDtoList); } if (album.getReleasedDate() != null) { albumDto.setReleasedDateDay(album.getReleasedDate().toDate()); } return albumDto; }
private TrackDto trackToDto(Track track) { TrackDto trackDto = new TrackDto(); PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); try { propertyUtilsBean.copyProperties(trackDto, track); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException("Can not create track Data Transfer Object", e); } return trackDto; }
private Track dtoToTrack(TrackDto trackDto) { Track track = new Track(); PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); try { propertyUtilsBean.copyProperties(track, trackDto); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException("Can not create track from Data Transfer Object", e); } return track; }
private Album dtoToAlbum(AlbumDto albumDto) { Album album = new Album(); PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); try { propertyUtilsBean.copyProperties(album, albumDto); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException("Can not create album Data Transfer Object", e); } if (albumDto.getTrackList() != null && !albumDto.getTrackList().isEmpty()) { List<Track> trackList = albumDto.getTrackList().stream() .map(this::dtoToTrack) .collect(toList()); album.setTrackList(trackList); } if (albumDto.getArtistList() != null && !albumDto.getArtistList().isEmpty()) { List<Artist.ShortInfo> artistShortInfoList = albumDto.getArtistList().stream() .map(this::artistDtoToShortInfo) .collect(toList()); album.setArtists(artistShortInfoList); } if (albumDto.getReleasedDateDay() != null) { album.setReleasedDate(new ODate(albumDto.getReleasedDateDay())); } return album; }
private ArtistDto artistShortInfoToDto(Artist.ShortInfo artistShortInfo) { ArtistDto artistDto = new ArtistDto(); PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); try { propertyUtilsBean.copyProperties(artistDto, artistShortInfo); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException("Can not create artist Data Transfer Object", e); } return artistDto; }
private Artist.ShortInfo artistDtoToShortInfo(ArtistDto artistDto) { Artist.ShortInfo artistShortInfo = new Artist.ShortInfo(); PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); try { propertyUtilsBean.copyProperties(artistShortInfo, artistDto); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException("Can not create album Data Transfer Object", e); } return artistShortInfo; }
private RateDto artistRateToDto(ArtistRate artistRate) { RateDto rateDto = new RateDto(); PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); try { propertyUtilsBean.copyProperties(rateDto, artistRate); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException("Can not create artist rate Data Transfer Object", e); } return rateDto; }
private RateDto albumRateToDto(AlbumRate albumRate) { RateDto rateDto = new RateDto(); PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); try { propertyUtilsBean.copyProperties(rateDto, albumRate); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException("Can not create album rate Data Transfer Object", e); } return rateDto; }
private AlbumDto shortInfoToAlbumDto(Album.ShortInfo albumShortInfo) { AlbumDto albumDto = new AlbumDto(); PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); try { propertyUtilsBean.copyProperties(albumDto, albumShortInfo); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException("Can not create album Data Transfer Object", e); } return albumDto; }
private Album.ShortInfo albumDtoToShortInfo(AlbumDto albumDto) { Album.ShortInfo albumShortInfo = new Album.ShortInfo(); PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); try { propertyUtilsBean.copyProperties(albumShortInfo, albumDto); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException("Can not create album Data Transfer Object", e); } return albumShortInfo; }
private ArtistDto artistToDto(Artist artist) { ArtistDto artistDto = new ArtistDto(); PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); try { propertyUtilsBean.copyProperties(artistDto, artist); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException("Can not create artist Data Transfer Object", e); } String slug = slugService.getSlugForArtist(artist); artistDto.setSlug(slug); return artistDto; }
private UserDto userToDto(User user) { UserDto userDto = new UserDto(); PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); try { propertyUtilsBean.copyProperties(userDto, user); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException("Can not create user Data Transfer Object", e); } userDto.setUsername(user.getId()); return userDto; }
private User dtoToUser(UserDto userDto) { User user = new User(); PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); try { propertyUtilsBean.copyProperties(user, userDto); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException("Can not create user from Data Transfer Object", e); } user.setId(userDto.getUsername()); return user; }
private static Type getType(Object bean, Field field) { //Because of type erasure, we will find the setter method and get the generic types off it's arguments PropertyUtilsBean propertyUtils = BeanUtilsBean.getInstance().getPropertyUtils(); PropertyDescriptor propertyDescriptor = null; try { propertyDescriptor = propertyUtils.getPropertyDescriptor(bean, field.getName()); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { handleReflectionException(e); } if (propertyDescriptor == null) { //Likely no accessors logger.debug("Property descriptor for object {} with field {} is null", bean, field); return null; } Method writeMethod = propertyUtils.getWriteMethod(propertyDescriptor); if (writeMethod == null) { logger.debug("No write method for property {}", propertyDescriptor); return null; } Type[] actualTypeArguments = ((ParameterizedType) writeMethod.getGenericParameterTypes()[0]).getActualTypeArguments(); Type type = (Map.class.isAssignableFrom(field.getType())) ? actualTypeArguments[1] : actualTypeArguments[0]; logger.debug("Got type {} from object {}, field {}", type, bean, field); return type; }
/** * Creates a BeanUtilsBean that is configured to use * type converters that throw a ConversionException * instead of using the default value when something * goes wrong. * * @return a configured BeanUtilsBean */ private static BeanUtilsBean createBeanUtilsBean() { final ConvertUtilsBean cub = new ConvertUtilsBean(); registerIntegralTypes(cub); registerCustomTypes(cub); return new BeanUtilsBean(cub, new PropertyUtilsBean()); }
public Object getValue(Object dataObject) { PropertyUtilsBean utils = BeanUtilsBean.getInstance().getPropertyUtils(); try { return utils.getNestedProperty(dataObject, getName()); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new IllegalStateException("cannot access field " + getName() + " for " + dataObject.getClass().getName(), e); } }
public void setValue(Object dataObject, Object value) { PropertyUtilsBean utils = BeanUtilsBean.getInstance().getPropertyUtils(); try { utils.setNestedProperty(dataObject, getName(), value); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new IllegalStateException("cannot access field " + getName() + " for " + dataObject.getClass().getName(), e); } }
protected void createAttributes(T meta) { Class<?> implClass = meta.getImplementationClass(); PropertyUtilsBean utils = BeanUtilsBean.getInstance().getPropertyUtils(); PropertyDescriptor[] descriptors = utils.getPropertyDescriptors(implClass); for (PropertyDescriptor desc : descriptors) { if (desc.getReadMethod().getDeclaringClass() != implClass) continue; // contained in super type createAttribute(meta, desc); } // }
private static void prepare(){ //使用自定义的替换 BeanUtilsBean beanUtilsBean = new BeanUtilsBean(new CustConvertUtilsBean(),new PropertyUtilsBean()); BeanUtilsBean.setInstance(beanUtilsBean); //注册转换器,处理日期 registDateConvert(); //注册转换器,处理枚举 registEnumConvert(); }
private static void prepare(){ //使用自定义的替换 PropertyUtilsBean propertyUtilsBean = new CustPropertyUtilsBean(); ConvertUtilsBean convertUtilsBean = new CustConvertUtilsBean(); BeanUtilsBean beanUtilsBean = new BeanUtilsBean(convertUtilsBean,propertyUtilsBean); BeanUtilsBean.setInstance(beanUtilsBean); //注册转换器,处理枚举 registEnumConvert(); }
private Color getValueOfProperty() { try { PropertyUtilsBean p = new PropertyUtilsBean(); return (Color) p.getProperty(bean, property); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException(e); } }
/** * JAVADOC Method Level Comments * * @param privilegeName JAVADOC. * @param typeName JAVADOC. * @param entity JAVADOC. * * @return JAVADOC. */ public boolean hasPermission(String privilegeName, Entity entity) { Assert.notNull(entity, "Entity is null"); Map<String, Object> map; try { map = new PropertyUtilsBean().describe(entity); } catch (Exception e) { throw new RuntimeException("Failure to convert object to map", e); } return hasPermission(privilegeName, entity.getClass().getName(), map); }
public static void initBeanUtils() { // begin Kuali Foundation modification ConvertUtilsBean convUtils = new ConvertUtilsBean(); PropertyUtilsBean propUtils = new PojoPropertyUtilsBean(); BeanUtilsBean pojoBeanUtils = new BeanUtilsBean(convUtils, propUtils); BeanUtilsBean.setInstance(pojoBeanUtils); logger.fine("Initialized BeanUtilsBean with " + pojoBeanUtils); // end Kuali Foundation modification }
@SuppressWarnings({ "unchecked" }) private List<Map<String, Object>> listDatanode(AjaxParams params) { CobarAdapterDAO perfAccesser = cobarAccesser.getAccesser(params.getCobarNodeId()); if (!perfAccesser.checkConnection()) { return null; } PropertyUtilsBean util = new PropertyUtilsBean(); List<DataNodesStatus> list = perfAccesser.listDataNodes(); ; if (null != list) { ListSortUtil.sortDataNodesByPoolName(list); } List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>(); for (DataNodesStatus c : list) { Map<String, Object> map = null; try { map = util.describe(c); } catch (Exception e1) { throw new RuntimeException(e1); } map.remove("class"); map.remove("executeCount"); map.put("executeCount", FormatUtil.formatNumber(c.getExecuteCount())); map.remove("recoveryTime"); if (-1 != c.getRecoveryTime()) { map.put("recoveryTime", FormatUtil.formatTime(c.getRecoveryTime() * 1000, 2)); } else { map.put("recoveryTime", c.getRecoveryTime()); } returnList.add(map); } return returnList; }
@SuppressWarnings("unchecked") @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { UserDO user = (UserDO) request.getSession().getAttribute("user"); List<ClusterDO> list = xmlAccesser.getClusterDAO().listAllCluster(); List<Map<String, Object>> clusterList = new ArrayList<Map<String, Object>>(); ListSortUtil.sortClusterBySortId(list); PropertyUtilsBean util = new PropertyUtilsBean(); for (ClusterDO e : list) { int count = xmlAccesser.getCobarDAO().getCobarList(e.getId(), ConstantDefine.ACTIVE).size(); count += xmlAccesser.getCobarDAO().getCobarList(e.getId(), ConstantDefine.IN_ACTIVE).size(); Map<String, Object> map; try { map = util.describe(e); } catch (Exception ex) { throw new RuntimeException(ex); } map.remove("class"); map.remove("name"); map.remove("deployDesc"); map.put("name", CobarStringUtil.htmlEscapedString(e.getName())); map.put("deployContact", CobarStringUtil.htmlEscapedString(e.getDeployContact())); map.put("cobarNum", count); clusterList.add(map); } return new ModelAndView("m_clusterList", new FluenceHashMap<String, Object>().putKeyValue("clusterList", clusterList).putKeyValue("user", user)); }