private void ParseQualifierAttribute() { var attr = Attribute.GetCustomAttribute(ObjectType, typeof(QualifierAttribute), true) as QualifierAttribute; if (attr != null) { var qualifier = new AutowireCandidateQualifier(attr.GetType()); if (!string.IsNullOrEmpty(attr.Value)) qualifier.SetAttribute(AutowireCandidateQualifier.VALUE_KEY, attr.Value); ParseQualifierProperties(attr, qualifier); AddQualifier(qualifier); } }
/// <summary> /// Parse a qualifier element. /// </summary> public void ParseQualifierElement(string name, XmlElement element, ParserContext parserContext, AbstractObjectDefinition od) { string typeName = GetAttributeValue(element, ObjectDefinitionConstants.TypeAttribute); string value = GetAttributeValue(element, ObjectDefinitionConstants.ValueAttribute); if (string.IsNullOrEmpty(typeName)) { throw new ObjectDefinitionStoreException( parserContext.ReaderContext.Resource, name, "Tag 'qualifier' must have a 'type' attribute"); } var qualifier = new AutowireCandidateQualifier(typeName); qualifier.Source = element; if (!string.IsNullOrEmpty(value)) qualifier.SetAttribute(AutowireCandidateQualifier.VALUE_KEY, value); foreach (XmlNode node in this.SelectNodes(element, ObjectDefinitionConstants.AttributeElement)) { var attributeEle = node as XmlElement; string attributeKey = GetAttributeValue(attributeEle, ObjectDefinitionConstants.KeyAttribute); string attributeValue = GetAttributeValue(attributeEle, ObjectDefinitionConstants.ValueAttribute); if (!string.IsNullOrEmpty(attributeKey) && !string.IsNullOrEmpty(attributeValue)) { var attribute = new ObjectMetadataAttribute(attributeKey, attributeValue); attribute.Source = attributeEle; qualifier.AddMetadataAttribute(attribute); } else { throw new ObjectDefinitionStoreException( parserContext.ReaderContext.Resource, name, "Qualifier 'attribute' tag must have a 'key' and 'value'"); } } od.AddQualifier(qualifier); }