Beispiel #1
0
        /// <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);
            }
        }