@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); } } }
protected void writeProperty(AutoConfigContext context, PropertyDescriptor descriptor, Object value) { try { Method writeMethod = descriptor.getWriteMethod(); writeMethod.invoke(context.getTargetObject(), value); } catch (Exception e) { throw new PropertiesConfigurationResolveException("Inject Property " + descriptor.getName() + " Error", e); } }
protected void writeProperty(AutoConfigContext context, PropertyDescriptor descriptor, Object value) { try { Method writeMethod = descriptor.getWriteMethod(); writeMethod.invoke(context.getTargetObject(), value); } catch (Exception e) { throw new PropertiesConfigurationResolveException("Inject Property " + descriptor.getName() + " Error", e); } }
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 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; } });
throw new PropertiesConfigurationResolveException("unsupported type " + type); return (Map<Object, Object>) clazz.newInstance(); } catch (Exception e) { throw new PropertiesConfigurationResolveException("unsupported type " + type, e);
private Collection createCollection(Type type) { Class<?> rawClass = getRawClass(type); Collection list; if (rawClass == AbstractCollection.class) { list = new ArrayList(); } else if (rawClass.isAssignableFrom(HashSet.class)) { list = new HashSet(); } else if (rawClass.isAssignableFrom(LinkedHashSet.class)) { list = new LinkedHashSet(); } else if (rawClass.isAssignableFrom(TreeSet.class)) { list = new TreeSet(); } else if (rawClass.isAssignableFrom(ArrayList.class)) { list = new ArrayList(); } else if (rawClass.isAssignableFrom(EnumSet.class)) { Type itemType; if (type instanceof ParameterizedType) { itemType = ((ParameterizedType) type).getActualTypeArguments()[0]; } else { itemType = Object.class; } list = EnumSet.noneOf((Class<Enum>) itemType); } else { try { list = (Collection) rawClass.newInstance(); } catch (Exception e) { throw new PropertiesConfigurationResolveException("create instance error, class " + rawClass.getName()); } } return list; }
throw new PropertiesConfigurationResolveException("unsupported type " + type); return (Map<Object, Object>) clazz.newInstance(); } catch (Exception e) { throw new PropertiesConfigurationResolveException("unsupported type " + type, e);
private Collection createCollection(Type type) { Class<?> rawClass = getRawClass(type); Collection list; if (rawClass == AbstractCollection.class) { list = new ArrayList(); } else if (rawClass.isAssignableFrom(HashSet.class)) { list = new HashSet(); } else if (rawClass.isAssignableFrom(LinkedHashSet.class)) { list = new LinkedHashSet(); } else if (rawClass.isAssignableFrom(TreeSet.class)) { list = new TreeSet(); } else if (rawClass.isAssignableFrom(ArrayList.class)) { list = new ArrayList(); } else if (rawClass.isAssignableFrom(EnumSet.class)) { Type itemType; if (type instanceof ParameterizedType) { itemType = ((ParameterizedType) type).getActualTypeArguments()[0]; } else { itemType = Object.class; } list = EnumSet.noneOf((Class<Enum>) itemType); } else { try { list = (Collection) rawClass.newInstance(); } catch (Exception e) { throw new PropertiesConfigurationResolveException("create instance error, class " + rawClass.getName()); } } return list; }
@Override public boolean call(String name, String key, String value) { String mapKey = key.substring(name.length() + 1); if (mapKey.startsWith("[") && mapKey.endsWith("]")) { mapKey = mapKey.substring(1, mapKey.length() - 1); } if (vClass == Class.class) { try { Class clazz = Class.forName(value); map.put(mapKey, clazz); } catch (ClassNotFoundException e) { throw new PropertiesConfigurationResolveException(e); } } else if (PrimitiveTypeUtils.isPrimitiveClass(vClass)) { map.put(mapKey, PrimitiveTypeUtils.convert(value, vClass)); } else { map.put(mapKey, JSON.parse(value, vClass)); } return true; } });
@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; } });
@Override public boolean call(String name, String key, String value) { String mapKey = key.substring(name.length() + 1); if (mapKey.startsWith("[") && mapKey.endsWith("]")) { mapKey = mapKey.substring(1, mapKey.length() - 1); } if (vClass == Class.class) { try { Class clazz = Class.forName(value); map.put(mapKey, clazz); } catch (ClassNotFoundException e) { throw new PropertiesConfigurationResolveException(e); } } else if (PrimitiveTypeUtils.isPrimitiveClass(vClass)) { map.put(mapKey, PrimitiveTypeUtils.convert(value, vClass)); } else { map.put(mapKey, JSON.parse(value, vClass)); } return true; } });
@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; } });
private void buildPropertyDescriptors() { propertyDescriptors = new ArrayList<PropertyDescriptor>(); Class<?> clazz = targetObj.getClass(); try { BeanInfo beanInfo = Introspector.getBeanInfo(clazz, Introspector.IGNORE_ALL_BEANINFO); PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor pd : pds) { if (Class.class == clazz && ("classLoader".equals(pd.getName()) || "protectionDomain".equals(pd.getName()))) { // Ignore Class.getClassLoader() and getProtectionDomain() methods - nobody needs to bind to those continue; } if (LOGGER.isTraceEnabled()) { LOGGER.trace("Found bean property '" + pd.getName() + "'" + (pd.getPropertyType() != null ? " of type [" + pd.getPropertyType().getName() + "]" : "") + (pd.getPropertyEditorClass() != null ? "; editor [" + pd.getPropertyEditorClass().getName() + "]" : "")); } propertyDescriptors.add(pd); } } catch (IntrospectionException e) { throw new PropertiesConfigurationResolveException(e); } } }
private void buildPropertyDescriptors() { propertyDescriptors = new ArrayList<PropertyDescriptor>(); Class<?> clazz = targetObj.getClass(); try { BeanInfo beanInfo = Introspector.getBeanInfo(clazz, Introspector.IGNORE_ALL_BEANINFO); PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor pd : pds) { if (Class.class == clazz && ("classLoader".equals(pd.getName()) || "protectionDomain".equals(pd.getName()))) { // Ignore Class.getClassLoader() and getProtectionDomain() methods - nobody needs to bind to those continue; } if (LOGGER.isTraceEnabled()) { LOGGER.trace("Found bean property '" + pd.getName() + "'" + (pd.getPropertyType() != null ? " of type [" + pd.getPropertyType().getName() + "]" : "") + (pd.getPropertyEditorClass() != null ? "; editor [" + pd.getPropertyEditorClass().getName() + "]" : "")); } propertyDescriptors.add(pd); } } catch (IntrospectionException e) { throw new PropertiesConfigurationResolveException(e); } } }
Array.set(array, index++, Class.forName(value)); } catch (ClassNotFoundException e) { throw new PropertiesConfigurationResolveException(e);
Array.set(array, index++, Class.forName(value)); } catch (ClassNotFoundException e) { throw new PropertiesConfigurationResolveException(e);
resolver.resolve(configContext, descriptor, propertyType); } else { throw new PropertiesConfigurationResolveException("Can not find Resolver for type:" + propertyType.getName());
resolver.resolve(configContext, descriptor, propertyType); } else { throw new PropertiesConfigurationResolveException("Can not find Resolver for type:" + propertyType.getName());