@Override public void resolve(final AutoConfigContext context, final PropertyDescriptor descriptor, final Class<?> propertyType) { doFilter(context, descriptor, new Filter() { @Override public boolean onCondition(String name, String key, String value) { return key.equals(name); } @Override public boolean call(String name, String key, String value) { Object v = PrimitiveTypeUtils.convert(value, propertyType); writeProperty(context, descriptor, v); return false; } }); }
@SuppressWarnings("unchecked") @Override public void resolve(final AutoConfigContext context, final PropertyDescriptor descriptor, final Class<?> propertyType) { doFilter(context, descriptor, new Filter() { @Override public boolean onCondition(String name, String key, String value) { return key.equals(name); } @Override public boolean call(String name, String key, String value) { Object v = Enum.valueOf((Class<Enum>) propertyType, value); writeProperty(context, descriptor, v); return false; } }); } }
@Override public void resolve(final AutoConfigContext context, final PropertyDescriptor descriptor, Class<?> propertyType) { doFilter(context, descriptor, new Filter() { @Override public boolean onCondition(String name, String key, String value) { return key.equals(name); } @Override public boolean call(String name, String key, String value) { try { Class clazz = Class.forName(value); writeProperty(context, descriptor, clazz); } catch (ClassNotFoundException e) { throw new PropertiesConfigurationResolveException(e); } return false; } }); } }
@Override public void resolve(AutoConfigContext context, PropertyDescriptor descriptor, Class<?> propertyType) { final Collection collection = createCollection(propertyType); final Class<?> itemType = GenericsUtils.getMethodGenericReturnType(descriptor.getReadMethod(), 0); doFilter(context, descriptor, new Filter() { @Override public boolean onCondition(String name, String key, String value) { return key.startsWith(name); } @Override public boolean call(String name, String key, String value) { if (itemType == Class.class) { try { collection.add(Class.forName(value)); } catch (ClassNotFoundException e) { throw new PropertiesConfigurationResolveException(e); } } else if (PrimitiveTypeUtils.isPrimitiveClass(itemType)) { collection.add(PrimitiveTypeUtils.convert(value, itemType)); } else { collection.add(JSON.parse(value, itemType)); } return true; } }); writeProperty(context, descriptor, collection); }
protected void doFilter(AutoConfigContext context, PropertyDescriptor descriptor, Filter filter) { Set<String> names = context.getNamesByDescriptor(descriptor); for (Map.Entry<String, String> entry : context.getPropMap().entrySet()) { String key = entry.getKey(); String value = entry.getValue(); for (String name : names) { if (filter.onCondition(name, key, value)) { filter.call(name, key, value); } } } }
@Override public void resolve(AutoConfigContext context, PropertyDescriptor descriptor, Class<?> propertyType) { final Map<String, String> includeMap = new HashMap<String, String>(); doFilter(context, descriptor, new Filter() { @Override public boolean onCondition(String name, String key, String value) { return key.startsWith(name); } @Override public boolean call(String name, String key, String value) { String subKey = key.substring(name.length() + 1); includeMap.put(subKey, value); return true; } }); Object value = PropertiesConfigurationFactory.createPropertiesConfiguration(propertyType, null, includeMap); if (value != null) { writeProperty(context, descriptor, value); } } }
@Override public boolean call(String name, String key, String value) { Object v = PrimitiveTypeUtils.convert(value, propertyType); writeProperty(context, descriptor, v); return false; } });
@Override public boolean call(String name, String key, String value) { Object v = Enum.valueOf((Class<Enum>) propertyType, value); writeProperty(context, descriptor, v); return false; } });
@Override public boolean call(String name, String key, String value) { try { Class clazz = Class.forName(value); writeProperty(context, descriptor, clazz); } catch (ClassNotFoundException e) { throw new PropertiesConfigurationResolveException(e); } return false; } });
private Class<?> getRawClass(Type type) { if (type instanceof Class<?>) { return (Class<?>) type; } else if (type instanceof ParameterizedType) { return getRawClass(((ParameterizedType) type).getRawType()); } else { throw new PropertiesConfigurationResolveException("can't resolve the rawClass by " + type); } } }
@Override public void resolve(AutoConfigContext context, PropertyDescriptor descriptor, Class<?> propertyType) { final Collection collection = createCollection(propertyType); final Class<?> itemType = GenericsUtils.getMethodGenericReturnType(descriptor.getReadMethod(), 0); doFilter(context, descriptor, new Filter() { @Override public boolean onCondition(String name, String key, String value) { return key.startsWith(name); } @Override public boolean call(String name, String key, String value) { if (itemType == Class.class) { try { collection.add(Class.forName(value)); } catch (ClassNotFoundException e) { throw new PropertiesConfigurationResolveException(e); } } else if (PrimitiveTypeUtils.isPrimitiveClass(itemType)) { collection.add(PrimitiveTypeUtils.convert(value, itemType)); } else { collection.add(JSON.parse(value, itemType)); } return true; } }); writeProperty(context, descriptor, collection); }
protected void doFilter(AutoConfigContext context, PropertyDescriptor descriptor, Filter filter) { Set<String> names = context.getNamesByDescriptor(descriptor); for (Map.Entry<String, String> entry : context.getPropMap().entrySet()) { String key = entry.getKey(); String value = entry.getValue(); for (String name : names) { if (filter.onCondition(name, key, value)) { filter.call(name, key, value); } } } }
@Override public void resolve(AutoConfigContext context, PropertyDescriptor descriptor, Class<?> propertyType) { final Map<String, String> includeMap = new HashMap<String, String>(); doFilter(context, descriptor, new Filter() { @Override public boolean onCondition(String name, String key, String value) { return key.startsWith(name); } @Override public boolean call(String name, String key, String value) { String subKey = key.substring(name.length() + 1); includeMap.put(subKey, value); return true; } }); Object value = PropertiesConfigurationFactory.createPropertiesConfiguration(propertyType, null, includeMap); if (value != null) { writeProperty(context, descriptor, value); } } }
@Override public void resolve(final AutoConfigContext context, final PropertyDescriptor descriptor, final Class<?> propertyType) { doFilter(context, descriptor, new Filter() { @Override public boolean onCondition(String name, String key, String value) { return key.equals(name); } @Override public boolean call(String name, String key, String value) { Object v = PrimitiveTypeUtils.convert(value, propertyType); writeProperty(context, descriptor, v); return false; } }); }
@SuppressWarnings("unchecked") @Override public void resolve(final AutoConfigContext context, final PropertyDescriptor descriptor, final Class<?> propertyType) { doFilter(context, descriptor, new Filter() { @Override public boolean onCondition(String name, String key, String value) { return key.equals(name); } @Override public boolean call(String name, String key, String value) { Object v = Enum.valueOf((Class<Enum>) propertyType, value); writeProperty(context, descriptor, v); return false; } }); } }
@Override public boolean call(String name, String key, String value) { Object v = PrimitiveTypeUtils.convert(value, propertyType); writeProperty(context, descriptor, v); return false; } });
@Override public boolean call(String name, String key, String value) { Object v = Enum.valueOf((Class<Enum>) propertyType, value); writeProperty(context, descriptor, v); return false; } });
@Override public void resolve(final AutoConfigContext context, final PropertyDescriptor descriptor, Class<?> propertyType) { doFilter(context, descriptor, new Filter() { @Override public boolean onCondition(String name, String key, String value) { return key.equals(name); } @Override public boolean call(String name, String key, String value) { try { Class clazz = Class.forName(value); writeProperty(context, descriptor, clazz); } catch (ClassNotFoundException e) { throw new PropertiesConfigurationResolveException(e); } return false; } }); } }
@Override public boolean call(String name, String key, String value) { try { Class clazz = Class.forName(value); writeProperty(context, descriptor, clazz); } catch (ClassNotFoundException e) { throw new PropertiesConfigurationResolveException(e); } return false; } });
private Class<?> getRawClass(Type type) { if (type instanceof Class<?>) { return (Class<?>) type; } else if (type instanceof ParameterizedType) { return getRawClass(((ParameterizedType) type).getRawType()); } else { throw new PropertiesConfigurationResolveException("can't resolve the rawClass by " + type); } } }