Example #1
0
        /// <summary>  Creates a copy of this Mappings object and adds the copy as a child of
        /// the specified parent. Note the root Mappings container cannot be copied. 
        /// If this method is called on the root an exception is raised.
        /// 
        /// This method performs a "deep copy", such that a copy is made of each 
        /// child Mappings, ObjectMapping, FieldMapping, ValueSet, and Property 
        /// instance.
        /// 
        /// </summary>
        /// <param name="newParent">The parent Mappings instance
        /// </param>
        /// <returns> A "deep copy" of this root Mappings object
        /// 
        /// </returns>
        /// <exception cref="OpenADK.Library.Tools.Mapping.AdkMappingException"> AdkMappingException thrown if this method is not called on the
        /// root Mappings container
        /// </exception>
        public Mappings Copy(Mappings newParent)
        {
            if (IsRoot())
            {
                throw new AdkMappingException
                    ("Mappings.copy cannot be called on the root Mappings container", null);
            }

            //	Create a new Mappings instance
            Mappings m = new Mappings(newParent, fId);

            //	Copy the DOM XmlElement if there is one
            if (fNode != null && newParent.fNode != null)
            {
                m.fNode = (XmlElement) newParent.fNode.OwnerDocument.ImportNode( fNode, false );
            }
             newParent.AddChild( m );

            //	Copy the filters
            m.SetSourceIdFilter(SourceIdFilterString);
            m.SetZoneIdFilter(ZoneIdFilterString);
            m.SetSIFVersionFilter(SIFVersionFilterString);

            //  Copy all Mappings children
            if (fChildren != null)
            {
                foreach (string key in fChildren.Keys)
                {
                    Mappings ch = fChildren[key];
                    m.AddChild(ch.Copy(m));
                }
            }

            //  Copy all ObjectMapping children
            if (fObjRules != null)
            {
                foreach (string key in fObjRules.Keys)
                {
                    ObjectMapping ch = fObjRules[key];
                    ObjectMapping copy = ch.Copy(m);
                    m.AddRules(copy, false);
                    //				if( m.fNode != null )
                    //					m.fNode.AppendChild( copy.fNode );
                }
            }

            //  Copy fValueSets
            if (fValueSets != null)
            {
                foreach (string key in fValueSets.Keys)
                {
                    ValueSet vs = fValueSets[key];
                    m.AddValueSet(vs.Copy(m));
                }
            }

            //	Copy properties
            if (fProps != null)
            {
                foreach (string key in fProps.Keys)
                {
                    string val = fProps[key];
                    m.SetProperty(key, val);
                }
            }

            return m;
        }
Example #2
0
        protected internal void Populate(XmlElement node,
                                         Mappings parent)
        {
            // TODO: We should probably be using a GetElementsby name query here
            // I think the java implementation might have been doing a recursive search here
            foreach (XmlElement n in new XmlUtils.XmlElementEnumerator(node))
            {
                if (n.Name.ToUpper() == XML_MAPPINGS.ToUpper())
                {
                    //  Get the ID
                    string id = n.GetAttribute("id");

                    //  Create a new child Mappings object
                    Mappings mappings = new Mappings(parent, id);
                    mappings.XmlElement = n;
                    if (parent.fChildren == null)
                    {
                        parent.fChildren = new Dictionary<String, Mappings>();
                    }
                    parent.fChildren[mappings.Id] = mappings;

                    //  Set a SifVersion filter if present
                    string ver = n.GetAttribute("sifVersion");
                    if (ver.Trim().Length > 0)
                    {
                        mappings.SetSIFVersionFilter(ver);
                    }

                    //  Set a ZoneId filter if present
                    string zoneIds = n.GetAttribute("zoneId");
                    if (zoneIds.Trim().Length > 0)
                    {
                        mappings.SetZoneIdFilter(zoneIds);
                    }

                    //  Set a SourceId filter if present
                    string sourceIds = n.GetAttribute("sourceId");
                    if (sourceIds.Trim().Length > 0)
                    {
                        mappings.SetSourceIdFilter(sourceIds);
                    }

                    //  Populate the Mappings object with rules
                    Populate(n, mappings);
                }
                else
                {
                    if (n.Name.ToUpper() == XML_OBJECT.ToUpper())
                    {
                        if (n.ParentNode.Name == XML_MAPPINGS)
                        {
                            string obj = n.GetAttribute(XML_OBJECT);
                            if (obj == null)
                            {
                                throw new AdkConfigException
                                    ("<object> element must have an object attribute");
                            }

                            ObjectMapping om = new ObjectMapping(obj);
                            om.XmlElement = n;
                            parent.AddRules(om, false);
                            PopulateObject(n, om);
                        }
                    }
                    else
                    {
                        if (n.Name.ToUpper() == "PROPERTY")
                        {
                            if (n.ParentNode.Name == XML_MAPPINGS)
                            {
                                parent.SetProperty
                                    (n.GetAttribute(AdkXmlConstants.Property.NAME),
                                     n.GetAttribute(AdkXmlConstants.Property.VALUE));
                            }
                        }
                        else
                        {
                            if (n.Name.ToUpper() == "VALUESET")
                            {
                                if (n.ParentNode.Name == XML_MAPPINGS)
                                {
                                    ValueSet set_Renamed =
                                        new ValueSet
                                            (n.GetAttribute("id"), n.GetAttribute("title"), n);
                                    parent.AddValueSet(set_Renamed);
                                    PopulateValueSet(n, set_Renamed);
                                }
                            }
                            else
                            {
                                Populate(n, parent);
                            }
                        }
                    }
                }
            }
        }