private String getLocalizedString(String string, String type, String defaultValue) { if (Property.DEFAULT_LOCAL_STRING.equals(string)) { Method getter = getGetter(); String propertyName = BeanUtils.getPropertyNameFromGetter(getter.getName()); Class<?> propOwner = getter.getDeclaringClass(); Bundle bundle = FrameworkUtil.getBundle(propOwner); ResourceBundle resourceBundle = Platform.getResourceBundle(bundle); String messageID = "meta." + propOwner.getName() + "." + propertyName + "." + type; String result = null; try { result = resourceBundle.getString(messageID); } catch (Exception e) { // Try to find the same property in parent classes for (Class parent = getter.getDeclaringClass().getSuperclass(); parent != null && parent != Object.class; parent = parent.getSuperclass()) { try { Method parentGetter = parent.getMethod(getter.getName(), getter.getParameterTypes()); Class<?> parentOwner = parentGetter.getDeclaringClass(); Bundle parentBundle = FrameworkUtil.getBundle(parentOwner); if (parentBundle == null || parentBundle == bundle) { continue; } ResourceBundle parentResourceBundle = Platform.getResourceBundle(parentBundle); messageID = "meta." + parentOwner.getName() + "." + propertyName + "." + type; try { result = parentResourceBundle.getString(messageID); break; } catch (Exception e1) { // Just skip it } } catch (NoSuchMethodException e1) { // Just skip it } } if (result == null) { if (type.equals(Property.RESOURCE_TYPE_NAME)) { log.debug( "Resource '" + messageID + "' not found in bundle " + bundle.getSymbolicName()); } return defaultValue; } } if (!result.equals(messageID)) { return result; } return defaultValue; } return string; }
public ObjectPropertyDescriptor( DBPPropertySource source, ObjectPropertyGroupDescriptor parent, Property propInfo, Method getter) { super(source, parent, getter, propInfo.id(), propInfo.order()); this.propInfo = propInfo; final String propertyName = BeanUtils.getPropertyNameFromGetter(getter.getName()); declaringClass = getter.getDeclaringClass(); Class<?> c = declaringClass; while (setter == null && c != Object.class && c != null) { this.setter = BeanUtils.getSetMethod(c, propertyName); if (setter == null) { c = c.getSuperclass(); } } // Obtain value transformer Class<? extends IPropertyValueTransformer> valueTransformerClass = propInfo.valueTransformer(); if (valueTransformerClass != null && valueTransformerClass != IPropertyValueTransformer.class) { try { valueTransformer = valueTransformerClass.newInstance(); } catch (Throwable e) { log.warn("Can't create value transformer", e); } } this.propName = propInfo.hidden() ? getId() : getLocalizedString(propInfo.name(), Property.RESOURCE_TYPE_NAME, getId()); this.propDescription = CommonUtils.isEmpty(propInfo.description()) ? propName : getLocalizedString(propInfo.name(), Property.RESOURCE_TYPE_DESCRIPTION, propName); }