/** * Get a property * * @param name the name * @return the property name */ public PropertyMetaData getProperty(String name) { if (name == null) throw new IllegalArgumentException("Null name"); if (properties != null && properties.size() > 0) { for (PropertyMetaData prop : properties) { if (name.equals(prop.getName())) return prop; } } return null; }
protected boolean isMetaDataComplete(PropertyMetaData pmd) { if (pmd == null) return false; ValueMetaData value = pmd.getValue(); Object underlyingValue = value.getUnderlyingValue(); return (underlyingValue instanceof AnnotationsMatcher == false); }
/** * Add property annotation metadata. * * @param name the property name * @param amd the annotation metadata * @return this builder */ protected BeanMetaDataBuilder addPropertyAnnotation(String name, AnnotationMetaData amd) { PropertyMetaData pmd = beanMetaData.getProperty(name); Set<AnnotationMetaData> annotations = pmd.getAnnotations(); if (annotations == null) { if (pmd instanceof AbstractFeatureMetaData == false) throw new IllegalArgumentException("PropertyMetaData is not AbstractFeatureMetaData instance: " + pmd); annotations = new HashSet<AnnotationMetaData>(); AbstractFeatureMetaData afmd = AbstractFeatureMetaData.class.cast(pmd); afmd.setAnnotations(annotations); } annotations.add(amd); return this; }
/** * Configure a bean property * * @param trace whether trace is enabled * @param object the object to configure * @param info the bean info * @param cl the classloader * @param metaData the property metadata * @throws Throwable for any error */ public static void configure(boolean trace, Object object, BeanInfo info, ClassLoader cl, PropertyMetaData metaData) throws Throwable { PropertyInfo ainfo = resolveProperty(trace, info, cl, metaData.getName(), metaData.getType()); configure(trace, object, ainfo, cl, metaData); }
if (pmd.isPreInstantiate()) propertyName = pmd.getName(); Object gp = visitorNodes.peek(); if (gp instanceof BeanMetaData)
/** * Get prototype class. * * @param cc the controller context * @return prototype's class */ protected Class<?> getPrototypeClass(ControllerContext cc) { if (cc instanceof KernelControllerContext == false) { return null; } KernelControllerContext kcc = (KernelControllerContext) cc; BeanMetaData bmd = kcc.getBeanMetaData(); Set<PropertyMetaData> properties = bmd.getProperties(); for (PropertyMetaData pmd : properties) { if ("bean".equals(pmd.getName())) { ValueMetaData value = pmd.getValue(); if (value != null && value.getUnderlyingValue() != null) { String className = value.getUnderlyingValue().toString(); return getBeanClass(className, kcc); } else { return null; } } } return null; }
/** * Update property annotations * * @param repository the repository * @param classloader the classloader * @param mutable the mutable * @param context the context * @param propertyMetaData the property * @param beanInfo the bean info * @param add true for add, false for remove */ private void updatePropertyAnnotations(MutableMetaDataRepository repository, ClassLoader classloader, ComponentMutableMetaData mutable, KernelControllerContext context, PropertyMetaData propertyMetaData, BeanInfo beanInfo, boolean add) { Set<AnnotationMetaData> propertyAnnotations = propertyMetaData.getAnnotations(); if (propertyAnnotations == null || propertyAnnotations.size() == 0) return; PropertyInfo propertyInfo = beanInfo.getProperty(propertyMetaData.getName()); // method annotations MethodInfo methodInfo = propertyInfo.getGetter(); if (methodInfo != null) updateAnnotations(repository, classloader, mutable, context, methodInfo, propertyAnnotations, add); methodInfo = propertyInfo.getSetter(); if (methodInfo != null) updateAnnotations(repository, classloader, mutable, context, methodInfo, propertyAnnotations, add); // field annotations FieldInfo fieldInfo = propertyInfo.getFieldInfo(); if (fieldInfo != null) updateAnnotations(repository, classloader, mutable, context, fieldInfo, propertyAnnotations, add); }
/** * Try to get type info from property's class. * * @return type info * @throws Throwable for any error */ protected TypeInfo getTypeInfo() throws Throwable { String className = property.getType(); if (className == null) return null; Kernel kernel = context.getKernel(); KernelConfigurator configurator = kernel.getConfigurator(); return configurator.getTypeInfo(className, cl); }
/** * Add a bean property * * @param property the property */ public void addBeanProperty(PropertyMetaData property) { PropertyMetaData properties = getProperty("properties"); AbstractMapMetaData map; if (properties == null) { map = new AbstractMapMetaData(); properties = new AbstractPropertyMetaData("properties", map); addProperty(properties); } else { map = (AbstractMapMetaData) properties.getValue(); } ValueMetaData valueMetaData = property.getValue(); valueMetaData = new AbstractValueMetaData(valueMetaData); map.put(new AbstractValueMetaData(property.getName()), valueMetaData); }
/** * Unconfigure a bean property * * @param object the object to unconfigure * @param cl the classloader * @param info the bean info * @param metaData the property metadata * @throws Throwable for any error */ public static void unconfigure(Object object, ClassLoader cl, BeanInfo info, PropertyMetaData metaData) throws Throwable { boolean trace = log.isTraceEnabled(); PropertyInfo ainfo = resolveProperty(trace, info, cl, metaData.getName(), metaData.getType()); unconfigure(trace, object, ainfo, metaData); }
public Object execute() throws Throwable String name = property.getName(); PropertyInfo propertyInfo = BeanInfoUtil.getPropertyInfo(beanInfo, target, name); TypeInfo propertyTypeInfo = propertyInfo.getType(); ValueMetaData valueMetaData = property.getValue(); Object value = valueMetaData.getValue(typeInfo, cl); validatePropertyValue(context, target, propertyInfo, value);
/** * Remove previous matching property. * * @param properties the properties * @param name the name * @return modified set of properties */ private Set<PropertyMetaData> removeProperty(Set<PropertyMetaData> properties, String name) { for (Iterator<PropertyMetaData> it = properties.iterator() ; it.hasNext() ; ) { PropertyMetaData property = it.next(); if (name.equals(property.getName())) { it.remove(); } } return properties; }
protected boolean isMetaDataComplete(PropertyMetaData pmd) { if (pmd == null) return false; ValueMetaData value = pmd.getValue(); Object underlyingValue = value.getUnderlyingValue(); return (underlyingValue instanceof AnnotationsMatcher == false); }
@Override protected boolean isMetaDataAlreadyPresent(ClassInfo info, SpringBean annotation, BeanMetaData beanMetaData) { Set<PropertyMetaData> properties = beanMetaData.getProperties(); if (properties != null && properties.isEmpty() == false) { for (PropertyMetaData property : properties) { if (BNP.equals(property.getName())) { return true; } } } return false; } }
/** * Get a bean property * * @param name the name * @return the value metadata */ public ValueMetaData getBeanProperty(String name) { if (name == null) throw new IllegalArgumentException("Null name"); PropertyMetaData properties = getProperty("properties"); if (properties == null) return null; AbstractMapMetaData map = (AbstractMapMetaData) properties.getValue(); for (Iterator<Map.Entry<MetaDataVisitorNode, MetaDataVisitorNode>> i = map.entrySet().iterator(); i.hasNext();) { Map.Entry<MetaDataVisitorNode, MetaDataVisitorNode> entry = i.next(); ValueMetaData key = (ValueMetaData) entry.getKey(); if (key.getUnderlyingValue().equals(name)) { ValueMetaData vmd = (ValueMetaData) entry.getValue(); return (ValueMetaData) vmd.getUnderlyingValue(); } } return null; }
/** * Get the property meta data. * * @param attachment bean meta data * @param name property name * @return property meta data or null if no match */ protected PropertyMetaData getPropertyMetaData(AbstractBeanMetaData attachment, String name) { PropertyMetaData propertyMetaData = null; Set<PropertyMetaData> properties = attachment.getProperties(); if (properties != null && properties.isEmpty() == false) { for(PropertyMetaData pmd : properties) { if (name.equals(pmd.getName())) { propertyMetaData = pmd; break; } } } return propertyMetaData; }
/** * Configure a bean property * * @param trace whether trace is enabled * @param object the object to configure * @param info the property info * @param cl the classloader * @param metaData the property metadata * @throws Throwable for any error */ public static void configure(boolean trace, Object object, PropertyInfo info, ClassLoader cl, PropertyMetaData metaData) throws Throwable { if (trace) log.trace("Configuring info=" + info + " metaData=" + metaData); if (trace) log.trace("Setting property " + info); info.set(object, metaData.getValue().getValue(info.getType(), cl)); }
/** * Get the property meta data. * * @param attachment bean meta data * @param name property name * @return property meta data or null if no match */ protected PropertyMetaData getPropertyMetaData(AbstractBeanMetaData attachment, String name) { PropertyMetaData propertyMetaData = null; Set<PropertyMetaData> properties = attachment.getProperties(); if (properties != null && properties.isEmpty() == false) { for(PropertyMetaData pmd : properties) { if (name.equals(pmd.getName())) { propertyMetaData = pmd; break; } } } return propertyMetaData; }