public bool IsReference(RmAttributeName attributeName) { RmAttributeInfo retValue = null; RmAttributeCache.TryGetValue(attributeName, out retValue); if (retValue == null) { return(false); } else { return(retValue.AttributeType == RmAttributeType.Reference); } }
public bool IsMultiValued(RmAttributeName attributeName) { RmAttributeInfo retValue = null; RmAttributeCache.TryGetValue(attributeName, out retValue); if (retValue == null) { return(false); } else { return(retValue.IsMultiValue); } }
/// <summary> /// GetAttributeType /// </summary> /// <param name="attributeName">Name of the attribute.</param> /// <returns>The FIM type of the attribute if found, null otherwise.</returns> /// <remarks>This method is only for testing, and should not be used /// directly by clients.</remarks> internal RmAttributeType?GetAttributeType(RmAttributeName attributeName) { RmAttributeInfo retValue = null; RmAttributeCache.TryGetValue(attributeName, out retValue); if (retValue == null) { return(null); } else { return(retValue.AttributeType); } }
public bool IsRequired(String objectType, RmAttributeName attributeName) { Dictionary <RmAttributeName, RmAttributeInfo> attributeValue = null; RmObjectCache.TryGetValue(objectType, out attributeValue); if (attributeValue == null) { return(false); } else { RmAttributeInfo attributeInfo = null; attributeValue.TryGetValue(attributeName, out attributeInfo); if (attributeInfo == null) { return(false); } else { return(attributeInfo.IsRequired); } } }
protected IComparable ConstructAttributeValue(RmAttributeName attributeName, String innerText) { if (innerText == null) { return(null); } RmAttributeInfo info = null; if (base.RmAttributeCache.TryGetValue(attributeName, out info) == false) { if (attributeName.Name.Equals(ObjectID)) { return(new RmReference(innerText)); } else { return(innerText); } } try { switch (info.AttributeType) { case RmAttributeType.String: return(innerText); case RmAttributeType.DateTime: return(DateTime.Parse(innerText)); case RmAttributeType.Integer: return(Int32.Parse(innerText)); case RmAttributeType.Reference: return(new RmReference(innerText)); case RmAttributeType.Binary: return(new RmBinary(innerText)); case RmAttributeType.Boolean: return(Boolean.Parse(innerText)); default: return(innerText); } } catch (FormatException ex) { throw new ArgumentException( String.Format( "Failed to parse attribute {0} with value {1} into type {2}. Please ensure the resource management schema is up to date.", attributeName, innerText, info.AttributeType.ToString()), ex); } catch (System.Text.EncoderFallbackException ex) { throw new ArgumentException( String.Format( "Failed to convert the string on binary attribute {0} into byte array.", attributeName), ex); } }
public RmFactory(XmlSchemaSet rmSchema) { if (rmSchema == null) { throw new ArgumentNullException("rmSchema"); } lock (rmSchema) { this.RmSchema = rmSchema; if (this.RmSchema.IsCompiled == false) { this.RmSchema.Compile(); } this.RmAttributeCache = new Dictionary <RmAttributeName, RmAttributeInfo>(); this.RmObjectCache = new Dictionary <string, Dictionary <RmAttributeName, RmAttributeInfo> >(); this.RmDoc = new XmlDocument(); this.RmNsManager = new XmlNamespaceManager(this.RmDoc.NameTable); this.RmNsManager.AddNamespace("rm", RmNamespace); foreach (XmlSchemaObject schemaObj in this.RmSchema.GlobalTypes.Values) { XmlSchemaComplexType schemaObjComplexType = schemaObj as XmlSchemaComplexType; if (schemaObjComplexType != null) { if (schemaObjComplexType.Name == null || schemaObjComplexType.Particle == null) { continue; } RmObjectCache[schemaObjComplexType.Name] = new Dictionary <RmAttributeName, RmAttributeInfo>(); XmlSchemaSequence schemaObjSequence = schemaObjComplexType.Particle as XmlSchemaSequence; if (schemaObjSequence != null) { foreach (XmlSchemaObject sequenceObj in schemaObjSequence.Items) { XmlSchemaElement sequenceElement = sequenceObj as XmlSchemaElement; if (sequenceElement != null) { RmAttributeInfo info = new RmAttributeInfo(); if (sequenceElement.MaxOccurs > Decimal.One) { info.IsMultiValue = true; } if (sequenceElement.MinOccurs > Decimal.Zero) { info.IsRequired = true; } String attributeTypeName = sequenceElement.ElementSchemaType.QualifiedName.Name.ToUpperInvariant(); if (attributeTypeName.Contains("COLLECTION")) { info.IsMultiValue = true; } if (attributeTypeName.Contains("REFERENCE")) { info.AttributeType = RmAttributeType.Reference; } else if (attributeTypeName.Contains("BOOLEAN")) { info.AttributeType = RmAttributeType.Boolean; } else if (attributeTypeName.Contains("INTEGER")) { info.AttributeType = RmAttributeType.Integer; } else if (attributeTypeName.Contains("DATETIME")) { info.AttributeType = RmAttributeType.DateTime; } else if (attributeTypeName.Contains("BINARY")) { info.AttributeType = RmAttributeType.Binary; } else { info.AttributeType = RmAttributeType.String; } RmAttributeName attributeName = new RmAttributeName(sequenceElement.Name); RmObjectCache[schemaObjComplexType.Name][attributeName] = info; RmAttributeCache[attributeName] = info; } } } } } } }
/// <summary> /// Creates an indexable cache of Resource Management attributes and objects based on the given schema set. /// </summary> /// <param name="rmSchema"></param> public RmFactory(XmlSchemaSet rmSchema) { if (rmSchema == null) { throw new ArgumentNullException("rmSchema"); } lock (rmSchema) { this.RmSchema = rmSchema; if (this.RmSchema.IsCompiled == false) { this.RmSchema.Compile(); } this.RmAttributeCache = new Dictionary<RmAttributeName, RmAttributeInfo>(); this.RmObjectCache = new Dictionary<string, Dictionary<RmAttributeName, RmAttributeInfo>>(); this.RmDoc = new XmlDocument(); this.RmNsManager = new XmlNamespaceManager(this.RmDoc.NameTable); this.RmNsManager.AddNamespace("rm", RmNamespace); foreach (XmlSchemaObject schemaObj in this.RmSchema.GlobalTypes.Values) { XmlSchemaComplexType schemaObjComplexType = schemaObj as XmlSchemaComplexType; if (schemaObjComplexType != null) { if (schemaObjComplexType.Name == null || schemaObjComplexType.Particle == null) { continue; } RmObjectCache[schemaObjComplexType.Name] = new Dictionary<RmAttributeName, RmAttributeInfo>(); XmlSchemaSequence schemaObjSequence = schemaObjComplexType.Particle as XmlSchemaSequence; if (schemaObjSequence != null) { foreach (XmlSchemaObject sequenceObj in schemaObjSequence.Items) { XmlSchemaElement sequenceElement = sequenceObj as XmlSchemaElement; if (sequenceElement != null) { RmAttributeInfo info = new RmAttributeInfo(); if (sequenceElement.MaxOccurs > Decimal.One) { info.IsMultiValue = true; } if (sequenceElement.MinOccurs > Decimal.Zero) { info.IsRequired = true; } string attributeTypeName = sequenceElement.ElementSchemaType.QualifiedName.Name.ToUpperInvariant(); if (string.IsNullOrEmpty(attributeTypeName)) { attributeTypeName = sequenceElement.SchemaType.TypeCode.ToString().ToUpperInvariant(); //Trace.TraceWarning("No type information for attribute '{0}' [{1}]", // sequenceElement.Name, // sequenceElement.ElementSchemaType.TypeCode); } if (string.IsNullOrEmpty(attributeTypeName)) { throw new ArgumentException(string.Format( "Could not get type for attribute {0}", sequenceElement.Name)); } if (attributeTypeName.Contains("COLLECTION")) { info.IsMultiValue = true; } if (attributeTypeName.Contains("REFERENCE")) { info.AttributeType = RmAttributeType.Reference; } else if (attributeTypeName.Contains("BOOLEAN")) { info.AttributeType = RmAttributeType.Boolean; } else if (attributeTypeName.Contains("INTEGER")) { info.AttributeType = RmAttributeType.Integer; } else if (attributeTypeName.Contains("DATETIME")) { info.AttributeType = RmAttributeType.DateTime; } else if (attributeTypeName.Contains("BINARY")) { info.AttributeType = RmAttributeType.Binary; } else if (attributeTypeName.Contains("STRING")) { info.AttributeType = RmAttributeType.String; } else if (attributeTypeName.Contains("TEXT")) { info.AttributeType = RmAttributeType.String; } else { throw new ArgumentException(string.Format( "Uknown type '{0}' for attribute {1}", attributeTypeName, sequenceElement.Name)); } RmAttributeName attributeName = new RmAttributeName(sequenceElement.Name); RmObjectCache[schemaObjComplexType.Name][attributeName] = info; RmAttributeCache[attributeName] = info; } } } } } } }