/// <summary> /// Returns the property sheet for the given object instance /// </summary> /// <param name="instanceName"></param> /// <returns></returns> public PropertySheet GetPropertySheet(String instanceName) { if (!_symbolTable.ContainsKey(instanceName)) { // if it is not in the symbol table, so construct // it based upon our raw property data RawPropertyData rpd = null; if (_rawPropertyMap.ContainsKey(instanceName)) { rpd = _rawPropertyMap[instanceName]; } if (rpd != null) { var className = rpd.ClassName; try { // now load the property-sheet by using the class annotation var propertySheet = new PropertySheet(Type.GetType(className, true), instanceName, this, rpd); _symbolTable.Put(instanceName, propertySheet); } catch (Exception) { Trace.Fail(string.Format("Class '{0}' not found in Assembly '{1}'", className, Assembly.GetCallingAssembly())); throw; } } } return(_symbolTable.Get(instanceName)); }
/// <summary> /// Receive notification of the end of an element. /// By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of each element (such as finalising a tree node or writing output to a file). /// </summary> /// <param name="uri"></param> /// <param name="localName"></param> /// <param name="qName"></param> public override void EndElement(URL uri, string localName, string qName) { if (qName.Equals("component")) { RPDMap.Put(RPD.Name, RPD); RPD = null; } else if (qName.Equals("property")) { // nothing to do } else if (qName.Equals("propertylist")) { if (RPD.Contains(ItemListName)) { throw new Exception("Duplicate property: " + ItemListName /*, locator*/); } RPD.Add(ItemListName, ItemList); ItemList = null; } else if (qName.Equals("item")) { ItemList.Add(CurItem.ToString().Trim()); CurItem = null; } }
private static PropertySheet GetPropSheetInstanceFromClass(Type targetClass, Dictionary <String, Object> defaultProps, string componentName, ConfigurationManager cm) { var rpd = new RawPropertyData(componentName, targetClass.Name); foreach (var entry in defaultProps) { var property = entry.Value; if (property.GetType().IsInstanceOfType(targetClass))//Todo: check behaviour. Note changing this results in UnitTest fails for Scorer. { property = property.GetType().Name; } rpd.GetProperties().Add(entry.Key, property); } return(new PropertySheet(targetClass, componentName, cm, rpd)); }
public void AddConfigurable(IConfigurable configurable, String name) { if (_symbolTable.ContainsKey(name)) { throw new ArgumentException("tried to override existing component name"); } var dummyRPD = new RawPropertyData(name, configurable.GetType().Name); var ps = new PropertySheet(configurable, name, dummyRPD, this); _symbolTable.Put(name, ps); _rawPropertyMap.Put(name, dummyRPD); foreach (IConfigurationChangeListener changeListener in _changeListeners) { changeListener.ComponentAdded(this, ps); } }
public PropertySheet(Type confClass, string name, ConfigurationManager cm, RawPropertyData rpd) { _ownerClass = confClass; _cm = cm; _instanceName = name; ParseClass(confClass); SetConfigurableClass(confClass); // now apply all xml properties var flatProps = rpd.Flatten(cm).GetProperties(); _rawProps = new HashMap <string, Object>(rpd.GetProperties()); foreach (var propName in _rawProps.Keys) { _propValues.Put(propName, flatProps.Get(propName)); } }
/// <summary> /// Returns a copy of this property data instance with all ${}-fields resolved. /// </summary> /// <param name="cm"></param> /// <returns></returns> public RawPropertyData Flatten(ConfigurationManager cm) { var copyRPD = new RawPropertyData(Name, ClassName); foreach (var entry in _properties) { var value = entry.Value; if (entry.Value is String) { if (((String)entry.Value).StartsWith("${")) { value = cm.GetGloPropReference(ConfigurationManagerUtils.StripGlobalSymbol((String)entry.Value)); } } copyRPD._properties.Add(entry.Key, value); } return(copyRPD); }
public override void StartElement(URL uri, string localName, string qName, Attributes attributes) { if (qName.Equals("config")) { // test if this configuration extends another one var extendedConfigName = attributes.getValue("extends"); if (extendedConfigName != null) { MergeConfigs(extendedConfigName, true); _replaceDuplicates = true; } } else if (qName.Equals("include")) { var includeFileName = attributes.getValue("file"); MergeConfigs(includeFileName, false); } else if (qName.Equals("extendwith")) { var includeFileName = attributes.getValue("file"); MergeConfigs(includeFileName, true); } else if (qName.Equals("component")) { var curComponent = attributes.getValue("name"); var curType = attributes.getValue("type"); if (RPDMap.Get(curComponent) != null && !_replaceDuplicates) { throw new XmlException("duplicate definition for " + curComponent); } RPD = new RawPropertyData(curComponent, curType); } else if (qName.Equals("property")) { var name = attributes.getValue("name"); var value = attributes.getValue("value"); if (attributes.getLength() != 2 || name == null || value == null) { throw new XmlException("property element must only have 'name' and 'value' attributes"); } if (RPD == null) { // we are not in a component so add this to the global // set of symbols // String symbolName = "${" + name + "}"; // why should we warp the global props here GlobalProperties.Put(name, value); } else if (RPD.Contains(name) && !_replaceDuplicates) { throw new XmlException("Duplicate property: " + name); } else { RPD.Add(name, value); } } else if (qName.Equals("propertylist")) { ItemListName = attributes.getValue("name"); if (attributes.getLength() != 1 || ItemListName == null) { throw new XmlException("list element must only have the 'name' attribute"); } ItemList = new List <String>(); } else if (qName.Equals("item")) { if (attributes.getLength() != 0) { throw new XmlException("unknown 'item' attribute"); } CurItem = new StringBuilder(); } else { throw new XmlException("Unknown element '" + qName + '\''); } }
public PropertySheet(IConfigurable configurable, string name, RawPropertyData rpd, ConfigurationManager configurationManager) : this(configurable.GetType(), name, configurationManager, rpd) { _owner = configurable; }