`

反射机制

    博客分类:
  • java
 
阅读更多
protected void setPropertyValue(Object obj, String propertyName,
            Class<?> propertyType, Object propertyValue) throws ISocException
    {
        try
        {
            Class<?> clazz = obj.getClass();
           
            Method method = clazz.getMethod(propertyName, propertyType);
           
            method.invoke(obj, propertyValue);
        }
        catch (Exception e)
        {
            throw ISocExceptionTranslator.convert(e);
        }
    }




protected Object getPropertyValue(Object obj, String propertyName)
            throws ISocException
    {
        try
        {
            Class<?> clazz = obj.getClass();
           
            Method method = clazz.getMethod(propertyName);
           
            Object prov = method.invoke(obj);
           
            return prov;
        }
        catch (Exception e)
        {
            throw ISocExceptionTranslator.convert(e);
        }
    }



private void initAlarmAssetId(List<Asset> assetList, Object obj)
            throws ISocException
    {
        String deviceIp = this.getPropertyValue(obj, "getDeviceIP").toString();
        if (null != assetList && !assetList.isEmpty())
        {
            fillAlarmAssetId(assetList, obj, deviceIp);
        }
        else
        {
            //该IP资产不存在
            logger.error("[############################################][ip:"
                    + deviceIp + "] errors : asset is null");
            throw new ISocException(ErrorCode.ASSET_NOT_EXIST);
        }
    }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics