public object ResolveDictionaryKey(Type propertyType, IXmlValue xmlValueKey) { if (xmlValueKey.ValueType == XmlValueType.String) { if (propertyType.FullName == "System.Type") { var resolvedType = Type.GetType(((XmlString)xmlValueKey).Value); if (resolvedType == null) { throw new JsonLibException("cannot resolve Type with the qualified name " + ((XmlString)xmlValueKey).Value); } return(resolvedType); } else { return(this.ResolveValue(propertyType, (XmlString)xmlValueKey)); } } else if (xmlValueKey.ValueType == XmlValueType.Number) { if (propertyType == typeof(string)) { return(Convert.ToString(((XmlNumber)xmlValueKey).Value, CultureInfo.InvariantCulture)); } else { return(((XmlNumber)xmlValueKey).Value); } } throw new JsonLibException("Unsupported type in xml for dictionary key"); }
public string ToValue(IXmlValue xmlValue) { if (xmlValue.ValueType == XmlValueType.String) { return(this.ToString((XmlString)xmlValue)); } else if (xmlValue.ValueType == XmlValueType.Number) { return(this.ToNumber((XmlNumber)xmlValue)); } else if (xmlValue.ValueType == XmlValueType.Bool) { return(this.ToBool((XmlBool)xmlValue)); } else if (xmlValue.ValueType == XmlValueType.Nullable) { return(this.ToNullable((XmlNullable)xmlValue)); } else if (xmlValue.ValueType == XmlValueType.Array) { return(this.ToArray((XmlArray)xmlValue)); } else if (xmlValue.ValueType == XmlValueType.Object) { return(this.ToObject((XmlObject)xmlValue)); } throw new JsonLibException("Cannot resolve Xml Value"); }
public string CreateDocument(IXmlValue xmlValue) { var declaration = this.xmlService.GetDeclaration(); var content = this.GetRoot(xmlValue); return(declaration + content); }
protected void CheckValue(IXmlValue xmlValue) { if (this.HasValues) { if (xmlValue.ValueType != this.Values[0].ValueType) { throw new JsonLibException("Array require items with same type"); } else if (xmlValue.NodeName != this.Values[0].NodeName) { throw new JsonLibException("Array require items with same node name"); } } }
public object Resolve(Type type, IXmlValue xmlValue, XmlMappingContainer mappings = null) { var xmlNillable = xmlValue as IXmlNillable; if (xmlNillable != null && xmlNillable.IsNil) { return(null); } else if (xmlValue.ValueType == XmlValueType.String) { return(this.ToValue(type, (XmlString)xmlValue)); } else if (xmlValue.ValueType == XmlValueType.Number) { return(this.ToValue(type, (XmlNumber)xmlValue)); } else if (xmlValue.ValueType == XmlValueType.Bool) { return(this.ToValue(type, (XmlBool)xmlValue)); } else if (xmlValue.ValueType == XmlValueType.Nullable) { return(this.ToValue(type, (XmlNullable)xmlValue)); } else if (xmlValue.ValueType == XmlValueType.Array) { return(this.ToEnumerable(type, (XmlArray)xmlValue, mappings)); } else if (xmlValue.ValueType == XmlValueType.Object) { // guess is object with only one node value if (typeof(IEnumerable).IsAssignableFrom(type)) { var xmlArray = this.ConvertToArray((XmlObject)xmlValue); return(this.ToEnumerable(type, xmlArray, mappings)); } else { return(this.ToObject(type, (XmlObject)xmlValue, mappings)); } } throw new JsonLibException("Cannot resolve value"); }
public XmlObject Add(string nodeName, IXmlValue xmlValue) { if (this.HasValue(nodeName)) { throw new JsonLibException("A value with the name " + nodeName + " is already registered"); } this.Values[nodeName] = xmlValue; if (!this.HasNils) { if (xmlValue.ValueType == XmlValueType.String) { if (((XmlString)xmlValue).IsNil) { this.HasNils = true; } } else if (xmlValue.ValueType == XmlValueType.Nullable) { if (((XmlNullable)xmlValue).IsNil) { this.HasNils = true; } } if (xmlValue.ValueType == XmlValueType.Object) { if (((XmlObject)xmlValue).IsNil || ((XmlObject)xmlValue).HasNils) { this.HasNils = true; } } else if (xmlValue.ValueType == XmlValueType.Array) { if (((XmlArray)xmlValue).IsNil || ((XmlArray)xmlValue).HasNils) { this.HasNils = true; } } } return(this); }
public bool HasNils(IXmlValue xmlValue) { if (xmlValue.ValueType == XmlValueType.String) { return(((XmlString)xmlValue).IsNil); } else if (xmlValue.ValueType == XmlValueType.Nullable) { return(((XmlNullable)xmlValue).IsNil); } else if (xmlValue.ValueType == XmlValueType.Object) { return(((XmlObject)xmlValue).HasNils); } else if (xmlValue.ValueType == XmlValueType.Array) { return(((XmlArray)xmlValue).HasNils); } return(false); }
public XmlArray Add(IXmlValue xmlValue) { this.CheckValue(xmlValue); this.Values.Add(xmlValue); if (!this.HasNils) { if (xmlValue.ValueType == XmlValueType.String) { if (((XmlString)xmlValue).IsNil) { this.HasNils = true; } } else if (xmlValue.ValueType == XmlValueType.Nullable) { if (((XmlNullable)xmlValue).IsNil) { this.HasNils = true; } } if (xmlValue.ValueType == XmlValueType.Object) { if (((XmlObject)xmlValue).IsNil || ((XmlObject)xmlValue).HasNils) { this.HasNils = true; } } else if (xmlValue.ValueType == XmlValueType.Array) { if (((XmlArray)xmlValue).IsNil || ((XmlArray)xmlValue).HasNils) { this.HasNils = true; } } } return(this); }
public void TestAttributeMethods() { SimpleElement se = new SimpleElement(); Assert.AreEqual(se.Attributes.Count, 0); IXmlValue attr1 = se.AddAttribute("attr1"); attr1.SetString("value1"); Assert.AreEqual(se.Attributes.Count, 1); Assert.IsNull(se.GetAttribute("attr2")); Assert.AreEqual(attr1, se.GetAttribute("attr1")); Exception e = null; try { se.GetAttribute(null); } catch (Exception ex) { e = ex; } Assert.IsNotNull(e); Assert.IsInstanceOf(typeof(ArgumentException), e); se.AddAttribute("attr2"); Assert.AreEqual(se.Attributes.Count, 2); se.SetAttribute("attr2", null); Assert.AreEqual(se.Attributes.Count, 1); se.SetAttribute("attr2", new SimpleValue("value2")); Assert.AreEqual(se.Attributes.Count, 2); Assert.IsNull(se.GetAttribute("attr3")); IXmlValue attr3 = se.GetSafeAttribute("attr3"); Assert.IsNotNull(attr3); Assert.IsFalse(attr3.IsMutable); }
public void TestAttributes() { SimpleElement se = new SimpleElement(); IDictionary attrs = se.Attributes; Assert.IsNotNull(attrs); Assert.AreEqual(attrs.Count, 0); Assert.IsFalse(attrs.IsReadOnly); Assert.IsFalse(attrs.IsFixedSize); Assert.IsNotNull(attrs.SyncRoot); Assert.IsFalse(attrs.IsSynchronized); SimpleValue sv = new SimpleValue("value"); Exception e = null; try { attrs.Add(3, sv); } catch (Exception ex) { e = ex; } Assert.IsNotNull(e); Assert.IsInstanceOf(typeof(ArgumentException), e); Assert.AreEqual(attrs.Count, 0); e = null; try { attrs.Add("?key1", sv); } catch (Exception ex) { e = ex; } Assert.IsNotNull(e); Assert.IsInstanceOf(typeof(ArgumentException), e); Assert.AreEqual(attrs.Count, 0); e = null; try { attrs.Add("key1", 3); } catch (Exception ex) { e = ex; } Assert.IsNotNull(e); Assert.IsInstanceOf(typeof(ArgumentException), e); Assert.AreEqual(attrs.Count, 0); Assert.IsNull(sv.Parent); Assert.IsFalse(sv.IsAttribute); attrs.Add("key1", sv); Assert.AreEqual(attrs.Count, 1); Assert.IsTrue(attrs.Contains("key1")); Assert.AreEqual(attrs.Keys.Count, 1); Assert.AreEqual(attrs.Values.Count, 1); IXmlValue v = (IXmlValue)attrs["key1"]; Assert.AreEqual(se, v.Parent); Assert.IsTrue(v.IsAttribute); SimpleElement se2 = (SimpleElement)se.Clone(); Assert.IsTrue(se.Attributes.Equals(se2.Attributes)); se.Attributes.Add("key2", v.Clone()); se2.Attributes.Add("key2", new SimpleValue(1000, true)); Assert.IsFalse(se.Attributes.Equals(se2.Attributes)); se.Attributes.Add("key3", v.Clone()); Assert.IsFalse(se.Attributes.Equals(se2.Attributes)); Assert.IsFalse(se.Attributes.Equals(se2)); Assert.AreEqual(attrs.Count, 3); Assert.IsInstanceOf(typeof(ICloneable), attrs); ICloneable cloneableAttrs = attrs as ICloneable; Assert.IsNotNull(cloneableAttrs); IDictionary clones = (IDictionary)cloneableAttrs.Clone(); Assert.AreEqual(clones.Count, 3); Assert.AreEqual(clones, attrs); attrs.Clear(); Assert.AreEqual(attrs.Count, 0); }
public string GetRoot(IXmlValue xmlValue) { var hasNils = this.HasNils(xmlValue); if (xmlValue.ValueType == XmlValueType.String) { var xmlString = xmlValue as XmlString; return(this.xmlService.GetRoot(xmlValue.NodeName, xmlString.Value, xmlString.IsNil)); } else if (xmlValue.ValueType == XmlValueType.Number) { var valueString = this.xmlService.GetNumber(((XmlNumber)xmlValue).Value); return(this.xmlService.GetRoot(xmlValue.NodeName, valueString)); } else if (xmlValue.ValueType == XmlValueType.Bool) { var valueString = ((XmlBool)xmlValue).Value == true ? "true" : "false"; return(this.xmlService.GetRoot(xmlValue.NodeName, valueString)); } else if (xmlValue.ValueType == XmlValueType.Nullable) { var xmlNullable = xmlValue as XmlNullable; var valueString = xmlNullable.IsNil ? null : this.GetNullableString(xmlNullable.Value); return(this.xmlService.GetRoot(xmlValue.NodeName, valueString, xmlNullable.IsNil)); } else if (xmlValue.ValueType == XmlValueType.Array) { var xmlArray = xmlValue as XmlArray; if (xmlArray.IsNil) { return(this.xmlService.GetRoot(xmlArray.NodeName, null, true)); } else { var result = new List <string>(); foreach (var xmlInnerValue in xmlArray.Values) { var valueResult = this.ToValue(xmlInnerValue); result.Add(valueResult); } return(this.xmlService.GetRoot(xmlArray.NodeName, string.Join("", result), xmlArray.HasNils)); } } else if (xmlValue.ValueType == XmlValueType.Object) { var xmlObject = xmlValue as XmlObject; if (xmlObject.IsNil) { return(this.xmlService.GetRoot(xmlObject.NodeName, null, true)); } else { var result = new List <string>(); foreach (var keyValue in xmlObject.Values) { var xmlInnerValue = keyValue.Value; var valueResult = this.ToValue(xmlInnerValue); result.Add(valueResult); } return(this.xmlService.GetRoot(xmlObject.NodeName, string.Join("", result), xmlObject.HasNils)); } } throw new JsonLibException("Cannot resolve Root"); }
/// <summary> /// Preprocess the Coherence properties specified either in the /// application configuration or environment variables. /// When both are specified, environment varialbe takes the precedence. /// </summary> /// <param name="xmlElement">The XML element to process.</param> /// <since>coherence 12.2.1.0.1</since> public static void PreprocessProp(IXmlElement xmlElement) { IXmlValue attr = xmlElement.GetAttribute("system-property"); if (attr != null) { string property = attr.GetString(); string val = ConfigurationUtils.GetProperty(property, null); if (val != null) { if (xmlElement.Value is Int32) { xmlElement.SetInt(Int32.Parse(val)); } else { xmlElement.SetString(val); } } xmlElement.Attributes.Remove("system-property"); } string value = xmlElement.Value.ToString(); string newValue = null; int next = value.IndexOf("${"); int i = next + 2; bool processedParam = false; while (next >= 0) { processedParam = true; string curParam = value.Substring(i, value.IndexOf('}', i) - i); string[] entry = curParam.Split(' '); string property = entry[0]; string val = ConfigurationUtils.GetProperty(property, null); if (val == null) { newValue += entry[1]; } else { newValue += val; } next = value.IndexOf("${", i); int start = value.IndexOf('}', i) + 1; if (next > 0) { newValue += value.Substring(start, next - start); i = next + 2; } else { i = start; } } if (processedParam) { if (i < value.Length) { newValue += value.Substring(i); } xmlElement.SetString(newValue); } }
public T Resolve <T>(IXmlValue xmlValue, XmlMappingContainer mappings = null) { return((T)this.Resolve(typeof(T), xmlValue, mappings)); }
public void TestProperties() { SimpleValue sv = new SimpleValue("value", false, false); Assert.IsFalse(sv.IsAttribute); Assert.IsTrue(sv.IsContent); Assert.IsFalse(sv.IsEmpty); Assert.IsNull(sv.Parent); sv.SetString(null); Assert.IsTrue(sv.IsEmpty); sv.SetString(""); Assert.IsTrue(sv.IsEmpty); sv.SetBinary(Binary.NO_BINARY); Assert.IsTrue(sv.IsEmpty); SimpleElement element = new SimpleElement(); sv.Parent = element; Assert.IsNotNull(sv.Parent); Exception e = null; try { sv.Parent = new SimpleElement(); //already set } catch (Exception ex) { e = ex; } Assert.IsNotNull(e); Assert.IsInstanceOf(typeof(InvalidOperationException), e); e = null; try { sv.Parent = null; //cannot be null } catch (Exception ex) { e = ex; } Assert.IsNotNull(e); Assert.IsInstanceOf(typeof(ArgumentException), e); e = null; IXmlValue immutable = element.GetSafeAttribute("attr"); Assert.IsNotNull(immutable); Assert.IsFalse(immutable.IsMutable); try { immutable.Parent = element; } catch (Exception ex) { e = ex; } Assert.IsNotNull(e); Assert.IsInstanceOf(typeof(InvalidOperationException), e); sv = new SimpleValue("value", false, false); Assert.IsTrue(sv.IsMutable); sv.Parent = element.GetSafeElement("test"); Assert.IsFalse(sv.IsMutable); }
public void Add(IXmlValue value) { m_Nodes.Add(value); }
public CXmlRpcParams(IXmlValue value) { m_Nodes.Add(value); }
public void Add(String name, IXmlValue v) { m_Nodes.Add(new CXmlRpcValueStructMember(name, v)); }
public CXmlRpcValueStructMember(String str, IXmlValue value) { this.m_Name = str; this.m_Value = value; }
public void Add(IXmlValue v) { m_Nodes.Add(v); }
public CXmlRpcValueArray(IXmlValue v) { m_Nodes.Add(v); }