private Map<Class<?>, List<PropertyDescriptor>> calcDescriptors( final Set<Class<?>> propertyDescriptorTypes) { final Map<Class<?>, List<PropertyDescriptor>> map = new HashMap<Class<?>, List<PropertyDescriptor>>(); for (final Class<?> type : propertyDescriptorTypes) { final PropertiesContext context = factoryCache.getContext(type); if (context == null) { LOG.debug("Cannot find context for type '" + type.getName() + "'. Skipping."); continue; } final PropertyMetaDataParser propertyDescriptorParser = PropertyMetaDataParser.create(context); final List<PropertyDescriptor> descriptors = propertyDescriptorParser.readDescriptors(type); map.put(type, descriptors); } return map; }
/** * Reads the property key information from the method. * * @param method the method to read the property key. * @return the property key provided by this method. */ public PropertyKey readKey(final Method method) { final String set = readPropertySetName(method); final String name = readPropertyKeyName(method); return PropertyKey.create(set, name); }
/** * Convenience constructor to generate property descriptors without comments. * * @return the created parser instance. */ public static PropertyMetaDataParser createWithoutContextAccess() { return new PropertyMetaDataParser(null); }
/** * Reads the property descriptor information from the method. * * @param method the method to read the property descriptor. * @return the property descriptor provided by this method. * @throws NullPointerException if {@code method} is <code>null</code>. */ public PropertyDescriptor readDescriptor(final Method method) throws NullPointerException { Arg.checkNotNull("method", method); final PropertyMetaData.Builder builder = new PropertyMetaData.Builder(); final Class<?> declaringType = method.getDeclaringClass(); final PropertyKey key = readKey(method); final PropertyType type = readType(method); builder.with(new PropertyContextProxy(context)) .withDeclaringType(declaringType).with(key).with(type); addValueRange(builder, method); addExpression(builder, method); addLifecycle(builder, method); addConstraints(builder, method); addDocumentProxy(builder, method, key); addComments(builder); addSecured(builder, method); addCategories(builder, method); addUseType(builder, method); return builder.build(); }
configurationProperties.getContext(declaringClass); final PropertyMetaDataParser parser = PropertyMetaDataParser.create(context); return parser.readKey(propertyMethod); return parser.readDescriptor(propertyMethod); final PropertyKey key = parser.readKey(method); final Object propertyValue = configurationProperties.getPropertyValue(key);
private void addPropertyDescriptors(final Class<?> propertySetType, final List<DuplicatePropertyDeclarationException> exceptions) { final Method[] methods = propertySetType.getMethods(); final PropertiesContext context = configurationRegistry.get(propertySetType); if (context == null) { LOG.warn("No context found for property set '" + propertySetType.getName() + "'. Skipped."); return; } final PropertyMetaDataParser propertyMetaDataParser = PropertyMetaDataParser.create(context); for (final Method method : methods) { if (PropertyUtils.isPropertyMethod(method)) { final PropertyDescriptor descriptor = propertyMetaDataParser.readDescriptor(method); addDescriptor(propertySetType, descriptor, exceptions); } } }
private PropertyDescriptor readDescriptor(final PropertyReport report, final Class<?> type, final JavaMethod javaMethod, final PropertyMetaDataParser metaDataParser) { final String methodName = javaMethod.getName(); final Method method = getMethod(report, type, methodName); final PropertyDescriptor descriptor = metaDataParser.readDescriptor(method); return descriptor; }
private void addReportSet(final PropertyReport report) { final String type = propertyDescriptorType.getFullyQualifiedName(); final String comment = propertyDescriptorType.getComment(); final PropertyReportSet.Builder builder = new PropertyReportSet.Builder(); builder.withType(type); builder.withComment(comment); final PropertyMetaDataParser metaDataParser = PropertyMetaDataParser.createWithoutContextAccess(); final String name = metaDataParser.readPropertySetName(propertySetJavaClass); builder.withPropertySetName(name); final ProjectdocMetaData metaData = projectdocCollector.getParentMetadata(); builder.with(metaData); final PropertyReportSet reportSet = builder.build(); report.handle(reportSet); }
private static List<Class<?>> readCategories(final Method method) { final List<Class<?>> categories = new ArrayList<Class<?>>(); final de.smartics.properties.api.core.annotations.PropertyCategories methodAnnotation = method .getAnnotation(de.smartics.properties.api.core.annotations.PropertyCategories.class); addCategoriesFromAnnotation(categories, methodAnnotation); final Class<?> type = method.getDeclaringClass(); final de.smartics.properties.api.core.annotations.PropertyCategories typeAnnotation = type.getAnnotation(de.smartics.properties.api.core.annotations.PropertyCategories.class); addCategoriesFromAnnotation(categories, typeAnnotation); return categories; }
/** * Reads the property descriptor information from the type. * * @param propertySetType the type to read the property descriptor. * @return the property descriptor provided by the methods of the type. * @throws NullPointerException if {@code propertySetType} is * <code>null</code>. * @throws IllegalArgumentException if {@code propertySetType} is not * annotated with {@link PropertySet}. */ public List<PropertyDescriptor> readDescriptors(final Class<?> propertySetType) throws NullPointerException, IllegalArgumentException { Arg.checkNotNull("propertySetType", propertySetType); PropertyUtils.checkPropertySetType(propertySetType); final Method[] methods = propertySetType.getMethods(); final List<PropertyDescriptor> descriptors = new ArrayList<PropertyDescriptor>(methods.length); for (final Method method : methods) { if (PropertyUtils.isPropertyMethod(method)) { final PropertyDescriptor descriptor = readDescriptor(method); descriptors.add(descriptor); } } return descriptors; }
private void addProperties(final MultiSourceProperties compositeProperties) { final Properties properties = new Properties(); final Class<?> type = BootProperties.class; final PropertiesContext context = configuration.getContext(type); final PropertyMetaDataParser propertyDescriptorParser = PropertyMetaDataParser.create(context); final List<PropertyDescriptor> descriptors = propertyDescriptorParser.readDescriptors(type); for (final PropertyDescriptor descriptor : descriptors) { final String propertyKey = descriptor.getKey().toString(); final Property property = compositeProperties.getValue(propertyKey); if (property != null && property.getValue() != null) { properties.put(propertyKey, property); } else { properties.remove(propertyKey); } } configuration.addDescriptors(type); final PropertyProvider provider = new PropertiesPropertyProvider(configuration.getKey(), new PropertyLocation("boot-various"), properties); configuration.addDefinitions(provider); }
/** * Convenience constructor to generate property descriptors with access to * property comments. * * @param context the context to access comment information for properties. * @return the created parser instance. * @throws NullPointerException if {@code context} is <code>null</code>. */ public static PropertyMetaDataParser create(final PropertiesContext context) throws NullPointerException { Arg.checkNotNull("context", context); return new PropertyMetaDataParser(context); }